-
Notifications
You must be signed in to change notification settings - Fork 81
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
VCF/BCF Writer - auto-recognize format and compression based on file extension #307
base: master
Are you sure you want to change the base?
Conversation
/// * `.vcf.gz`. -> compressed VCF | ||
/// * `.vcf.gzip` -> compressed VCF | ||
/// * `.vcf.bgzf` -> compressed VCF | ||
/// * `.bcf` -> compressed BCF |
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 (fields[length-1] == "gz" || fields[length-1] == "gzip" || fields[length-1] == "bgzf") { false } | ||
else if (fields[length-1] == "bcf") { false } | ||
else if (fields[length-1] == "vcf") { true } | ||
else { true } // FIXME |
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.
I'd try to use the extension
method of Path. It returns Option<&OsStr>
, which is a bit cumbersome to use since it's no "regular" String/&str, but can be transformed into one, see here.
let length = fields.len(); | ||
// FIXME: check that we have enough fields | ||
let uncompressed: bool = { | ||
if (fields[length-1] == "gz" || fields[length-1] == "gzip" || fields[length-1] == "bgzf") { false } |
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.
In addition to @tedil's recommendation, also have a look at the match statement for a more idiomatic construct when checking these different extensions:
https://doc.rust-lang.org/rust-by-example/flow_control/match.html
Good to see you over here! This is definitely a good addition that will make it easier to write VCF/BCF. As for pointers for more idiomatic Rust, beyond those provided in the code, one great feature of Rust are And finally, if you want some automated recommendations on your code, you could check out Also, don't hesitate to ask anything! |
This is my first every PR in rust, in any repo, so please forgive my non-idiomatic way of writing Rust.
I was surprised to find that there was no way to create a writer that would auto-recognize the compression and format based on file extension, so here's a first incomplete path. I am happy to write some tests, clean up the code to be more idiomatic (with help). But before I do this, I wanted to get the maintainers' thoughts.