-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: argument bounds checking and option filtering #25
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
})); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ mod pileup; | |
mod structs_and_traits; | ||
mod sync; | ||
mod vcf; | ||
mod filter_stats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Thanks. Just keep in mind we'll need to redefine these ErrorKind's into some custom Error type which we can chain in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I am going to do this right after. What do you mean by chaining errors? All I had in mind was a couple (2-4) error structs that encompassed most of the current "errors" and implementing unique display methods for each of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one error caused another in a cascade, we need to chain them to identify the root cause. I have not looked too hard into implementing this manually, but I believe the anyhow crate implements this. You may use that crate for all the error handling-related stuff or you may implement things yourself from scratch.