Skip to content

Commit 7096aa7

Browse files
committed
style: closures to functions and inline format args
1 parent d1b61ef commit 7096aa7

18 files changed

Lines changed: 94 additions & 137 deletions

File tree

src/align/read_align.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub fn align_read(
205205

206206
if seeds.is_empty() {
207207
if debug_read {
208-
eprintln!("[DEBUG {}] No seeds found — unmapped", read_name);
208+
eprintln!("[DEBUG {read_name}] No seeds found — unmapped");
209209
}
210210
return Ok((Vec::new(), Vec::new(), 0, Some(UnmappedReason::Other)));
211211
}
@@ -266,7 +266,7 @@ pub fn align_read(
266266

267267
if clusters.is_empty() {
268268
if debug_read {
269-
eprintln!("[DEBUG {}] No clusters — unmapped", read_name);
269+
eprintln!("[DEBUG {read_name}] No clusters — unmapped");
270270
}
271271
return Ok((Vec::new(), Vec::new(), 0, Some(UnmappedReason::Other)));
272272
}
@@ -525,11 +525,7 @@ pub fn align_read(
525525
if pre_filter_count > transcripts.len() {
526526
let filtered = pre_filter_count - transcripts.len();
527527
log::debug!(
528-
"Read {}: Filtered {}/{} transcripts: {:?}",
529-
read_name,
530-
filtered,
531-
pre_filter_count,
532-
filter_reasons
528+
"Read {read_name}: Filtered {filtered}/{pre_filter_count} transcripts: {filter_reasons:?}"
533529
);
534530
}
535531

@@ -2165,8 +2161,7 @@ mod tests {
21652161
}
21662162
assert!(
21672163
firsts.len() >= 2,
2168-
"expected different seeds to pick different primaries, got {:?}",
2169-
firsts
2164+
"expected different seeds to pick different primaries, got {firsts:?}"
21702165
);
21712166
}
21722167

src/align/seed.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ mod tests {
669669
fn make_test_index(sequence: &str) -> GenomeIndex {
670670
let mut file = NamedTempFile::new().unwrap();
671671
writeln!(file, ">chr1").unwrap();
672-
writeln!(file, "{}", sequence).unwrap();
672+
writeln!(file, "{sequence}").unwrap();
673673

674674
let dir = tempfile::tempdir().unwrap();
675675

@@ -888,8 +888,7 @@ mod tests {
888888
// R→L search should find seeds because RC(read) = AACCTTGG matches genome
889889
assert!(
890890
!rc_seeds.is_empty(),
891-
"R→L search should find seeds (RC of read matches genome). All seeds: {:?}",
892-
seeds
891+
"R→L search should find seeds (RC of read matches genome). All seeds: {seeds:?}"
893892
);
894893

895894
// Verify R→L seeds have valid read positions

src/chimeric/detect.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ impl<'a> ChimericDetector<'a> {
165165
}
166166

167167
let donor_seg = transcript_to_segment(tr_donor)
168-
.map_err(|e| Error::Chimeric(format!("soft-clip donor: {}", e)))?;
168+
.map_err(|e| Error::Chimeric(format!("soft-clip donor: {e}")))?;
169169
let acceptor_seg = transcript_to_segment(tr_acceptor)
170-
.map_err(|e| Error::Chimeric(format!("soft-clip acceptor: {}", e)))?;
170+
.map_err(|e| Error::Chimeric(format!("soft-clip acceptor: {e}")))?;
171171

172172
let (repeat_len_donor, repeat_len_acceptor) = calculate_repeat_length(
173173
&index.genome,
@@ -292,7 +292,7 @@ impl<'a> ChimericDetector<'a> {
292292
};
293293

294294
let new_seg = transcript_to_segment(&clip_tr)
295-
.map_err(|e| Error::Chimeric(format!("tier3 segment: {}", e)))?;
295+
.map_err(|e| Error::Chimeric(format!("tier3 segment: {e}")))?;
296296

297297
// Donor / acceptor ordered by read position
298298
let (donor_seg, acceptor_seg): (&ChimericSegment, &ChimericSegment) =
@@ -897,9 +897,9 @@ pub fn detect_chimeric_old(
897897

898898
// Build chimeric segments
899899
let donor_seg = transcript_to_segment(tr_donor)
900-
.map_err(|e| Error::Chimeric(format!("chimeric donor segment: {}", e)))?;
900+
.map_err(|e| Error::Chimeric(format!("chimeric donor segment: {e}")))?;
901901
let acceptor_seg = transcript_to_segment(tr_acceptor)
902-
.map_err(|e| Error::Chimeric(format!("chimeric acceptor segment: {}", e)))?;
902+
.map_err(|e| Error::Chimeric(format!("chimeric acceptor segment: {e}")))?;
903903

904904
// Minimum segment length check
905905
if !donor_seg.meets_min_length(params.chim_segment_min)

src/chimeric/output.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,9 @@ impl ChimericJunctionWriter {
8484
// Write line
8585
writeln!(
8686
self.writer,
87-
"{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}",
88-
donor_chr,
89-
donor_bp,
90-
donor_strand,
91-
acceptor_chr,
92-
acceptor_bp,
93-
acceptor_strand,
94-
junction_type,
95-
repeat_donor,
96-
repeat_acceptor,
97-
read_name,
98-
donor_start,
99-
donor_cigar,
100-
acceptor_start,
101-
acceptor_cigar,
87+
"{donor_chr}\t{donor_bp}\t{donor_strand}\t{acceptor_chr}\t{acceptor_bp}\t{acceptor_strand}\t{junction_type}\t{repeat_donor}\t{repeat_acceptor}\t{read_name}\t{donor_start}\t{donor_cigar}\t{acceptor_start}\t{acceptor_cigar}",
10288
)
103-
.map_err(|e| Error::Chimeric(format!("Failed to write chimeric junction: {}", e)))?;
89+
.map_err(|e| Error::Chimeric(format!("Failed to write chimeric junction: {e}")))?;
10490

10591
Ok(())
10692
}
@@ -109,7 +95,7 @@ impl ChimericJunctionWriter {
10995
pub fn flush(&mut self) -> Result<(), Error> {
11096
self.writer
11197
.flush()
112-
.map_err(|e| Error::Chimeric(format!("Failed to flush chimeric junction file: {}", e)))
98+
.map_err(|e| Error::Chimeric(format!("Failed to flush chimeric junction file: {e}")))
11399
}
114100
}
115101

@@ -200,7 +186,7 @@ fn build_segment_record(
200186
let pos = (seg.genome_start - chr_start + 1) as usize;
201187
*record.alignment_start_mut() = Some(
202188
pos.try_into()
203-
.map_err(|e| Error::Chimeric(format!("invalid chimeric position {}: {}", pos, e)))?,
189+
.map_err(|e| Error::Chimeric(format!("invalid chimeric position {pos}: {e}")))?,
204190
);
205191

206192
*record.mapping_quality_mut() = MappingQuality::new(mapq);
@@ -549,7 +535,7 @@ mod tests {
549535
// Donor record's SA tag should point to acceptor
550536
let sa_tag = Tag::new(b'S', b'A');
551537
let donor_sa = records[0].data().get(&sa_tag).unwrap();
552-
let donor_sa_str = format!("{:?}", donor_sa);
538+
let donor_sa_str = format!("{donor_sa:?}");
553539
// SA tag: chr22,89,-,37M,255,1; (pos = 600-512+1=89, strand=-, nm=1)
554540
assert!(
555541
donor_sa_str.contains("chr22"),
@@ -566,7 +552,7 @@ mod tests {
566552

567553
// Acceptor record's SA tag should point to donor
568554
let acceptor_sa = records[1].data().get(&sa_tag).unwrap();
569-
let acceptor_sa_str = format!("{:?}", acceptor_sa);
555+
let acceptor_sa_str = format!("{acceptor_sa:?}");
570556
assert!(
571557
acceptor_sa_str.contains("chr9"),
572558
"SA tag must name donor chr"

src/genome/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,30 +210,30 @@ impl Genome {
210210
let chr_name_path = dir.join("chrName.txt");
211211
let mut f = fs::File::create(&chr_name_path).map_err(|e| Error::io(e, &chr_name_path))?;
212212
for name in &self.chr_name {
213-
writeln!(f, "{}", name).map_err(|e| Error::io(e, &chr_name_path))?;
213+
writeln!(f, "{name}").map_err(|e| Error::io(e, &chr_name_path))?;
214214
}
215215

216216
// Write chrLength.txt
217217
let chr_length_path = dir.join("chrLength.txt");
218218
let mut f =
219219
fs::File::create(&chr_length_path).map_err(|e| Error::io(e, &chr_length_path))?;
220220
for &len in &self.chr_length {
221-
writeln!(f, "{}", len).map_err(|e| Error::io(e, &chr_length_path))?;
221+
writeln!(f, "{len}").map_err(|e| Error::io(e, &chr_length_path))?;
222222
}
223223

224224
// Write chrStart.txt (includes the extra n_genome entry)
225225
let chr_start_path = dir.join("chrStart.txt");
226226
let mut f = fs::File::create(&chr_start_path).map_err(|e| Error::io(e, &chr_start_path))?;
227227
for &start in &self.chr_start {
228-
writeln!(f, "{}", start).map_err(|e| Error::io(e, &chr_start_path))?;
228+
writeln!(f, "{start}").map_err(|e| Error::io(e, &chr_start_path))?;
229229
}
230230

231231
// Write chrNameLength.txt (tab-separated)
232232
let chr_name_length_path = dir.join("chrNameLength.txt");
233233
let mut f = fs::File::create(&chr_name_length_path)
234234
.map_err(|e| Error::io(e, &chr_name_length_path))?;
235235
for (name, &len) in self.chr_name.iter().zip(&self.chr_length) {
236-
writeln!(f, "{}\t{}", name, len).map_err(|e| Error::io(e, &chr_name_length_path))?;
236+
writeln!(f, "{name}\t{len}").map_err(|e| Error::io(e, &chr_name_length_path))?;
237237
}
238238

239239
// Write genomeParameters.txt — byte-for-byte matching STAR's
@@ -319,7 +319,7 @@ impl Genome {
319319
.sjdb_gtf_file
320320
.as_ref()
321321
.map_or_else(|| "-".to_string(), |p| p.display().to_string());
322-
writeln!(f, "sjdbGTFfile\t{}", gtf_str).map_err(|e| Error::io(e, &path))?;
322+
writeln!(f, "sjdbGTFfile\t{gtf_str}").map_err(|e| Error::io(e, &path))?;
323323
writeln!(f, "sjdbGTFchrPrefix\t-").map_err(|e| Error::io(e, &path))?;
324324
writeln!(f, "sjdbGTFfeatureExon\texon").map_err(|e| Error::io(e, &path))?;
325325
writeln!(f, "sjdbGTFtagExonParentTranscript\ttranscript_id")

src/index/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn load_genome(genome_dir: &Path, _params: &Parameters) -> Result<Genome, Error>
138138
let chr_name_path = genome_dir.join("chrName.txt");
139139
let chr_name_contents =
140140
std::fs::read_to_string(&chr_name_path).map_err(|e| Error::io(e, &chr_name_path))?;
141-
let chr_name: Vec<String> = chr_name_contents.lines().map(|s| s.to_string()).collect();
141+
let chr_name: Vec<String> = chr_name_contents.lines().map(ToString::to_string).collect();
142142

143143
let chr_length_path = genome_dir.join("chrLength.txt");
144144
let chr_length_contents =

src/index/sa_index.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ impl SaIndex {
6565
let num_indices = Self::calculate_num_indices(nbases);
6666

6767
log::info!(
68-
"Building SA index: nbases={}, num_indices={}, word_length={}",
69-
nbases,
70-
num_indices,
71-
word_length
68+
"Building SA index: nbases={nbases}, num_indices={num_indices}, word_length={word_length}"
7269
);
7370

7471
// Initialize packed array with "absent" markers
@@ -258,7 +255,7 @@ mod tests {
258255
fn make_test_index_with_sa(sequence: &str, bin_nbits: u32, sa_nbases: u32) -> (SaIndex, usize) {
259256
let mut file = NamedTempFile::new().unwrap();
260257
writeln!(file, ">test").unwrap();
261-
writeln!(file, "{}", sequence).unwrap();
258+
writeln!(file, "{sequence}").unwrap();
262259

263260
let bin_nbits_str = bin_nbits.to_string();
264261
let sa_nbases_str = sa_nbases.to_string();
@@ -423,13 +420,11 @@ mod tests {
423420
let (new_sa_start, _, matched_level, _) = new_result.unwrap();
424421
assert_eq!(
425422
new_sa_start, old_sa_pos as usize,
426-
"SA start should match for k-mer {}",
427-
kmer_idx
423+
"SA start should match for k-mer {kmer_idx}"
428424
);
429425
assert_eq!(
430426
matched_level, 2,
431-
"Should match at full level for k-mer {}",
432-
kmer_idx
427+
"Should match at full level for k-mer {kmer_idx}"
433428
);
434429
}
435430
}

src/index/suffix_array.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ impl SuffixArray {
6060

6161
let sa_length = suffixes.len();
6262
log::info!(
63-
"Building suffix array with {} entries (gstrand_bit={}, word_length={})",
64-
sa_length,
65-
gstrand_bit,
66-
word_length
63+
"Building suffix array with {sa_length} entries (gstrand_bit={gstrand_bit}, word_length={word_length})"
6764
);
6865

6966
// Sort suffixes using custom comparator
@@ -218,7 +215,7 @@ mod tests {
218215
fn make_test_genome(sequence: &str, bin_nbits: u32) -> Genome {
219216
let mut file = NamedTempFile::new().unwrap();
220217
writeln!(file, ">test").unwrap();
221-
writeln!(file, "{}", sequence).unwrap();
218+
writeln!(file, "{sequence}").unwrap();
222219

223220
let bin_nbits_str = bin_nbits.to_string();
224221
let args = vec![

src/io/bam.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ fn write_bam_header_lenient<W: Write>(
281281
writer.write_i32::<LittleEndian>(n_ref)?;
282282
for (name, rs) in refs {
283283
let c_name = CString::new(name.to_vec()).map_err(|e| {
284-
Error::Index(format!("reference name contains interior NUL byte: {}", e))
284+
Error::Index(format!("reference name contains interior NUL byte: {e}"))
285285
})?;
286286
let name_bytes = c_name.as_bytes_with_nul();
287287
let l_name = u32::try_from(name_bytes.len()).map_err(|_| {

src/io/fastq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl FastqReader {
134134
.map_err(|e| {
135135
Error::from(std::io::Error::new(
136136
std::io::ErrorKind::InvalidData,
137-
format!("invalid UTF-8 in read name: {}", e),
137+
format!("invalid UTF-8 in read name: {e}"),
138138
))
139139
})?
140140
.to_string();
@@ -672,7 +672,7 @@ mod tests {
672672
fn test_paired_batch_reading() {
673673
let mut tmpfile1 = NamedTempFile::new().unwrap();
674674
for i in 1..=5 {
675-
writeln!(tmpfile1, "@read{}/1", i).unwrap();
675+
writeln!(tmpfile1, "@read{i}/1").unwrap();
676676
writeln!(tmpfile1, "ACGT").unwrap();
677677
writeln!(tmpfile1, "+").unwrap();
678678
writeln!(tmpfile1, "IIII").unwrap();
@@ -681,7 +681,7 @@ mod tests {
681681

682682
let mut tmpfile2 = NamedTempFile::new().unwrap();
683683
for i in 1..=5 {
684-
writeln!(tmpfile2, "@read{}/2", i).unwrap();
684+
writeln!(tmpfile2, "@read{i}/2").unwrap();
685685
writeln!(tmpfile2, "GGCC").unwrap();
686686
writeln!(tmpfile2, "+").unwrap();
687687
writeln!(tmpfile2, "JJJJ").unwrap();

0 commit comments

Comments
 (0)