Skip to content

Commit 9a440f0

Browse files
committed
lints
1 parent 4bf3c3e commit 9a440f0

File tree

9 files changed

+88
-70
lines changed

9 files changed

+88
-70
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ zoe = { version = "0.0.19", default-features = false, features = [
2323

2424
[profile.release]
2525
strip = true
26+
27+
[lints.clippy]
28+
pedantic = "warn"

src/main.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
#![allow(unreachable_patterns)]
1+
#![warn(clippy::pedantic)]
2+
#![allow(
3+
unreachable_patterns,
4+
clippy::missing_panics_doc,
5+
clippy::missing_errors_doc
6+
)]
27
use crate::processes::{
3-
all_sample_hd::*, all_sample_nt_diffs::*, find_chemistry::*, plotter::*,
4-
positions_of_interest::*, variants_of_interest::*,
8+
all_sample_hd::{HammingArgs, all_sample_hd_process},
9+
all_sample_nt_diffs::{NTDiffsArgs, all_sample_nt_diffs_process},
10+
find_chemistry::{FindChemArgs, find_chemistry_process},
11+
plotter::{PlotterArgs, plotter_process},
12+
positions_of_interest::{PositionsArgs, positions_of_interest_process},
13+
variants_of_interest::{VariantsArgs, variants_of_interest_process},
514
};
615
use clap::{Parser, Subcommand};
716
use processes::prepare_mira_reports::{ReportsArgs, prepare_mira_reports_process};
@@ -39,20 +48,21 @@ fn main() {
3948

4049
match args.command {
4150
Commands::VariantsOfInterest(cmd_args) => {
42-
variants_of_interest_process(cmd_args).expect(&format!("{module}::VariantsOfInterest"))
51+
variants_of_interest_process(cmd_args)
52+
.unwrap_or_else(|_| panic!("{module}::VariantsOfInterest"));
4353
}
4454
Commands::PositionsOfInterest(cmd_args) => positions_of_interest_process(cmd_args)
45-
.expect(&format!("{module}::PositionsOfInterest")),
55+
.unwrap_or_else(|_| panic!("{module}::PositionsOfInterest")),
4656

4757
Commands::FindChemistry(cmd_args) => {
48-
find_chemistry_process(cmd_args).unwrap_or_die(&format!("{module}::FindChemistry"))
58+
find_chemistry_process(&cmd_args).unwrap_or_die(&format!("{module}::FindChemistry"));
4959
}
5060
Commands::Hamming(cmd_args) => {
51-
all_sample_hd_process(cmd_args).unwrap_or_die(&format!("{module}::Hamming"));
61+
all_sample_hd_process(&cmd_args).unwrap_or_die(&format!("{module}::Hamming"));
5262
}
53-
Commands::NTDiffs(cmd_args) => all_sample_nt_diffs_process(cmd_args),
63+
Commands::NTDiffs(cmd_args) => all_sample_nt_diffs_process(&cmd_args),
5464
Commands::Plotter(cmd_args) => {
55-
plotter_process(cmd_args).unwrap_or_else(|_| panic!("{module}::Plotter"))
65+
plotter_process(cmd_args).unwrap_or_else(|_| panic!("{module}::Plotter"));
5666
}
5767
Commands::PrepareMiraReports(cmd_args) => prepare_mira_reports_process(cmd_args)
5868
.unwrap_or_else(|_| panic!("{module}::PrepareMiraReports")),

src/processes/all_sample_hd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct ValidSeq {
3131
sequence: Nucleotides,
3232
}
3333

34-
pub fn all_sample_hd_process(args: HammingArgs) -> Result<(), std::io::Error> {
34+
pub fn all_sample_hd_process(args: &HammingArgs) -> Result<(), std::io::Error> {
3535
//let args = APDArgs::parse();
3636
let delim = args.output_delimiter.unwrap_or(',');
3737

src/processes/all_sample_nt_diffs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct ValidSeq {
3131
sequence: Nucleotides,
3232
}
3333

34-
pub fn all_sample_nt_diffs_process(args: NTDiffsArgs) {
34+
pub fn all_sample_nt_diffs_process(args: &NTDiffsArgs) {
3535
//let args = NTDiffsArgs::parse();
3636
let delim = args.output_delimiter.unwrap_or(',');
3737

@@ -80,10 +80,10 @@ pub fn all_sample_nt_diffs_process(args: NTDiffsArgs) {
8080
)
8181
.unwrap();
8282

83-
all_sequences.iter().for_each(|f| {
83+
for f in &all_sequences {
8484
let name_1 = &f.name;
8585
let seq1 = &f.sequence;
86-
all_sequences.iter().for_each(|f| {
86+
for f in &all_sequences {
8787
let name_2 = &f.name;
8888
let seq2 = &f.sequence;
8989
for (i, (nt1, nt2)) in seq1.iter().zip(seq2.iter()).enumerate() {
@@ -97,6 +97,6 @@ pub fn all_sample_nt_diffs_process(args: NTDiffsArgs) {
9797
.unwrap();
9898
}
9999
}
100-
});
101-
});
100+
}
101+
}
102102
}

src/processes/find_chemistry.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,13 @@ impl FindChemArgs {
4646
/// Flu experiment.
4747
fn validate(&self) -> Result<(), String> {
4848
match self.irma_config {
49-
IRMAConfig::Sensitive
49+
IRMAConfig::Sensitive | IRMAConfig::Secondary | IRMAConfig::UTR
5050
if self.experiment == Experiment::FluIllumina
5151
|| self.experiment == Experiment::FluONT =>
5252
{
5353
Ok(())
5454
}
55-
IRMAConfig::Secondary
56-
if self.experiment == Experiment::FluIllumina
57-
|| self.experiment == Experiment::FluONT =>
58-
{
59-
Ok(())
60-
}
61-
IRMAConfig::UTR
62-
if self.experiment == Experiment::FluIllumina
63-
|| self.experiment == Experiment::FluONT =>
64-
{
65-
Ok(())
66-
}
67-
IRMAConfig::Custom => Ok(()),
68-
IRMAConfig::NoConfig => Ok(()),
55+
IRMAConfig::Custom | IRMAConfig::NoConfig => Ok(()),
6956
_ => Err(format!(
7057
"Invalid combination: {:?} cannot be used with {:?}",
7158
self.experiment, self.irma_config
@@ -128,15 +115,13 @@ impl ValueEnum for Experiment {
128115

129116
impl Experiment {
130117
/// Selects the appropriate IRMA Module from the user provided experiment type
131-
fn get_module(&self) -> IrmaModule {
118+
fn get_module(self) -> IrmaModule {
132119
match self {
133120
Self::FluIllumina => IrmaModule::FLU,
134-
Self::RSVIllumina => IrmaModule::RSV,
135-
Self::SC2WholeGenomeIllumina => IrmaModule::CoV,
121+
Self::RSVIllumina | Self::RSVONT => IrmaModule::RSV,
122+
Self::SC2WholeGenomeIllumina | Self::SC2WholeGenomeONT => IrmaModule::CoV,
136123
Self::FluONT => IrmaModule::FLUMinion,
137124
Self::SC2SpikeOnlyONT => IrmaModule::CoVsGene,
138-
Self::SC2WholeGenomeONT => IrmaModule::CoV,
139-
Self::RSVONT => IrmaModule::RSV,
140125
}
141126
}
142127
}
@@ -188,7 +173,7 @@ fn get_config_path(args: &FindChemArgs, seq_len: Option<usize>) -> String {
188173
}
189174

190175
let path_extension = match (args.experiment, seq_len, args.irma_config) {
191-
(_, None, _) => return "".to_string(),
176+
(_, None, _) => return String::new(),
192177
(_, _, IRMAConfig::Sensitive) => "/bin/irma_config/FLU-sensitive.sh",
193178
(_, _, IRMAConfig::Secondary) => "/bin/irma_config/FLU-secondary.sh",
194179
(_, _, IRMAConfig::UTR) => "/bin/irma_config/FLU-utr.sh",
@@ -309,15 +294,15 @@ fn parse_chemistry_args(args: &FindChemArgs) -> Result<ChemistryOutput, std::io:
309294
Ok(out)
310295
}
311296

312-
pub fn find_chemistry_process(args: FindChemArgs) -> Result<(), std::io::Error> {
297+
pub fn find_chemistry_process(args: &FindChemArgs) -> Result<(), std::io::Error> {
313298
//let args = CheckChemArgs::parse();
314299
// handle input validation to ensure valid combinations of
315300
if let Err(e) = args.validate() {
316301
eprintln!("Error: {e}");
317302
std::process::exit(1);
318303
}
319304
// parse the arguments into output format
320-
let output = parse_chemistry_args(&args)?;
305+
let output = parse_chemistry_args(args)?;
321306
let filename = format!("{}_chemistry.csv", args.sample);
322307
let headers = "sample_ID,irma_custom,subsample,irma_module";
323308

src/processes/plotter.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::collections::HashMap;
99
use std::error::Error;
1010
use std::fs::File;
1111
use std::io::{BufRead, BufReader};
12-
use std::path::PathBuf;
12+
use std::path::{Path, PathBuf};
1313

1414
// Add this function to generate consistent colors for segment names
1515
fn get_segment_color(segment_name: &str) -> &'static str {
@@ -35,7 +35,7 @@ fn get_segment_color(segment_name: &str) -> &'static str {
3535
// For any other segments, use a hash of the segment name to pick a color
3636
let hash = segment_name
3737
.bytes()
38-
.fold(0u32, |acc, b| acc.wrapping_add(b as u32));
38+
.fold(0u32, |acc, b| acc.wrapping_add(u32::from(b)));
3939
match hash % 10 {
4040
0 => "#3366CC", // blue
4141
1 => "#DC3912", // red
@@ -105,7 +105,7 @@ pub struct PlotterArgs {
105105
output: Option<PathBuf>,
106106
}
107107

108-
fn generate_plot_coverage(input_directory: &PathBuf) -> Result<Plot, Box<dyn Error>> {
108+
fn generate_plot_coverage(input_directory: &Path) -> Result<Plot, Box<dyn Error>> {
109109
// Create a Plotly plot
110110
let mut plot = Plot::new();
111111

@@ -193,7 +193,7 @@ fn generate_plot_coverage(input_directory: &PathBuf) -> Result<Plot, Box<dyn Err
193193
Ok(plot)
194194
}
195195

196-
fn generate_plot_coverage_seg(input_directory: &PathBuf) -> Result<Plot, Box<dyn Error>> {
196+
fn generate_plot_coverage_seg(input_directory: &Path) -> Result<Plot, Box<dyn Error>> {
197197
// Init a Plotly plot
198198
let mut plot = Plot::new();
199199

@@ -470,7 +470,7 @@ fn generate_plot_coverage_seg(input_directory: &PathBuf) -> Result<Plot, Box<dyn
470470
}
471471

472472
// TO DO: fix colors for Sankey diagram
473-
fn generate_sankey_plot(input_directory: &PathBuf) -> Result<Plot, Box<dyn Error>> {
473+
fn generate_sankey_plot(input_directory: &Path) -> Result<Plot, Box<dyn Error>> {
474474
// Path to READ_COUNTS.txt
475475
let read_counts_path = input_directory.join("tables").join("READ_COUNTS.txt");
476476

@@ -658,7 +658,10 @@ fn generate_sankey_plot(input_directory: &PathBuf) -> Result<Plot, Box<dyn Error
658658
let mut plot = Plot::new();
659659

660660
// Create Sankey trace
661-
let node_labels_refs: Vec<&str> = node_labels.iter().map(|s| s.as_str()).collect();
661+
let node_labels_refs: Vec<&str> = node_labels
662+
.iter()
663+
.map(std::string::String::as_str)
664+
.collect();
662665

663666
// Explicitly define x and y positions for each node
664667
let n = node_labels.len();
@@ -696,7 +699,7 @@ fn generate_sankey_plot(input_directory: &PathBuf) -> Result<Plot, Box<dyn Error
696699
_ => {
697700
// Segment nodes: stack vertically in last column
698701
x[i] = 0.7;
699-
y[i] = 0.1 + 0.8 * (seg_idx as f64) / ((n - 5).max(1) as f64);
702+
y[i] = 0.1 + 0.8 * f64::from(seg_idx) / ((n - 5).max(1) as f64);
700703
seg_idx += 1;
701704
}
702705
}

src/processes/positions_of_interest.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ impl Entry<'_> {
139139
{
140140
// Use match for cleaner handling of `hold_aa_mut` cases
141141
self.phenotypic_consequences = match hold_aa_mut.as_str() {
142-
"." => "amino acid information missing".to_string(),
143142
"~" => "partial amino acid".to_string(),
144143
"-" => "amino acid covered".to_string(),
145-
"X" => "amino acid information missing".to_string(),
144+
"." | "X" => "amino acid information missing".to_string(),
146145
aa if aa == muts_entry.aa => muts_entry.description.clone(),
147146
_ => String::new(),
148147
};
@@ -318,8 +317,8 @@ pub fn positions_of_interest_process(args: PositionsArgs) -> Result<(), Box<dyn
318317
.expect("Invalid UTF-8 sequence")
319318
.to_string();
320319
entry.aa_position = tail_index + 1;
321-
entry.aa_ref = '~' as char;
322-
entry.aa_mut = '~' as char;
320+
entry.aa_ref = '~';
321+
entry.aa_mut = '~';
323322

324323
if entry.update_entry_from_alignment(
325324
&ref_entry.subtype,

src/processes/prepare_mira_reports.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
#![allow(dead_code, unused_imports)]
2-
use crate::utils::{data_ingest::*, data_processing::*, writing_outputs::*};
2+
use crate::utils::{
3+
data_ingest::{
4+
DaisSeqData, allele_data_collection, amended_consensus_data_collection,
5+
coverage_data_collection, create_reader, create_vtype_data, dais_insertion_data_collection,
6+
dais_ref_seq_data_collection, dias_deletion_data_collection, dias_sequence_data_collection,
7+
get_reference_lens, indels_data_collection, read_csv, reads_data_collection,
8+
},
9+
data_processing::{
10+
DaisVarsData, HasSampleId, HasSampleType, ProcessedCoverage, Subtype,
11+
collect_analysis_metadata, collect_negatives, collect_sample_id, compute_cvv_dais_variants,
12+
compute_dais_variants, create_prelim_irma_summary_df, extract_field, extract_subtype_flu,
13+
extract_subtype_sc2, melt_reads_data, process_position_coverage_data,
14+
process_wgs_coverage_data, return_seg_data,
15+
},
16+
writing_outputs::{
17+
negative_qc_statement, write_reads_to_parquet, write_ref_data_json,
18+
write_structs_to_csv_file, write_structs_to_split_json_file,
19+
},
20+
};
321
use clap::Parser;
422
use csv::ReaderBuilder;
523
use either::Either;

src/utils/writing_outputs.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ pub struct ReadQC {
2424
/// Function to serialize a vector of structs into split-oriented JSON with precision and indexing
2525
pub fn write_structs_to_split_json_file<T: Serialize>(
2626
file_path: &str,
27-
data: &Vec<T>,
28-
columns: &Vec<&str>,
29-
struct_values: &Vec<&str>,
27+
data: &[T],
28+
columns: &[&str],
29+
struct_values: &[&str],
3030
) -> Result<(), Box<dyn Error>> {
3131
// Create the "split-oriented" JSON structure
3232
let split_json = json!({
@@ -58,9 +58,9 @@ pub fn write_structs_to_split_json_file<T: Serialize>(
5858
/// Write to CSV
5959
pub fn write_structs_to_csv_file<T: Serialize>(
6060
file_path: &str,
61-
data: &Vec<T>,
62-
columns: &Vec<&str>,
63-
struct_values: &Vec<&str>,
61+
data: &[T],
62+
columns: &[&str],
63+
struct_values: &[&str],
6464
) -> Result<(), Box<dyn Error>> {
6565
let mut csv_writer = Writer::from_path(file_path)?;
6666

@@ -94,8 +94,8 @@ pub fn write_structs_to_csv_file<T: Serialize>(
9494
pub fn write_ref_data_json(
9595
file_path: &str,
9696
ref_lens: &HashMap<String, usize>,
97-
segments: &Vec<String>,
98-
segset: &Vec<String>,
97+
segments: &[String],
98+
segset: &[String],
9999
segcolor: &HashMap<String, &str>,
100100
) -> Result<(), Box<dyn Error>> {
101101
let json_data = json!({
@@ -117,22 +117,22 @@ pub fn write_ref_data_json(
117117

118118
/// Write the reads data to parquet file.
119119
pub fn write_reads_to_parquet(
120-
reads_data: &Vec<ReadsData>,
120+
reads_data: &[ReadsData],
121121
output_file: &str,
122122
) -> Result<(), Box<dyn Error>> {
123123
// Convert values in struct to vector of values
124124
let sample_ids_vec: Vec<Option<String>> =
125-
extract_field(reads_data.clone(), |item| item.sample_id.clone());
126-
let record_vec = extract_field(reads_data.clone(), |item| item.record.clone());
127-
let reads_vec = extract_field(reads_data.clone(), |item| item.reads);
128-
let patterns_vec = extract_string_fields_as_float(reads_data.clone(), |item| &item.patterns);
125+
extract_field(reads_data.to_owned(), |item| item.sample_id.clone());
126+
let record_vec = extract_field(reads_data.to_owned(), |item| item.record.clone());
127+
let reads_vec = extract_field(reads_data.to_owned(), |item| item.reads);
128+
let patterns_vec = extract_string_fields_as_float(reads_data.to_owned(), |item| &item.patterns);
129129
let pairs_and_windows_vec =
130-
extract_string_fields_as_float(reads_data.clone(), |item| &item.pairs_and_windows);
131-
let stages_vec = extract_string_fields_as_int(reads_data.clone(), |item| {
130+
extract_string_fields_as_float(reads_data.to_owned(), |item| &item.pairs_and_windows);
131+
let stages_vec = extract_string_fields_as_int(reads_data.to_owned(), |item| {
132132
item.stage.as_deref().unwrap_or("")
133133
});
134-
let runid_vec = extract_field(reads_data.clone(), |item| item.run_id.clone());
135-
let instrument_vec = extract_field(reads_data.clone(), |item| item.instrument.clone());
134+
let runid_vec = extract_field(reads_data.to_owned(), |item| item.run_id.clone());
135+
let instrument_vec = extract_field(reads_data.to_owned(), |item| item.instrument.clone());
136136

137137
// Convert the vectors into Arrow columns
138138
let sample_array: ArrayRef = Arc::new(StringArray::from(sample_ids_vec));
@@ -183,8 +183,8 @@ pub fn write_reads_to_parquet(
183183

184184
pub fn negative_qc_statement(
185185
output_file: &str,
186-
reads_data: &Vec<ReadsData>,
187-
neg_control_list: &Vec<String>,
186+
reads_data: &[ReadsData],
187+
neg_control_list: &[String],
188188
) -> Result<(), Box<dyn Error>> {
189189
let filtered_reads_data = filter_struct_by_ids(reads_data, neg_control_list.to_vec());
190190

@@ -207,7 +207,7 @@ pub fn negative_qc_statement(
207207

208208
if total_reads_stage_3 > 0 {
209209
let percent_mapping =
210-
(total_reads_stage_3 as f64 / reads_stage_1 as f64 * 100.0).round();
210+
(f64::from(total_reads_stage_3) / f64::from(reads_stage_1) * 100.0).round();
211211

212212
results.push(ReadQC {
213213
sample_id: sample_id.clone(),

0 commit comments

Comments
 (0)