Skip to content

Commit

Permalink
Made kmer_min_cutoff generic over types that implement UInt
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellewell14 committed Jan 27, 2025
1 parent b06fdca commit d45e944
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
19 changes: 5 additions & 14 deletions src/io_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,9 @@ pub fn get_2_fastq_path(files: &[InputFastx]) -> (String, String) {
}

/// Calculates minimum kmer cutoff depending on user provided argument
pub fn kmer_min_cutoff(
pub fn kmer_min_cutoff<IntT: for<'a> UInt<'a>>(
v: &Option<ValidMinKmer>,
files: &[InputFastx],
rep_64: bool,
k: &usize,
rc: bool,
verbose: bool,
Expand All @@ -192,18 +191,10 @@ pub fn kmer_min_cutoff(
// auto-calculate & there are enough fastq files
ValidMinKmer::Auto if count_fastq(files).ge(&2) => {
let (fastq_fwd, fastq_rev) = get_2_fastq_path(files);
let out: u16;
if rep_64 {
let mut cov =
CoverageHistogram::<u64>::new(&fastq_fwd, &fastq_rev, *k, rc, verbose);
out = cov.fit_histogram().expect("Couldn't fit coverage model") as u16;
cov.plot_hist();
} else {
let mut cov =
CoverageHistogram::<u128>::new(&fastq_fwd, &fastq_rev, *k, rc, verbose);
out = cov.fit_histogram().expect("Couldn't fit coverage model") as u16;
cov.plot_hist();
}
let mut cov =
CoverageHistogram::<IntT>::new(&fastq_fwd, &fastq_rev, *k, rc, verbose);
let out = cov.fit_histogram().expect("Couldn't fit coverage model") as u16;
cov.plot_hist();
log::info!("Using inferred minimum kmer value of {}", out);
out
}
Expand Down
35 changes: 16 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,26 +504,16 @@ pub fn main() {
// Read input
let input_files = get_input_list(file_list, seq_files);
let rc = !*single_strand;

// Are using 64 or 128 bit representation
let rep_64: bool = k.le(&31);
if rep_64 {
log::info!("k={}: using 64-bit representation", *k);
} else {
log::info!("k={}: using 128-bit representation", *k);
}

// Calculate minimum kmer cutoff
let cutoff = kmer_min_cutoff(min_count, &input_files, rep_64, k, rc, args.verbose);

let quality = QualOpts {
min_count: cutoff,
min_qual: *min_qual,
qual_filter: *qual_filter,
};

// Build, merge
if rep_64 {
// check for 64 or 128 bit representation
if k.le(&31) {
log::info!("k={}: using 64-bit representation", *k);
let cutoff = kmer_min_cutoff::<u64>(min_count, &input_files, k, rc, args.verbose);
let quality = QualOpts {
min_count: cutoff,
min_qual: *min_qual,
qual_filter: *qual_filter,
};
let merged_dict = build_and_merge::<u64>(
&input_files,
*k,
Expand All @@ -536,6 +526,13 @@ pub fn main() {
// Save
save_skf(&merged_dict, output);
} else {
log::info!("k={}: using 128-bit representation", *k);
let cutoff = kmer_min_cutoff::<u128>(min_count, &input_files, k, rc, args.verbose);
let quality = QualOpts {
min_count: cutoff,
min_qual: *min_qual,
qual_filter: *qual_filter,
};
let merged_dict = build_and_merge::<u128>(
&input_files,
*k,
Expand Down

0 comments on commit d45e944

Please sign in to comment.