Skip to main content

SamRecordClipper

Struct SamRecordClipper 

Source
pub struct SamRecordClipper { /* private fields */ }
Expand description

Utility for clipping BAM/SAM records in various ways

Implementations§

Source§

impl SamRecordClipper

Source

pub fn new(mode: ClippingMode) -> SamRecordClipper

Creates a new clipper with the specified mode

Source

pub fn with_auto_clip( mode: ClippingMode, auto_clip_attributes: bool, ) -> SamRecordClipper

Creates a new clipper with auto-clip attributes enabled

When enabled with hard clipping mode, any tags that are the same length as the read’s sequence will be automatically clipped to match. This ensures per-base tags (like quality arrays, per-base depths, etc.) stay synchronized with the sequence.

Source

pub fn clip_start_of_alignment( &self, record: &mut RecordBuf, bases_to_clip: usize, ) -> usize

Clips a specified number of bases from the start (left side) of the alignment

Returns the number of bases actually clipped

Source

pub fn clip_end_of_alignment( &self, record: &mut RecordBuf, bases_to_clip: usize, ) -> usize

Clips a specified number of bases from the end (right side) of the alignment

Returns the number of bases actually clipped

Source

pub fn clip_5_prime_end_of_alignment( &self, record: &mut RecordBuf, bases_to_clip: usize, ) -> usize

Clips bases from the 5’ end of the read (strand-aware)

For positive strand reads, clips from the start of alignment. For negative strand reads, clips from the end of alignment.

Returns the number of bases actually clipped

Source

pub fn clip_3_prime_end_of_alignment( &self, record: &mut RecordBuf, bases_to_clip: usize, ) -> usize

Clips bases from the 3’ end of the read (strand-aware)

For positive strand reads, clips from the end of alignment. For negative strand reads, clips from the start of alignment.

Returns the number of bases actually clipped

Source

pub fn clip_overlapping_reads( &self, r1: &mut RecordBuf, r2: &mut RecordBuf, ) -> (usize, usize)

Clips overlapping portions of an FR read pair

Important: Only clips reads that are in FR (forward-reverse) orientation. Non-FR pairs (FF, RR, RF) are not clipped.

This implementation matches fgbio’s midpoint approach: calculates the midpoint between the 5’ ends of the two reads and clips both reads at that position.

Returns (bases_clipped_r1, bases_clipped_r2)

Source

pub fn num_bases_extending_past_mate( record: &RecordBuf, mate_unclipped_start: usize, mate_unclipped_end: usize, ) -> usize

Calculates the number of bases in a read that extend past the mate’s unclipped boundary

This matches fgbio’s numBasesExtendingPastMate function exactly.

§Arguments
  • record - The SAM record to check
  • mate_unclipped_start - The mate’s unclipped start position
  • mate_unclipped_end - The mate’s unclipped end position
§Returns

The number of bases that extend past the mate’s boundary, or 0 if not applicable

Source

pub fn clip_extending_past_mate_ends( &self, r1: &mut RecordBuf, r2: &mut RecordBuf, ) -> (usize, usize)

Clips reads that extend beyond their mate’s alignment ends

This matches fgbio’s clipExtendingPastMateEnds function exactly.

Important: Only clips reads that are in FR (forward-reverse) orientation. Non-FR pairs (FF, RR, RF) are not clipped.

Returns (bases_clipped_r1, bases_clipped_r2)

Source

pub fn clip_start_of_read( &self, record: &mut RecordBuf, clip_length: usize, ) -> usize

Ensures at least clip_length bases are clipped at the start of the read

This includes any existing hard and soft clipping. If more clipping is needed, delegates to clip_start_of_alignment.

Returns the number of additional bases clipped (not including existing clips)

Source

pub fn clip_end_of_read( &self, record: &mut RecordBuf, clip_length: usize, ) -> usize

Ensures at least clip_length bases are clipped at the end of the read

This includes any existing hard and soft clipping. If more clipping is needed, delegates to clip_end_of_alignment.

Returns the number of additional bases clipped (not including existing clips)

Source

pub fn clip_5_prime_end_of_read( &self, record: &mut RecordBuf, clip_length: usize, ) -> usize

Ensures at least clip_length bases are clipped at the 5’ end (strand-aware)

For positive strand: clips from start. For negative strand: clips from end.

Returns the number of additional bases clipped

Source

pub fn clip_3_prime_end_of_read( &self, record: &mut RecordBuf, clip_length: usize, ) -> usize

Ensures at least clip_length bases are clipped at the 3’ end (strand-aware)

For positive strand: clips from end. For negative strand: clips from start.

Returns the number of additional bases clipped

Source

pub fn upgrade_all_clipping( &self, record: &mut RecordBuf, ) -> Result<(usize, usize), Error>

Upgrades all existing clipping in a read to the current clipping mode

E.g., converts soft clips to hard clips if mode is Hard, or soft clips to soft-with-mask if mode is SoftWithMask

Returns (leading_clipped, trailing_clipped) - the number of soft-clipped bases that were converted to hard clips at the 5’ and 3’ ends respectively. Returns (0, 0) if no conversion occurred.

§Panics

Panics if an adjacent hard-clip CIGAR op disappears between the last() check and the subsequent access (should not happen in practice), or if a BAM tag is not exactly 2 bytes.

§Errors

Returns Result for API compatibility, but the current implementation is infallible and always returns Ok.

Source

pub fn clipped_bases(record: &RecordBuf) -> usize

Returns the number of bases that are currently clipped in the read

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.