From 2fe59f3bb1e14b7f487ed4180daa76dfc2de5ceb Mon Sep 17 00:00:00 2001 From: Chris Macklin Date: Wed, 20 Mar 2024 13:42:28 -0700 Subject: [PATCH] enable many clippy lints, and fix lint errors (#400) * Delete unused variables. * Tighten up all lint warnings to errors. * Add -Drust_2018_idioms and fix errors. * Add a few pedantic clippy lints and auto-fix errors. * Add clippy::filter_map_next and manually fix errors. * Add clippy::implicit_clone and auto-fix errors. * Add clippy::inefficient_to_string and auto-fix. * Add clippy::manual_string_new and auto-fix. * Add clippy::semicolon_if_nothing_returned and auto-fix. * Add clippy::used_underscore_binding and manually fix. * Add clippy::redundant_else and manually fix. * Add clippy::complexity which surprisingly requires no fixes. * Leave a few notes in the lint rules. --- .cargo/config | 61 +++++++++++--- align_tools/src/lib.rs | 2 +- ansi_escape/src/ansi_to_html.rs | 6 +- bio_edit/src/alignment/pairwise/mod.rs | 2 +- enclone/src/allele.rs | 13 ++- enclone/src/bin/post_process_test.rs | 2 +- enclone/src/innate.rs | 2 +- enclone/src/join.rs | 17 ++-- enclone/src/join2.rs | 3 +- enclone/src/misc1.rs | 2 +- enclone/src/misc2.rs | 16 +--- enclone/src/misc3.rs | 12 +-- enclone_args/src/load_gex.rs | 3 +- enclone_args/src/load_gex_core.rs | 21 ++--- enclone_args/src/load_gex_util.rs | 8 +- enclone_args/src/proc_args.rs | 5 +- enclone_args/src/proc_args2.rs | 32 ++++---- enclone_args/src/proc_args3.rs | 85 +++++++++---------- enclone_args/src/proc_args_check.rs | 95 ++++++++++------------ enclone_args/src/proc_args_post.rs | 23 +++--- enclone_args/src/process_special_arg2.rs | 12 +-- enclone_args/src/read_json.rs | 2 +- enclone_core/src/align_to_vdj_ref.rs | 12 +-- enclone_core/src/join_one.rs | 7 +- enclone_core/src/lib.rs | 4 +- enclone_core/src/linear_condition.rs | 2 +- enclone_core/src/opt_d.rs | 2 +- enclone_core/src/set_speakers.rs | 6 +- enclone_core/src/test_def.rs | 8 +- enclone_print/src/build_table_stuff.rs | 14 ++-- enclone_print/src/define_mat.rs | 30 +++---- enclone_print/src/filter.rs | 28 +++---- enclone_print/src/finish_table.rs | 2 +- enclone_print/src/gene_scan.rs | 12 +-- enclone_print/src/loupe.rs | 2 +- enclone_print/src/print_clonotypes.rs | 14 ++-- enclone_print/src/print_utils1.rs | 8 +- enclone_print/src/print_utils2.rs | 20 ++--- enclone_print/src/print_utils3.rs | 4 +- enclone_print/src/print_utils4.rs | 24 +++--- enclone_print/src/print_utils5.rs | 10 +-- enclone_print/src/proc_cvar_auto.rs | 10 +-- enclone_print/src/proc_lvar2.rs | 8 +- enclone_print/src/proc_lvar_auto.rs | 36 ++++---- enclone_ranger/src/stop.rs | 4 +- enclone_stuff/src/analyze_dref.rs | 10 +-- enclone_stuff/src/disintegrate.rs | 9 +- enclone_stuff/src/doublets.rs | 12 +-- enclone_stuff/src/fcell.rs | 12 ++- enclone_stuff/src/filter_umi.rs | 19 ++--- enclone_stuff/src/inconsistent.rs | 4 +- enclone_stuff/src/merge_onesies.rs | 6 +- enclone_stuff/src/some_filters.rs | 12 +-- enclone_stuff/src/split_orbits.rs | 6 +- enclone_stuff/src/start.rs | 26 ++---- enclone_stuff/src/vars.rs | 10 +-- enclone_stuff/src/weak_chains.rs | 4 +- enclone_vars/src/export_code.rs | 4 +- enclone_vars/src/var.rs | 2 +- hyperbase/src/lib.rs | 6 +- io_utils/src/lib.rs | 2 +- stats_utils/src/lib.rs | 12 +-- stirling_numbers/src/lib.rs | 2 +- string_utils/src/lib.rs | 2 +- tables/src/lib.rs | 4 +- vdj_ann/src/annotate.rs | 46 +++++------ vdj_ann/src/transcript.rs | 8 +- vdj_ann_ref/src/bin/build_supp_ref.rs | 2 +- vdj_ann_ref/src/bin/build_vdj_ref.rs | 18 ++-- vdj_ann_ref/src/bin/build_vdj_ref_exons.rs | 14 ++-- vdj_types/src/lib.rs | 2 +- 71 files changed, 447 insertions(+), 498 deletions(-) diff --git a/.cargo/config b/.cargo/config index 6abfcae1a..23702a96e 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,29 +1,68 @@ [build] rustflags = [ + # --- lint deny --- + # rustc lints + "-Dfuture_incompatible", + "-Dnonstandard_style", + "-Drust_2018_idioms", + "-Dunused", + "-D", "rust_2018_compatibility", + "-D", "rust_2021_compatibility", + + # clippy categorical + "-Dclippy::complexity", "-D", "clippy::perf", "-D", "clippy::style", "-D", "clippy::suspicious", - "-A", "clippy::comparison_chain", - "-W", "future_incompatible", - "-W", "nonstandard_style", - "-W", "rust_2018_compatibility", - "-W", "rust_2021_compatibility", - "-W", "unused", + + # clippy pedantic + "-Dclippy::cloned_instead_of_copied", "-D", "clippy::enum_glob_use", + "-Dclippy::explicit_deref_methods", + "-Dclippy::explicit_into_iter_loop", + "-Dclippy::explicit_iter_loop", + "-Dclippy::filter_map_next", + "-Dclippy::flat_map_option", + "-Dclippy::from_iter_instead_of_collect", + "-Dclippy::implicit_clone", + "-Dclippy::inefficient_to_string", + # we should audit the codebase for panics that should be errors before turning + # this lint on + # "-Dclippy::manual_assert", + "-Dclippy::manual_let_else", + "-Dclippy::manual_string_new", + "-Dclippy::map_unwrap_or", + "-Dclippy::match_wildcard_for_single_variants", + "-Dclippy::mut_mut", + "-Dclippy::needless_bitwise_bool", + "-Dclippy::needless_continue", + "-Dclippy::needless_for_each", + + "-Dclippy::semicolon_if_nothing_returned", + "-Dclippy::uninlined_format_args", + "-Dclippy::unused_self", + "-Dclippy::used_underscore_binding", + "-Dclippy::redundant_else", "-D", "clippy::needless_lifetimes", "-D", "clippy::redundant_closure_for_method_calls", "-D", "clippy::unused_io_amount", "-D", "clippy::wildcard_imports", "-D", "clippy::unnecessary_unwrap", "-D", "clippy::uninlined_format_args", - "-W", "clippy::disallowed_names", - "-W", "clippy::enum_variant_names", - "-W", "clippy::large-enum-variant", - "-W", "clippy::missing_safety_doc", + "-D", "clippy::disallowed_names", + "-D", "clippy::enum_variant_names", + "-D", "clippy::large-enum-variant", + "-D", "clippy::missing_safety_doc", + "-D", "clippy::result_unit_err", + # clippy nursery + "-Dclippy::needless_collect", + "-Dclippy::or_fun_call", + # --- lint allow --- + "-A", "clippy::comparison_chain", + # TODO: burn down these allow exceptions and then deny them "-A", "clippy::type_complexity", "-A", "clippy::too_many_arguments", "-A", "clippy::needless_range_loop", - "-W", "clippy::result_unit_err", ] [target.x86_64-unknown-linux-gnu] diff --git a/align_tools/src/lib.rs b/align_tools/src/lib.rs index 12722040f..b45ac8bd7 100644 --- a/align_tools/src/lib.rs +++ b/align_tools/src/lib.rs @@ -244,7 +244,7 @@ pub fn vis_align(s1: &[u8], s2: &[u8], ops: &[AlignmentOperation], width: usize) let mut start = 0; while start < n { let stop = min(start + width, n); - for seq in [&d, &t1, &t2].iter() { + for seq in &[&d, &t1, &t2] { x.append(&mut seq[start..stop].to_vec().clone()); x.push(b'\n'); } diff --git a/ansi_escape/src/ansi_to_html.rs b/ansi_escape/src/ansi_to_html.rs index d7e220243..89df57dd3 100644 --- a/ansi_escape/src/ansi_to_html.rs +++ b/ansi_escape/src/ansi_to_html.rs @@ -231,7 +231,7 @@ pub fn compress_ansi_escapes(x: &str) -> String { // Emit bold, then color, then background. - for e in escapes.iter() { + for e in &escapes { if e.solo() && e[0] == 1 { if reset || new_state.bold != old_state.bold { out += strme(&pack_ansi_escape(e)); @@ -395,7 +395,7 @@ impl ColorState { write!(s, "background-color:{};", self.background).unwrap(); } if self.bold { - s += "font-weight:bold;" + s += "font-weight:bold;"; } s += "\">"; s @@ -413,7 +413,7 @@ impl ColorState { write!(s, "fill: {};", self.color).unwrap(); } if self.bold { - s += "font-weight: bold;" + s += "font-weight: bold;"; } s += "\">"; s diff --git a/bio_edit/src/alignment/pairwise/mod.rs b/bio_edit/src/alignment/pairwise/mod.rs index 1136ee21f..ee1354b52 100644 --- a/bio_edit/src/alignment/pairwise/mod.rs +++ b/bio_edit/src/alignment/pairwise/mod.rs @@ -1388,7 +1388,7 @@ impl TracebackCell { "Expected a value <= TB_MAX while setting traceback bits" ); self.v = (self.v & !bits) // First clear the bits - | (value << pos) // And set the bits + | (value << pos); // And set the bits } #[inline(always)] diff --git a/enclone/src/allele.rs b/enclone/src/allele.rs index 77982c06c..0a1792ea4 100644 --- a/enclone/src/allele.rs +++ b/enclone/src/allele.rs @@ -11,7 +11,7 @@ use itertools::Itertools; use rayon::prelude::*; use stats_utils::percent_ratio; use std::cmp::{max, min, PartialOrd}; -use std::time::Instant; + use vector_utils::{erase_if, next_diff, next_diff1_2, next_diff1_3, reverse_sort, unique_sort}; // ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ @@ -102,7 +102,7 @@ pub fn find_alleles( } } let mut results = Vec::<(usize, Vec<(usize, usize, DnaString, usize, bool)>)>::new(); - for v in vs.iter() { + for v in &vs { results.push((*v, Vec::new())); } results.par_iter_mut().for_each(|res| { @@ -372,9 +372,9 @@ pub fn find_alleles( ); println!("{id} = |{}| = {}", refdata.id[id], refdata.name[id]); println!("ps = {}", ps.iter().format(",")); - for x in keep.iter() { + for x in &keep { let mut bases = String::new(); - for z in x.0.iter() { + for z in &x.0 { bases.push(*z as char); } print!("{bases} [{}] {:.1}", x.1, x.2); @@ -425,7 +425,7 @@ pub fn find_alleles( } } erase_if(&mut ps, &to_delete); - for j in keep.iter_mut() { + for j in &mut keep { erase_if(&mut j.0, &to_delete); } let mut keep0 = Vec::>::new(); @@ -437,7 +437,7 @@ pub fn find_alleles( // Save alternate references. - for x in keep.iter() { + for x in &keep { if !x.3 || analysis_mode { let mut b = refdata.refs[id].clone(); for (&x0, &ps) in x.0.iter().zip(ps.iter()) { @@ -512,7 +512,6 @@ pub fn sub_alts( info: &mut Vec, exact_clonotypes: &mut [ExactClonotype], ) { - let t = Instant::now(); for i in 0..info.len() { for j in 0..info[i].vs.len() { if info[i].vs[j].len() - ctl.heur.ref_v_trim <= info[i].tigs[j].len() { diff --git a/enclone/src/bin/post_process_test.rs b/enclone/src/bin/post_process_test.rs index 41ba74766..620d79721 100644 --- a/enclone/src/bin/post_process_test.rs +++ b/enclone/src/bin/post_process_test.rs @@ -18,7 +18,7 @@ fn main() { for line in stdin.lock().lines() { let line = line.unwrap(); let mut rejected = false; - for r in reject.iter() { + for r in &reject { if line.contains(r) { rejected = true; } diff --git a/enclone/src/innate.rs b/enclone/src/innate.rs index 0a2332b98..1f53597d9 100644 --- a/enclone/src/innate.rs +++ b/enclone/src/innate.rs @@ -236,7 +236,7 @@ pub fn mark_innate(refdata: &RefData, ex: &mut Vec) { } } } - for share in e.share.iter_mut() { + for share in &mut e.share { share.inkt_alpha_chain_gene_match = have_inkt_tra; share.inkt_alpha_chain_junction_match = have_inkt_tra_cdr3; share.inkt_beta_chain_gene_match = have_inkt_trb; diff --git a/enclone/src/join.rs b/enclone/src/join.rs index 08ad0aaff..62b976702 100644 --- a/enclone/src/join.rs +++ b/enclone/src/join.rs @@ -24,7 +24,7 @@ use rayon::prelude::*; use std::cmp::min; use std::collections::HashMap; use std::io::Write; -use std::time::Instant; + use vector_utils::{bin_member, erase_if, next_diff1_2}; pub fn join_exacts( @@ -42,7 +42,6 @@ pub fn join_exacts( // // Run special option for joining by barcode identity. - let timer1 = Instant::now(); if ctl.join_alg_opt.bcjoin { let mut eq: EquivRel = EquivRel::new(info.len() as i32); let mut bcx = Vec::<(String, usize)>::new(); // {(barcode, info_index)} @@ -105,8 +104,6 @@ pub fn join_exacts( println!("comparing {} simple clonotypes", info.len()); } - let timer2 = Instant::now(); - let joinf = |r: &mut ( usize, usize, @@ -119,7 +116,7 @@ pub fn join_exacts( let joins = &mut r.2; let errors = &mut r.3; let logplus = &mut r.4; - let mut pot = Vec::::new(); + let mut pot = Vec::>::new(); // Main join logic. If you change par_iter_mut to iter_mut above, and run happening, // a lot of time shows up on the following line. If further you manually inline join_core @@ -186,7 +183,7 @@ pub fn join_exacts( { let (k1, k2) = (x[0] as usize + i, x[1] as usize + i); let k = min(k1, k2); - for pj in to_pot[k - i].iter() { + for pj in &to_pot[k - i] { let cd = pot[*pj].cd; let shares = &pot[*pj].shares; @@ -256,10 +253,10 @@ pub fn join_exacts( fwriteln!(log, "\nJOIN ERROR"); } let (mut lena1, mut lena2) = (Vec::::new(), Vec::::new()); - for l1 in info[k1].origin.iter() { + for l1 in &info[k1].origin { lena1.push(ctl.origin_info.dataset_id[*l1].clone()); } - for l2 in info[k2].origin.iter() { + for l2 in &info[k2].origin { lena2.push(ctl.origin_info.dataset_id[*l2].clone()); } fwriteln!( @@ -287,7 +284,7 @@ pub fn join_exacts( fwrite!(log, "{}={}", t, refdata.transcript[*t]); } fwriteln!(log, ""); - for l1 in info[k1].origin.iter() { + for l1 in &info[k1].origin { fwriteln!( log, "{} = {}", @@ -295,7 +292,7 @@ pub fn join_exacts( ctl.origin_info.descrips[*l1] ); } - for l2 in info[k2].origin.iter() { + for l2 in &info[k2].origin { fwriteln!( log, "{} = {}", diff --git a/enclone/src/join2.rs b/enclone/src/join2.rs index 0840e7ea5..1097da8a8 100644 --- a/enclone/src/join2.rs +++ b/enclone/src/join2.rs @@ -5,7 +5,7 @@ use enclone_core::defs::{CloneInfo, EncloneControl}; use equiv::EquivRel; use stats_utils::percent_ratio; -use std::time::Instant; + use vector_utils::next_diff1_2; // ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ @@ -26,7 +26,6 @@ pub fn finish_join( // Tally results. let (mut joins, mut errors) = (0, 0); - let timer3 = Instant::now(); for r in results { joins += r.2; errors += r.3; diff --git a/enclone/src/misc1.rs b/enclone/src/misc1.rs index 1a4b4bbbe..12a81b3bf 100644 --- a/enclone/src/misc1.rs +++ b/enclone/src/misc1.rs @@ -122,7 +122,7 @@ pub fn lookup_heavy_chain_reuse( for z1 in 0..25 { for z2 in z1 + 1..25 { let mut xcdr3 = cdr3.clone(); - for cdr in xcdr3.iter_mut() { + for cdr in &mut xcdr3 { if cdr.0.len() > z2 { let mut t = cdr.0.as_bytes().to_vec(); t[z1] = b'*'; diff --git a/enclone/src/misc2.rs b/enclone/src/misc2.rs index 911ace84e..d477f1c5d 100644 --- a/enclone/src/misc2.rs +++ b/enclone/src/misc2.rs @@ -15,7 +15,7 @@ use std::collections::HashMap; use std::fmt::Write as _; use std::io::Write; -use std::time::Instant; + use string_utils::strme; use vdj_ann::refx::RefData; use vector_utils::{ @@ -278,7 +278,6 @@ pub fn find_exact_subclonotypes( let mut exact_clonotypes = Vec::::new(); let mut r = 0; let mut groups = Vec::<(usize, usize)>::new(); - let t = Instant::now(); while r < tig_bc.len() { let mut s = r + 1; while s < tig_bc.len() { @@ -322,7 +321,6 @@ pub fn find_exact_subclonotypes( r = s; } - let t = Instant::now(); let mut results = Vec::<( usize, Vec, @@ -400,15 +398,8 @@ pub fn find_exact_subclonotypes( // Explore consensus. - let mut _count = 0; - study_consensus( - &mut _count, - ctl, - &share, - &clones, - &exact_clonotypes, - refdata, - ); + let mut count = 0; + study_consensus(&mut count, ctl, &share, &clones, &exact_clonotypes, refdata); // Filter out putative gel bead contamination. @@ -424,7 +415,6 @@ pub fn find_exact_subclonotypes( } }); - let t = Instant::now(); let mut max_exact = 0; for i in 0..results.len() { if !results[i].1.is_empty() { diff --git a/enclone/src/misc3.rs b/enclone/src/misc3.rs index e703bea30..a56b0fa18 100644 --- a/enclone/src/misc3.rs +++ b/enclone/src/misc3.rs @@ -104,7 +104,7 @@ pub fn sort_tig_bc(ctl: &EncloneControl, tig_bc: &mut [Vec], refdata: & // - find code simplifications. pub fn study_consensus( - _count: &mut usize, + count: &mut usize, ctl: &EncloneControl, share: &[TigData1], clones: &[Vec], @@ -127,7 +127,7 @@ pub fn study_consensus( log, "\n[{}] rev lefts for exact subclonotype {}, chain {}, \ vs = {}, utrs = {}, cdr3 = {}\n", - *_count + 1, + *count + 1, exact_clonotypes.len(), z, v_ids.iter().format(","), @@ -197,7 +197,7 @@ pub fn study_consensus( } if !(minlen == maxlen && diffs == 0 && utr_ids.len() == 1) { print!("{}", strme(&log)); - *_count += 1; + *count += 1; } } } @@ -212,7 +212,7 @@ pub fn study_consensus( fwriteln!( log, "\n[{}] rights for exact subclonotype {}, chain {}, cs = {:?}\n", - *_count + 1, + *count + 1, exact_clonotypes.len(), z, c_ref_ids.iter().format(",") @@ -226,7 +226,7 @@ pub fn study_consensus( if x.len() > SHOW { x.truncate(SHOW); } - rights.push(x.to_vec()); + rights.push(x.clone()); bcs.push(clone[0].barcode.clone()); } let rconst = c_ref_ids @@ -310,7 +310,7 @@ pub fn study_consensus( } // if !( minlen == maxlen && diffs == 0 && utr_ids.len() == 1 ) { print!("{}", strme(&log)); - *_count += 1; + *count += 1; // } } } diff --git a/enclone_args/src/load_gex.rs b/enclone_args/src/load_gex.rs index d17d8bbe8..47f81399a 100644 --- a/enclone_args/src/load_gex.rs +++ b/enclone_args/src/load_gex.rs @@ -8,8 +8,8 @@ use enclone_core::defs::{EncloneControl, GexInfo}; use hdf5::Dataset; use rayon::prelude::*; +use std::collections::HashMap; use std::fmt::Write; -use std::{collections::HashMap, time::Instant}; use vector_utils::{bin_position, unique_sort}; // ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ @@ -52,7 +52,6 @@ pub fn get_gex_info(ctl: &mut EncloneControl) -> Result { &mut json_metrics, &mut metrics, )?; - let t = Instant::now(); if ctl.gen_opt.gene_scan_test.is_some() && !ctl.gen_opt.accept_inconsistent { let mut allf = gex_features.clone(); unique_sort(&mut allf); diff --git a/enclone_args/src/load_gex_core.rs b/enclone_args/src/load_gex_core.rs index af156c5b1..ca6a80fdf 100644 --- a/enclone_args/src/load_gex_core.rs +++ b/enclone_args/src/load_gex_core.rs @@ -13,7 +13,7 @@ use io_utils::{dir_list, open_for_read, open_userfile_for_read, path_exists}; use itertools::Itertools; use rayon::prelude::*; use serde_json::Value; -use std::{collections::HashMap, fmt::Write, fs::read_to_string, io::BufRead, time::Instant}; +use std::{collections::HashMap, fmt::Write, fs::read_to_string, io::BufRead}; use string_utils::{parse_csv, TextUtils}; use vector_utils::{unique_sort, VecUtils}; @@ -56,7 +56,6 @@ pub fn load_gex( json_metrics: &mut Vec>, metrics: &mut Vec, ) -> Result<(), String> { - let t = Instant::now(); let mut results = Vec::<(usize, LoadResult)>::new(); for i in 0..ctl.origin_info.gex_path.len() { results.push((i, LoadResult::default())); @@ -100,7 +99,7 @@ pub fn load_gex( "raw_gene_bc_matrices_h5.h5", "multi/count/raw_feature_bc_matrix.h5", ]; - for x in h5p.iter() { + for x in &h5p { let p = format!("{outs}/{x}"); if path_exists(&p) { pathlist.push(p.clone()); @@ -128,7 +127,7 @@ pub fn load_gex( analysis.push(format!("{outs}/count/analysis")); let pso1 = format!("{outs}/per_sample_outs"); let pso2 = format!("{outs}/../per_sample_outs"); - for pso in [pso1, pso2].iter() { + for pso in &[pso1, pso2] { if path_exists(pso) { let samples = dir_list(pso); if samples.solo() { @@ -150,7 +149,7 @@ pub fn load_gex( // Proceed. - for f in [pca_file.clone(), cluster_file.clone()].iter() { + for f in &[pca_file.clone(), cluster_file.clone()] { if !path_exists(f) { r.error = format!( "\nThe file\n{f}\ndoes not exist. \ @@ -166,9 +165,8 @@ pub fn load_gex( directory.\n" ); return; - } else { - pathlist.push(f.to_string()); } + pathlist.push(f.to_string()); } // Find metrics summary file. @@ -240,7 +238,7 @@ pub fn load_gex( let m = std::fs::read_to_string(&json_metrics_file).unwrap(); let v: Value = serde_json::from_str(&m).unwrap(); let z = v.as_object().unwrap(); - for (var, value) in z.iter() { + for (var, value) in z { if value.as_f64().is_some() { let value = value.as_f64().unwrap(); r.json_metrics.insert(var.to_string(), value); @@ -557,7 +555,6 @@ pub fn load_gex( // Test for error. - let t = Instant::now(); for (_, r) in &results { if !r.error.is_empty() { return Err(r.error.clone()); @@ -592,7 +589,7 @@ pub fn load_gex( "Gene Expression,GRCh38 Median UMI counts per cell (20k raw reads per cell)", ), ]; - for x in extras.iter() { + for x in &extras { let metric_name = x.0.to_string(); let metric_display_name = x.1.to_string(); let mut have = false; @@ -602,7 +599,7 @@ pub fn load_gex( } } if have { - for (_, result) in results.iter_mut() { + for (_, result) in &mut results { let mut value = String::new(); if result.json_metrics.contains_key(&metric_name) { value = format!("{:.3}", result.json_metrics[&metric_name]); @@ -612,7 +609,7 @@ pub fn load_gex( } } - for (_, r) in results.into_iter() { + for (_, r) in results { gex_features.push(r.gex_features); gex_barcodes.push(r.gex_barcodes); gex_mults.push(r.gex_mult.unwrap_or(1.0)); diff --git a/enclone_args/src/load_gex_util.rs b/enclone_args/src/load_gex_util.rs index c0cd64360..bec9577c5 100644 --- a/enclone_args/src/load_gex_util.rs +++ b/enclone_args/src/load_gex_util.rs @@ -11,7 +11,7 @@ pub fn find_pca_file( pathlist: &mut Vec, ) -> String { let mut pca_file = String::new(); - for x in analysis.iter() { + for x in analysis { pca_file = format!("{x}/pca/10_components/projection.csv"); if path_exists(&pca_file) { pathlist.push(pca_file.clone()); @@ -34,7 +34,7 @@ pub fn find_json_metrics_file( ) -> String { let mut json_metrics_file = String::new(); if !ctl.gen_opt.cellranger { - for x in analysis.iter() { + for x in analysis { let f = format!("{x}/metrics_summary_json.json"); if path_exists(&f) { json_metrics_file = f.clone(); @@ -54,7 +54,7 @@ pub fn find_feature_metrics_file( ) -> String { let mut feature_metrics_file = String::new(); if !ctl.gen_opt.cellranger { - for x in analysis.iter() { + for x in analysis { let f = format!("{x}/per_feature_metrics.csv"); if path_exists(&f) { feature_metrics_file = f.clone(); @@ -94,7 +94,7 @@ pub fn find_cluster_file( pathlist: &mut Vec, ) -> String { let mut cluster_file = String::new(); - for x in analysis.iter() { + for x in analysis { cluster_file = format!("{x}/clustering/graphclust/clusters.csv"); if path_exists(&cluster_file) { pathlist.push(cluster_file.clone()); diff --git a/enclone_args/src/proc_args.rs b/enclone_args/src/proc_args.rs index f9795ba4e..783523371 100644 --- a/enclone_args/src/proc_args.rs +++ b/enclone_args/src/proc_args.rs @@ -11,7 +11,7 @@ use enclone_core::test_def::replace_at_test; use enclone_core::{require_readable_file, tilde_expand_me}; use itertools::Itertools; use std::fmt::Write; -use std::{process::Command, time::Instant}; +use std::process::Command; use string_utils::{strme, TextUtils}; // Process arguments. @@ -20,7 +20,6 @@ pub fn proc_args(ctl: &mut EncloneControl, args: &[String]) -> Result<(), String // // Start. - let targs = Instant::now(); let evil_eye = ctl.gen_opt.evil_eye; if evil_eye { println!("processing args"); @@ -261,7 +260,7 @@ pub fn proc_args(ctl: &mut EncloneControl, args: &[String]) -> Result<(), String } } const F: &str = include_str!["enclone.testdata.bcr.gex"]; - for n in y.iter() { + for n in &y { if *n != "m1" { if n.parse::().is_err() || n.force_usize() < 1 || n.force_usize() > 47 { return Err( diff --git a/enclone_args/src/proc_args2.rs b/enclone_args/src/proc_args2.rs index 49de3c519..2280522a6 100644 --- a/enclone_args/src/proc_args2.rs +++ b/enclone_args/src/proc_args2.rs @@ -5,7 +5,7 @@ use io_utils::{open_userfile_for_read, path_exists}; use rayon::prelude::*; use std::fmt::Write; use std::fs::{remove_file, File}; -use std::{io::BufRead, time::Instant}; +use std::io::BufRead; use string_utils::TextUtils; use vector_utils::next_diff; @@ -71,12 +71,11 @@ pub fn is_usize_arg(arg: &str, x: &str) -> Result { let val = arg.after(&format!("{x}=")).parse::(); if val.is_ok() { return Ok(true); - } else { - return Err(format!( - "\nYour command line includes \"{arg}\", which is not a valid argument.\n\ - Perhaps you meant \"{x}=n\", where n >= 0 is an integer.\n" - )); } + return Err(format!( + "\nYour command line includes \"{arg}\", which is not a valid argument.\n\ + Perhaps you meant \"{x}=n\", where n >= 0 is an integer.\n" + )); } Ok(false) } @@ -93,12 +92,11 @@ pub fn is_i32_arg(arg: &str, x: &str) -> Result { let val = arg.after(&format!("{x}=")).parse::(); if val.is_ok() { return Ok(true); - } else { - return Err(format!( - "\nYour command line includes \"{arg}\", which is not a valid argument.\n\ - Perhaps you meant \"{x}=n\", where n is an integer.\n" - )); } + return Err(format!( + "\nYour command line includes \"{arg}\", which is not a valid argument.\n\ + Perhaps you meant \"{x}=n\", where n is an integer.\n" + )); } Ok(false) } @@ -113,12 +111,11 @@ pub fn is_f64_arg(arg: &str, x: &str) -> Result { let val = arg.after(&format!("{x}=")).parse::(); if val.is_ok() { return Ok(true); - } else { - return Err(format!( - "\nYour command line includes \"{arg}\", which is not a valid argument.\n\ - Perhaps you meant \"{x}=n\", where n is a floating point number.\n" - )); } + return Err(format!( + "\nYour command line includes \"{arg}\", which is not a valid argument.\n\ + Perhaps you meant \"{x}=n\", where n is a floating point number.\n" + )); } Ok(false) } @@ -138,7 +135,6 @@ pub fn is_string_arg(arg: &str, x: &str) -> Result { // ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ pub fn proc_args_tail(ctl: &mut EncloneControl, args: &[String]) -> Result<(), String> { - let tall = Instant::now(); let mut lvars_specified = false; for arg in args.iter().skip(1) { if arg.starts_with("LVARS=") { @@ -205,7 +201,7 @@ pub fn proc_args_tail(ctl: &mut EncloneControl, args: &[String]) -> Result<(), S if ctl.gen_opt.internal_run || ctl.gen_opt.descrip || ctl.gen_opt.vis_dump { ctl.origin_info.descrips.clear(); - let mut results = vec![(0, "".to_string()); ctl.origin_info.n()]; + let mut results = vec![(0, String::new()); ctl.origin_info.n()]; for i in 0..ctl.origin_info.n() { results[i].0 = i; } diff --git a/enclone_args/src/proc_args3.rs b/enclone_args/src/proc_args3.rs index 24a7a9af8..b4ad6ba62 100644 --- a/enclone_args/src/proc_args3.rs +++ b/enclone_args/src/proc_args3.rs @@ -15,7 +15,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::thread; use std::time; -use std::time::Instant; + use string_utils::TextUtils; use vector_utils::unique_sort; @@ -93,11 +93,10 @@ fn expand_analysis_sets(x: &str, ctl: &EncloneControl) -> Result tokens2.push(id.to_string()); } continue; - } else { - return Err(format!( - "\nIt looks like you've provided an incorrect analysis set ID {setid}.\n" - )); } + return Err(format!( + "\nIt looks like you've provided an incorrect analysis set ID {setid}.\n" + )); } else if setid.parse::().is_ok() { let mut set_file = format!("~/enclone/sets/{setid}"); tilde_expand_me(&mut set_file); @@ -129,7 +128,7 @@ fn expand_analysis_sets(x: &str, ctl: &EncloneControl) -> Result // Functions to find the path to data. pub fn get_path_fail(p: &str, ctl: &EncloneControl, source: &str) -> Result { - for x in ctl.gen_opt.pre.iter() { + for x in &ctl.gen_opt.pre { let pp = format!("{x}/{p}"); if path_exists(&pp) { return Ok(pp); @@ -144,35 +143,33 @@ pub fn get_path_fail(p: &str, ctl: &EncloneControl, source: &str) -> Result String { *ok = false; - for x in ctl.gen_opt.pre.iter() { + for x in &ctl.gen_opt.pre { let mut pp = format!("{x}/{p}"); if pp.starts_with('~') { tilde_expand_me(&mut pp); @@ -222,7 +219,7 @@ fn get_path_or_internal_id( msg += "In fact, there are no configuration variables.\n"; } else { msg += "Here are the configuration variables that are defined:\n\n"; - for (key, value) in ctl.gen_opt.config.iter() { + for (key, value) in &ctl.gen_opt.config { write!(msg, "{key} = {value}").unwrap(); } msg += "\n"; @@ -264,14 +261,13 @@ fn get_path_or_internal_id( if filesystem access blinks in and out of existence,\n\ other more cryptic events are likely to occur.\n" )); - } else { - return Err(format!( - "\nIt looks like you've provided an analysis ID for \ + } + return Err(format!( + "\nIt looks like you've provided an analysis ID for \ which the pipeline outs folder\n{p}\nhas not yet been generated.\n\ This path did not exist:\n{pp}\n\n\ Here is the stdout:\n{m}\n" - )); - } + )); } } else { return Err(format!( @@ -341,8 +337,8 @@ fn parse_bc(mut bc: String, ctl: &mut EncloneControl, call_type: &str) -> Result "\nThe file\n{bc}\n{origin}\nis missing the barcode field.\n", )); } - for x in fields.iter() { - fieldnames.push(x.to_string()); + for x in &fields { + fieldnames.push((*x).to_string()); } for i in 0..fields.len() { if fields[i] == "color" { @@ -449,7 +445,6 @@ pub fn proc_xcr( { return Err("\nOnly one of TCR, BCR, or TCRGD can be specified.\n".to_string()); } - let t = Instant::now(); ctl.gen_opt.tcr = f.starts_with("TCR="); ctl.gen_opt.tcrgd = f.starts_with("TCRGD="); ctl.gen_opt.bcr = f.starts_with("BCR="); @@ -508,7 +503,6 @@ pub fn proc_xcr( )); } - let t = Instant::now(); for (id, d) in donor_groups.iter().enumerate() { let origin_groups = if ctl.gen_opt.cellranger { vec![&d[..]] @@ -551,7 +545,7 @@ pub fn proc_xcr( } else { (*s).split(',').collect::>() }; - for ds in datasets.iter_mut() { + for ds in &mut datasets { if ds.ends_with('/') { *ds = ds.rev_before("/"); } @@ -586,7 +580,7 @@ pub fn proc_xcr( } } for (ix, x) in datasets.iter().enumerate() { - ctl.origin_info.color.push("".to_string()); + ctl.origin_info.color.push(String::new()); ctl.origin_info.tag.push(HashMap::::new()); let donor_name = format!("d{}", id + 1); let origin_name = format!("s{}", is + 1); @@ -615,7 +609,6 @@ pub fn proc_xcr( // clock time for these can add up. There should be a way to do this that does not involve // multithreading. - let t = Instant::now(); let source = if f.contains('=') { f.before("=") } else { f }; let mut results = Vec::<(String, String, bool, String)>::new(); for (id, d) in donor_groups.iter().enumerate() { @@ -641,7 +634,6 @@ pub fn proc_xcr( } } - let t = Instant::now(); let spinlock: Arc = Arc::new(AtomicUsize::new(0)); results.par_iter_mut().for_each(|res| { let (p, pg) = (&mut res.0, &mut res.1); @@ -718,7 +710,7 @@ pub fn proc_meta_core(lines: &[String], ctl: &mut EncloneControl) -> Result<(), "tcrgd".to_string(), "color".to_string(), ]; - for x in fields.iter() { + for x in &fields { if !allowed_fields.contains(x) { return Err(format!( "\nThe CSV file that you specified using the META or METAX argument \ @@ -771,8 +763,8 @@ pub fn proc_meta_core(lines: &[String], ctl: &mut EncloneControl) -> Result<(), let mut gpath = String::new(); let mut origin = "s1".to_string(); let mut donor = "d1".to_string(); - let mut color = "".to_string(); - let mut bc = "".to_string(); + let mut color = String::new(); + let mut bc = String::new(); for i in 0..fields.len() { let x = &fields[i]; let mut y = val[i].to_string(); @@ -843,8 +835,7 @@ pub fn proc_meta_core(lines: &[String], ctl: &mut EncloneControl) -> Result<(), let dp = donors .iter() .enumerate() - .filter_map(|(j, dj)| if donor == *dj { Some(j) } else { None }) - .next(); + .find_map(|(j, dj)| if donor == *dj { Some(j) } else { None }); if dp.is_none() { donors.push(donor.clone()); } @@ -862,7 +853,7 @@ pub fn proc_meta_core(lines: &[String], ctl: &mut EncloneControl) -> Result<(), pub fn proc_meta(v: &[String], ctl: &mut EncloneControl) -> Result<(), String> { let mut lines_all = Vec::>::new(); - for f in v.iter() { + for f in v { if !path_exists(f) { return Err(format!( "\nCan't find the file {f} referenced by your META argument.\n" diff --git a/enclone_args/src/proc_args_check.rs b/enclone_args/src/proc_args_check.rs index 2a3985dfb..00a9fb83f 100644 --- a/enclone_args/src/proc_args_check.rs +++ b/enclone_args/src/proc_args_check.rs @@ -10,7 +10,7 @@ use enclone_core::defs::{EncloneControl, GexInfo}; use itertools::Itertools; use rayon::prelude::*; use regex::Regex; -use std::time::Instant; + use string_utils::{strme, TextUtils}; use vector_utils::{bin_member, unique_sort}; @@ -40,23 +40,23 @@ pub fn get_known_features(gex_info: &GexInfo) -> Result, String> { } for z in 0..2 { if ff[2].starts_with("Antibody") { - for s in suffixes.iter() { + for s in &suffixes { res.1.push(format!("{}_ab{s}", ff[z])); } } else if ff[2].starts_with("CRISPR") { - for s in suffixes.iter() { + for s in &suffixes { res.1.push(format!("{}_cr{s}", ff[z])); } } else if ff[2].starts_with("CUSTOM") { - for s in suffixes.iter() { + for s in &suffixes { res.1.push(format!("{}_cu{s}", ff[z])); } } else if ff[2].starts_with("Antigen") { - for s in suffixes.iter() { + for s in &suffixes { res.1.push(format!("{}_ag{s}", ff[z])); } } else { - for s in suffixes_g.iter() { + for s in &suffixes_g { res.1.push(format!("{}_g{s}", ff[z])); } } @@ -84,8 +84,8 @@ pub fn involves_gex_fb(x: &str) -> bool { ]; let suffixes = ["", "_min", "_max", "_μ", "_Σ"]; let mut ends = Vec::::new(); - for z in ends0.iter() { - for y in suffixes.iter() { + for z in &ends0 { + for y in &suffixes { ends.push(format!("{z}{y}")); } } @@ -187,16 +187,15 @@ fn check_gene_fb( "\nParseable field {x} does not make sense because neither gene expression \ nor feature barcode data\nwere provided as input.\n" )); - } else { - return Err(format!( - "\nLead variable {x} does not make sense because neither gene expression \ - not feature barcode data\nwere provided as input.\n" - )); } + return Err(format!( + "\nLead variable {x} does not make sense because neither gene expression \ + not feature barcode data\nwere provided as input.\n" + )); } if !gex_info.have_gex { let mut problem = false; - for y in g_ends.iter() { + for y in &g_ends { if x.ends_with(y) { problem = true; } @@ -215,12 +214,11 @@ fn check_gene_fb( "\nParseable field {x} does not make sense because gene expression \ data\nwere not provided as input.\n" )); - } else { - return Err(format!( - "\nLead variable {x} does not make sense because gene expression \ - data\nwere not provided as input.\n" - )); } + return Err(format!( + "\nLead variable {x} does not make sense because gene expression \ + data\nwere not provided as input.\n" + )); } } if !gex_info.have_fb { @@ -234,12 +232,11 @@ fn check_gene_fb( "\nParseable field {x} does not make sense because feature \ barcode data\nwere not provided as input.\n" )); - } else { - return Err(format!( - "\nLead variable {x} does not make sense because feature barcode \ - data\nwere not provided as input.\n" - )); } + return Err(format!( + "\nLead variable {x} does not make sense because feature barcode \ + data\nwere not provided as input.\n" + )); } } } @@ -345,7 +342,7 @@ fn check_gene_fb( } if !n_var { let mut alts = Vec::<&str>::new(); - for y in known_features.iter() { + for y in &known_features { if x.eq_ignore_ascii_case(y) { alts.push(y.as_str()); } @@ -366,23 +363,22 @@ fn check_gene_fb( "\nThe variable {x} for LVARS is unrecognized. Please type \ \"enclone help lvars\".\n" )); - } else { - if !alts.is_empty() { - return Err(format!( - "\nUnrecognized parseable variable {}. Might you have meant {}?\n\ + } + if !alts.is_empty() { + return Err(format!( + "\nUnrecognized parseable variable {}. Might you have meant {}?\n\ Please type \ \"enclone help parseable\".\nIf the variable is a chain variable \ (cvar), please make sure it is suffixed with the chain index.\n", - x, - alts.iter().format(" or "), - )); - } - return Err(format!( - "\nUnrecognized parseable variable {x}. Please type \ - \"enclone help parseable\".\nIf the variable is a chain variable (cvar), \ - please make sure it is suffixed with the chain index.\n" + x, + alts.iter().format(" or "), )); } + return Err(format!( + "\nUnrecognized parseable variable {x}. Please type \ + \"enclone help parseable\".\nIf the variable is a chain variable (cvar), \ + please make sure it is suffixed with the chain index.\n" + )); } } } @@ -410,7 +406,7 @@ pub fn check_pcols( let pchains = &ctl.parseable_opt.pchains; let ends = build_ends(); let mut nd_used = false; - for x in cols.iter() { + for x in cols { let mut x = x.to_string(); if x.contains(':') { x = x.after(":").to_string(); @@ -428,7 +424,7 @@ pub fn check_pcols( if bin_member(&alt_bcs, &x) { ok = true; } - for y in ctl.clono_print_opt.lvars.iter() { + for y in &ctl.clono_print_opt.lvars { if y.contains(':') { let y = y.before(":"); if x == y { @@ -436,12 +432,12 @@ pub fn check_pcols( } } } - for y in PLVARS_ALLOWED.iter() { + for y in &PLVARS_ALLOWED { if x == *y { ok = true; } } - for y in ctl.origin_info.dataset_list.iter() { + for y in &ctl.origin_info.dataset_list { if *x == format!("{y}_barcodes") { ok = true; } @@ -450,7 +446,7 @@ pub fn check_pcols( if x == "barcode" { ok = true; } - for y in ctl.origin_info.dataset_list.iter() { + for y in &ctl.origin_info.dataset_list { if *x == format!("{y}_barcode") { ok = true; } @@ -522,7 +518,7 @@ pub fn check_pcols( // Check cvars args. pub fn check_cvars(ctl: &EncloneControl) -> Result<(), String> { - for x in ctl.clono_print_opt.cvars.iter() { + for x in &ctl.clono_print_opt.cvars { let mut x = x.to_string(); if x.contains(':') { x = x.after(":").to_string(); @@ -736,9 +732,8 @@ pub fn check_one_lvar( "\nUnrecognized variable {x} for LVARS. Please type \ \"enclone help lvars\".\n" )); - } else { - return Ok(false); } + return Ok(false); } Ok(true) } @@ -751,8 +746,8 @@ pub fn build_ends() -> Vec { "_g", "_ab", "_ag", "_cr", "_cu", "_g_μ", "_ab_μ", "_ag_μ", "_cr_μ", "_cu_μ", "_g_%", ]; let suffixes = ["", "_min", "_max", "_μ", "_Σ"]; - for x in ends0.iter() { - for y in suffixes.iter() { + for x in &ends0 { + for y in &suffixes { ends.push(format!("{x}{y}")); } } @@ -764,11 +759,10 @@ pub fn build_ends() -> Vec { // Check lvars args. pub fn check_lvars(ctl: &EncloneControl, gex_info: &GexInfo) -> Result<(), String> { - let t = Instant::now(); let mut to_check = Vec::::new(); let ends = build_ends(); let mut nd_used = false; - for x in ctl.clono_print_opt.lvars.iter() { + for x in &ctl.clono_print_opt.lvars { if x.ends_with("_cell") { return Err( "\nFields ending with _cell cannot be used in LVARS or LVARSP.\n".to_string(), @@ -779,7 +773,6 @@ pub fn check_lvars(ctl: &EncloneControl, gex_info: &GexInfo) -> Result<(), Strin } } - let t = Instant::now(); if !to_check.is_empty() { check_gene_fb(ctl, gex_info, &to_check, "lead")?; } @@ -792,7 +785,7 @@ pub fn check_lvars(ctl: &EncloneControl, gex_info: &GexInfo) -> Result<(), Strin // Check gvars args. pub fn check_gvars(ctl: &EncloneControl) -> Result<(), String> { - for x in ctl.gen_opt.gvars.iter() { + for x in &ctl.gen_opt.gvars { if !GVARS_ALLOWED.contains(&x.as_str()) { return Err(format!("\nUnknown global variable {x}.\n")); } diff --git a/enclone_args/src/proc_args_post.rs b/enclone_args/src/proc_args_post.rs index 1f12161ea..8b2b1bed2 100644 --- a/enclone_args/src/proc_args_post.rs +++ b/enclone_args/src/proc_args_post.rs @@ -11,7 +11,7 @@ use expr_tools::vars_of_node; use io_utils::{open_for_read, open_userfile_for_read, path_exists}; use std::collections::HashMap; use std::io::BufRead; -use std::time::Instant; + use string_utils::{parse_csv, TextUtils}; use vector_utils::{bin_member, next_diff, sort_sync2, unique_sort}; @@ -50,8 +50,8 @@ fn parse_bc_joint(ctl: &mut EncloneControl) -> Result<(), String> { if !fields.contains(&"barcode") { return Err(format!("\nThe file\n{bc}\nis missing the barcode field.\n",)); } - for x in fields.iter() { - fieldnames.push(x.to_string()); + for x in &fields { + fieldnames.push((*x).to_string()); } for (i, field) in fields.into_iter().enumerate() { if field == "color" { @@ -157,7 +157,6 @@ pub fn proc_args_post( ) -> Result<(), String> { // Process INFO. - let t = Instant::now(); if ctl.gen_opt.info.is_some() { let f = open_for_read![&ctl.gen_opt.info.as_ref().unwrap()]; let mut lines = Vec::::new(); @@ -206,7 +205,7 @@ pub fn proc_args_post( vj2 = vals[i].to_string(); } else { other.push(vals[i].to_string()); - let mut log10_val = "".to_string(); + let mut log10_val = String::new(); if vals[i].parse::().is_ok() { let val = vals[i].force_f64(); if val > 0.0 { @@ -250,7 +249,7 @@ pub fn proc_args_post( &mut ctl.gen_opt.dref_file, &mut ctl.parseable_opt.pout, ]; - for f in files.iter_mut() { + for f in &mut files { tilde_expand_me(f); } @@ -491,7 +490,6 @@ pub fn proc_args_post( // Process TCR, BCR and META. - let t = Instant::now(); check_cvars(ctl)?; if !metas.is_empty() { let mut v = Vec::::with_capacity(metas.len()); @@ -528,10 +526,9 @@ pub fn proc_args_post( // More argument sanity checking. - let t = Instant::now(); if ctl.clono_filt_opt.dataset.is_some() { let d = &ctl.clono_filt_opt.dataset.as_ref().unwrap(); - for x in d.iter() { + for x in *d { if !ctl.origin_info.dataset_id.contains(x) { return Err(format!( "\nDATASET argument has {} in it, which is not a known \ @@ -551,7 +548,7 @@ pub fn proc_args_post( ]; if !ctl.gen_opt.bcr { for arg in &args[1..] { - for x in bcr_only.iter() { + for x in &bcr_only { if arg == x || arg.starts_with(&format!("{x}=")) { return Err(format!("\nThe option {x} does not make sense for TCR.\n")); } @@ -638,15 +635,15 @@ pub fn proc_args_post( let mut origin_for_bc = Vec::::new(); let mut donor_for_bc = Vec::::new(); for i in 0..ctl.origin_info.n() { - for x in ctl.origin_info.origin_for_bc[i].iter() { + for x in &ctl.origin_info.origin_for_bc[i] { origins.push(x.1.clone()); origin_for_bc.push(x.1.clone()); } - for x in ctl.origin_info.donor_for_bc[i].iter() { + for x in &ctl.origin_info.donor_for_bc[i] { donors.push(x.1.clone()); donor_for_bc.push(x.1.clone()); } - for x in ctl.origin_info.tag[i].iter() { + for x in &ctl.origin_info.tag[i] { tags.push((x.1).clone()); } donors.push(ctl.origin_info.donor_id[i].clone()); diff --git a/enclone_args/src/process_special_arg2.rs b/enclone_args/src/process_special_arg2.rs index 65ef7b695..a0bfe6cac 100644 --- a/enclone_args/src/process_special_arg2.rs +++ b/enclone_args/src/process_special_arg2.rs @@ -465,7 +465,7 @@ pub fn process_special_arg2( .extend(arg.after("PCOLS_SHOW=").split(',').map(str::to_string)); } else if arg.starts_with("VJ=") { ctl.clono_filt_opt.vj = arg.after("VJ=").as_bytes().to_vec(); - for &c in ctl.clono_filt_opt.vj.iter() { + for &c in &ctl.clono_filt_opt.vj { if !(c == b'A' || c == b'C' || c == b'G' || c == b'T') { return Err("\nIllegal value for VJ, must be over alphabet ACGT.\n".to_string()); } @@ -477,7 +477,7 @@ pub fn process_special_arg2( ctl.clono_print_opt.amino.push(x.to_string()); } } - for x in ctl.clono_print_opt.amino.iter() { + for x in &ctl.clono_print_opt.amino { let mut ok = false; if *x == "cdr1" || *x == "cdr2" @@ -515,7 +515,7 @@ pub fn process_special_arg2( ctl.clono_print_opt.cvars.push(x.to_string()); } } - for x in ctl.clono_print_opt.cvars.iter_mut() { + for x in &mut ctl.clono_print_opt.cvars { *x = x.replace("_sum", "_Σ"); *x = x.replace("_mean", "_μ"); } @@ -525,7 +525,7 @@ pub fn process_special_arg2( ctl.clono_print_opt.cvars.push(x.to_string()); } } - for x in ctl.clono_print_opt.cvars.iter_mut() { + for x in &mut ctl.clono_print_opt.cvars { *x = x.replace("_sum", "_Σ"); *x = x.replace("_mean", "_μ"); } @@ -534,7 +534,7 @@ pub fn process_special_arg2( for x in arg.after("LVARS=").split(',') { ctl.clono_print_opt.lvars.push(x.to_string()); } - for x in ctl.clono_print_opt.lvars.iter_mut() { + for x in &mut ctl.clono_print_opt.lvars { *x = x.replace("_sum", "_Σ"); *x = x.replace("_mean", "_μ"); } @@ -543,7 +543,7 @@ pub fn process_special_arg2( for x in lvarsp { ctl.clono_print_opt.lvars.push(x.to_string()); } - for x in ctl.clono_print_opt.lvars.iter_mut() { + for x in &mut ctl.clono_print_opt.lvars { *x = x.replace("_sum", "_Σ"); *x = x.replace("_mean", "_μ"); } diff --git a/enclone_args/src/read_json.rs b/enclone_args/src/read_json.rs index d66fceb31..c081b0ca9 100644 --- a/enclone_args/src/read_json.rs +++ b/enclone_args/src/read_json.rs @@ -605,7 +605,7 @@ fn read_json( LazyJsonReader::with_reader(BufReader::new(open_maybe_compressed(&jsonx))) .map_err(|err| format!("{err:#?}"))?; - for entry in reader.into_iter() { + for entry in reader { let result = process_json_annotation( entry.map_err(|err| err.to_string())?, json, diff --git a/enclone_core/src/align_to_vdj_ref.rs b/enclone_core/src/align_to_vdj_ref.rs index cdfe7a654..bab87a6a8 100644 --- a/enclone_core/src/align_to_vdj_ref.rs +++ b/enclone_core/src/align_to_vdj_ref.rs @@ -139,7 +139,7 @@ pub fn cigar( _ => {} }; - let mut cigar = "".to_owned(); + let mut cigar = String::new(); if ops.is_empty() { return cigar; } @@ -149,7 +149,7 @@ pub fn cigar( write!(cigar, "{xstart}{clip_str}").unwrap(); } let mut k = 1; - for &op in ops[1..].iter() { + for &op in &ops[1..] { if op == last { k += 1; } else { @@ -160,7 +160,7 @@ pub fn cigar( } add_op(last, k, &mut cigar); if xlen > xend { - write!(cigar, "{}{clip_str}", xlen - xend).unwrap() + write!(cigar, "{}{clip_str}", xlen - xend).unwrap(); } cigar } @@ -329,7 +329,7 @@ pub fn align_to_vdj_ref( j += 1; } let k = j - i; - for bi in [b1, b2, b3].iter() { + for bi in &[b1, b2, b3] { let bi = *bi; // Maybe can shift right one. @@ -366,7 +366,7 @@ pub fn align_to_vdj_ref( i = j; } } - for x in edits.iter() { + for x in &edits { ops[x.0] = x.1; } @@ -401,7 +401,7 @@ pub fn align_to_vdj_ref( println!("seq = {}", strme(seq)); println!("ref = {}", strme(&concat)); use itertools::Itertools; - for zo in zos1.iter() { + for zo in &zos1 { print!("{}", zo.iter().format("")); } println!(); diff --git a/enclone_core/src/join_one.rs b/enclone_core/src/join_one.rs index aa5df576d..fd6846ee5 100644 --- a/enclone_core/src/join_one.rs +++ b/enclone_core/src/join_one.rs @@ -449,14 +449,14 @@ pub fn join_one<'a>( // Reject if barcode overlap. (not documented) let (mut bcs1, mut bcs2) = (Vec::<&'a str>::new(), Vec::<&'a str>::new()); - for origin in info[k1].origin.iter() { + for origin in &info[k1].origin { bcs1.extend( to_bc[&(*origin, info[k1].clonotype_id)] .iter() .map(String::as_str), ); } - for origin in info[k2].origin.iter() { + for origin in &info[k2].origin { bcs2.extend( to_bc[&(*origin, info[k2].clonotype_id)] .iter() @@ -645,9 +645,8 @@ pub fn join_one<'a>( } i += indel.1 as usize; continue 'seq; - } else { - ref_pos += -indel.1 as usize; } + ref_pos += -indel.1 as usize; } } if i >= n || ref_pos >= concat.len() { diff --git a/enclone_core/src/lib.rs b/enclone_core/src/lib.rs index bf914f99f..93853762a 100644 --- a/enclone_core/src/lib.rs +++ b/enclone_core/src/lib.rs @@ -36,10 +36,10 @@ use tilde_expand::tilde_expand; // tilde_expand_me: not that this is NOT implementd for Windows -pub fn tilde_expand_me(_s: &mut String) { +pub fn tilde_expand_me(s: &mut String) { #[cfg(not(target_os = "windows"))] { - *_s = stringme(&tilde_expand(_s.as_bytes())); + *s = stringme(&tilde_expand(s.as_bytes())); } } diff --git a/enclone_core/src/linear_condition.rs b/enclone_core/src/linear_condition.rs index 051fb147d..2de73d80f 100644 --- a/enclone_core/src/linear_condition.rs +++ b/enclone_core/src/linear_condition.rs @@ -90,7 +90,7 @@ impl LinearCondition { } else { parts.push(stringme(&lhsx[last + 1..])); } - for part in parts.iter_mut() { + for part in &mut parts { *part = part.replace('(', ""); *part = part.replace(')', ""); if part.contains('*') { diff --git a/enclone_core/src/opt_d.rs b/enclone_core/src/opt_d.rs index 2c95709df..5c0615dfb 100644 --- a/enclone_core/src/opt_d.rs +++ b/enclone_core/src/opt_d.rs @@ -139,7 +139,7 @@ pub fn opt_d( // Go through every D segment, or possibly every concatenation of D segments. let mut todo = vec![vec![]]; - for i in refdata.ds.iter() { + for i in &refdata.ds { todo.push(vec![*i]); } let mut ds = Vec::>::new(); diff --git a/enclone_core/src/set_speakers.rs b/enclone_core/src/set_speakers.rs index 6ffa43cd5..3f6fab658 100644 --- a/enclone_core/src/set_speakers.rs +++ b/enclone_core/src/set_speakers.rs @@ -53,7 +53,7 @@ pub fn set_speakers(ctl: &EncloneControl, parseable_fields: &mut Vec, ma all_lvars.push(x.to_string()); } } - for x in all_lvars.iter() { + for x in &all_lvars { if (*x == "sec" || *x == "mem") && !ctl.gen_opt.using_secmem { continue; } @@ -115,14 +115,14 @@ pub fn set_speakers(ctl: &EncloneControl, parseable_fields: &mut Vec, ma speaker!("clonotype_id"); speaker!("exact_subclonotype_id"); speaker!("barcodes"); - for x in ctl.origin_info.dataset_list.iter() { + for x in &ctl.origin_info.dataset_list { if !x.is_empty() { speaker!(&format!("{x}_barcodes")); } } if ctl.parseable_opt.pbarcode { speaker!("barcode"); - for x in ctl.origin_info.dataset_list.iter() { + for x in &ctl.origin_info.dataset_list { speaker!(&format!("{x}_barcode")); } } diff --git a/enclone_core/src/test_def.rs b/enclone_core/src/test_def.rs index 6fe68f45f..8f9993796 100644 --- a/enclone_core/src/test_def.rs +++ b/enclone_core/src/test_def.rs @@ -33,28 +33,28 @@ pub fn replace_at_test(x: &mut String) { pub fn test_donor_id(x: usize) -> usize { let test1 = expand_integer_ranges(&TEST1.replace(':', ",")); let test1 = test1.split(',').collect::>(); - for t in test1.iter() { + for t in &test1 { if t.force_usize() == x { return 1; } } let test2 = expand_integer_ranges(&TEST2.replace(':', ",")); let test2 = test2.split(',').collect::>(); - for t in test2.iter() { + for t in &test2 { if t.force_usize() == x { return 2; } } let test3 = expand_integer_ranges(&TEST3.replace(':', ",")); let test3 = test3.split(',').collect::>(); - for t in test3.iter() { + for t in &test3 { if t.force_usize() == x { return 3; } } let test4 = expand_integer_ranges(&TEST4.replace(':', ",")); let test4 = test4.split(',').collect::>(); - for t in test4.iter() { + for t in &test4 { if t.force_usize() == x { return 4; } diff --git a/enclone_print/src/build_table_stuff.rs b/enclone_print/src/build_table_stuff.rs index 773f8ac37..23a6b662d 100644 --- a/enclone_print/src/build_table_stuff.rs +++ b/enclone_print/src/build_table_stuff.rs @@ -45,7 +45,7 @@ pub fn build_table_stuff( // Insert main chain row. Then insert chain info row if we're using CHAIN_SPLIT. - let mut row = vec!["".to_string(); row1.len()]; + let mut row = vec![String::new(); row1.len()]; for j in 0..cols { if rsi.chain_descrip[j].contains(&"IGH".to_string()) || rsi.chain_descrip[j].contains(&"TRB".to_string()) @@ -59,7 +59,7 @@ pub fn build_table_stuff( } } rows.push(row); - let mut row = vec!["".to_string(); row1.len()]; + let mut row = vec![String::new(); row1.len()]; for j in 0..cols { if !ctl.gen_opt.fold_headers { if rsi.chain_descrip[j].contains(&"IGH".to_string()) @@ -82,7 +82,7 @@ pub fn build_table_stuff( } rows.push(row); if ctl.gen_opt.fold_headers { - let mut row = vec!["".to_string(); row1.len()]; + let mut row = vec![String::new(); row1.len()]; for j in 0..cols { let mut next = rsi.chain_descrip[j].after(" ◆ ").to_string(); if next.contains(" ◆ ") { @@ -107,7 +107,7 @@ pub fn build_table_stuff( } } if have_last { - let mut row = vec!["".to_string(); row1.len()]; + let mut row = vec![String::new(); row1.len()]; for j in 0..cols { let mut last = String::new(); if rsi.chain_descrip[j].after(" ◆ ").contains(" ◆ ") { @@ -132,7 +132,7 @@ pub fn build_table_stuff( // Insert divider row (horizontal line across the chains). - let mut row = vec!["".to_string(); lvars.len() + 1]; + let mut row = vec![String::new(); lvars.len() + 1]; let mut ncall = 0; for j in 0..cols { ncall += rsi.cvars[j].len(); @@ -148,7 +148,7 @@ pub fn build_table_stuff( // Insert main per-chain header row. - let mut row = vec!["".to_string(); row1.len()]; + let mut row = vec![String::new(); row1.len()]; for cx in 0..cols { let show = &show_aa[cx]; for j in 0..rsi.cvars[cx].len() { @@ -156,7 +156,7 @@ pub fn build_table_stuff( if drows.is_empty() { row.push(rsi.cvars[cx][j].to_string()); } else { - row.push("".to_string()); + row.push(String::new()); } continue; } diff --git a/enclone_print/src/define_mat.rs b/enclone_print/src/define_mat.rs index 1490fe37b..8c6e6dc03 100644 --- a/enclone_print/src/define_mat.rs +++ b/enclone_print/src/define_mat.rs @@ -27,7 +27,7 @@ fn joiner( let u1 = info[j1].clonotype_index; let v1 = to_exacts[&u1]; let m1s = &info[j1].exact_cols; - for i2 in raw_joinsx[i1].iter() { + for i2 in &raw_joinsx[i1] { let j2 = infos[*i2]; let u2 = info[j2].clonotype_index; let v2 = to_exacts[&u2]; @@ -58,7 +58,7 @@ pub fn setup_define_mat( info: &[CloneInfo], ) -> (Vec<(Vec, usize, i32)>, Vec) { let mut od = Vec::<(Vec, usize, i32)>::new(); - for id in orbit.iter() { + for id in orbit { let x: &CloneInfo = &info[*id as usize]; od.push((x.origin.clone(), x.clonotype_id, *id)); } @@ -136,7 +136,7 @@ pub fn define_mat( let mut raw_joinsx = vec![Vec::::new(); infos.len()]; for (&j1, raw_i1) in infos.iter().zip(raw_joinsx.iter_mut()) { - for x in raw_joins[j1].iter() { + for x in &raw_joins[j1] { let i2 = bin_position(&infos, x); if i2 >= 0 { raw_i1.push(i2 as usize); @@ -154,22 +154,22 @@ pub fn define_mat( let mut extras = Vec::<(usize, usize)>::new(); for (i1, (raw_i1, &j1)) in raw_joinsx.iter().zip(infos.iter()).enumerate() { - for &i2 in raw_i1.iter() { + for &i2 in raw_i1 { let j2 = infos[i2]; let (u1, u2) = (info[j1].clonotype_index, info[j2].clonotype_index); let (ex1, ex2) = (&exact_clonotypes[u1], &exact_clonotypes[u2]); let (v1, v2) = (to_exacts[&u1], to_exacts[&u2]); if ex1.share.len() > 2 || ex2.share.len() > 2 { let (s1, s2) = (&to_infos[v1], &to_infos[v2]); - for k1 in s1.iter() { - for k2 in s2.iter() { + for k1 in s1 { + for k2 in s2 { let (k1, k2) = (*k1, *k2); if (k1 == i1 && k2 == i2) || (k1 == i2 && k2 == i1) { continue; } let (l1, l2) = (infos[k1], infos[k2]); if info[l1].lens == info[l2].lens { - let mut pot = Vec::::new(); + let mut pot = Vec::>::new(); if join_one( is_bcr, l1, @@ -191,7 +191,7 @@ pub fn define_mat( } } } - for x in extras.iter() { + for x in &extras { raw_joinsx[x.0].push(x.1); } @@ -238,14 +238,14 @@ pub fn define_mat( // This partially addresses the "second reason" described above. It is partial because we // picked an info entry above at random, rather than trying them all. - for f1 in rxir.iter() { - for f2 in rxir.iter() { + for f1 in &rxir { + for f2 in &rxir { if f1.0 != f2.0 || f1.1 != f2.1 { let (i1, i2) = (infos[f1.2], infos[f2.2]); if info[i1].lens != info[i2].lens { continue; } - let mut pot = Vec::::new(); + let mut pot = Vec::>::new(); if join_one( is_bcr, i1, @@ -284,7 +284,7 @@ pub fn define_mat( [2, 0, 1], [2, 1, 0], ]; - for z in zs.iter() { + for z in &zs { if ex.share[z[0]].left && !ex.share[z[2]].left { let p1 = e.class_id(bin_position(&chains, &(u, z[0]))); let p2 = e.class_id(bin_position(&chains, &(u, z[1]))); @@ -305,8 +305,8 @@ pub fn define_mat( // join algorithm would not have joined the third. In this case, if the third chains are // "close enough", we join them anyway. As before, we only test representatives. - for t1 in threes.iter() { - 't2_loop: for t2 in threes.iter() { + for t1 in &threes { + 't2_loop: for t2 in &threes { if t1 == t2 { continue; } @@ -381,7 +381,7 @@ pub fn define_mat( chainsox.push((c.2, c.3, i)); } chainsox.sort_unstable(); - for ri in r.iter_mut() { + for ri in &mut r { *ri = chainsox[*ri as usize].2 as i32; } r.sort_unstable(); diff --git a/enclone_print/src/filter.rs b/enclone_print/src/filter.rs index 951ec850c..72a2b4bce 100644 --- a/enclone_print/src/filter.rs +++ b/enclone_print/src/filter.rs @@ -43,7 +43,7 @@ pub fn survives_filter( if ctl.clono_filt_opt.inkt { let mut evidence = false; - for s in exacts.iter() { + for s in exacts { let ex = &exact_clonotypes[*s]; if ex.share[0].inkt_alpha_chain_gene_match || ex.share[0].inkt_alpha_chain_junction_match @@ -59,7 +59,7 @@ pub fn survives_filter( } if ctl.clono_filt_opt.mait { let mut evidence = false; - for s in exacts.iter() { + for s in exacts { let ex = &exact_clonotypes[*s]; if ex.share[0].mait_alpha_chain_gene_match || ex.share[0].mait_alpha_chain_junction_match @@ -78,7 +78,7 @@ pub fn survives_filter( if ctl.clono_filt_opt.marked { let mut marked = false; - for s in exacts.iter() { + for s in exacts { let ex = &exact_clonotypes[*s]; for i in 0..ex.clones.len() { if ex.clones[i][0].marked { @@ -95,7 +95,7 @@ pub fn survives_filter( if ctl.clono_filt_opt_def.marked_b { let mut marked_b = false; - for s in exacts.iter() { + for s in exacts { let ex = &exact_clonotypes[*s]; for i in 0..ex.clones.len() { if ex.clones[i][0].marked { @@ -119,8 +119,8 @@ pub fn survives_filter( if ctl.clono_filt_opt.dataset.is_some() { let mut ok = false; - for d in ctl.clono_filt_opt.dataset.as_ref().unwrap().iter() { - for s in exacts.iter() { + for d in ctl.clono_filt_opt.dataset.as_ref().unwrap() { + for s in exacts { let ex = &exact_clonotypes[*s]; for i in 0..ex.clones.len() { if ctl.origin_info.dataset_id[ex.clones[i][0].dataset_index] == *d { @@ -138,7 +138,7 @@ pub fn survives_filter( if !ctl.clono_filt_opt.barcode.is_empty() { let mut ok = false; - for s in exacts.iter() { + for s in exacts { let ex = &exact_clonotypes[*s]; for i in 0..ex.clones.len() { for j in 0..ctl.clono_filt_opt.barcode.len() { @@ -157,7 +157,7 @@ pub fn survives_filter( if ctl.clono_filt_opt.del { let mut ok = false; - for s in exacts.iter() { + for s in exacts { let ex = &exact_clonotypes[*s]; for m in 0..ex.share.len() { if ex.share[m].seq_del.contains(&b'-') { @@ -193,7 +193,7 @@ pub fn survives_filter( if ctl.clono_filt_opt.cdiff { let mut cdiff = false; - for s in exacts.iter() { + for s in exacts { let ex = &exact_clonotypes[*s]; for m in 0..ex.share.len() { let cstart = ex.share[m].j_stop; @@ -233,7 +233,7 @@ pub fn survives_filter( if !ctl.clono_filt_opt.vj.is_empty() { let mut have_vj = false; - for s in exacts.iter() { + for s in exacts { let ex = &exact_clonotypes[*s]; for j in 0..ex.share.len() { if ex.share[j].seq == ctl.clono_filt_opt.vj { @@ -388,7 +388,7 @@ pub fn survives_filter( return false; } let mut lis = Vec::::new(); - for s in exacts.iter() { + for s in exacts { let mut z = exact_clonotypes[*s].dataset_indices(); lis.append(&mut z); } @@ -403,7 +403,7 @@ pub fn survives_filter( // Clonotypes found in at least n origins let mut origins = Vec::::new(); - for id in lis.iter() { + for id in &lis { origins.push(ctl.origin_info.origin_id[*id].clone()); } unique_sort(&mut origins); @@ -414,7 +414,7 @@ pub fn survives_filter( // Clonotypes found in at least n donors let mut donors = Vec::::new(); - for id in lis.iter() { + for id in &lis { donors.push(ctl.origin_info.donor_id[*id].clone()); } unique_sort(&mut donors); @@ -458,7 +458,7 @@ pub fn survives_filter( if ctl.clono_filt_opt.cdr3.is_some() { let mut ok = false; - for s in exacts.iter() { + for s in exacts { let ex = &exact_clonotypes[*s]; for j in 0..ex.share.len() { if ctl diff --git a/enclone_print/src/finish_table.rs b/enclone_print/src/finish_table.rs index 5cec60f1e..1e3f174f6 100644 --- a/enclone_print/src/finish_table.rs +++ b/enclone_print/src/finish_table.rs @@ -226,7 +226,7 @@ pub fn finish_table( // Make table. - for row in rows.iter_mut() { + for row in &mut rows { for v in row.iter_mut() { *v = v.replace("|TRX", "TRB").replace("|TRY", "TRA"); } diff --git a/enclone_print/src/gene_scan.rs b/enclone_print/src/gene_scan.rs index 68c18615a..c5b2fca53 100644 --- a/enclone_print/src/gene_scan.rs +++ b/enclone_print/src/gene_scan.rs @@ -23,7 +23,7 @@ pub fn gene_scan_test( .map(|xn| { stats .iter() - .filter_map(|stat| { + .find_map(|stat| { if stat.0 == *xn { Some( stat.1 @@ -35,7 +35,6 @@ pub fn gene_scan_test( None } }) - .next() .unwrap_or_default() / n as f64 }) @@ -50,7 +49,7 @@ pub fn gene_scan_test( .map(|xn| { stats .iter() - .filter_map(|stat| { + .find_map(|stat| { if stat.0 == *xn { Some( stat.1 @@ -62,7 +61,6 @@ pub fn gene_scan_test( None } }) - .next() .unwrap_or_default() / n as f64 }) @@ -89,9 +87,8 @@ pub fn gene_scan_test( } } break; - } else { - count += 1; } + count += 1; } } let n = vals.len() as f64; @@ -112,9 +109,8 @@ pub fn gene_scan_test( } } break; - } else { - count += 1; } + count += 1; } } means.push(vals.into_iter().sum::() / n as f64); diff --git a/enclone_print/src/loupe.rs b/enclone_print/src/loupe.rs index 89c3c63b0..2abb10fe8 100644 --- a/enclone_print/src/loupe.rs +++ b/enclone_print/src/loupe.rs @@ -48,7 +48,7 @@ pub fn make_donor_refs( k - i + 1 ); let refx = refdata.refs[ref_id].to_ascii_vec(); - let mut cigar = "".to_string(); + let mut cigar = String::new(); let mut matches = 0; for p in 0..refx.len() { if alt[p] == refx[p] { diff --git a/enclone_print/src/print_clonotypes.rs b/enclone_print/src/print_clonotypes.rs index 4efa45eb1..186dcd8aa 100644 --- a/enclone_print/src/print_clonotypes.rs +++ b/enclone_print/src/print_clonotypes.rs @@ -63,8 +63,8 @@ pub fn print_clonotypes( raw_joins: &[Vec], gex_info: &GexInfo, vdj_cells: &[Vec], - d_readers: &[Option], - ind_readers: &[Option], + d_readers: &[Option>], + ind_readers: &[Option>], h5_data: &[(usize, Vec, Vec)], pics: &mut Vec, exacts: &mut Vec>, @@ -133,7 +133,7 @@ pub fn print_clonotypes( } } all_vars.append(&mut extra_parseables); - for x in extra_args.iter() { + for x in &extra_args { if !rsi_vars.contains(x) { all_vars.push(x.as_str()); } @@ -168,7 +168,7 @@ pub fn print_clonotypes( .take(ctl.origin_info.n()) { let mut n = 0; - for y in gex.iter() { + for y in gex { if bin_member(vdj, y.0) { n += 1; } @@ -226,7 +226,7 @@ pub fn print_clonotypes( let i = res.0; let o = &orbits[i]; let mut od = Vec::<(Vec, usize, i32)>::new(); - for id in o.iter() { + for id in o { let x: &CloneInfo = &info[*id as usize]; od.push((x.origin.clone(), x.clonotype_id, *id)); } @@ -518,7 +518,7 @@ pub fn print_clonotypes( } let lvars = lvarsc.clone(); let mut lvarsh = HashSet::::new(); - for x in lvars.iter() { + for x in &lvars { lvarsh.insert(x.to_string()); } @@ -925,7 +925,7 @@ pub fn print_clonotypes( // Write loupe output. let mut all_loupe_clonotypes = Vec::::new(); - for r in results.iter_mut() { + for r in &mut results { all_loupe_clonotypes.append(&mut r.6); } loupe_out(ctl, all_loupe_clonotypes, refdata, dref); diff --git a/enclone_print/src/print_utils1.rs b/enclone_print/src/print_utils1.rs index bc3689f96..44ac7de9c 100644 --- a/enclone_print/src/print_utils1.rs +++ b/enclone_print/src/print_utils1.rs @@ -508,7 +508,7 @@ pub fn start_gen( .collect::>(); bc.sort_unstable(); speak!(u, "barcodes", format!("{}", bc.iter().format(","))); - for d in ctl.origin_info.dataset_list.iter() { + for d in &ctl.origin_info.dataset_list { if !d.is_empty() { let mut bc = Vec::<&str>::new(); for q in &exact_clonotypes[eu].clones { @@ -530,7 +530,7 @@ pub fn start_gen( .map(|x| x[0].barcode.as_str()) .collect::>(); speak!(u, "barcode", format!("{}", bc.iter().format(POUT_SEP))); - for d in ctl.origin_info.dataset_list.iter() { + for d in &ctl.origin_info.dataset_list { if !d.is_empty() { let mut bc = Vec::<&str>::new(); for i in 0..exact_clonotypes[eu].clones.len() { @@ -838,7 +838,7 @@ pub fn cdr3_aa_con( } else if style == "x" { c.push('X'); } else { - for m in classes.iter() { + for m in &classes { if meet_size(&vals, m.1) == vals.len() { c.push(m.0); break; @@ -876,7 +876,7 @@ pub fn extra_args(ctl: &EncloneControl) -> Vec { extra_args.append(&mut ctl.plot_opt.sim_mat_plot_vars.clone()); for i in 0..ctl.gen_opt.var_def.len() { let x = &ctl.gen_opt.var_def[i].2; - for v in vars_of_node(x).iter() { + for v in &vars_of_node(x) { extra_args.push(decode_arith(v)); } } diff --git a/enclone_print/src/print_utils2.rs b/enclone_print/src/print_utils2.rs index ca03c1152..d5b362ae0 100644 --- a/enclone_print/src/print_utils2.rs +++ b/enclone_print/src/print_utils2.rs @@ -57,8 +57,8 @@ pub fn row_fill( rsi: &ColInfo, dref: &[DonorReferenceItem], groups: &HashMap>, - d_readers: &[Option], - ind_readers: &[Option], + d_readers: &[Option>], + ind_readers: &[Option>], h5_data: &[(usize, Vec, Vec)], stats: &mut Vec<(String, Vec)>, stats_pass1: &[Vec<(String, Vec)>], @@ -83,7 +83,7 @@ pub fn row_fill( let clonotype_id = exacts[u]; let ex = &exact_clonotypes[clonotype_id]; let mut pcols_sort = ctl.parseable_opt.pcols_sort.clone(); - for pcol in pcols_sort.iter_mut() { + for pcol in &mut pcols_sort { *pcol = pcol.replace("_Σ", "_sum").replace("_μ", "_mean"); } pcols_sort.sort(); @@ -145,10 +145,10 @@ pub fn row_fill( } unique_sort(&mut dataset_indices); let mut lenas = Vec::::new(); - for l in dataset_indices.iter() { + for l in &dataset_indices { lenas.push(ctl.origin_info.dataset_id[*l].clone()); } - row.push("".to_string()); // row number (#), filled in below + row.push(String::new()); // row number (#), filled in below let mut counts = Vec::::new(); let mut gex_counts_unsorted = Vec::::new(); let mut gex_fcounts_unsorted = Vec::::new(); @@ -261,7 +261,7 @@ pub fn row_fill( } gex_counts_unsorted = counts.clone(); counts.sort_unstable(); - for n in counts.iter() { + for n in &counts { if *n < 100 { *gex_low += 1; } @@ -370,7 +370,7 @@ pub fn row_fill( let mut median = String::new(); let mut out_valsf = Vec::::new(); let mut all_float = true; - for y in out_vals.iter() { + for y in &out_vals { if y.parse::().is_err() { all_float = false; } else { @@ -382,7 +382,7 @@ pub fn row_fill( median = format!("{:.1}", median_f64(&out_valsf)); } if i < lvars.len() { - row.push(median.clone()) + row.push(median.clone()); } if pass == 2 { if ctl.parseable_opt.pbarcode { @@ -592,12 +592,12 @@ pub fn row_fill( speakc!(u, col, "vj_seq_nl".to_string(), stringme(&dna)); speakc!(u, col, "seq".to_string(), stringme(&xm.full_seq)); let mut vv = Vec::::new(); - for x in vars_amino[col].iter() { + for x in &vars_amino[col] { vv.push(*x / 3); } unique_sort(&mut vv); let mut varaa = Vec::::new(); - for p in vv.iter() { + for p in &vv { // what does it mean if this fails? if 3 * p + 3 <= seq_amino.len() { if seq_amino[3 * p..3 * p + 3].to_vec() == b"---".to_vec() { diff --git a/enclone_print/src/print_utils3.rs b/enclone_print/src/print_utils3.rs index 663afdc90..9378eea26 100644 --- a/enclone_print/src/print_utils3.rs +++ b/enclone_print/src/print_utils3.rs @@ -692,7 +692,7 @@ pub fn insert_reference_rows( } row.push(refx); for _ in 1..rsi.cvars[cz].len() { - row.push("".to_string()); + row.push(String::new()); } } rows.push(row); @@ -753,7 +753,7 @@ pub fn get_extra_parseables<'a>(ctl: &'a EncloneControl, pcols_sort: &'a [String exclusions.push(v); } unique_sort(&mut exclusions); - for x in pcols_sort.iter() { + for x in pcols_sort { let chars = x.char_indices().collect::>(); let mut trim = 0; for c in chars.iter().rev() { diff --git a/enclone_print/src/print_utils4.rs b/enclone_print/src/print_utils4.rs index 04b310d67..591a65356 100644 --- a/enclone_print/src/print_utils4.rs +++ b/enclone_print/src/print_utils4.rs @@ -62,7 +62,7 @@ pub fn build_show_aa( let cols = rsi.vids.len(); let mut show_aa = vec![Vec::::new(); cols]; for cx in 0..cols { - for x in ctl.clono_print_opt.amino.iter() { + for x in &ctl.clono_print_opt.amino { if x.contains('-') { let (start, stop) = (x.before("-").force_usize(), x.after("-").force_usize()); for p in start..=stop { @@ -278,7 +278,7 @@ pub fn compute_some_stats( let mut creds = 0; let mut z = Vec::<(f64, String)>::new(); let x = &gex_info.pca[li][&bc.clone()]; - for y in gex_info.pca[li].iter() { + for y in &gex_info.pca[li] { let dist2 = x .iter() .zip(y.1.iter()) @@ -296,7 +296,7 @@ pub fn compute_some_stats( let pc = 100.0 * creds as f64 / top as f64; cred.push(format!("{pc:.1}")); } else { - cred.push("".to_string()); + cred.push(String::new()); } } } @@ -386,12 +386,12 @@ pub fn compute_some_stats( let mat = bcs .iter() .zip(lis.iter()) - .map(|(bc, &li)| gex_info.pca[li][&bc.to_string()].clone()) + .map(|(bc, &li)| gex_info.pca[li][&(*bc).to_string()].clone()) .collect::>(); let mut matg = Vec::>::new(); for li in 0..ctl.origin_info.n() { - for i in gex_info.pca[li].iter() { - matg.push(i.1.to_vec()); + for i in &gex_info.pca[li] { + matg.push(i.1.clone()); } } let mut x = vec![0; bcs.len()]; @@ -518,7 +518,7 @@ pub fn compute_bu( let cols = mat.len(); *subrows = Vec::>::new(); if ctl.clono_print_opt.bu { - for bcl in bli.iter() { + for bcl in bli { let mut row = Vec::::new(); let bc = &bcl.0; let li = bcl.1; @@ -711,7 +711,7 @@ pub fn compute_bu( } let y0 = y; let suffixes = ["_min", "_max", "_μ", "_Σ", "_cell", "_%"]; - for &s in suffixes.iter() { + for &s in &suffixes { if y.ends_with(s) { y = y.rev_before(s); break; @@ -728,7 +728,7 @@ pub fn compute_bu( .unwrap_or_default(); if !ux.is_empty() { computed = true; - for fid in ux.iter() { + for fid in &ux { let counti = get_gex_matrix_entry( ctl, gex_info, *fid, d_all, ind_all, li, l, y, ); @@ -758,14 +758,14 @@ pub fn compute_bu( } } if row.len() == nr { - row.push("".to_string()); + row.push(String::new()); } } let mut ncall = 0; for k in 0..cols { ncall += rsi.cvars[k].len(); } - let mut cx = vec!["".to_string(); ncall]; + let mut cx = vec![String::new(); ncall]; let mut cp = 0; for (m, cvars) in mat.iter().take(cols).zip(rsi.cvars.iter()) { if let Some(m) = m[u] { @@ -870,5 +870,5 @@ pub fn compute_bu( subrows.push(row); } } - sr.push((row.to_vec(), subrows.to_vec(), varmat[u].clone(), u)); + sr.push((row.to_vec(), subrows.clone(), varmat[u].clone(), u)); } diff --git a/enclone_print/src/print_utils5.rs b/enclone_print/src/print_utils5.rs index 2759a08e2..a86c23d36 100644 --- a/enclone_print/src/print_utils5.rs +++ b/enclone_print/src/print_utils5.rs @@ -405,7 +405,7 @@ pub fn build_diff_row( row.push(v); } } - for r in row.iter_mut() { + for r in &mut row { *r = format!("{}", *r); } } @@ -457,7 +457,7 @@ pub fn insert_consensus_row( } unique_sort(&mut codons); let mut gap = false; - for x in codons.iter() { + for x in &codons { if x.contains(&b'-') { gap = true; } @@ -476,7 +476,7 @@ pub fn insert_consensus_row( xdots += "X"; } else { let mut aas = Vec::::new(); - for x in codons.iter() { + for x in &codons { aas.push(codon_to_aa(x)); } unique_sort(&mut aas); @@ -485,7 +485,7 @@ pub fn insert_consensus_row( } else if style == "x" { xdots += "X"; } else { - for m in classes.iter() { + for m in &classes { if meet_size(&aas, m.1) == aas.len() { xdots.push(m.0); break; @@ -496,7 +496,7 @@ pub fn insert_consensus_row( } row.push(xdots); } else { - row.push("".to_string()); + row.push(String::new()); } } } diff --git a/enclone_print/src/proc_cvar_auto.rs b/enclone_print/src/proc_cvar_auto.rs index d526b1a2f..1c5419a2f 100644 --- a/enclone_print/src/proc_cvar_auto.rs +++ b/enclone_print/src/proc_cvar_auto.rs @@ -570,7 +570,7 @@ pub fn proc_cvar_auto( if scores.len() > 1 { delta = scores[0] - scores[1]; } - score = format!("{delta:.1}") + score = format!("{delta:.1}"); } (score, Vec::new(), "exact".to_string()) @@ -641,7 +641,7 @@ pub fn proc_cvar_auto( if scores.len() > 1 { score = scores[1]; } - scorex = format!("{score:.1}") + scorex = format!("{score:.1}"); } (scorex, Vec::new(), "exact".to_string()) @@ -672,7 +672,7 @@ pub fn proc_cvar_auto( if scores.len() > 1 { delta = scores[0] - scores[1]; } - del = format!("{delta:.1}") + del = format!("{delta:.1}"); } (del, Vec::new(), "exact".to_string()) @@ -781,7 +781,7 @@ pub fn proc_cvar_auto( if scores.len() > 1 { delta = scores[0] - scores[1]; } - del = format!("{delta:.1}") + del = format!("{delta:.1}"); } (del, Vec::new(), "exact".to_string()) @@ -1548,7 +1548,7 @@ pub fn proc_cvar_auto( if val.1.is_empty() { stats.push((abbrc, vec![exact.to_string(); ex.ncells()])); } else { - stats.push((abbrc, cell.to_vec())); + stats.push((abbrc, cell.clone())); } } else if !cell.is_empty() && pass == 2 diff --git a/enclone_print/src/proc_lvar2.rs b/enclone_print/src/proc_lvar2.rs index 20c4ebc99..a18157889 100644 --- a/enclone_print/src/proc_lvar2.rs +++ b/enclone_print/src/proc_lvar2.rs @@ -101,7 +101,7 @@ pub fn proc_lvar2( let y0 = y; for _ in 1..=2 { let suffixes = ["_min", "_max", "_μ", "_Σ", "_cell", "_%"]; - for s in suffixes.iter() { + for s in &suffixes { if y.ends_with(s) { y = y.rev_before(s); break; @@ -121,7 +121,7 @@ pub fn proc_lvar2( if p >= 0 { computed = true; let mut raw_count = 0.0; - for fid in ux.iter() { + for fid in &ux { let raw_counti = get_gex_matrix_entry(ctl, gex_info, *fid, d_all, ind_all, li, l, y); raw_count += raw_counti; @@ -145,7 +145,7 @@ pub fn proc_lvar2( } if computed { let mut f = Vec::::new(); - for x in fcounts_sub.iter() { + for x in &fcounts_sub { f.push(format!("{x}")); } if !y0.ends_with("_%") { @@ -201,7 +201,7 @@ pub fn proc_lvar2( lvar![i, x, format!("{median}")]; } } else if i < lvars.len() { - lvar_stats1![i, x, "".to_string()]; + lvar_stats1![i, x, String::new()]; } true } diff --git a/enclone_print/src/proc_lvar_auto.rs b/enclone_print/src/proc_lvar_auto.rs index 8cce1db10..f18fd59e5 100644 --- a/enclone_print/src/proc_lvar_auto.rs +++ b/enclone_print/src/proc_lvar_auto.rs @@ -44,8 +44,8 @@ pub fn proc_lvar_auto( gex_counts_unsorted: &[usize], gex_fcounts_unsorted: &[f64], n_gexs: &[usize], - d_readers: &[Option], - ind_readers: &[Option], + d_readers: &[Option>], + ind_readers: &[Option>], h5_data: &[(usize, Vec, Vec)], alt_bcs: &[&str], ) -> Result { @@ -120,7 +120,7 @@ pub fn proc_lvar_auto( (val, Vec::new(), "exact") } else if vname == "clonotype_ncells" { let mut n = 0; - for u in exacts.iter() { + for u in exacts { n += exact_clonotypes[*u].ncells(); } @@ -137,7 +137,7 @@ pub fn proc_lvar_auto( clust.push(cid); } let mut clustf = Vec::::new(); - for x in clust.iter() { + for x in &clust { clustf.push(format!("{x}")); } clust.sort_unstable(); @@ -563,7 +563,7 @@ pub fn proc_lvar_auto( let mut creds = 0; let mut z = Vec::<(f64, &str)>::new(); let x = &gex_info.pca[li][&bc.clone()]; - for y in gex_info.pca[li].iter() { + for y in &gex_info.pca[li] { let dist2 = y.1.iter() .zip(x.iter()) @@ -601,7 +601,7 @@ pub fn proc_lvar_auto( let mut creds = 0; let mut z = Vec::<(f64, &str)>::new(); let x = &gex_info.pca[li][&bc.clone()]; - for y in gex_info.pca[li].iter() { + for y in &gex_info.pca[li] { let dist2 = y.1.iter() .zip(x.iter()) @@ -865,7 +865,7 @@ pub fn proc_lvar_auto( entropy = median_f64(&entropies); } let mut e = Vec::::new(); - for x in entropies_unsorted.iter() { + for x in &entropies_unsorted { e.push(format!("{x:.2}")); } @@ -957,7 +957,7 @@ pub fn proc_lvar_auto( entropy = median_f64(&entropies); } let mut e = Vec::::new(); - for x in entropies_unsorted.iter() { + for x in &entropies_unsorted { e.push(format!("{x:.2}")); } @@ -970,7 +970,7 @@ pub fn proc_lvar_auto( continue; } let mut d = 0_isize; - for c in fp[u].iter() { + for c in &fp[u] { for j in 0..varmat[u][*c].len() { if varmat[u][*c][j] != varmat[i2][*c][j] { d += 1; @@ -1001,7 +1001,7 @@ pub fn proc_lvar_auto( (String::new(), fates, "cell") } else if vname == "gex" { let mut f = Vec::::new(); - for x in gex_fcounts_unsorted.iter() { + for x in gex_fcounts_unsorted { f.push(format!("{}", *x)); } let mut counts = gex_counts_unsorted.to_owned(); @@ -1011,7 +1011,7 @@ pub fn proc_lvar_auto( (format!("{gex_median}"), f, "cell-exact") } else if vname == "gex_cell" { let mut f = Vec::::new(); - for x in gex_fcounts_unsorted.iter() { + for x in gex_fcounts_unsorted { f.push(format!("{}", *x)); } let mut counts = gex_counts_unsorted.to_owned(); @@ -1324,7 +1324,7 @@ pub fn proc_lvar_auto( } else if vname == "n_gex" { let mut n = Vec::::new(); let mut n_gex = 0; - for x in n_gexs.iter() { + for x in n_gexs { n.push(format!("{}", *x)); n_gex += *x; } @@ -1333,7 +1333,7 @@ pub fn proc_lvar_auto( } else if vname == "n_gex_cell" { let mut n = Vec::::new(); let mut n_gex = 0; - for x in n_gexs.iter() { + for x in n_gexs { n.push(format!("{}", *x)); n_gex += *x; } @@ -1409,7 +1409,7 @@ pub fn proc_lvar_auto( continue; } let mut d = 0; - for c in fp[u].iter() { + for c in &fp[u] { for j in 0..varmat[u][*c].len() { if varmat[u][*c][j] != varmat[i2][*c][j] { d += 1; @@ -1528,7 +1528,7 @@ pub fn proc_lvar_auto( eprintln!("i = {i}, lvars.len() = {}", lvars.len()); } if i < lvars.len() { - row.push(String::new()) + row.push(String::new()); } if pass == 2 { speak!(u, abbr, String::new()); @@ -1543,7 +1543,7 @@ pub fn proc_lvar_auto( eprintln!("i = {i}, lvars.len() = {}", lvars.len()); } if i < lvars.len() { - row.push(exact.clone()) + row.push(exact.clone()); } if pass == 2 { speak!(u, abbr, exact.to_string()); @@ -1551,13 +1551,13 @@ pub fn proc_lvar_auto( if cell.is_empty() { stats.push((abbr.to_string(), vec![exact; ex.ncells()])); } else { - stats.push((abbr.to_string(), cell.to_vec())); + stats.push((abbr.to_string(), cell.clone())); } } else if !cell.is_empty() { if pass == 2 { speak!(u, abbr, format!("{}", cell.iter().format(POUT_SEP))); } - stats.push((abbr.to_string(), cell.to_vec())); + stats.push((abbr.to_string(), cell.clone())); } Ok(true) } diff --git a/enclone_ranger/src/stop.rs b/enclone_ranger/src/stop.rs index 5dd88a6f1..dad6d7ecb 100644 --- a/enclone_ranger/src/stop.rs +++ b/enclone_ranger/src/stop.rs @@ -28,8 +28,8 @@ pub fn main_enclone_stop_ranger(mut inter: EncloneIntermediates) -> Result<(), S // Load the GEX and FB data. This is quite horrible: the code and computation are duplicated // verbatim in fcell.rs. - let mut d_readers = Vec::>::new(); - let mut ind_readers = Vec::>::new(); + let mut d_readers = Vec::>>::new(); + let mut ind_readers = Vec::>>::new(); for li in 0..ctl.origin_info.n() { if !ctl.origin_info.gex_path[li].is_empty() { let x = gex_info.h5_data[li].as_ref(); diff --git a/enclone_stuff/src/analyze_dref.rs b/enclone_stuff/src/analyze_dref.rs index d8f0b87dd..af0a25d57 100644 --- a/enclone_stuff/src/analyze_dref.rs +++ b/enclone_stuff/src/analyze_dref.rs @@ -115,7 +115,7 @@ pub fn analyze_donor_ref( for ar in &alleles { m = min(m, ar.0.len()); } - for ar in alleles.iter_mut() { + for ar in &mut alleles { if ar.0.len() > m { ar.0 = &ar.0[..m]; } @@ -175,7 +175,7 @@ pub fn analyze_donor_ref( let mut imgts = Vec::<&str>::new(); for ar in &allelesg { - for n in ar.0.iter() { + for n in &ar.0 { if !n.starts_with('d') && !n.starts_with('u') { imgts.push(n); } @@ -218,7 +218,7 @@ pub fn analyze_donor_ref( row }, { - let mut row = vec!["".to_string()]; + let mut row = vec![String::new()]; row.append(&mut vec![ "\\hline".to_string(); ndonors + nimgt + dp.len() @@ -226,7 +226,7 @@ pub fn analyze_donor_ref( row }, { - let mut row = vec!["".to_string()]; + let mut row = vec![String::new()]; for d in 0..ndonors { row.push(format!("{}", d + 1)); } @@ -245,7 +245,7 @@ pub fn analyze_donor_ref( let allele_name = (b'A' + r as u8) as char; let mut an = String::new(); an.push(allele_name); - for n in alleleg.0.iter() { + for n in &alleleg.0 { if n.starts_with("uref") { an.push('*'); break; diff --git a/enclone_stuff/src/disintegrate.rs b/enclone_stuff/src/disintegrate.rs index b5c67af9f..f74d6dcf1 100644 --- a/enclone_stuff/src/disintegrate.rs +++ b/enclone_stuff/src/disintegrate.rs @@ -6,7 +6,7 @@ use enclone_core::defs::{CloneInfo, EncloneControl, ExactClonotype}; use equiv::EquivRel; use std::collections::HashMap; -use std::time::Instant; + use vector_utils::unique_sort; pub fn disintegrate_onesies( @@ -19,7 +19,6 @@ pub fn disintegrate_onesies( raw_joins: &mut Vec<(i32, i32)>, ) { if ctl.clono_filt_opt_def.weak_onesies { - let t = Instant::now(); let ncells_total = exact_clonotypes .iter() .map(enclone_core::defs::ExactClonotype::ncells) @@ -57,9 +56,9 @@ pub fn disintegrate_onesies( let mut join_info2 = Vec::new(); for ji in join_info.iter() { let (u1, u2) = (ji.0, ji.1); - for v1 in to_exact_new[u1].iter() { + for v1 in &to_exact_new[u1] { join_info2.reserve(to_exact_new[u2].len()); - for v2 in to_exact_new[u2].iter() { + for v2 in &to_exact_new[u2] { let mut x = ji.clone(); x.0 = *v1; x.1 = *v2; @@ -68,7 +67,6 @@ pub fn disintegrate_onesies( } } - let t = Instant::now(); *join_info = join_info2; *exact_clonotypes = exacts2; let mut info2 = Vec::::new(); @@ -92,7 +90,6 @@ pub fn disintegrate_onesies( to_info2.push(x); } - let t = Instant::now(); *info = info2; let mut raw_joins2 = Vec::<(i32, i32)>::new(); for i in 0..raw_joins.len() { diff --git a/enclone_stuff/src/doublets.rs b/enclone_stuff/src/doublets.rs index 753a7a2c9..83a585882 100644 --- a/enclone_stuff/src/doublets.rs +++ b/enclone_stuff/src/doublets.rs @@ -14,7 +14,7 @@ use itertools::Itertools; use qd::Double; use rayon::prelude::*; use std::collections::HashMap; -use std::time::Instant; + use vdj_ann::refx::RefData; use vector_utils::{bin_member, erase_if, next_diff, next_diff1_2, sort_sync2}; @@ -32,7 +32,6 @@ pub fn delete_doublets( fate: &mut [HashMap], ) { if ctl.clono_filt_opt_def.doublet { - let t = Instant::now(); // Define pure subclonotypes. To do this we break each clonotype up by chain signature. // Note duplication of code with print_clonotypes.rs. And this is doing some // superfluous compute. @@ -43,7 +42,6 @@ pub fn delete_doublets( } let mut pures = Vec::>::new(); - let t = Instant::now(); results.par_iter_mut().for_each(|res| { let i = res.0; let o = orbits[i].clone(); @@ -92,14 +90,13 @@ pub fn delete_doublets( let mut npure = vec![0; pures.len()]; for j in 0..pures.len() { - for id in pures[j].iter() { + for id in &pures[j] { npure[j] += exact_clonotypes[*id].ncells(); } } // Find the pairs of pure subclonotypes that share identical CDR3 sequences. - let t = Instant::now(); let mut shares = Vec::<(usize, usize)>::new(); { let mut content = Vec::<(&str, usize)>::new(); @@ -114,7 +111,6 @@ pub fn delete_doublets( content.par_sort(); content.dedup(); - let t = Instant::now(); let mut j = 0; while j < content.len() { let k = next_diff1_2(&content, j as i32) as usize; @@ -133,7 +129,6 @@ pub fn delete_doublets( // Find triples of pure subclonotypes in which the first two have no share, but both // of the first two share with the third. - let t = Instant::now(); const MIN_MULT_DOUBLET: usize = 5; let mut trips = Vec::<(usize, usize, usize)>::new(); { @@ -186,7 +181,6 @@ pub fn delete_doublets( // Delete some of the third members of the triples. - let t = Instant::now(); let mut to_delete = vec![false; exact_clonotypes.len()]; for (v1, v2, v0) in trips { let verbose = false; @@ -220,7 +214,7 @@ pub fn delete_doublets( println!("[{}] {}", u + 1, cdrs.iter().format(",")); } } - for m in pures[v0].iter() { + for m in &pures[v0] { to_delete[*m] = true; } } diff --git a/enclone_stuff/src/fcell.rs b/enclone_stuff/src/fcell.rs index c59afeddd..efde76f65 100644 --- a/enclone_stuff/src/fcell.rs +++ b/enclone_stuff/src/fcell.rs @@ -12,7 +12,7 @@ use rayon::prelude::*; use std::env; use std::thread; use std::time; -use std::time::Instant; + use vector_utils::{bin_position, erase_if}; pub fn filter_by_fcell( @@ -26,9 +26,8 @@ pub fn filter_by_fcell( // Load the GEX and FB data. This is quite horrible: the code and computation are // duplicated verbatim in stop.rs. - let tdi = Instant::now(); - let mut d_readers = Vec::>::new(); - let mut ind_readers = Vec::>::new(); + let mut d_readers = Vec::>>::new(); + let mut ind_readers = Vec::>>::new(); for li in 0..ctl.origin_info.n() { if !ctl.origin_info.gex_path[li].is_empty() { let x = gex_info.h5_data[li].as_ref(); @@ -73,9 +72,8 @@ pub fn filter_by_fcell( } msg += "Aborting.\n"; return Err(msg); - } else { - println!("h5 path exists."); } + println!("h5 path exists."); } else { println!("Path exists."); } @@ -150,7 +148,7 @@ pub fn filter_by_fcell( let li = clone[0].dataset_index; let bc = &clone[0].barcode; let mut keep = true; - for x in ctl.clono_filt_opt_def.fcell.iter() { + for x in &ctl.clono_filt_opt_def.fcell { let alt = &ctl.origin_info.alt_bc_fields[li]; let vars = x.iter_variable_identifiers().collect::>(); let mut vals = Vec::::new(); diff --git a/enclone_stuff/src/filter_umi.rs b/enclone_stuff/src/filter_umi.rs index f4a85568d..7c6819259 100644 --- a/enclone_stuff/src/filter_umi.rs +++ b/enclone_stuff/src/filter_umi.rs @@ -232,18 +232,17 @@ pub fn filter_umi( if nbads == 0 { orbits2.push(o.clone()); continue 'orbit; - } else { - let p = 0.1; - let bound = 0.01; + } + let p = 0.1; + let bound = 0.01; - // Find probability of observing nbads or more events of probability - // p in a sample of size ncells, and if that is at least bound, - // don't delete any cells. + // Find probability of observing nbads or more events of probability + // p in a sample of size ncells, and if that is at least bound, + // don't delete any cells. - if binomial_sum(ncells, ncells - nbads, 1.0 - p) >= bound { - orbits2.push(o.clone()); - continue 'orbit; - } + if binomial_sum(ncells, ncells - nbads, 1.0 - p) >= bound { + orbits2.push(o.clone()); + continue 'orbit; } } let mut to_deletex = vec![false; o.len()]; diff --git a/enclone_stuff/src/inconsistent.rs b/enclone_stuff/src/inconsistent.rs index 68b79225a..d96be6cdc 100644 --- a/enclone_stuff/src/inconsistent.rs +++ b/enclone_stuff/src/inconsistent.rs @@ -17,7 +17,7 @@ use enclone_core::defs::{EncloneControl, ExactClonotype, GexInfo, TigData}; use rayon::prelude::*; use stats_utils::binomial_sum; -use std::time::Instant; + use vector_utils::{bin_member, bin_position, reverse_sort}; pub fn test_vdj_gex_inconsistent( @@ -27,8 +27,6 @@ pub fn test_vdj_gex_inconsistent( vdj_cells: &[Vec], gex_info: &GexInfo, ) -> Result<(), &'static str> { - let tinc = Instant::now(); - let mut results = Vec::<(usize, String)>::new(); for li in 0..ctl.origin_info.n() { results.push((li, String::new())); diff --git a/enclone_stuff/src/merge_onesies.rs b/enclone_stuff/src/merge_onesies.rs index 5788a1299..dd93fee54 100644 --- a/enclone_stuff/src/merge_onesies.rs +++ b/enclone_stuff/src/merge_onesies.rs @@ -42,7 +42,7 @@ pub fn merge_onesies( } } alltigs2.sort(); - for x in onesies.iter() { + for x in &onesies { let low = lower_bound1_2(&alltigs2, &info[*x].tigs[0]); let high = upper_bound1_2(&alltigs2, &info[*x].tigs[0]); let mut ms = Vec::::new(); @@ -59,7 +59,7 @@ pub fn merge_onesies( } let mut o = Vec::::new(); eq.orbit(alltigs2[ms[j]].1 as i32, &mut o); - for z in o.iter() { + for z in &o { exacts.push(info[*z as usize].clonotype_index); } } @@ -80,7 +80,7 @@ pub fn merge_onesies( let mut donors = vec![Vec::>::new(); 2]; let orbs = [&orb1, &orb2]; for (pass, orb) in orbs.iter().enumerate() { - for id in orbits[**orb].iter() { + for id in &orbits[**orb] { let ex = &exact_clonotypes[info[*id as usize].clonotype_id]; for i in 0..ex.clones.len() { donors[pass].push(ex.clones[i][0].donor_index); diff --git a/enclone_stuff/src/some_filters.rs b/enclone_stuff/src/some_filters.rs index 5d31edb12..051f505f6 100644 --- a/enclone_stuff/src/some_filters.rs +++ b/enclone_stuff/src/some_filters.rs @@ -14,7 +14,7 @@ use qd::Double; use rayon::prelude::*; use std::cmp::max; use std::collections::{HashMap, HashSet}; -use std::time::Instant; + use vdj_ann::refx::RefData; use vector_utils::{erase_if, next_diff1_2, unique_sort}; @@ -55,7 +55,6 @@ pub fn some_filters( // // Note duplication of calls to define_mat with other code. This is expensive. - let tsig = Instant::now(); const SIG_MULT: usize = 20; let mut results = Vec::<(usize, Vec<(usize, String, BarcodeFate)>, Vec)>::new(); for i in 0..orbits.len() { @@ -123,7 +122,7 @@ pub fn some_filters( for j in 0..freq.len() { if j != i && freq[j].1.len() == 2 { let mut share = false; - for x in freq[j].1.iter() { + for x in &freq[j].1 { if freq[i].1.contains(x) { share = true; } @@ -189,12 +188,10 @@ pub fn some_filters( // Merge onesies where totally unambiguous. - let tmerge = Instant::now(); merge_onesies(orbits, ctl, exact_clonotypes, info, eq, disintegrated); // Check for disjoint orbits. - let tsplit = Instant::now(); split_orbits( orbits, is_bcr, @@ -210,7 +207,6 @@ pub fn some_filters( // Test for weak chains. - let tweak = Instant::now(); weak_chains( orbits, is_bcr, @@ -227,7 +223,6 @@ pub fn some_filters( // Check for disjoint orbits (again). - let tsplit = Instant::now(); split_orbits( orbits, is_bcr, @@ -412,7 +407,7 @@ pub fn some_filters( for j in 0..results[i].1.len() { fate[results[i].1[j].0].insert(results[i].1[j].1.clone(), results[i].1[j].2.clone()); } - for x in results[i].2.iter() { + for x in &results[i].2 { to_delete[*x] = true; } } @@ -430,7 +425,6 @@ pub fn some_filters( // Check for disjoint orbits (again again). - let tsplit = Instant::now(); split_orbits( orbits, is_bcr, diff --git a/enclone_stuff/src/split_orbits.rs b/enclone_stuff/src/split_orbits.rs index c828148b7..59d6dbf37 100644 --- a/enclone_stuff/src/split_orbits.rs +++ b/enclone_stuff/src/split_orbits.rs @@ -126,9 +126,9 @@ pub fn split_orbits( for (l2, eqm) in lists.iter().zip(eqm.into_iter()) { if eqm { let u1 = l1[0]; - for &u2 in l2.iter() { - for &i1 in to_infos[u1].iter() { - for &i2 in to_infos[u2].iter() { + for &u2 in l2 { + for &i1 in &to_infos[u1] { + for &i2 in &to_infos[u2] { eqx.join(i1 as i32, i2 as i32); } } diff --git a/enclone_stuff/src/start.rs b/enclone_stuff/src/start.rs index 8eff7d561..5199b4024 100644 --- a/enclone_stuff/src/start.rs +++ b/enclone_stuff/src/start.rs @@ -34,7 +34,6 @@ use std::{ env, fs::File, io::{BufRead, BufWriter, Write}, - time::Instant, }; use string_utils::{add_commas, TextUtils}; use vector_utils::{bin_member, erase_if, next_diff12_3, sort_sync2, unique_sort}; @@ -102,7 +101,6 @@ pub fn stirling2_ratio_table_double(n_max: usize) -> Vec> { // ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ pub fn main_enclone_start(setup: EncloneSetup) -> Result { - let tr = Instant::now(); let ctl = &setup.ctl; let gex_info = &setup.gex_info; let refdata = &setup.refdata; @@ -119,8 +117,6 @@ pub fn main_enclone_start(setup: EncloneSetup) -> Result Result::new(); let mut fr2_starts = Vec::>::new(); let mut fr3_starts = Vec::>::new(); @@ -163,7 +158,6 @@ pub fn main_enclone_start(setup: EncloneSetup) -> Result Result::new(); for ex in &exact_clonotypes { @@ -282,13 +275,11 @@ pub fn main_enclone_start(setup: EncloneSetup) -> Result = build_info(refdata, ctl, &mut exact_clonotypes, &mut fate); // Derive consensus sequences for alternate alleles of V segments. Then create donor // reference sequences for Loupe. - let talt = Instant::now(); // {(donor, ref id, alt seq, support, is_ref)}: let mut alt_refs = Vec::<(usize, usize, DnaString, usize, bool)>::new(); if !ctl.gen_opt.no_alt_alleles { @@ -324,7 +315,6 @@ pub fn main_enclone_start(setup: EncloneSetup) -> Result Result>::new(); for (i, ex) in exact_clonotypes.iter().enumerate() { for clone in &ex.clones { @@ -352,12 +341,10 @@ pub fn main_enclone_start(setup: EncloneSetup) -> Result Result>::new(); for (i, ex) in exact_clonotypes.iter().enumerate() { for clone in &ex.clones { @@ -454,7 +440,6 @@ pub fn main_enclone_start(setup: EncloneSetup) -> Result>::new(); filter_umi( &eq, @@ -639,7 +624,7 @@ pub fn main_enclone_start(setup: EncloneSetup) -> Result, usize, i32)>::new(); - for id in o.iter() { + for id in o { let x: &CloneInfo = &info[*id as usize]; od.push((x.origin.clone(), x.clonotype_id, *id)); } @@ -670,7 +655,7 @@ pub fn main_enclone_start(setup: EncloneSetup) -> Result Result Result Result<(), String> { // Find matching features for _g etc. - let tstar = Instant::now(); ctl.clono_print_opt.regex_match = vec![HashMap::>::new(); ctl.origin_info.n()]; let ends0 = [ @@ -23,22 +22,21 @@ pub fn match_vars(ctl: &mut EncloneControl, gex_info: &GexInfo) -> Result<(), St let mut ends = Vec::::new(); let mut endsz = Vec::::new(); for (ix, x) in ends0.iter().enumerate() { - for y in suffixes.iter() { + for y in &suffixes { ends.push(format!("{x}{y}")); endsz.push(ends1[ix].to_string()); } } let mut vars = ctl.clono_print_opt.lvars.clone(); vars.append(&mut ctl.parseable_opt.pcols.clone()); - for con in ctl.clono_filt_opt_def.fcell.iter() { + for con in &ctl.clono_filt_opt_def.fcell { for var in con.iter_variable_identifiers() { vars.push(var.to_string()); } } unique_sort(&mut vars); - let tomega = Instant::now(); - for x in vars.iter() { + for x in &vars { for (iy, y) in ends.iter().enumerate() { let mut xc = x.clone(); if x.ends_with("_cell") { diff --git a/enclone_stuff/src/weak_chains.rs b/enclone_stuff/src/weak_chains.rs index 05196854f..6bb4a2ad7 100644 --- a/enclone_stuff/src/weak_chains.rs +++ b/enclone_stuff/src/weak_chains.rs @@ -75,7 +75,7 @@ pub fn weak_chains( } for j in 0..cols { if ncells[j] <= 20 && 8 * ncells[j] < total_cells { - for d in col_entries[j].iter() { + for d in &col_entries[j] { if ctl.clono_filt_opt_def.weak_chains { res.2.push(exacts[*d]); } @@ -98,7 +98,7 @@ pub fn weak_chains( for j in 0..results[i].1.len() { fate[results[i].1[j].0].insert(results[i].1[j].1.clone(), results[i].1[j].2.clone()); } - for x in results[i].2.iter() { + for x in &results[i].2 { to_delete[*x] = true; } } diff --git a/enclone_vars/src/export_code.rs b/enclone_vars/src/export_code.rs index 35fd3187e..6e68150b5 100644 --- a/enclone_vars/src/export_code.rs +++ b/enclone_vars/src/export_code.rs @@ -659,7 +659,7 @@ pub fn export_code(level: usize) -> Vec<(String, String)> { fwrite!(f, "{}", cvar_vdj_start); let vars = std::fs::read_to_string(&vars_loc).unwrap(); let vars = parse_variables(&vars); - for v in vars.iter() { + for v in &vars { if v.inputs == "cvar_vdj" { let (mut exact, mut cell) = (String::new(), String::new()); let mut code = v.code.clone(); @@ -831,7 +831,7 @@ pub fn export_code(level: usize) -> Vec<(String, String)> { fwrite!(f, "{}", lvar_vdj_start); let vars = std::fs::read_to_string(&vars_loc).unwrap(); let vars = parse_variables(&vars); - for v in vars.iter() { + for v in &vars { if v.inputs == "lvar_vdj" { let (mut exact, mut cell) = (String::new(), String::new()); let mut code = v.code.clone(); diff --git a/enclone_vars/src/var.rs b/enclone_vars/src/var.rs index 854cd7c66..deec63f33 100644 --- a/enclone_vars/src/var.rs +++ b/enclone_vars/src/var.rs @@ -99,7 +99,7 @@ pub fn parse_variables(input: &str) -> Vec { // Form variables. let mut vars = Vec::::new(); - for g in groups.iter() { + for g in &groups { vars.push(Variable { name: g[0].clone(), inputs: g[1].clone(), diff --git a/hyperbase/src/lib.rs b/hyperbase/src/lib.rs index c4c0d772b..7dc8fb90a 100644 --- a/hyperbase/src/lib.rs +++ b/hyperbase/src/lib.rs @@ -560,7 +560,7 @@ impl Hyper { let mut maxread: i32 = -1; for e in 0..self.h.g.edge_count() { - for id in self.ids[e].iter() { + for id in &self.ids[e] { maxread = max(maxread, *id as i32); } } @@ -678,7 +678,7 @@ impl Hyper { } to_delete.push(edge_id.index() as u32); for p in (self.h.k - 1)..(edge.len() as i32) { - new_edge.push(edge.get(p as usize)) + new_edge.push(edge.get(p as usize)); } v = self .h @@ -921,7 +921,7 @@ impl Hyper { fn total_supp(&mut self) -> usize { let mut total = 0; for e in 0..self.h.g.edge_count() { - total += self.ids[e].len() + total += self.ids[e].len(); } total } diff --git a/io_utils/src/lib.rs b/io_utils/src/lib.rs index 3b393a10a..b92803af8 100644 --- a/io_utils/src/lib.rs +++ b/io_utils/src/lib.rs @@ -180,7 +180,7 @@ pub fn write_obj + Debug>(g: &T, filename: P) { }; let mut writer = std::io::BufWriter::new(f); serialize_into(&mut writer, &g) - .unwrap_or_else(|_| panic!("write_obj of file {:?} failed", filename)) + .unwrap_or_else(|_| panic!("write_obj of file {:?} failed", filename)); } pub fn read_obj + Debug>(filename: P) -> T { diff --git a/stats_utils/src/lib.rs b/stats_utils/src/lib.rs index 259c132fe..fc673a774 100644 --- a/stats_utils/src/lib.rs +++ b/stats_utils/src/lib.rs @@ -11,12 +11,12 @@ pub fn n50(v: &[i32]) -> i32 { if v.is_empty() { return 0; } - for n in v.iter() { + for n in v { assert!(*n > 0); } let mut sum: i64 = 0; let mut half: i64 = 0; - for n in v.iter() { + for n in v { sum += i64::from(*n); } let mut vs = v.to_owned(); @@ -37,12 +37,12 @@ pub fn n90(v: &[i32]) -> i32 { if v.is_empty() { return 0; } - for n in v.iter() { + for n in v { assert!(*n > 0); } let mut sum: i64 = 0; let mut part: i64 = 0; - for n in v.iter() { + for n in v { sum += i64::from(*n); } let mut vs = v.to_owned(); @@ -64,7 +64,7 @@ pub fn n90(v: &[i32]) -> i32 { pub fn mean(v: &[i32]) -> f64 { let sum1 = v.len() as f64; let mut sum2 = 0_f64; - for x in v.iter() { + for x in v { sum2 += f64::from(*x); } if sum1 == 0_f64 { @@ -80,7 +80,7 @@ pub fn mean(v: &[i32]) -> f64 { pub fn len_weighted_mean(v: &[i32]) -> f64 { let mut sum1 = 0_f64; let mut sum2 = 0_f64; - for x in v.iter() { + for x in v { sum1 += f64::from(*x); sum2 += f64::from(*x) * f64::from(*x); } diff --git a/stirling_numbers/src/lib.rs b/stirling_numbers/src/lib.rs index 7b3e16210..0c9866f91 100644 --- a/stirling_numbers/src/lib.rs +++ b/stirling_numbers/src/lib.rs @@ -203,7 +203,7 @@ mod tests { let mut seeds = Vec::<[u8; 32]>::with_capacity(group); for _ in 0..group { let mut x = [0_u8; 32]; - for xj in x.iter_mut() { + for xj in &mut x { *xj = rng.gen_range(0..255); } seeds.push(x); diff --git a/string_utils/src/lib.rs b/string_utils/src/lib.rs index fbff74c27..f6633a211 100644 --- a/string_utils/src/lib.rs +++ b/string_utils/src/lib.rs @@ -207,7 +207,7 @@ pub fn cap1(s: &str) -> String { let mut x = s.as_bytes().to_vec(); let c = x[0].to_ascii_uppercase(); x[0] = c; - String::from_utf8(x.to_vec()).unwrap() + String::from_utf8(x.clone()).unwrap() } // stolen from internet, add commas to number diff --git a/tables/src/lib.rs b/tables/src/lib.rs index 03c494cbe..182c0c4be 100644 --- a/tables/src/lib.rs +++ b/tables/src/lib.rs @@ -15,7 +15,7 @@ pub fn package_characters_with_escapes(c: &[u8]) -> Vec> { let mut x = Vec::>::new(); let mut escaped = false; let mut package = Vec::::new(); - for b in c.iter() { + for b in c { if escaped && *b != b'm' { package.push(*b); } else if *b == b'' { @@ -37,7 +37,7 @@ pub fn package_characters_with_escapes_char(c: &[char]) -> Vec> { let mut x = Vec::>::new(); let mut escaped = false; let mut package = Vec::::new(); - for b in c.iter() { + for b in c { if escaped && *b != 'm' { package.push(*b); } else if *b == '' { diff --git a/vdj_ann/src/annotate.rs b/vdj_ann/src/annotate.rs index ed0587a47..e76bd4ce2 100644 --- a/vdj_ann/src/annotate.rs +++ b/vdj_ann/src/annotate.rs @@ -358,7 +358,7 @@ pub fn annotate_seq_core( } if verbose { fwriteln!(log, "\nINITIAL PERF ALIGNMENTS\n"); - for s in perf.iter() { + for s in &perf { fwriteln!( log, "t = {}, offset = {}, tig start = {}, ref start = {}, len = {}", @@ -439,7 +439,7 @@ pub fn annotate_seq_core( perf.sort_unstable(); if verbose { fwriteln!(log, "\nPERF ALIGNMENTS\n"); - for s in perf.iter() { + for s in &perf { fwriteln!( log, "t = {}, offset = {}, tig start = {}, ref start = {}, len = {}", @@ -871,7 +871,7 @@ pub fn annotate_seq_core( // { ( sequence start, match length, ref tig, ref tig start, {mismatches} ) }. let mut annx = Vec::::new(); - for x in semi.iter() { + for x in &semi { annx.push(PreAnnotation { tig_start: x.2, match_len: x.3, @@ -886,7 +886,7 @@ pub fn annotate_seq_core( if !allow_improper { let mut to_delete: Vec = vec![false; annx.len()]; - for annxi in annx.iter_mut() { + for annxi in &mut annx { std::mem::swap(&mut annxi.tig_start, &mut annxi.ref_id); std::mem::swap(&mut annxi.match_len, &mut annxi.ref_start); } @@ -911,7 +911,7 @@ pub fn annotate_seq_core( i1 = j1 as usize; } erase_if(&mut annx, &to_delete); - for annxi in annx.iter_mut() { + for annxi in &mut annx { std::mem::swap(&mut annxi.tig_start, &mut annxi.ref_id); std::mem::swap(&mut annxi.match_len, &mut annxi.ref_start); } @@ -1037,12 +1037,12 @@ pub fn annotate_seq_core( } over += stop as i64; over -= start as i64; - for x in annx[u1].mismatches.iter() { + for x in &annx[u1].mismatches { if *x >= start && *x < stop { m1 += 1; } } - for x in annx[u2].mismatches.iter() { + for x in &annx[u2].mismatches { if *x >= start && *x < stop { m2 += 1; } @@ -1496,12 +1496,12 @@ pub fn annotate_seq_core( utr2 = refdata.has_utr[name2]; } let (mut have_utr_align1, mut have_utr_align2) = (false, false); - for j in data[i1].2.iter() { + for j in &data[i1].2 { if refdata.is_u(annx[*j].ref_id as usize) { have_utr_align1 = true; } } - for j in data[i2].2.iter() { + for j in &data[i2].2 { if refdata.is_u(annx[*j].ref_id as usize) { have_utr_align2 = true; } @@ -1511,13 +1511,13 @@ pub fn annotate_seq_core( let n = b_seq.len(); let (mut mis1, mut mis2) = (vec![false; n], vec![false; n]); - for j in data[i1].2.iter() { - for p in annx[*j].mismatches.iter() { + for j in &data[i1].2 { + for p in &annx[*j].mismatches { mis1[*p as usize] = true; } } - for j in data[i2].2.iter() { - for p in annx[*j].mismatches.iter() { + for j in &data[i2].2 { + for p in &annx[*j].mismatches { mis2[*p as usize] = true; } } @@ -1765,7 +1765,7 @@ pub fn annotate_seq_core( // Make decision. if win1 { - for l in data[i2].2.iter() { + for l in &data[i2].2 { to_delete[*l] = true; } deleted[i2] = true; @@ -2015,7 +2015,7 @@ pub fn annotate_seq_core( let start = max(0, vstop - VJTRIM); let stop = min(b.len() as i32, jstart + VJTRIM); const MAX_MISMATCHES: usize = 3; - for t in refdata.ds.iter() { + for t in &refdata.ds { if refdata.rtype[*t] == v_rtype { let r = &refdata.refs[*t]; for m in start..=stop - (r.len() as i32) { @@ -2535,7 +2535,7 @@ pub fn annotate_seq_core( // Transform. ann.clear(); - for x in annx.iter() { + for x in &annx { ann.push(Annotation { tig_start: x.tig_start, match_len: x.match_len, @@ -2665,7 +2665,7 @@ pub struct CDR3Annotation { right_flank_score: usize, } -pub fn get_cdr3(contig: &DnaStringSlice) -> Vec { +pub fn get_cdr3(contig: &DnaStringSlice<'_>) -> Vec { const MIN_TOTAL_CDR3_SCORE: usize = 10; // about as high as one can go let left_motifs = cdr3_motif_left(); @@ -2760,8 +2760,8 @@ pub fn get_cdr3(contig: &DnaStringSlice) -> Vec { aa_seq: amino_acid_seq [cdr3_start_pos..right_motif_start_pos + 2 + 1] .to_vec(), - left_flank_score: left_flank_score, - right_flank_score: right_flank_score, + left_flank_score, + right_flank_score, }); } } @@ -2795,7 +2795,7 @@ pub fn get_cdr3(contig: &DnaStringSlice) -> Vec { found_cdr3s } -pub fn print_cdr3(tig: &DnaStringSlice, log: &mut Vec) { +pub fn print_cdr3(tig: &DnaStringSlice<'_>, log: &mut Vec) { let cdr3_anns = get_cdr3(tig); for cdr3 in cdr3_anns { fwriteln!( @@ -2999,7 +2999,7 @@ impl AnnotationUnit { for c in cig.chars() { if c.is_ascii_alphabetic() { if c == 'S' { - s_pos.push(char_pos) + s_pos.push(char_pos); } char_pos += 1; } @@ -3496,7 +3496,7 @@ mod tests { for c in ann.cigar.chars() { if c.is_ascii_alphabetic() { if c == 'S' { - s_pos.push(char_pos) + s_pos.push(char_pos); } char_pos += 1; } @@ -3505,7 +3505,7 @@ mod tests { println!("Cigar : {:?}", ann.cigar); println!("Soft clipping at : {s_pos:?}"); for p in &s_pos { - assert!(*p == 0 || *p == (char_pos - 1)) + assert!(*p == 0 || *p == (char_pos - 1)); } } } diff --git a/vdj_ann/src/transcript.rs b/vdj_ann/src/transcript.rs index 36e73c231..f21d5f2d1 100644 --- a/vdj_ann/src/transcript.rs +++ b/vdj_ann/src/transcript.rs @@ -167,7 +167,7 @@ fn evaluate_contig_status( !(vstart.tig_start..jstop.tig_stop - 3) .step_by(3) .any(|j| have_stop(contig, j)), - ) + ); }; let found_cdr3s = get_cdr3_using_ann(contig, reference, ann); @@ -192,7 +192,7 @@ fn evaluate_contig_status( }; let observed_order: Vec = ann - .into_iter() + .iter() .map(|a| reference.segtype[a.ref_id as usize]) .map(|s| match s { "U" => 0, @@ -309,7 +309,7 @@ pub fn junction_supp_core( // ◼ What we're doing here is converting a Vec into a Vec. // ◼ There should be a function to do that. for e in 0..x.h.g.edge_count() { - for id in x.ids[e].iter() { + for id in &x.ids[e] { ids.push(*id as i32); } } @@ -364,7 +364,7 @@ pub fn junction_supp_core( cov = false; } let mut reach = 0; - for m in mm.iter() { + for m in &mm { if m.0 <= reach { reach = max(reach, m.1); } diff --git a/vdj_ann_ref/src/bin/build_supp_ref.rs b/vdj_ann_ref/src/bin/build_supp_ref.rs index ca3ec431d..02de2b913 100644 --- a/vdj_ann_ref/src/bin/build_supp_ref.rs +++ b/vdj_ann_ref/src/bin/build_supp_ref.rs @@ -37,7 +37,7 @@ use fasta_tools::read_fasta_into_vec_dna_string_plus_headers; use std::{collections::HashMap, env}; use string_utils::TextUtils; -fn print_fasta(header: &str, seq: &DnaStringSlice) { +fn print_fasta(header: &str, seq: &DnaStringSlice<'_>) { println!(">{}\n{}", header, seq.to_string()); } diff --git a/vdj_ann_ref/src/bin/build_vdj_ref.rs b/vdj_ann_ref/src/bin/build_vdj_ref.rs index 7d36a7810..c665712bc 100644 --- a/vdj_ann_ref/src/bin/build_vdj_ref.rs +++ b/vdj_ann_ref/src/bin/build_vdj_ref.rs @@ -148,7 +148,7 @@ fn header_from_gene(gene: &str, is_utr: bool, record: &mut usize, source: &str) format!("{record}|{gene} {source}|{gene}|{region_type}|{header_tail}") } -fn print_fasta(out: &mut R, header: &str, seq: &DnaStringSlice, none: bool) { +fn print_fasta(out: &mut R, header: &str, seq: &DnaStringSlice<'_>, none: bool) { if none { return; } @@ -158,7 +158,7 @@ fn print_fasta(out: &mut R, header: &str, seq: &DnaStringSlice, none: fn print_oriented_fasta( out: &mut R, header: &str, - seq: &DnaStringSlice, + seq: &DnaStringSlice<'_>, fw: bool, none: bool, ) { @@ -988,8 +988,8 @@ fn main() { .expect("git commit failed"); } // ◼ Add balbc if we're going ot use it. - for species in ["human", "mouse"].iter() { - for ftype in ["gff3", "gtf", "fasta"].iter() { + for species in &["human", "mouse"] { + for ftype in &["gff3", "gtf", "fasta"] { fetch(species, ftype, release); } } @@ -1125,7 +1125,7 @@ fn main() { // More fixing. Replace e.g. "alpha " by A. - for x in [ + for x in &[ "alpha", "beta", "gamma", @@ -1139,9 +1139,7 @@ fn main() { "joining", "constant", "heavy", - ] - .iter() - { + ] { gene2 = gene2.replace(&format!("{x} "), &x[0..1].to_uppercase()); } @@ -1229,7 +1227,7 @@ fn main() { using = false; } } else if using { - last += &s + last += &s; } } if using { @@ -1274,7 +1272,7 @@ fn main() { if !exons[i].6 { x.reverse(); for k in 0..x.len() { - x[k] = x[k].rc().to_owned(); + x[k] = x[k].rc().clone(); } } dnas.push((x, i, j)); diff --git a/vdj_ann_ref/src/bin/build_vdj_ref_exons.rs b/vdj_ann_ref/src/bin/build_vdj_ref_exons.rs index 7b24f62b9..fcfafbe6c 100644 --- a/vdj_ann_ref/src/bin/build_vdj_ref_exons.rs +++ b/vdj_ann_ref/src/bin/build_vdj_ref_exons.rs @@ -629,8 +629,8 @@ fn main() { .expect("git commit failed"); } // ◼ Add balbc if we're going ot use it. - for species in ["human", "mouse"].iter() { - for ftype in ["gff3", "gtf", "fasta"].iter() { + for species in &["human", "mouse"] { + for ftype in &["gff3", "gtf", "fasta"] { fetch(species, ftype, release); } } @@ -766,7 +766,7 @@ fn main() { // More fixing. Replace e.g. "alpha " by A. - for x in [ + for x in &[ "alpha", "beta", "gamma", @@ -780,9 +780,7 @@ fn main() { "joining", "constant", "heavy", - ] - .iter() - { + ] { gene2 = gene2.replace(&format!("{x} "), &x[0..1].to_uppercase()); } @@ -857,7 +855,7 @@ fn main() { } let mut h = s.get(1..).unwrap(); if h.contains(' ') { - h = h.before(" ") + h = h.before(" "); } if bin_member(&all_chrs, h) { rheaders.push(h.to_string()); @@ -866,7 +864,7 @@ fn main() { using = false; } } else if using { - last += &s + last += &s; } } if using { diff --git a/vdj_types/src/lib.rs b/vdj_types/src/lib.rs index c8b4b9c7b..4b4b57740 100644 --- a/vdj_types/src/lib.rs +++ b/vdj_types/src/lib.rs @@ -254,7 +254,7 @@ mod tests { assert_eq!( chain.to_string().parse::().unwrap(), contig_chain - ) + ); } assert_eq!(VdjContigChain::Multi.to_string(), "Multi"); assert_eq!(