Skip to content

Commit

Permalink
deny clippy::needless_range_loop (#402)
Browse files Browse the repository at this point in the history
Remove the exception to the clippy::needless_range_loop lint and fix many violations.
  • Loading branch information
macklin-10x authored Mar 29, 2024
1 parent 9ff82a8 commit 6246175
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 422 deletions.
1 change: 0 additions & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ rustflags = [
"-A", "clippy::comparison_chain",
# TODO: burn down these allow exceptions and then deny them
"-A", "clippy::too_many_arguments",
"-A", "clippy::needless_range_loop",
]

[target.x86_64-unknown-linux-gnu]
Expand Down
19 changes: 7 additions & 12 deletions dna/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ pub fn tm_nearest_neighbor_full(s: &str, s_mol: f64, na_mol: f64, locked: &[bool
for c in s.chars() {
sx.push(c);
}
let mut gc = 0;
for i in 0..sx.len() {
if sx[i] == 'G' || sx[i] == 'C' {
gc += 1;
}
}
let gc = sx.iter().filter(|c| **c == 'G' || **c == 'C').count();
let gc_fract = gc as f64 / sx.len() as f64;
let ln_na_mol = na_mol.ln();

Expand Down Expand Up @@ -431,12 +426,12 @@ pub fn thermodynamic_sums_dna(
sx.push(c);
}
let mut b = Vec::<usize>::new();
for i in 0..sx.len() {
if sx[i] == 'A' {
for sx_i in &sx {
if *sx_i == 'A' {
b.push(0);
} else if sx[i] == 'C' {
} else if *sx_i == 'C' {
b.push(1);
} else if sx[i] == 'G' {
} else if *sx_i == 'G' {
b.push(2);
} else {
b.push(3);
Expand All @@ -451,8 +446,8 @@ pub fn thermodynamic_sums_dna(
// Handle locked bases.

let mut have_lock = false;
for i in 0..locked.len() {
if locked[i] {
for locked_i in locked {
if *locked_i {
have_lock = true;
}
}
Expand Down
4 changes: 1 addition & 3 deletions fasta_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ pub fn read_fasta_contents_into_vec_dna_string_plus_headers(
) {
let mut last: String = String::new();
let mut first = true;
let lines = f.split('\n').collect::<Vec<&str>>();
for i in 0..lines.len() {
let s = &lines[i];
for s in f.split('\n') {
if first {
if !s.starts_with('>') {
panic!("fasta format failure reading {}", f);
Expand Down
20 changes: 10 additions & 10 deletions graph_simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ where
fn get_predecessors(&self, v: &[i32], x: &mut Vec<u32>) {
let mut check: Vec<u32> = Vec::new();
let mut tov: HashSet<u32> = HashSet::new();
for j in 0..v.len() {
let s: u32 = v[j] as u32;
for v_i in v {
let s: u32 = *v_i as u32;
check.push(s);
tov.insert(s);
}
Expand Down Expand Up @@ -205,8 +205,8 @@ where
fn get_successors(&self, v: &[i32], x: &mut Vec<u32>) {
let mut check: Vec<u32> = Vec::new();
let mut fromv: HashSet<u32> = HashSet::new();
for j in 0..v.len() {
let s: u32 = v[j] as u32;
for v_i in v {
let s: u32 = *v_i as u32;
check.push(s);
fromv.insert(s);
}
Expand Down Expand Up @@ -275,23 +275,23 @@ where

fn components_e(&self, comp: &mut Vec<Vec<u32>>) {
self.components(comp);
for j in 0..comp.len() {
for comp_i in comp {
let mut c = Vec::<u32>::new();
for i in 0..comp[j].len() {
let v = comp[j][i];
for comp_i_j in comp_i.iter() {
let v = *comp_i_j;
let n = self.n_from(v as usize);
for l in 0..n {
c.push(self.e_from(v as usize, l) as u32);
}
}
comp[j] = c;
*comp_i = c;
}
}

fn components_e_pos_sorted(&self, comp: &mut Vec<Vec<u32>>) {
self.components_e(comp);
for u in 0..comp.len() {
comp[u].sort_by(|a, b| {
for comp_i in comp {
comp_i.sort_by(|a, b| {
if a == b {
return std::cmp::Ordering::Equal;
}
Expand Down
46 changes: 20 additions & 26 deletions hyperbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ pub fn debruijn_to_petgraph_hyperbasevector<K: Kmer>(
// the natural equivalence relation.

let mut eq: EquivRel = EquivRel::new(2 * edges.len() as i32);
for i in 0..adj.len() {
let left = adj[i].0;
let right = adj[i].1;
for (left, right) in adj {
eq.join(2 * left + 1, 2 * right);
}
let mut reps = Vec::<i32>::new();
Expand All @@ -132,13 +130,13 @@ pub fn debruijn_to_petgraph_hyperbasevector<K: Kmer>(
for i in 0..reps.len() {
g_out.add_node(i as u32);
}
for e in 0..edges.len() {
for (e, edge) in edges.into_iter().enumerate() {
let v = bin_position(&reps, &eq.class_id((2 * e) as i32));
let w = bin_position(&reps, &eq.class_id((2 * e + 1) as i32));
g_out.add_edge(
NodeIndex::<u32>::new(v as usize),
NodeIndex::<u32>::new(w as usize),
edges[e].2.clone(),
edge.2,
);
}
}
Expand Down Expand Up @@ -273,10 +271,9 @@ impl Hyper {
pub fn print(&self) {
let mut comp = Vec::<Vec<u32>>::new();
self.h.g.components_e(&mut comp);
for j in 0..comp.len() {
for (j, comp_j) in comp.into_iter().enumerate() {
println!("\nCOMPONENT {}", j + 1);
for i in 0..comp[j].len() {
let e = comp[j][i];
for e in comp_j {
let v = self.h.g.to_left(e);
let w = self.h.g.to_right(e);
let b: DnaString = self.h.g[EdgeIndex::<u32>::new(e as usize)].clone();
Expand Down Expand Up @@ -304,11 +301,10 @@ impl Hyper {
let mut comp = Vec::<Vec<u32>>::new();
self.h.g.components_e(&mut comp);
let mut n = 0;
for j in 0..comp.len() {
for comp_j in comp {
let mut have_ann = false;
for i in 0..comp[j].len() {
let e = comp[j][i] as usize;
if !ann[e].is_empty() {
for e in &comp_j {
if !ann[*e as usize].is_empty() {
have_ann = true;
}
}
Expand All @@ -317,8 +313,8 @@ impl Hyper {
}
n += 1;
println!("\nCOMPONENT {n}");
for i in 0..comp[j].len() {
let e = comp[j][i] as usize;
for e in comp_j {
let e = e as usize;
let v = self.h.g.to_left(e as u32);
let w = self.h.g.to_right(e as u32);
let b: DnaString = self.h.g[EdgeIndex::<u32>::new(e)].clone();
Expand Down Expand Up @@ -422,22 +418,22 @@ impl Hyper {
make_kmer_lookup_20_single(&edges, &mut kmers_plus);
drop(edges);
let mut maxread = 0;
for id in 0..reads.len() {
maxread = max(maxread, reads[id].len());
for read in reads {
maxread = max(maxread, read.len());
}
if maxread < k as usize {
return;
}
let mut next_rpos: Vec<i32> = vec![0; reads.len()];
for pos in 0..maxread - (k as usize) + 1 {
for id in 0..reads.len() {
if pos + k as usize > reads[id].len() {
for (id, read) in reads.iter().enumerate() {
if pos + k as usize > read.len() {
continue;
}
if pos < next_rpos[id] as usize {
continue;
}
let x: Kmer20 = reads[id].get_kmer(pos);
let x: Kmer20 = read.get_kmer(pos);
let p = bin_position1_3(&kmers_plus, &x);
if p < 0 {
continue;
Expand All @@ -448,17 +444,15 @@ impl Hyper {
let mut epos = kmers_plus[p as usize].2 + k;
self.ids[e as usize].push(id as u32);
loop {
if rpos == reads[id].len() {
if rpos == read.len() {
break;
}
let mut next = false;
if epos == self.h.bases(e as u32) as i32 {
let v = self.h.g.to_right(e as u32);
for j in 0..self.h.g.n_from(v as usize) {
let f = self.h.g.e_from(v as usize, j);
if self.h.g.edge_obj(f as u32).get((k - 1) as usize)
== reads[id].get(rpos)
{
if self.h.g.edge_obj(f as u32).get((k - 1) as usize) == read.get(rpos) {
e = f as i32;
self.ids[e as usize].push(id as u32);
epos = k - 1;
Expand All @@ -472,7 +466,7 @@ impl Hyper {
}
}
if !next {
if reads[id].get(rpos) != self.h.g.edge_obj(e as u32).get(epos as usize) {
if read.get(rpos) != self.h.g.edge_obj(e as u32).get(epos as usize) {
break;
}
rpos += 1;
Expand Down Expand Up @@ -893,8 +887,8 @@ impl Hyper {
let mut comp = Vec::<Vec<u32>>::new();
self.h.g.components_e(&mut comp);
let mut sizes = Vec::<usize>::new();
for j in 0..comp.len() {
sizes.push(comp[j].len());
for c in comp {
sizes.push(c.len());
}
reverse_sort(&mut sizes);
print!("component sizes = [");
Expand Down
Loading

0 comments on commit 6246175

Please sign in to comment.