Skip to content

Commit

Permalink
feat: argument bounds checking
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdjpj committed Jul 14, 2024
1 parent a78f40b commit cf7116d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
57 changes: 57 additions & 0 deletions src/base/filter_stats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use std::io::{self, Error, ErrorKind};

use crate::base::*;

impl Parse<FilterStats> for FilterStats {
fn lparse(&self) -> io::Result<Box<FilterStats>> {
let remove_ns = self.remove_ns.clone();
let remove_monoallelic = self.remove_monoallelic.clone();
let keep_lowercase_reference = self.keep_lowercase_reference.clone();
let max_base_error_rate = if self.max_base_error_rate <= 1.0 && self.max_base_error_rate >= 0.0 {
self.max_base_error_rate.clone()
} else {
return Err(Error::new(
ErrorKind::Other,
"Invalid range. max_base_error_rate must be between 0.0 and 1.0",
));
};
let min_coverage_depth = self.min_coverage_depth;
let min_coverage_breadth = if self.min_coverage_breadth <= 1.0 && self.max_base_error_rate >= 0.0 {
self.min_coverage_breadth.clone()
} else {
return Err(Error::new(
ErrorKind::Other,
"Invalid range. min_coverage_breadth must be between 0.0 and 1.0",
));
};
let min_allele_frequency = if self.min_allele_frequency <= 1.0 && self.min_allele_frequency >= 0.0 {
self.min_allele_frequency.clone()
} else {
return Err(Error::new(
ErrorKind::Other,
"Invalid range. min_allele_frequency must be between 0.0 and 1.0",
));
};
let max_missingness_rate = if self.max_missingness_rate <= 1.0 && self.max_missingness_rate >= 0.0 {
self.max_missingness_rate.clone()
} else {
return Err(Error::new(
ErrorKind::Other,
"Invalid range. max_missingness_rate must be between 0.0 and 1.0",
));
};
let pool_sizes = self.pool_sizes.clone();
return Ok(Box::new(FilterStats {
remove_ns,
remove_monoallelic,
keep_lowercase_reference,
max_base_error_rate,
min_coverage_depth,
min_coverage_breadth,
min_allele_frequency,
max_missingness_rate,
pool_sizes,
}));
}
}

1 change: 1 addition & 0 deletions src/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ mod pileup;
mod structs_and_traits;
mod sync;
mod vcf;
mod filter_stats;
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn main() {
format: phen_format,
};
let phen = file_phen.lparse().unwrap();
let filter_stats = base::FilterStats {
let file_filter_stats = base::FilterStats {
remove_ns: !args.keep_ns,
remove_monoallelic: args.remove_monoallelic,
keep_lowercase_reference: args.keep_lowercase_reference,
Expand All @@ -204,6 +204,7 @@ fn main() {
max_missingness_rate: args.max_missingness_rate,
pool_sizes: phen.pool_sizes.clone(),
};
let filter_stats = file_filter_stats.lparse().unwrap();
if args.analysis == String::from("pileup2sync") {
// PILEUP INPUT
let file_pileup = base::FilePileup {
Expand Down

0 comments on commit cf7116d

Please sign in to comment.