Skip to content

Commit d1b61ef

Browse files
authored
chore: clippy borrow and infallible functions (#60)
1 parent f6df086 commit d1b61ef

9 files changed

Lines changed: 72 additions & 78 deletions

File tree

src/align/read_align.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub fn align_read(
311311
junction_db,
312312
params.align_transcripts_per_window_nmax,
313313
debug_name,
314-
)?;
314+
);
315315
if debug_read {
316316
eprintln!(
317317
"[DEBUG {}] Cluster[{}]: {} transcripts from DP",
@@ -814,7 +814,7 @@ pub fn align_paired_read(
814814
params.align_transcripts_per_window_nmax,
815815
params.align_mates_gap_max.into(),
816816
debug_name,
817-
)?;
817+
);
818818

819819
for wt in &wts {
820820
let split_result =

src/align/score.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl AlignmentScorer {
206206
genome_pos
207207
};
208208
let motif = self.detect_splice_motif(donor, len, genome);
209-
let score = self.score_splice_junction(&motif);
209+
let score = self.score_splice_junction(motif);
210210
(
211211
score,
212212
GapType::SpliceJunction {
@@ -235,7 +235,7 @@ impl AlignmentScorer {
235235
rc_donor
236236
};
237237
let motif = self.detect_splice_motif(donor, del_len, genome);
238-
let score = self.score_splice_junction(&motif);
238+
let score = self.score_splice_junction(motif);
239239
(
240240
score,
241241
GapType::SpliceJunction {
@@ -389,7 +389,7 @@ impl AlignmentScorer {
389389
donor_sa
390390
};
391391
let motif = self.detect_splice_motif(donor_fwd, del as u32, genome);
392-
let motif_score = self.score_splice_junction(&motif);
392+
let motif_score = self.score_splice_junction(motif);
393393
let score2 = score1 + motif_score;
394394

395395
if score2 > max_score2 {
@@ -493,7 +493,7 @@ impl AlignmentScorer {
493493
donor_sa
494494
};
495495
best_motif = self.detect_splice_motif(donor_fwd, del as u32, genome);
496-
best_motif_score = self.score_splice_junction(&best_motif);
496+
best_motif_score = self.score_splice_junction(best_motif);
497497
}
498498
}
499499

@@ -518,7 +518,7 @@ impl AlignmentScorer {
518518
}
519519

520520
/// Score a splice junction based on motif
521-
pub(crate) fn score_splice_junction(&self, motif: &SpliceMotif) -> i32 {
521+
pub(crate) fn score_splice_junction(&self, motif: SpliceMotif) -> i32 {
522522
match motif {
523523
SpliceMotif::GtAg | SpliceMotif::CtAc => self.score_gap,
524524
SpliceMotif::GcAg | SpliceMotif::CtGc => self.score_gap_gcag,
@@ -695,7 +695,7 @@ mod tests {
695695
let motif = scorer.detect_splice_motif(2, 12, &genome);
696696
assert_eq!(motif, SpliceMotif::GtAg);
697697

698-
let score = scorer.score_splice_junction(&motif);
698+
let score = scorer.score_splice_junction(motif);
699699
assert_eq!(score, 0); // Canonical
700700
}
701701

@@ -738,7 +738,7 @@ mod tests {
738738
let motif = scorer.detect_splice_motif(2, 12, &genome);
739739
assert_eq!(motif, SpliceMotif::GcAg);
740740

741-
let score = scorer.score_splice_junction(&motif);
741+
let score = scorer.score_splice_junction(motif);
742742
assert_eq!(score, -4);
743743
}
744744

@@ -781,7 +781,7 @@ mod tests {
781781
let motif = scorer.detect_splice_motif(2, 12, &genome);
782782
assert_eq!(motif, SpliceMotif::AtAc);
783783

784-
let score = scorer.score_splice_junction(&motif);
784+
let score = scorer.score_splice_junction(motif);
785785
assert_eq!(score, -8);
786786
}
787787

@@ -822,7 +822,7 @@ mod tests {
822822
let motif = scorer.detect_splice_motif(2, 12, &genome);
823823
assert_eq!(motif, SpliceMotif::NonCanonical);
824824

825-
let score = scorer.score_splice_junction(&motif);
825+
let score = scorer.score_splice_junction(motif);
826826
assert_eq!(score, -8);
827827
}
828828

@@ -1017,7 +1017,7 @@ mod tests {
10171017
let motif = scorer.detect_splice_motif(2, 12, &genome_ctac);
10181018
assert_eq!(motif, SpliceMotif::CtAc);
10191019
// Should score same as canonical GT-AG
1020-
assert_eq!(scorer.score_splice_junction(&motif), 0);
1020+
assert_eq!(scorer.score_splice_junction(motif), 0);
10211021

10221022
// CT-GC motif: (1,3,2,1) — reverse complement of GC-AG
10231023
let seq_ctgc = vec![
@@ -1030,7 +1030,7 @@ mod tests {
10301030
let genome_ctgc = make_test_genome(&seq_ctgc);
10311031
let motif = scorer.detect_splice_motif(2, 12, &genome_ctgc);
10321032
assert_eq!(motif, SpliceMotif::CtGc);
1033-
assert_eq!(scorer.score_splice_junction(&motif), -4);
1033+
assert_eq!(scorer.score_splice_junction(motif), -4);
10341034

10351035
// GT-AT motif: (2,3,0,3) — reverse complement of AT-AC
10361036
let seq_gtat = vec![
@@ -1043,7 +1043,7 @@ mod tests {
10431043
let genome_gtat = make_test_genome(&seq_gtat);
10441044
let motif = scorer.detect_splice_motif(2, 12, &genome_gtat);
10451045
assert_eq!(motif, SpliceMotif::GtAt);
1046-
assert_eq!(scorer.score_splice_junction(&motif), -8);
1046+
assert_eq!(scorer.score_splice_junction(motif), -8);
10471047
}
10481048

10491049
#[test]

src/align/seed.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Seed {
6969
false,
7070
debug_name,
7171
&mut seeds,
72-
)?;
72+
);
7373

7474
// Cap check between directions (STAR: seedPerReadNmax applies across both)
7575
if seeds.len() >= params.seed_per_read_nmax {
@@ -87,7 +87,7 @@ impl Seed {
8787
true,
8888
debug_name,
8989
&mut seeds,
90-
)?;
90+
);
9191

9292
// STAR's storeAligns dedup: same rStart + same Length → skip duplicate.
9393
// Multiple istart chains can find the same (read_pos, length, direction) seed.
@@ -217,7 +217,7 @@ fn search_direction_sparse(
217217
is_rc: bool,
218218
debug_name: &str,
219219
seeds: &mut Vec<Seed>,
220-
) -> Result<(), Error> {
220+
) {
221221
let read_len = read_seq.len();
222222

223223
// STAR (ReadAlign_mapOneRead.cpp lines 41-42):
@@ -262,7 +262,7 @@ fn search_direction_sparse(
262262
}
263263

264264
let result =
265-
find_seed_at_position(read_seq, pos, index, min_seed_length, false, params)?;
265+
find_seed_at_position(read_seq, pos, index, min_seed_length, false, params);
266266

267267
if !debug_name.is_empty() {
268268
let dir = if is_rc { "RC" } else { "FWD" };
@@ -292,16 +292,14 @@ fn search_direction_sparse(
292292
seeds.push(seed);
293293

294294
if seeds.len() >= params.seed_per_read_nmax {
295-
return Ok(());
295+
return;
296296
}
297297
}
298298

299299
pos += result.advance; // Always advance by MMP length (matches STAR)
300300
// Remaining-length check at loop top: stop when < seedMapMin bases remain
301301
}
302302
}
303-
304-
Ok(())
305303
}
306304

307305
/// Find a seed starting at a specific position in the read.
@@ -317,23 +315,23 @@ fn find_seed_at_position(
317315
min_seed_length: usize,
318316
is_reverse: bool,
319317
params: &Parameters,
320-
) -> Result<MmpResult, Error> {
318+
) -> MmpResult {
321319
if read_pos >= read_seq.len() {
322-
return Ok(MmpResult {
320+
return MmpResult {
323321
seed: None,
324322
advance: 1,
325-
});
323+
};
326324
}
327325

328326
// Extract k-mer for SAindex lookup
329327
let sa_nbases = index.sa_index.nbases as usize;
330328
let remaining = read_seq.len() - read_pos;
331329

332330
if remaining < min_seed_length {
333-
return Ok(MmpResult {
331+
return MmpResult {
334332
seed: None,
335333
advance: 1,
336-
});
334+
};
337335
}
338336

339337
// Build k-mer for SAindex lookup, stopping at first N base
@@ -351,10 +349,10 @@ fn find_seed_at_position(
351349
}
352350

353351
if actual_len == 0 {
354-
return Ok(MmpResult {
352+
return MmpResult {
355353
seed: None,
356354
advance: 1,
357-
}); // First base is N
355+
}; // First base is N
358356
}
359357

360358
// Hierarchical SAindex lookup (STAR's maxMappableLength2strands approach).
@@ -367,17 +365,17 @@ fn find_seed_at_position(
367365
.hierarchical_lookup(kmer_idx, actual_len as u32, n_sa);
368366

369367
let Some((sa_start, sa_end, matched_level, bounds_tight)) = result else {
370-
return Ok(MmpResult {
368+
return MmpResult {
371369
seed: None,
372370
advance: 1,
373-
});
371+
};
374372
};
375373

376374
if sa_start >= sa_end {
377-
return Ok(MmpResult {
375+
return MmpResult {
378376
seed: None,
379377
advance: 1,
380-
});
378+
};
381379
}
382380

383381
// STAR short-circuit (maxMappableLength2strands.cpp):
@@ -407,14 +405,14 @@ fn find_seed_at_position(
407405
// Uses narrowed range (accurate loci count, not overestimated k-mer range)
408406
let n_loci = narrowed_end - narrowed_start;
409407
if n_loci > params.seed_multimap_nmax {
410-
return Ok(MmpResult {
408+
return MmpResult {
411409
seed: None,
412410
advance,
413-
});
411+
};
414412
}
415413

416414
if match_length >= min_seed_length {
417-
Ok(MmpResult {
415+
MmpResult {
418416
seed: Some(Seed {
419417
read_pos,
420418
length: match_length,
@@ -425,12 +423,12 @@ fn find_seed_at_position(
425423
mate_id: 2, // Single-end default
426424
}),
427425
advance,
428-
})
426+
}
429427
} else {
430-
Ok(MmpResult {
428+
MmpResult {
431429
seed: None,
432430
advance,
433-
})
431+
}
434432
}
435433
}
436434

@@ -1023,16 +1021,15 @@ mod tests {
10231021
// Count how many seeds dense would produce (every position that has a match)
10241022
let mut dense_count = 0;
10251023
for read_pos in 0..read.len() {
1026-
let result = find_seed_at_position(&read, read_pos, &index, 4, false, &params).unwrap();
1024+
let result = find_seed_at_position(&read, read_pos, &index, 4, false, &params);
10271025
if result.seed.is_some() {
10281026
dense_count += 1;
10291027
}
10301028
}
10311029
// Also count R→L dense seeds
10321030
let rc_read = reverse_complement_read(&read);
10331031
for rc_pos in 0..rc_read.len() {
1034-
let result =
1035-
find_seed_at_position(&rc_read, rc_pos, &index, 4, false, &params).unwrap();
1032+
let result = find_seed_at_position(&rc_read, rc_pos, &index, 4, false, &params);
10361033
if result.seed.is_some() {
10371034
dense_count += 1;
10381035
}

src/align/stitch.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
use crate::align::score::AlignmentScorer;
33
use crate::align::seed::Seed;
44
use crate::align::transcript::{CigarOpExt as _, Transcript};
5-
use crate::error::Error;
65
use crate::index::GenomeIndex;
76
use noodles::sam::alignment::record::cigar;
87

@@ -1500,7 +1499,7 @@ pub fn stitch_seeds(
15001499
read_seq: &[u8],
15011500
index: &GenomeIndex,
15021501
scorer: &AlignmentScorer,
1503-
) -> Result<Vec<Transcript>, Error> {
1502+
) -> Vec<Transcript> {
15041503
stitch_seeds_with_jdb(cluster, read_seq, index, scorer, None, 1)
15051504
}
15061505

@@ -1519,7 +1518,7 @@ pub fn stitch_seeds_with_jdb(
15191518
scorer: &AlignmentScorer,
15201519
junction_db: Option<&crate::junction::SpliceJunctionDb>,
15211520
max_transcripts_per_window: usize,
1522-
) -> Result<Vec<Transcript>, Error> {
1521+
) -> Vec<Transcript> {
15231522
stitch_seeds_with_jdb_debug(
15241523
cluster,
15251524
read_seq,
@@ -2469,7 +2468,7 @@ pub(crate) fn stitch_seeds_with_jdb_debug(
24692468
junction_db: Option<&crate::junction::SpliceJunctionDb>,
24702469
max_transcripts_per_window: usize,
24712470
debug_read_name: &str,
2472-
) -> Result<Vec<Transcript>, Error> {
2471+
) -> Vec<Transcript> {
24732472
let (working_transcripts, stitch_cluster, stitch_is_reverse, stitch_read) = stitch_seeds_core(
24742473
cluster,
24752474
read_seq,
@@ -2479,7 +2478,7 @@ pub(crate) fn stitch_seeds_with_jdb_debug(
24792478
max_transcripts_per_window,
24802479
0,
24812480
debug_read_name,
2482-
)?;
2481+
);
24832482

24842483
// Finalize working transcripts → Transcript (filtering by overhang+repeat check)
24852484
let mut transcripts: Vec<Transcript> = Vec::with_capacity(working_transcripts.len());
@@ -2583,7 +2582,7 @@ pub(crate) fn stitch_seeds_with_jdb_debug(
25832582
});
25842583
transcripts.truncate(max_transcripts_per_window);
25852584

2586-
Ok(transcripts)
2585+
transcripts
25872586
}
25882587

25892588
/// Shared core: preprocessing + recursive stitcher, returns working transcripts + context.
@@ -2597,7 +2596,7 @@ pub(crate) fn stitch_seeds_core(
25972596
max_transcripts_per_window: usize,
25982597
align_mates_gap_max: u64,
25992598
debug_read_name: &str,
2600-
) -> Result<(Vec<WorkingTranscript>, SeedCluster, bool, Vec<u8>), Error> {
2599+
) -> (Vec<WorkingTranscript>, SeedCluster, bool, Vec<u8>) {
26012600
let debug = !debug_read_name.is_empty();
26022601

26032602
// Include ALL seeds (anchor and non-anchor) in the stitcher.
@@ -2730,12 +2729,12 @@ pub(crate) fn stitch_seeds_core(
27302729
}
27312730

27322731
if wa_entries.is_empty() {
2733-
return Ok((
2732+
return (
27342733
Vec::new(),
27352734
stitch_cluster,
27362735
stitch_is_reverse,
27372736
stitch_read_owned,
2738-
));
2737+
);
27392738
}
27402739

27412740
if debug {
@@ -2924,12 +2923,12 @@ pub(crate) fn stitch_seeds_core(
29242923
);
29252924
}
29262925

2927-
Ok((
2926+
(
29282927
working_transcripts,
29292928
stitch_cluster,
29302929
stitch_is_reverse,
29312930
stitch_read_owned,
2932-
))
2931+
)
29332932
}
29342933

29352934
#[cfg(test)]

0 commit comments

Comments
 (0)