diff --git a/src/detect.rs b/src/detect.rs index 82e8702..2aaf470 100644 --- a/src/detect.rs +++ b/src/detect.rs @@ -5,7 +5,7 @@ use noodles::{ bam, core::Position, gff, - sam::{self, header::ReferenceSequences}, + sam::{self, alignment::Record, header::ReferenceSequences}, }; use crate::{count::get_tree, Entry, Features, SegmentPosition, StrandSpecification}; @@ -142,8 +142,6 @@ pub fn detect_specification

( where P: AsRef, { - use crate::record::alignment_end; - let mut reader = File::open(src).map(bam::io::Reader::new)?; reader.read_header()?; @@ -166,10 +164,11 @@ where }; let alignment_start = record.alignment_start().transpose()?; - let cigar = record.cigar(); + let alignment_end = record.alignment_end().transpose()?; - let start = alignment_start.expect("missing alignment start"); - let end = alignment_end(alignment_start, &cigar).expect("missing alignment end")?; + let (Some(start), Some(end)) = (alignment_start, alignment_end) else { + panic!("missing alignment context"); + }; if flags.is_segmented() { counts.paired += 1; diff --git a/src/lib.rs b/src/lib.rs index 576ad94..e6e4097 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,6 @@ pub mod feature; mod gff; mod match_intervals; pub mod normalization; -pub mod record; pub mod record_pairs; pub use self::cli::Cli; diff --git a/src/record.rs b/src/record.rs deleted file mode 100644 index 352fee4..0000000 --- a/src/record.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::io; - -use noodles::{bam::record::Cigar, core::Position}; - -pub fn alignment_end( - alignment_start: Option, - cigar: &Cigar<'_>, -) -> Option> { - let start = alignment_start?; - - let span = match alignment_span(cigar) { - Ok(n) => n, - Err(e) => return Some(Err(e)), - }; - - let end = usize::from(start) + span - 1; - - Position::new(end).map(Ok) -} - -fn alignment_span(cigar: &Cigar<'_>) -> io::Result { - let mut span = 0; - - for result in cigar.iter() { - let op = result?; - - if op.kind().consumes_reference() { - span += op.len(); - } - } - - Ok(span) -}