Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions modkit-core/src/modbam_util/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,10 @@ pub struct ModSummarize {
interval_size: u32,
}

fn sampling_fraction_log_message(fraction: f64) -> String {
format!("sampling {}% of reads", fraction * 100f64)
}

impl ModSummarize {
pub fn run(&self) -> anyhow::Result<()> {
let _handle = init_logging(self.log_filepath.as_ref());
Expand Down Expand Up @@ -1807,7 +1811,9 @@ impl ModSummarize {
(None, Some(num_reads)) => {
info!("sampling {num_reads} reads from BAM")
}
(Some(pct), None) => info!("sampling {pct}% of reads"),
(Some(fraction), None) => {
info!("{}", sampling_fraction_log_message(fraction))
}
(Some(_), Some(_)) => unreachable!(),
});

Expand Down Expand Up @@ -1932,7 +1938,11 @@ impl ModSummarize {
multi_progress.clone(),
)?;

if self.mapped_only || self.matched_only || self.motif.is_some() {
if self.mapped_only
|| self.matched_only
|| self.motif.is_some()
|| self.cpg
{
qual_hist
} else if let Some(nr) = self.num_reads {
if qual_hist.ok_records < nr {
Expand Down Expand Up @@ -2473,3 +2483,13 @@ impl ModMode {
}
}
}

#[cfg(test)]
mod tests {
use super::sampling_fraction_log_message;

#[test]
fn summary_sampling_fraction_log_uses_percentage_units() {
assert_eq!(sampling_fraction_log_message(0.1), "sampling 10% of reads");
}
}
9 changes: 7 additions & 2 deletions modkit-core/src/summarize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ pub struct ModSummary<'a> {

impl<'a> ModSummary<'a> {
pub(crate) fn mod_bases(&self) -> String {
self.mod_call_counts
.keys()
[DnaBase::A, DnaBase::C, DnaBase::G, DnaBase::T]
.into_iter()
.filter(|base| {
self.mod_call_counts.contains_key(base)
|| self.filtered_mod_call_counts.contains_key(base)
|| self.per_base_mod_codes.contains_key(base)
})
.map(|d| d.char().to_string())
.collect::<Vec<String>>()
.join(",")
Expand Down
Loading