Skip to content

Commit e1b6ee4

Browse files
clippy
1 parent 12ed058 commit e1b6ee4

File tree

10 files changed

+159
-201
lines changed

10 files changed

+159
-201
lines changed

src/agc_index.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl AgcIndex {
5353
if !agc.open(agc_path, true) {
5454
return Err(io::Error::new(
5555
io::ErrorKind::InvalidData,
56-
format!("Failed to open AGC file: {}", agc_path),
56+
format!("Failed to open AGC file: {agc_path}"),
5757
));
5858
}
5959

@@ -78,7 +78,7 @@ impl AgcIndex {
7878
for (sample, contigs) in sample_contigs {
7979
for contig in contigs {
8080
// Create a key that combines full contig name and sample name
81-
let key = format!("{}@{}", contig, sample);
81+
let key = format!("{contig}@{sample}");
8282
index.sample_contig_to_agc.insert(key.clone(), agc_idx);
8383

8484
// Also insert just the full contig name if it's unique
@@ -102,7 +102,7 @@ impl AgcIndex {
102102
// If short name differs from full name, also create mappings for short name
103103
if short_contig != contig {
104104
// Create key with short contig name and sample
105-
let short_key = format!("{}@{}", short_contig, sample);
105+
let short_key = format!("{short_contig}@{sample}");
106106
index
107107
.sample_contig_to_agc
108108
.entry(short_key)
@@ -154,7 +154,7 @@ impl AgcIndex {
154154
let agc_idx = agc_idx.ok_or_else(|| {
155155
io::Error::new(
156156
io::ErrorKind::NotFound,
157-
format!("Sequence '{}' not found in any AGC file", seq_name),
157+
format!("Sequence '{seq_name}' not found in any AGC file"),
158158
)
159159
})?;
160160

@@ -164,8 +164,7 @@ impl AgcIndex {
164164
.get_contig_sequence(&sample, &contig, start, end - 1)
165165
.map_err(|e| {
166166
io::Error::other(format!(
167-
"Failed to fetch sequence '{}@{}:{}:{}': {}",
168-
contig, sample, start, end, e
167+
"Failed to fetch sequence '{contig}@{sample}:{start}:{end}': {e}"
169168
))
170169
})?;
171170

@@ -178,7 +177,7 @@ impl AgcIndex {
178177
let agc_idx = agc_idx.ok_or_else(|| {
179178
io::Error::new(
180179
io::ErrorKind::NotFound,
181-
format!("Sequence '{}' not found in any AGC file", seq_name),
180+
format!("Sequence '{seq_name}' not found in any AGC file"),
182181
)
183182
})?;
184183

src/commands/lace.rs

Lines changed: 47 additions & 66 deletions
Large diffs are not rendered by default.

src/commands/partition.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn partition_alignments(
5454
let file = File::open(path).map_err(|e| {
5555
io::Error::new(
5656
io::ErrorKind::NotFound,
57-
format!("Could not open starting sequences file {}: {}", path, e),
57+
format!("Could not open starting sequences file {path}: {e}"),
5858
)
5959
})?;
6060

@@ -75,8 +75,7 @@ pub fn partition_alignments(
7575
starting_sequences.push((seq_id, 0, seq_length));
7676
} else if debug {
7777
debug!(
78-
"Sequence {} from starting file not found in index",
79-
trimmed_name
78+
"Sequence {trimmed_name} from starting file not found in index"
8079
);
8180
}
8281
}
@@ -316,14 +315,14 @@ pub fn partition_alignments(
316315
(total_partitioned_length as f64 / total_sequence_length as f64) * 100.0;
317316
// Create formatted percentage strings with conditional scientific notation
318317
let current_percentage_str = if current_percentage < 0.0001 {
319-
format!("{:.4e}%", current_percentage)
318+
format!("{current_percentage:.4e}%")
320319
} else {
321-
format!("{:.4}%", current_percentage)
320+
format!("{current_percentage:.4}%")
322321
};
323322
let total_percentage_str = if total_percentage < 0.0001 {
324-
format!("{:.4e}%", total_percentage)
323+
format!("{total_percentage:.4e}%")
325324
} else {
326-
format!("{:.4}%", total_percentage)
325+
format!("{total_percentage:.4}%")
327326
};
328327
//let calc_time = calc_start.elapsed();
329328

@@ -372,7 +371,7 @@ pub fn partition_alignments(
372371
_ => {
373372
return Err(io::Error::new(
374373
io::ErrorKind::InvalidInput,
375-
format!("Unsupported output format: {}", output_format),
374+
format!("Unsupported output format: {output_format}"),
376375
));
377376
}
378377
}
@@ -392,7 +391,7 @@ pub fn partition_alignments(
392391
_ => {
393392
return Err(io::Error::new(
394393
io::ErrorKind::InvalidInput,
395-
format!("Unsupported output format: {}", output_format),
394+
format!("Unsupported output format: {output_format}"),
396395
));
397396
}
398397
}
@@ -452,7 +451,7 @@ pub fn partition_alignments(
452451
.try_for_each(|partition_idx| -> io::Result<()> {
453452
let temp_bed_file = create_output_path(
454453
output_folder,
455-
&format!("partition{}.bed.tmp", partition_idx),
454+
&format!("partition{partition_idx}.bed.tmp"),
456455
)?;
457456

458457
// Read intervals from temporary BED file using parse_bed_file
@@ -503,14 +502,13 @@ pub fn partition_alignments(
503502
let final_percentage = (total_partitioned_length as f64 / total_sequence_length as f64) * 100.0;
504503
// Create formatted percentage string with conditional scientific notation
505504
let final_percentage_str = if final_percentage < 0.0001 {
506-
format!("{:.4e}%", final_percentage)
505+
format!("{final_percentage:.4e}%")
507506
} else {
508-
format!("{:.4}%", final_percentage)
507+
format!("{final_percentage:.4}%")
509508
};
510509

511510
info!(
512-
"Partitioned into {} regions: {} bp total written / {} bp total sequence ({})",
513-
partition_num, total_partitioned_length, total_sequence_length, final_percentage_str
511+
"Partitioned into {partition_num} regions: {total_partitioned_length} bp total written / {total_sequence_length} bp total sequence ({final_percentage_str})"
514512
);
515513

516514
Ok(())
@@ -588,8 +586,7 @@ fn select_and_window_sequences(
588586
let seq_name = impg.seq_index.get_name(seq_id).unwrap();
589587

590588
debug!(
591-
"Selected sequence {} with most missing sequence ({}bp)",
592-
seq_name, max_total_missing
589+
"Selected sequence {seq_name} with most missing sequence ({max_total_missing}bp)"
593590
);
594591

595592
ranges_to_window.push((seq_id, 0, seq_length));
@@ -1232,7 +1229,7 @@ fn write_partition(
12321229
}
12331230
_ => Err(io::Error::new(
12341231
io::ErrorKind::InvalidInput,
1235-
format!("Unsupported output format: {}", output_format),
1232+
format!("Unsupported output format: {output_format}"),
12361233
)),
12371234
}
12381235
}
@@ -1246,8 +1243,8 @@ fn write_partition_bed(
12461243
) -> io::Result<()> {
12471244
// Create filename with optional suffix
12481245
let filename = match suffix {
1249-
Some(s) => format!("partition{}.bed{}", partition_num, s),
1250-
None => format!("partition{}.bed", partition_num),
1246+
Some(s) => format!("partition{partition_num}.bed{s}"),
1247+
None => format!("partition{partition_num}.bed"),
12511248
};
12521249

12531250
// Create full path with output folder
@@ -1265,7 +1262,7 @@ fn write_partition_bed(
12651262
(query_interval.last, query_interval.first)
12661263
};
12671264

1268-
writeln!(writer, "{}\t{}\t{}", name, start, end)?;
1265+
writeln!(writer, "{name}\t{start}\t{end}")?;
12691266
}
12701267

12711268
writer.flush()?;
@@ -1289,13 +1286,13 @@ fn write_partition_gfa(
12891286
);
12901287

12911288
// Create output file
1292-
let filename = format!("partition{}.gfa", partition_num);
1289+
let filename = format!("partition{partition_num}.gfa");
12931290
let full_path = create_output_path(output_folder, &filename)?;
12941291
let file = File::create(full_path)?;
12951292
let mut writer = BufWriter::new(file);
12961293

12971294
// Write the GFA output to the file
1298-
writeln!(writer, "{}", gfa_output)?;
1295+
writeln!(writer, "{gfa_output}")?;
12991296
writer.flush()?;
13001297
Ok(())
13011298
}
@@ -1317,13 +1314,13 @@ fn write_partition_maf(
13171314
);
13181315

13191316
// Create output file
1320-
let filename = format!("partition{}.maf", partition_num);
1317+
let filename = format!("partition{partition_num}.maf");
13211318
let full_path = create_output_path(output_folder, &filename)?;
13221319
let file = File::create(full_path)?;
13231320
let mut writer = BufWriter::new(file);
13241321

13251322
// Write the MAF output to the file
1326-
write!(writer, "{}", maf_output)?;
1323+
write!(writer, "{maf_output}")?;
13271324
writer.flush()?;
13281325
Ok(())
13291326
}
@@ -1338,7 +1335,7 @@ fn write_partition_fasta(
13381335
reverse_complement: bool,
13391336
) -> io::Result<()> {
13401337
// Create output file
1341-
let filename = format!("partition{}.fasta", partition_num);
1338+
let filename = format!("partition{partition_num}.fasta");
13421339
let full_path = create_output_path(output_folder, &filename)?;
13431340
let file = File::create(full_path)?;
13441341
let mut writer = BufWriter::new(file);
@@ -1369,7 +1366,7 @@ fn write_partition_fasta(
13691366
} else {
13701367
""
13711368
};
1372-
writeln!(writer, ">{}:{}-{}{}", query_name, start, end, header_suffix)?;
1369+
writeln!(writer, ">{query_name}:{start}-{end}{header_suffix}")?;
13731370

13741371
// Write sequence in lines of 80 characters
13751372
let sequence_str = String::from_utf8_lossy(&sequence);
@@ -1404,7 +1401,7 @@ fn write_single_partition_file(
14041401
(query_interval.last, query_interval.first)
14051402
};
14061403

1407-
writeln!(writer, "{} {} {} {}", name, start, end, partition_num)?;
1404+
writeln!(writer, "{name} {start} {end} {partition_num}")?;
14081405
}
14091406
}
14101407

@@ -1414,8 +1411,7 @@ fn write_single_partition_file(
14141411
_ => Err(io::Error::new(
14151412
io::ErrorKind::InvalidInput,
14161413
format!(
1417-
"Single-file output not supported for format: {}",
1418-
output_format
1414+
"Single-file output not supported for format: {output_format}"
14191415
),
14201416
)),
14211417
}

src/commands/similarity.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn compute_and_output_similarities(
131131
// Lock stdout and write both header and results
132132
let stdout = stdout_mutex.lock().unwrap();
133133
let mut handle = stdout.lock();
134-
write!(handle, "{}", similarity_output)?;
134+
write!(handle, "{similarity_output}")?;
135135

136136
Ok(())
137137
})?;
@@ -194,7 +194,7 @@ fn compute_similarities_for_region(
194194
delim_pos: u16,
195195
region: &str,
196196
) -> io::Result<String> {
197-
debug!("Computing similarities for region {:?}", region);
197+
debug!("Computing similarities for region {region:?}");
198198

199199
let (groups, msa_chars) = prepare_groups_and_msa(
200200
impg,
@@ -330,7 +330,7 @@ fn compute_pca_for_region(
330330
n_components: 0,
331331
})
332332
} else {
333-
Err(io::Error::other(format!("PCA/MDS failed: {}", e)))
333+
Err(io::Error::other(format!("PCA/MDS failed: {e}")))
334334
}
335335
}
336336
}
@@ -393,8 +393,7 @@ fn format_similarity_line(
393393
emit_distances: bool,
394394
) {
395395
output.push_str(&format!(
396-
"{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t",
397-
chrom, start, end, name_a, name_b, len_a, len_b, intersection
396+
"{chrom}\t{start}\t{end}\t{name_a}\t{name_b}\t{len_a}\t{len_b}\t{intersection}\t"
398397
));
399398

400399
if emit_distances {
@@ -417,7 +416,7 @@ fn format_similarity_line(
417416
}
418417

419418
fn format_value(value: f32) -> String {
420-
let formatted = format!("{:.7}", value);
419+
let formatted = format!("{value:.7}");
421420
let trimmed = formatted.trim_end_matches('0');
422421
if trimmed.ends_with('.') {
423422
trimmed.trim_end_matches('.').to_string()
@@ -583,8 +582,7 @@ impl PcaResult {
583582
let pc_value = self.coordinates[group_idx][pc_idx];
584583

585584
output.push_str(&format!(
586-
"{}\t{}\t{}\t{}\t{}\t{:.7}\n",
587-
chrom, start, end, group_name, pc_rank, pc_value
585+
"{chrom}\t{start}\t{end}\t{group_name}\t{pc_rank}\t{pc_value:.7}\n"
588586
));
589587
}
590588
}
@@ -733,7 +731,7 @@ fn polarize_pca_result_with_guides(
733731
if guide_indices[i].iter().all(|idx| idx.is_none()) {
734732
return Err(io::Error::new(
735733
io::ErrorKind::InvalidInput,
736-
format!("Guide sample '{}' not found in any window", guide_name),
734+
format!("Guide sample '{guide_name}' not found in any window"),
737735
));
738736
}
739737
}
@@ -973,7 +971,7 @@ pub fn build_distance_matrix(
973971
_ => {
974972
return Err(io::Error::new(
975973
io::ErrorKind::InvalidInput,
976-
format!("Unknown similarity type: {}", similarity_type),
974+
format!("Unknown similarity type: {similarity_type}"),
977975
))
978976
}
979977
};

src/faidx.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl FastaIndex {
2626
index.fasta_paths.push(fasta_path.clone());
2727

2828
// Read the .fai file to get sequence names
29-
let fai_path = format!("{}.fai", fasta_path);
29+
let fai_path = format!("{fasta_path}.fai");
3030

3131
// Try to open the .fai file, if it doesn't exist, try to create it
3232
let fai_content = match std::fs::read_to_string(&fai_path) {
@@ -40,8 +40,7 @@ impl FastaIndex {
4040
}
4141
Err(e) => {
4242
return Err(io::Error::other(format!(
43-
"Failed to create FASTA index for '{}': {}",
44-
fasta_path, e
43+
"Failed to create FASTA index for '{fasta_path}': {e}"
4544
)));
4645
}
4746
}
@@ -80,12 +79,12 @@ impl FastaIndex {
8079
let fasta_path = self.get_fasta_path(seq_name).ok_or_else(|| {
8180
io::Error::new(
8281
io::ErrorKind::NotFound,
83-
format!("Sequence '{}' not found in any FASTA file", seq_name),
82+
format!("Sequence '{seq_name}' not found in any FASTA file"),
8483
)
8584
})?;
8685

8786
let reader = faidx::Reader::from_path(fasta_path).map_err(|e| {
88-
io::Error::other(format!("Failed to open FASTA file '{}': {}", fasta_path, e))
87+
io::Error::other(format!("Failed to open FASTA file '{fasta_path}': {e}"))
8988
})?;
9089

9190
// Fetch sequence and properly handle memory
@@ -102,8 +101,7 @@ impl FastaIndex {
102101
}
103102
Err(e) => {
104103
return Err(io::Error::other(format!(
105-
"Failed to fetch sequence for {}: {}",
106-
seq_name, e
104+
"Failed to fetch sequence for {seq_name}: {e}"
107105
)))
108106
}
109107
};
@@ -115,7 +113,7 @@ impl FastaIndex {
115113
self.sequence_lengths.get(seq_name).copied().ok_or_else(|| {
116114
io::Error::new(
117115
io::ErrorKind::NotFound,
118-
format!("Sequence '{}' not found", seq_name),
116+
format!("Sequence '{seq_name}' not found"),
119117
)
120118
})
121119
}

0 commit comments

Comments
 (0)