-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc4a5d9
commit ab57edb
Showing
8 changed files
with
52 additions
and
34 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
use std::error::Error; | ||
|
||
use itertools::Itertools; | ||
use bio::alphabets::dna::n_alphabet; | ||
use rust_htslib::bcf::{self, Read, Format}; | ||
use itertools::Itertools; | ||
use rust_htslib::bcf::{self, Format, Read}; | ||
|
||
pub fn fix_iupac_alleles() -> Result<(), Box<dyn Error>> { | ||
let mut inbcf = bcf::Reader::from_stdin()?; | ||
let mut outbcf = bcf::Writer::from_stdout(&bcf::Header::from_template(inbcf.header()), false, Format::BCF)?; | ||
let mut outbcf = bcf::Writer::from_stdout( | ||
&bcf::Header::from_template(inbcf.header()), | ||
false, | ||
Format::BCF, | ||
)?; | ||
let valid_alphabet = n_alphabet(); | ||
|
||
for res in inbcf.records() { | ||
let mut rec = res?; | ||
|
||
let alleles = rec.alleles(); | ||
if !alleles.iter().all(|allele| valid_alphabet.is_word(*allele)) { | ||
let fixed = alleles.into_iter().map(|allele| { | ||
let fixed = allele.into_iter().map(|base| { | ||
if valid_alphabet.is_word(&[*base]) { | ||
*base | ||
} else { | ||
b'N' | ||
} | ||
}).collect_vec(); | ||
fixed | ||
}).collect_vec(); | ||
let fixed = alleles | ||
.into_iter() | ||
.map(|allele| { | ||
let fixed = allele | ||
.into_iter() | ||
.map(|base| { | ||
if valid_alphabet.is_word(&[*base]) { | ||
*base | ||
} else { | ||
b'N' | ||
} | ||
}) | ||
.collect_vec(); | ||
fixed | ||
}) | ||
.collect_vec(); | ||
|
||
rec.set_alleles(&fixed.iter().map(|allele| allele.as_slice()).collect_vec())?; | ||
} | ||
|
||
outbcf.write(&rec)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
//! Tools that work on VCF and BCF files. | ||
pub mod annotate_dgidb; | ||
pub mod baf; | ||
pub mod fix_iupac_alleles; | ||
pub mod match_variants; | ||
pub mod to_txt; | ||
pub mod fix_iupac_alleles; |
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