Skip to content

Commit

Permalink
behold the glory of clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nrminor committed Apr 11, 2024
1 parent 6d24340 commit 0022546
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() -> Result<()> {
expected_cells,
output_prefix,
}) => {
scrnaseq::give_a_sheet(input_dir, fastq_ext, &expected_cells, output_prefix)?;
scrnaseq::give_a_sheet(input_dir, fastq_ext, expected_cells, output_prefix)?;
}
None => {
eprintln!("{}\n", cli::INFO);
Expand Down
15 changes: 6 additions & 9 deletions src/scrnaseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn retrieve_samples(file_paths: &[Rc<Path>]) -> HashSet<Rc<str>> {
let illumina_pattern = Regex::new(r"_L\d{3}_R\d_\d{3}\.fastq\.gz$").unwrap();

file_paths
.into_iter()
.iter()
.map(|path| {
Rc::from(
path.file_name()
Expand Down Expand Up @@ -38,21 +38,18 @@ fn collect_per_sample(
) -> Result<String> {
// figure out which FASTQ files go with the provided sample_id
let sample_fastqs: Vec<&str> = fastq_paths
.into_iter()
.map(|x| match x.to_str() {
Some(path_str_slice) => path_str_slice,
None => &"",
})
.iter()
.map(|x| x.to_str().unwrap_or(""))
.filter(|x| x.contains(sample_id.as_ref()))
.collect();

// pull out the R1 and R2 FASTQ files
let fastq1: &str = &sample_fastqs
let fastq1 = sample_fastqs
.iter()
.find(|x| x.contains("R1"))
.ok_or("No fastq file with 'R1' found")
.unwrap();
let fastq2: &str = &sample_fastqs
let fastq2 = sample_fastqs
.iter()
.find(|x| x.contains("R2"))
.ok_or("No fastq file with 'R2' found")
Expand All @@ -61,7 +58,7 @@ fn collect_per_sample(
let cell_str = expected_cells.to_string();

// instantiate an illumina line and return it
Ok(vec![sample_id, fastq1, fastq2, &cell_str].join(","))
Ok([sample_id.as_ref(), fastq1, fastq2, &cell_str].join(","))
}

fn concat_lines(
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn write_lines(lines: &[String], header: &str, output_prefix: &Option<String

writeln!(buf_writer, "{}", header)?;
lines
.into_iter()
.iter()
.try_for_each(|line| writeln!(buf_writer, "{}", line))?;

Ok(())
Expand Down
17 changes: 7 additions & 10 deletions src/viralrecon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,36 @@ impl CollectByPlatform for SeqPlatform {
SeqPlatform::Illumina => {
// figure out which FASTQ files go with the provided sample_id
let sample_fastqs: Vec<&str> = fastq_paths
.into_iter()
.map(|x| match x.to_str() {
Some(path_str_slice) => path_str_slice,
None => &"",
})
.iter()
.map(|x| x.to_str().unwrap_or(""))
.filter(|x| x.contains(sample_id.as_ref()))
.collect();

// pull out the R1 and R2 FASTQ files
let fastq1: &str = &sample_fastqs
let fastq1 = sample_fastqs
.iter()
.find(|x| x.contains("R1"))
.ok_or("No fastq file with 'R1' found")
.unwrap();
let fastq2: &str = &sample_fastqs
let fastq2 = sample_fastqs
.iter()
.find(|x| x.contains("R2"))
.ok_or("No fastq file with 'R2' found")
.unwrap();

// instantiate an illumina line and return it
Ok(vec![sample_id, fastq1, fastq2].join(","))
Ok([sample_id.as_ref(), fastq1, fastq2].join(","))
}
SeqPlatform::Nanopore => {
// pull out the barcode
let barcode = if sample_id.starts_with("0") {
let barcode = if sample_id.starts_with('0') {
sample_id.replace("barcode", "").chars().skip(1).collect()
} else {
sample_id.replace("barcode", "")
};

// instantiate a Nanopore line and return it
Ok(vec![sample_id.as_ref(), &barcode].join(","))
Ok([sample_id.as_ref(), &barcode].join(","))
}
}
}
Expand Down

0 comments on commit 0022546

Please sign in to comment.