Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMoelder committed Feb 28, 2020
1 parent fc4a5d9 commit ab57edb
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 34 deletions.
8 changes: 6 additions & 2 deletions src/bam/call_consensus_reads/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod pipeline;
use log::info;
use pipeline::CallConsensusRead;
use rust_htslib::bam;
use rust_htslib::bam::{Header, Read, Format};
use rust_htslib::bam::{Format, Header, Read};
use std::error::Error;

pub fn call_consensus_reads_from_paths(
Expand All @@ -16,7 +16,11 @@ pub fn call_consensus_reads_from_paths(
info!("Reading input files:\n {}", bam_in);
info!("Writing output to:\n {}", bam_out);
let bam_reader = bam::Reader::from_path(bam_in)?;
let bam_writer = bam::Writer::from_path(bam_out, &Header::from_template(bam_reader.header()), Format::BAM)?;
let bam_writer = bam::Writer::from_path(
bam_out,
&Header::from_template(bam_reader.header()),
Format::BAM,
)?;
CallConsensusRead::new(bam_reader, bam_writer, seq_dist, verbose_read_names)
.call_consensus_reads()
}
14 changes: 6 additions & 8 deletions src/bcf/annotate_dgidb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use itertools::Itertools;
use regex::Regex;
use reqwest;
use rust_htslib::bcf;
use rust_htslib::bcf::{Read, Format};
use rust_htslib::bcf::{Format, Read};
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::error::Error;
Expand Down Expand Up @@ -102,13 +102,11 @@ fn extract_genes<'a>(
) -> Result<Option<impl Iterator<Item = String> + 'a>, Box<dyn Error>> {
let annotation = rec.info("ANN".as_bytes()).string()?;
match annotation {
Some(transcripts) => Ok(Some(transcripts.into_iter().map(
|transcript| {
str::from_utf8(transcript.split(|c| *c == b'|').nth(3).unwrap())
.unwrap()
.to_owned()
},
))),
Some(transcripts) => Ok(Some(transcripts.into_iter().map(|transcript| {
str::from_utf8(transcript.split(|c| *c == b'|').nth(3).unwrap())
.unwrap()
.to_owned()
}))),
None => Ok(None),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bcf/baf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use itertools::repeat_n;
use itertools::Itertools;
use rust_htslib::bcf;
use rust_htslib::bcf::record::Numeric;
use rust_htslib::bcf::{Read, Format};
use rust_htslib::bcf::{Format, Read};
use std::error::Error;
use std::f32;

Expand Down
40 changes: 25 additions & 15 deletions src/bcf/fix_iupac_alleles.rs
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(())
}
}
6 changes: 3 additions & 3 deletions src/bcf/match_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use itertools::Itertools;
use log::{info, warn};
use quick_error::quick_error;
use rust_htslib::bcf;
use rust_htslib::bcf::{Read, Format};
use rust_htslib::bcf::{Format, Read};
use std::collections::{btree_map, BTreeMap, HashMap};
use std::error::Error;
use std::str;
Expand All @@ -32,7 +32,7 @@ impl VarIndex {
match reader.read(&mut rec) {
Ok(true) => (),
Ok(false) => break,
Err(e) => return Err(Box::new(e))
Err(e) => return Err(Box::new(e)),
};
if let Some(rid) = rec.rid() {
let chrom = reader.header().rid2name(rid)?;
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn match_variants(
match inbcf.read(&mut rec) {
Ok(true) => (),
Ok(false) => break,
Err(e) => return Err(Box::new(e))
Err(e) => return Err(Box::new(e)),
};
outbcf.translate(&mut rec);

Expand Down
2 changes: 1 addition & 1 deletion src/bcf/mod.rs
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;
2 changes: 1 addition & 1 deletion src/bcf/to_txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn to_txt(
match reader.read(&mut rec) {
Ok(true) => (),
Ok(false) => break,
Err(e) => return Err(Box::new(e))
Err(e) => return Err(Box::new(e)),
};
let alleles = rec
.alleles()
Expand Down
12 changes: 9 additions & 3 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,15 @@ fn vcf_match_same() {
#[test]
fn vcf_fix_iupac_alleles() {
assert!(Command::new("bash")
.arg("-c")
.arg("target/debug/rbt vcf-fix-iupac-alleles < tests/test-iupac.vcf > tests/iupac-fixed.bcf")
.spawn().unwrap().wait().unwrap().success());
.arg("-c")
.arg(
"target/debug/rbt vcf-fix-iupac-alleles < tests/test-iupac.vcf > tests/iupac-fixed.bcf"
)
.spawn()
.unwrap()
.wait()
.unwrap()
.success());
test_output("tests/iupac-fixed.bcf", "tests/expected/iupac-fixed.bcf");
}

Expand Down

0 comments on commit ab57edb

Please sign in to comment.