Skip to content

Commit ab57edb

Browse files
committed
Cargo fmt
1 parent fc4a5d9 commit ab57edb

File tree

8 files changed

+52
-34
lines changed

8 files changed

+52
-34
lines changed

src/bam/call_consensus_reads/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod pipeline;
44
use log::info;
55
use pipeline::CallConsensusRead;
66
use rust_htslib::bam;
7-
use rust_htslib::bam::{Header, Read, Format};
7+
use rust_htslib::bam::{Format, Header, Read};
88
use std::error::Error;
99

1010
pub fn call_consensus_reads_from_paths(
@@ -16,7 +16,11 @@ pub fn call_consensus_reads_from_paths(
1616
info!("Reading input files:\n {}", bam_in);
1717
info!("Writing output to:\n {}", bam_out);
1818
let bam_reader = bam::Reader::from_path(bam_in)?;
19-
let bam_writer = bam::Writer::from_path(bam_out, &Header::from_template(bam_reader.header()), Format::BAM)?;
19+
let bam_writer = bam::Writer::from_path(
20+
bam_out,
21+
&Header::from_template(bam_reader.header()),
22+
Format::BAM,
23+
)?;
2024
CallConsensusRead::new(bam_reader, bam_writer, seq_dist, verbose_read_names)
2125
.call_consensus_reads()
2226
}

src/bcf/annotate_dgidb.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use itertools::Itertools;
22
use regex::Regex;
33
use reqwest;
44
use rust_htslib::bcf;
5-
use rust_htslib::bcf::{Read, Format};
5+
use rust_htslib::bcf::{Format, Read};
66
use serde::{Deserialize, Serialize};
77
use std::collections::{HashMap, HashSet};
88
use std::error::Error;
@@ -102,13 +102,11 @@ fn extract_genes<'a>(
102102
) -> Result<Option<impl Iterator<Item = String> + 'a>, Box<dyn Error>> {
103103
let annotation = rec.info("ANN".as_bytes()).string()?;
104104
match annotation {
105-
Some(transcripts) => Ok(Some(transcripts.into_iter().map(
106-
|transcript| {
107-
str::from_utf8(transcript.split(|c| *c == b'|').nth(3).unwrap())
108-
.unwrap()
109-
.to_owned()
110-
},
111-
))),
105+
Some(transcripts) => Ok(Some(transcripts.into_iter().map(|transcript| {
106+
str::from_utf8(transcript.split(|c| *c == b'|').nth(3).unwrap())
107+
.unwrap()
108+
.to_owned()
109+
}))),
112110
None => Ok(None),
113111
}
114112
}

src/bcf/baf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use itertools::repeat_n;
99
use itertools::Itertools;
1010
use rust_htslib::bcf;
1111
use rust_htslib::bcf::record::Numeric;
12-
use rust_htslib::bcf::{Read, Format};
12+
use rust_htslib::bcf::{Format, Read};
1313
use std::error::Error;
1414
use std::f32;
1515

src/bcf/fix_iupac_alleles.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
11
use std::error::Error;
22

3-
use itertools::Itertools;
43
use bio::alphabets::dna::n_alphabet;
5-
use rust_htslib::bcf::{self, Read, Format};
4+
use itertools::Itertools;
5+
use rust_htslib::bcf::{self, Format, Read};
66

77
pub fn fix_iupac_alleles() -> Result<(), Box<dyn Error>> {
88
let mut inbcf = bcf::Reader::from_stdin()?;
9-
let mut outbcf = bcf::Writer::from_stdout(&bcf::Header::from_template(inbcf.header()), false, Format::BCF)?;
9+
let mut outbcf = bcf::Writer::from_stdout(
10+
&bcf::Header::from_template(inbcf.header()),
11+
false,
12+
Format::BCF,
13+
)?;
1014
let valid_alphabet = n_alphabet();
1115

1216
for res in inbcf.records() {
1317
let mut rec = res?;
1418

1519
let alleles = rec.alleles();
1620
if !alleles.iter().all(|allele| valid_alphabet.is_word(*allele)) {
17-
let fixed = alleles.into_iter().map(|allele| {
18-
let fixed = allele.into_iter().map(|base| {
19-
if valid_alphabet.is_word(&[*base]) {
20-
*base
21-
} else {
22-
b'N'
23-
}
24-
}).collect_vec();
25-
fixed
26-
}).collect_vec();
21+
let fixed = alleles
22+
.into_iter()
23+
.map(|allele| {
24+
let fixed = allele
25+
.into_iter()
26+
.map(|base| {
27+
if valid_alphabet.is_word(&[*base]) {
28+
*base
29+
} else {
30+
b'N'
31+
}
32+
})
33+
.collect_vec();
34+
fixed
35+
})
36+
.collect_vec();
2737

2838
rec.set_alleles(&fixed.iter().map(|allele| allele.as_slice()).collect_vec())?;
2939
}
30-
40+
3141
outbcf.write(&rec)?;
3242
}
3343

3444
Ok(())
35-
}
45+
}

src/bcf/match_variants.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use itertools::Itertools;
1313
use log::{info, warn};
1414
use quick_error::quick_error;
1515
use rust_htslib::bcf;
16-
use rust_htslib::bcf::{Read, Format};
16+
use rust_htslib::bcf::{Format, Read};
1717
use std::collections::{btree_map, BTreeMap, HashMap};
1818
use std::error::Error;
1919
use std::str;
@@ -32,7 +32,7 @@ impl VarIndex {
3232
match reader.read(&mut rec) {
3333
Ok(true) => (),
3434
Ok(false) => break,
35-
Err(e) => return Err(Box::new(e))
35+
Err(e) => return Err(Box::new(e)),
3636
};
3737
if let Some(rid) = rec.rid() {
3838
let chrom = reader.header().rid2name(rid)?;
@@ -82,7 +82,7 @@ pub fn match_variants(
8282
match inbcf.read(&mut rec) {
8383
Ok(true) => (),
8484
Ok(false) => break,
85-
Err(e) => return Err(Box::new(e))
85+
Err(e) => return Err(Box::new(e)),
8686
};
8787
outbcf.translate(&mut rec);
8888

src/bcf/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Tools that work on VCF and BCF files.
22
pub mod annotate_dgidb;
33
pub mod baf;
4+
pub mod fix_iupac_alleles;
45
pub mod match_variants;
56
pub mod to_txt;
6-
pub mod fix_iupac_alleles;

src/bcf/to_txt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn to_txt(
111111
match reader.read(&mut rec) {
112112
Ok(true) => (),
113113
Ok(false) => break,
114-
Err(e) => return Err(Box::new(e))
114+
Err(e) => return Err(Box::new(e)),
115115
};
116116
let alleles = rec
117117
.alleles()

tests/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,15 @@ fn vcf_match_same() {
128128
#[test]
129129
fn vcf_fix_iupac_alleles() {
130130
assert!(Command::new("bash")
131-
.arg("-c")
132-
.arg("target/debug/rbt vcf-fix-iupac-alleles < tests/test-iupac.vcf > tests/iupac-fixed.bcf")
133-
.spawn().unwrap().wait().unwrap().success());
131+
.arg("-c")
132+
.arg(
133+
"target/debug/rbt vcf-fix-iupac-alleles < tests/test-iupac.vcf > tests/iupac-fixed.bcf"
134+
)
135+
.spawn()
136+
.unwrap()
137+
.wait()
138+
.unwrap()
139+
.success());
134140
test_output("tests/iupac-fixed.bcf", "tests/expected/iupac-fixed.bcf");
135141
}
136142

0 commit comments

Comments
 (0)