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
Merge VCF headers #343
Comments
Hi stupid question but do you want to combine multiple or just 2 files ? let mut out_header = Header::from_template(vcfA.header()); Then you can iterate over header from file 2 and push into 1st, no ? UPDATE: Otherwise I would do something like that: use rustc_hash::FxHashMap;
let mut vcf_contigs : FxHashMap<String,linear_map::LinearMap<String,String>> = FxHashMap::default();
for entries in vcf_a.header().header_records() {
match entries {
rust_htslib::bcf::header::HeaderRecord::Contig{key,mut values} => {
values.remove("IDX").expect("ERROR:could not remove ID entry!");
vcf_contigs.insert(values.get("ID").expect("ERROR: could not get ID of contig!").to_string(), values);
},
_ => println!("Not interesting"),
};
};
for entries in vcf_b.header().header_records() {
match entries {
rust_htslib::bcf::header::HeaderRecord::Contig{key,mut values} => {
values.remove("IDX").expect("ERROR:could not remove ID entry!");
let id = values.get("ID").expect("ERROR: could not get ID of contig!").to_string();
let length = values.get("length").expect("ERROR: could not get length of contig!").to_string();
if let Some(existant) = vcf_contigs.get(&id){
if existant.get("length").expect("ERROR: could not get length of contig!").to_string() != length {
panic!("ERROR: length of similar contig IDs differed!");
}else{
continue
}
}else{
vcf_contigs.insert(values.get("ID").expect("ERROR: could not get ID of contig!").to_string(), values);
}
},
_ => println!("Not interesting"),
};
};
for (_,value) in vcf_contigs.iter() {
let id = value.get("ID").expect("ERROR: could not get ID of contig!").to_string();
let length = value.get("length").expect("ERROR: could not get ID of contig!").to_string();
let assembly = value.get("assembly").expect("ERROR: could not get ID of contig!").to_string();
vcf_header.push_record(format!("##contig=<ID={},length={},assembly={}>", id, length, assembly).as_bytes());
} This is only to match e.g. the header contig entries and to assure they are compatible. |
I encounter though now a weird problem doing that.
Now I am generating a new header in this process for the new comparison vcf writer. Is there a way similar to :
a way to modify the associated header or change the associated header ? UPDATE: Obviously one way to do it is then to use UPDATE: vcf.translate(record); It translates a record into the new writer and one can then push additional information |
Is it possible to merge VCF headers to combine records from different files? I'am trying to do something like this
The text was updated successfully, but these errors were encountered: