From 570d403953f68704515dd044f73370a45cb54dc6 Mon Sep 17 00:00:00 2001 From: wdecoster Date: Tue, 31 Oct 2023 16:15:30 +0100 Subject: [PATCH] do not subtract softclipped fragments with --ubam --- src/extract_from_bam.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/extract_from_bam.rs b/src/extract_from_bam.rs index c1f7857..b09b6c9 100644 --- a/src/extract_from_bam.rs +++ b/src/extract_from_bam.rs @@ -58,11 +58,11 @@ pub fn extract(args: &crate::Cli) -> Data { .inspect(|_| all_counts += 1) .filter(|read| filter_closure(read)) { - lengths.push( - read.seq_len() as u128 - - read.cigar().leading_softclips() as u128 - - read.cigar().trailing_softclips() as u128, - ); + if args.ubam { + lengths.push(read.seq_len() as u128); + } else { + lengths.push(read.seq_len() as u128 - softclipped_bases(&read)); + } if args.karyotype || args.phased { tids.push(read.tid()); } @@ -190,3 +190,7 @@ fn get_exon_number(record: &bam::Record) -> usize { exon_count } + +fn softclipped_bases(read: &bam::Record) -> u128 { + (read.cigar().leading_softclips() + read.cigar().trailing_softclips()) as u128 +}