Skip to content

Commit

Permalink
deny clippy::type_complexity (#401)
Browse files Browse the repository at this point in the history
Removes the allow exception for clippy::type_complexity and fixes all errors. I was mostly able to replace anonymous tuples with structs, but one section relied on some existing tuple-specific logic so I created a type alias and moved on.
  • Loading branch information
macklin-10x authored Mar 22, 2024
1 parent 2fe59f3 commit 3a73cf0
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 113 deletions.
1 change: 0 additions & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ rustflags = [
# --- 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",
]
Expand Down
53 changes: 19 additions & 34 deletions enclone/src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
// contigs that represent the sequence of the "other" allele. This does not look easy to
// execute.

use enclone_core::enclone_structs::JoinInfo;
use vdj_ann::{annotate, refx};

use self::annotate::print_annotations;
use self::refx::RefData;
use crate::join2::finish_join;
use crate::join2::{finish_join, JoinResult};
use crate::join_core::join_core;
use debruijn::dna_string::DnaString;
use enclone_core::defs::{CloneInfo, EncloneControl, ExactClonotype, PotentialJoin};
Expand All @@ -34,7 +35,7 @@ pub fn join_exacts(
ctl: &EncloneControl,
exact_clonotypes: &[ExactClonotype],
info: &[CloneInfo],
join_info: &mut Vec<(usize, usize, bool, Vec<u8>)>,
join_info: &mut Vec<JoinInfo>,
raw_joins: &mut Vec<(i32, i32)>,
sr: &[Vec<Double>],
dref: &[DonorReferenceItem],
Expand Down Expand Up @@ -66,14 +67,7 @@ pub fn join_exacts(
// Find potential joins.

let mut i = 0;
let mut results = Vec::<(
usize, // i
usize, // j
usize, // joins
usize, // errors
Vec<(usize, usize, bool, Vec<u8>)>, // log+ (index1, index2, err?, log)
Vec<(usize, usize)>, // joinlist
)>::new();
let mut results = Vec::<JoinResult>::new();
while i < info.len() {
let mut j = i + 1;
while j < info.len() {
Expand All @@ -90,32 +84,18 @@ pub fn join_exacts(
}
j += 1;
}
results.push((
i,
j,
0,
0,
Vec::<(usize, usize, bool, Vec<u8>)>::new(),
Vec::<(usize, usize)>::new(),
));
results.push(JoinResult::new(i, j));
i = j;
}
if !ctl.silent {
println!("comparing {} simple clonotypes", info.len());
}

let joinf = |r: &mut (
usize,
usize,
usize,
usize,
Vec<(usize, usize, bool, Vec<u8>)>,
Vec<(usize, usize)>,
)| {
let (i, j) = (r.0, r.1);
let joins = &mut r.2;
let errors = &mut r.3;
let logplus = &mut r.4;
let joinf = |r: &mut JoinResult| {
let (i, j) = (r.i, r.j);
let joins = &mut r.joins;
let errors = &mut r.errors;
let logplus = &mut r.join_info;
let mut pot = Vec::<PotentialJoin<'_>>::new();

// Main join logic. If you change par_iter_mut to iter_mut above, and run happening,
Expand Down Expand Up @@ -228,7 +208,7 @@ pub fn join_exacts(

// Save join and tally stats.

r.5.push((k1, k2));
r.join_list.push((k1, k2));
*joins += 1;
if err {
*errors += 1;
Expand Down Expand Up @@ -592,16 +572,21 @@ pub fn join_exacts(
}
}
*/
logplus.push((info[k1].clonotype_index, info[k2].clonotype_index, err, log));
logplus.push(JoinInfo {
index1: info[k1].clonotype_index,
index2: info[k2].clonotype_index,
err,
log,
});
}
};

results.par_iter_mut().for_each(joinf);

for r in &results {
for &j in &r.5 {
for &j in &r.join_list {
raw_joins.push((j.0 as i32, j.1 as i32));
}
}
finish_join(ctl, info, &results, join_info)
finish_join(ctl, info, results, join_info)
}
89 changes: 41 additions & 48 deletions enclone/src/join2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,54 @@

// This file provides the tail end code for join.rs, plus a small function used there.

use enclone_core::defs::{CloneInfo, EncloneControl};
use enclone_core::{
defs::{CloneInfo, EncloneControl},
enclone_structs::JoinInfo,
};
use equiv::EquivRel;
use stats_utils::percent_ratio;

use vector_utils::next_diff1_2;

// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
pub struct JoinResult {
pub i: usize,
pub j: usize,
pub joins: usize,
pub errors: usize,
pub join_info: Vec<JoinInfo>,
pub join_list: Vec<(usize, usize)>,
}

impl JoinResult {
pub fn new(i: usize, j: usize) -> Self {
Self {
i,
j,
joins: 0,
errors: 0,
join_info: Default::default(),
join_list: Default::default(),
}
}
}

pub fn finish_join(
ctl: &EncloneControl,
info: &[CloneInfo],
results: &[(
usize,
usize,
usize,
usize,
Vec<(usize, usize, bool, Vec<u8>)>,
Vec<(usize, usize)>,
)],
join_info: &mut Vec<(usize, usize, bool, Vec<u8>)>,
results: Vec<JoinResult>,
join_info: &mut Vec<JoinInfo>,
) -> EquivRel {
// Tally results.

// Make equivalence relation.
let (mut joins, mut errors) = (0, 0);
let mut eq: EquivRel = EquivRel::new(info.len() as i32);

for r in results {
joins += r.2;
errors += r.3;
for i in &r.4 {
let u1 = i.0;
let u2 = i.1;
let err = i.2;
let log = i.3.clone();
join_info.push((u1, u2, err, log));
joins += r.joins;
errors += r.errors;
join_info.extend(r.join_info.into_iter());
for j in &r.join_list {
eq.join(j.0 as i32, j.1 as i32);
}
}
if !ctl.silent {
Expand All @@ -43,14 +58,12 @@ pub fn finish_join(
println!("{errors} errors");
}
}

// Make equivalence relation.

let mut eq: EquivRel = EquivRel::new(info.len() as i32);
for r in results {
for j in &r.5 {
eq.join(j.0 as i32, j.1 as i32);
}
// Report whitelist contamination.
// WARNING: THIS ONLY WORKS IF YOU RUN WITH CLONES=1 AND NO OTHER FILTERS.
// TODO: we should actually make an assertion that this is true.
if ctl.clono_filt_opt_def.whitef || ctl.clono_print_opt.cvars.iter().any(|var| var == "white") {
let bad_rate = percent_ratio(joins, errors);
println!("whitelist contamination rate = {bad_rate:.2}%");
}

// Join orbits that cross subclones of a clone. This arose because we split up multi-chain
Expand All @@ -70,25 +83,5 @@ pub fn finish_join(
i = j;
}

// Tally whitelist contamination.
// WARNING: THIS ONLY WORKS IF YOU RUN WITH CLONES=1 AND NO OTHER FILTERS.

let mut white = ctl.clono_filt_opt_def.whitef;
for j in 0..ctl.clono_print_opt.cvars.len() {
if ctl.clono_print_opt.cvars[j] == "white" {
white = true;
}
}
if white {
let mut bads = 0;
let mut denom = 0;
for r in results {
bads += r.2;
denom += r.3;
}
let bad_rate = percent_ratio(bads, denom);
println!("whitelist contamination rate = {bad_rate:.2}%");
}

eq
}
10 changes: 9 additions & 1 deletion enclone_core/src/enclone_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ pub struct EncloneExacts {
pub info: Vec<CloneInfo>,
pub orbits: Vec<Vec<i32>>,
pub vdj_cells: Vec<Vec<String>>,
pub join_info: Vec<(usize, usize, bool, Vec<u8>)>,
pub join_info: Vec<JoinInfo>,
pub drefs: Vec<DonorReferenceItem>,
pub sr: Vec<Vec<Double>>,
pub fate: Vec<HashMap<String, BarcodeFate>>, // GETS MODIFIED SUBSEQUENTLY
pub is_bcr: bool,
pub allele_data: AlleleData,
}

#[derive(Clone)]
pub struct JoinInfo {
pub index1: usize,
pub index2: usize,
pub err: bool,
pub log: Vec<u8>,
}
1 change: 1 addition & 0 deletions enclone_core/src/mammalian_fixed_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use vdj_ann::vdj_features::{cdr1_start, cdr2_start, cdr3_start, fr1_start, fr2_s

// {chain, feature, len, {{(count, amino_acid)}}}

#[allow(clippy::type_complexity)]
pub fn mammalian_fixed_len() -> Vec<(&'static str, &'static str, usize, Vec<Vec<(u32, u8)>>)> {
const X: &str = include_str!("mammalian_fixed_len.table");
X.lines()
Expand Down
12 changes: 6 additions & 6 deletions enclone_print/src/define_mat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ fn joiner(
e
}

pub fn setup_define_mat(
orbit: &[i32],
info: &[CloneInfo],
) -> (Vec<(Vec<usize>, usize, i32)>, Vec<usize>) {
let mut od = Vec::<(Vec<usize>, usize, i32)>::new();
// TOOD: refactor this into a struct
pub type Od = (Vec<usize>, usize, i32);

pub fn setup_define_mat(orbit: &[i32], info: &[CloneInfo]) -> (Vec<Od>, Vec<usize>) {
let mut od = Vec::<Od>::new();
for id in orbit {
let x: &CloneInfo = &info[*id as usize];
od.push((x.origin.clone(), x.clonotype_id, *id));
Expand All @@ -83,7 +83,7 @@ pub fn define_mat(
ctl: &EncloneControl,
exact_clonotypes: &[ExactClonotype],
exacts: &[usize],
od: &[(Vec<usize>, usize, i32)],
od: &[Od],
info: &[CloneInfo],
raw_joins: &[Vec<usize>],
refdata: &RefData,
Expand Down
15 changes: 10 additions & 5 deletions enclone_print/src/finish_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ use string_utils::TextUtils;
use vdj_ann::refx::RefData;
use vector_utils::bin_member;

pub struct Sr {
pub row: Vec<String>,
pub subrows: Vec<Vec<String>>,
}

pub fn finish_table(
n: usize,
ctl: &EncloneControl,
Expand All @@ -28,7 +33,7 @@ pub fn finish_table(
mlog: &mut Vec<u8>,
logz: &mut String,
stats: &[(String, Vec<String>)],
sr: &mut [(Vec<String>, Vec<Vec<String>>, Vec<Vec<u8>>, usize)],
sr: Vec<Sr>,
extra_args: &[String],
pcols_sort: &[String],
out_data: &mut Vec<HashMap<String, String>>,
Expand Down Expand Up @@ -144,10 +149,10 @@ pub fn finish_table(

// Finish building table content.

for (j, srj) in sr.iter_mut().enumerate() {
srj.0[0] = format!("{}", j + 1); // row number (#)
rows.push(srj.0.clone());
rows.extend(srj.1.clone());
for (j, mut srj) in sr.into_iter().enumerate() {
srj.row[0] = format!("{}", j + 1); // row number (#)
rows.push(srj.row);
rows.extend(srj.subrows);
}

// Add sum and mean rows.
Expand Down
11 changes: 5 additions & 6 deletions enclone_print/src/print_clonotypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
//
// Problem: stack traces from this file consistently do not go back to the main program.

use crate::define_mat::define_mat;
use crate::define_mat::{define_mat, Od};
use crate::filter::survives_filter;
use crate::finish_table::finish_table;
use crate::finish_table::{finish_table, Sr};
use crate::gene_scan::gene_scan_test;
use crate::loupe::{loupe_out, make_loupe_clonotype};
use crate::print_utils1::{compute_field_types, extra_args, start_gen};
Expand Down Expand Up @@ -225,7 +225,7 @@ pub fn print_clonotypes(
results.par_iter_mut().for_each(|res| {
let i = res.0;
let o = &orbits[i];
let mut od = Vec::<(Vec<usize>, usize, i32)>::new();
let mut od = Vec::<Od>::new();
for id in o {
let x: &CloneInfo = &info[*id as usize];
od.push((x.origin.clone(), x.clonotype_id, *id));
Expand Down Expand Up @@ -524,7 +524,7 @@ pub fn print_clonotypes(

// Now build table content.

let mut sr = Vec::<(Vec<String>, Vec<Vec<String>>, Vec<Vec<u8>>, usize)>::new();
let mut sr = Vec::<Sr>::new();
let mut groups = HashMap::<usize, Vec<usize>>::new();
for lvar in &lvars {
if let Some(Ok(d)) = lvar.strip_prefix('g').map(str::parse::<usize>) {
Expand Down Expand Up @@ -712,7 +712,6 @@ pub fn print_clonotypes(
exact_clonotypes,
&mut row,
&mut subrows,
&varmat,
have_gex,
gex_info,
&rsi,
Expand Down Expand Up @@ -883,7 +882,7 @@ pub fn print_clonotypes(
&mut mlog,
&mut logz,
&stats,
&mut sr,
sr,
&extra_args,
pcols_sort,
&mut out_data,
Expand Down
Loading

0 comments on commit 3a73cf0

Please sign in to comment.