Skip to content

Commit

Permalink
Formatting adjustments with Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
olliecheng committed Dec 2, 2024
1 parent bd27a9e commit d2a913e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
17 changes: 7 additions & 10 deletions src/call.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use crate::duplicates::{DuplicateMap, RecordIdentifier};
use crate::io::{iter_duplicates, until_err, write_read, ReadType, Record, UMIGroup};
use crate::duplicates::DuplicateMap;
use crate::io::{iter_duplicates, until_err, ReadType, Record, UMIGroup};

use needletail::parser::{FastqReader, FastxReader, SequenceRecord};
use spoa::{AlignmentEngine, AlignmentType};

use std::fs::File;
use std::io::prelude::*;
use std::io::{Cursor, Seek, SeekFrom};
use std::process::{Command, Stdio};
use std::io::Cursor;

use anyhow::{anyhow, Context, Result};
use anyhow::Result;

use crate::io;
use pariter::IteratorExt as _;
Expand Down Expand Up @@ -96,7 +93,7 @@ fn call_record(group: UMIGroup, output_originals: bool) -> Vec<u8> {
// for singletons, the read is its own consensus
if length == 1 {
let record = &group.records[0];
io::write_read(&mut output, record, &group, ReadType::CONSENSUS, false).unwrap();
io::write_read(&mut output, record, &group, ReadType::Consensus, false).unwrap();
return output.into_inner();
}

Expand All @@ -109,7 +106,7 @@ fn call_record(group: UMIGroup, output_originals: bool) -> Vec<u8> {
for record in group.records.iter() {
if output_originals {
// Write the original reads as well
io::write_read(&mut output, record, &group, ReadType::ORIGINAL, false).unwrap();
io::write_read(&mut output, record, &group, ReadType::Original, false).unwrap();
}

// Align to the graph
Expand All @@ -135,7 +132,7 @@ fn call_record(group: UMIGroup, output_originals: bool) -> Vec<u8> {
qual: "".to_string(),
};

io::write_read(&mut output, &consensus, &group, ReadType::CONSENSUS, false).unwrap();
io::write_read(&mut output, &consensus, &group, ReadType::Consensus, false).unwrap();

output.into_inner()
}
Expand Down
2 changes: 1 addition & 1 deletion src/duplicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct RecordIdentifier {

impl std::fmt::Display for RecordIdentifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.tail.len() == 0 {
if self.tail.is_empty() {
f.write_str(&self.head)
} else {
write!(f, "{}_{}", self.head, self.tail)
Expand Down
10 changes: 4 additions & 6 deletions src/generate_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use regex::Regex;
use crate::generate_index::IndexGenerationErr::{InvalidClusterRow, RowNotInClusters};
use anyhow::{bail, Context, Result};
use needletail::parser::SequenceRecord;
use needletail::{FastxReader, Sequence};
use needletail::FastxReader;
use thiserror::Error;

use crate::file::FastqFile;
Expand Down Expand Up @@ -127,12 +127,10 @@ fn iter_lines_with_cluster_file<W: Write>(
for result in clusters.records() {
let record = result?;

let len = record.len();

let read_id = record[0].to_string();
let identifier = match record.len() {
2 => record[1].to_string(),
3 => format!("{}_{}", record[1].to_string(), record[2].to_string()),
3 => format!("{}_{}", &record[1], &record[2]),
_ => bail!(InvalidClusterRow {row: record.as_slice().to_string()})
};

Expand Down Expand Up @@ -165,7 +163,7 @@ fn iter_lines_with_cluster_file<W: Write>(
};
info.matched_read_count += 1;

total_quality += write_read(wtr, &rec, &identifier, position)?;
total_quality += write_read(wtr, &rec, identifier, position)?;
total_len += rec.num_bases();
}

Expand Down Expand Up @@ -239,7 +237,7 @@ pub fn construct_index(
None => { iter_lines_with_regex(reader, &mut wtr, &re, skip_unmatched, file_info) }
Some(filepath) => {
let mut cluster_rdr = csv::ReaderBuilder::new()
.delimiter(';' as u8)
.delimiter(b';')
.has_headers(false)
.from_path(filepath)?;

Expand Down
11 changes: 9 additions & 2 deletions src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,24 @@ pub fn group(
false,
)?;

let mut count = 0usize;

duplicate_iterator
// iterate until an error is found, writing into &err
.scan(&mut err, until_err)
.try_for_each(|group| -> Result<()> {
count += 1;
if count % 500000 == 0 {
info!("Processed: {} reads", count);
}

for rec in group.records.iter() {
// write to the output file
crate::io::write_read(
writer,
&rec,
rec,
&group,
ReadType::ORIGINAL,
ReadType::Original,
true,
)?
}
Expand Down
13 changes: 7 additions & 6 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::fs::File;
use std::io::{Seek, SeekFrom, Write};

pub enum ReadType {
CONSENSUS,
ORIGINAL,
Consensus,
Original,
}

pub struct Record {
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn get_read_at_position(
Ok(Record {
id: String::from_utf8(rec.id().to_vec())?,
seq: String::from_utf8(rec.seq().to_vec())?,
qual: String::from_utf8(rec.qual().unwrap_or_else(|| &[]).to_vec())?,
qual: String::from_utf8(rec.qual().unwrap_or(&[]).to_vec())?,
})
}

Expand All @@ -80,7 +80,8 @@ pub fn get_read_at_position(
/// This function will return an error if:
/// * The file cannot be opened.
/// * The record cannot be read at the specified position.
/// The iterator yield Some(Err) if:
///
/// The iterator yields Some(Err) if:
/// * There are issues reading the read at at the specified position. See the documentation for
/// `get_read_at_position` for more.
pub fn iter_duplicates(
Expand Down Expand Up @@ -176,8 +177,8 @@ pub fn write_read(
fastq: bool,
) -> std::io::Result<()> {
let read_type_label = match read_type {
ReadType::CONSENSUS => { "CONSENSUS" }
ReadType::ORIGINAL => { "ORIGINAL" }
ReadType::Consensus => { "CONSENSUS" }
ReadType::Original => { "ORIGINAL" }
};

if fastq {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// disable unused code warnings for dev builds
#![cfg_attr(debug_assertions, allow(dead_code, unused_imports, unused_variables))]
// #![cfg_attr(debug_assertions, allow(dead_code, unused_imports, unused_variables))]

extern crate env_logger;
#[macro_use]
Expand Down
5 changes: 2 additions & 3 deletions src/summary.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::duplicates;
use anyhow::{Context, Result};
use serde_json::json;
use std::collections::HashMap;

// include the template HTML file at compile time as a string literal
const TEMPLATE_HTML: &str = include_str!("summary_template.html");
Expand All @@ -24,8 +23,8 @@ pub fn summarize(index: &str, output: &str) -> Result<()> {
);

let file = std::fs::File::create(output)?;
let mut reg = handlebars::Handlebars::new();
reg.render_template_to_write(TEMPLATE_HTML, &data, file);
let reg = handlebars::Handlebars::new();
reg.render_template_to_write(TEMPLATE_HTML, &data, file)?;

Ok(())
}

0 comments on commit d2a913e

Please sign in to comment.