VCF/BCF Writer - auto-recognize format and compression based on file extension#307
VCF/BCF Writer - auto-recognize format and compression based on file extension#307nh13 wants to merge 1 commit intorust-bio:masterfrom
Conversation
| /// * `.vcf.gz`. -> compressed VCF | ||
| /// * `.vcf.gzip` -> compressed VCF | ||
| /// * `.vcf.bgzf` -> compressed VCF | ||
| /// * `.bcf` -> compressed BCF |
There was a problem hiding this comment.
| 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.
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.
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.