Open essut opened 2 years ago
use std::str::from_utf8
trans BufferedBackend
to &str
use rust_htslib::bcf::{Read, Reader};
fn main() {
let mut bcf = Reader::from_path("test.vcf").unwrap_or_else(|e| panic!("{}", e));
for record in bcf.records() {
let record = record.unwrap();
let tag = "T".as_bytes();
println!("{:?}", record.header().info_type(tag));
println!("{:#?}", std::str::from_utf8(record.info(tag).string().except("No T tag in info!").expect("This record T tag has no value!")));
println!("{:?}", record.header().format_type(tag));
println!("{:#?}", std::str::from_utf8(record.format(tag).string().expect("No T tag in format!")));
}
println!("{:#?}", bcf.header().header_records());
}
Hi, I am trying to solve issue rust-bio/rust-bio-tools#52, where the user triggered a code path that should not be possible: a FORMAT tag having a flag tag type.
I was able to reproduce by this passing a INFO tag as a FORMAT tag
rbt vcf-to-txt --fmt T < tests/test.vcf
, which is surprising to me since I expected therust-htslib
would panic given the tag does not exist as a FORMAT tag.I then wrote my own code and using test.vcf as the input:
If "T" is interpreted as a INFO tag, all is well:
However, I am surprised that interpreting "T" as a FORMAT tag does not generate any errors:
Although in the header information, "T" is identified as a INFO tag:
I am not sure if this is an expected behaviour or not. If it is not, it would help fixing this here instead of relying on downstream tools to catch this error. I am also not sure if this had been discussed before, so apologies for duplicates.
Versions:
rust-bio-tools
0.39.0rust-htslib
0.38.2