/// Creates a vector of CigarPos, which contain each cigar operation and the reference position
/// and read position at the start of the operation
///
/// # Arguments
/// - `refpos`: the starting reference position for the read
/// - `cigar_string_view` - cigar string to create cigar position list for
///
/// # Returns
/// A vector of CigarPos corresponding to the CIGAR string.
Creates a vector of CigarPos, which contain each cigar operation and the reference position
and read position at the start of the operation
Creates a vector of CigarPos which contain each cigar operation and the reference position and read position at the start of the operation
pub fn create_augmented_cigarlist(
    refpos: u32,
    cigar_string_view: &CigarStringView,
) -> Result<Vec<CigarPos>> {
    let mut rpos = refpos;
    let mut qpos = 0u32; // position within read
    let mut j = 0; // index into cigar operation vector
    let mut cigar_list: Vec<CigarPos> = Vec::with_capacity(cigar_string_view.len());
    // find first cigar operation referring to qpos = 0 (and thus bases in record.seq()),
    // because all augmentations of qpos and rpos before that are invalid
    for (i, c) in cigar_string_view.iter().enumerate() {
        match c {
            &Cigar::Match(_) |
            &Cigar::Diff(_) |
            &Cigar::Equal(_) |
            // this is unexpected, but bwa + GATK indel realignment can produce insertions
            // before matching positions
            &Cigar::Ins(_) => {
                j = i;
                break;
            }
            &Cigar::SoftClip(_) => {
                j = i;
                break;
            }
            &Cigar::Del(_) => {
                bail!(ErrorKind::UnexpectedCigarOperation(
                    "'deletion' (D) found before any operation describing read sequence".to_owned()
                ));
            }
            &Cigar::RefSkip(_) => {
                bail!(ErrorKind::UnexpectedCigarOperation(
                    "'reference skip' (N) found before any operation describing read sequence".to_owned()
                ));
            }
            &Cigar::HardClip(_) if i > 0 && i < cigar_string_view.len() - 1 => {
                bail!(ErrorKind::UnexpectedCigarOperation(
                    "'hard clip' (H) found in between operations, contradicting SAMv1 spec that hard clips can only be at the ends of reads".to_owned()
                ));
            }
            // if we have reached the end of the CigarString with only pads and hard clips, we have no read position matching the variant
            &Cigar::Pad(_) | &Cigar::HardClip(_) if i == cigar_string_view.len() - 1 => return Ok(cigar_list),
            // skip leading HardClips and Pads, as they consume neither read sequence nor reference sequence
            &Cigar::Pad(_) | &Cigar::HardClip(_) => ()
        }
    }
    while j < cigar_string_view.len() {
        // append CigarPos to list (contains cigar op, ref position, read position)
        match &cigar_string_view[j] {
            &Cigar::Match(_)
            | &Cigar::Diff(_)
            | &Cigar::Equal(_)
            | &Cigar::Ins(_)
            | &Cigar::Del(_)
            | &Cigar::RefSkip(_) => {
                // push the current cigar operation, ref position, and query position onto the list
                cigar_list.push(CigarPos {
                    cig: cigar_string_view[j].clone(),
                    ref_pos: rpos,
                    read_pos: qpos,
                });
            }
            &Cigar::SoftClip(_) | &Cigar::Pad(_) | &Cigar::HardClip(_) => {}
        }
        // move the reference and query positions forward
        match &cigar_string_view[j] {
            &Cigar::Match(l) | &Cigar::Diff(l) | &Cigar::Equal(l) => {
                rpos += l;
                qpos += l;
                j += 1;
            }
            &Cigar::SoftClip(l) => {
                qpos += l;
                j += 1;
            }
            &Cigar::Ins(l) => {
                qpos += l;
                j += 1;
            }
            &Cigar::RefSkip(l) | &Cigar::Del(l) => {
                rpos += l;
                j += 1;
            }
            &Cigar::Pad(_) => {
                j += 1;
            }
            &Cigar::HardClip(_) if j < cigar_string_view.len() - 1 => {
                bail!(ErrorKind::UnexpectedCigarOperation(
                    "'hard clip' (H) found in between operations, contradicting SAMv1 spec that hard clips can only be at the ends of reads".to_owned()
                ));
            }
            &Cigar::HardClip(_) => {
                j += 1;
            }
        }
    }
    Ok(cigar_list)
}
pub fn create_augmented_cigarlist ( refpos : u32 , cigar_string_view : & CigarStringView , ) -> Result < Vec < CigarPos > > { let mut rpos = refpos ; let mut qpos = 0u32 ; // position within read let mut j = 0 ; // index into cigar operation vector let mut cigar_list : Vec < CigarPos > = Vec :: with_capacity ( cigar_string_view . len ( ) ) ; // find first cigar operation referring to qpos = 0 (and thus bases in record.seq()), // because all augmentations of qpos and rpos before that are invalid for ( i , c ) in cigar_string_view . iter ( ) . enumerate ( ) { match c { & Cigar :: Match ( _ ) | & Cigar :: Diff ( _ ) | & Cigar :: Equal ( _ ) | // this is unexpected, but bwa + GATK indel realignment can produce insertions // before matching positions & Cigar :: Ins ( _ ) => { j = i ; break ; } & Cigar :: SoftClip ( _ ) => { j = i ; break ; } & Cigar :: Del ( _ ) => { bail ! ( ErrorKind UnexpectedCigarOperation ( " " to_owned ( ) ) ) ; } & Cigar :: RefSkip ( _ ) => { bail ! ( ErrorKind UnexpectedCigarOperation ( " " to_owned ( ) ) ) ; } & Cigar :: HardClip ( _ ) if i > 0 && i < cigar_string_view . len ( ) - 1 => { bail ! ( ErrorKind UnexpectedCigarOperation ( " " to_owned ( ) ) ) ; } // if we have reached the end of the CigarString with only pads and hard clips, we have no read position matching the variant & Cigar :: Pad ( _ ) | & Cigar :: HardClip ( _ ) if i == cigar_string_view . len ( ) - 1 => return Ok ( cigar_list ) , // skip leading HardClips and Pads, as they consume neither read sequence nor reference sequence & Cigar :: Pad ( _ ) | & Cigar :: HardClip ( _ ) => ( ) } } while j < cigar_string_view . len ( ) { // append CigarPos to list (contains cigar op, ref position, read position) match & cigar_string_view [ j ] { & Cigar :: Match ( _ ) | & Cigar :: Diff ( _ ) | & Cigar :: Equal ( _ ) | & Cigar :: Ins ( _ ) | & Cigar :: Del ( _ ) | & Cigar :: RefSkip ( _ ) => { // push the current cigar operation, ref position, and query position onto the list cigar_list . push ( CigarPos { cig : cigar_string_view [ j ] . clone ( ) , ref_pos : rpos , read_pos : qpos , } ) ; } & Cigar :: SoftClip ( _ ) | & Cigar :: Pad ( _ ) | & Cigar :: HardClip ( _ ) => { } } // move the reference and query positions forward match & cigar_string_view [ j ] { & Cigar :: Match ( l ) | & Cigar :: Diff ( l ) | & Cigar :: Equal ( l ) => { rpos += l ; qpos += l ; j += 1 ; } & Cigar :: SoftClip ( l ) => { qpos += l ; j += 1 ; } & Cigar :: Ins ( l ) => { qpos += l ; j += 1 ; } & Cigar :: RefSkip ( l ) | & Cigar :: Del ( l ) => { rpos += l ; j += 1 ; } & Cigar :: Pad ( _ ) => { j += 1 ; } & Cigar :: HardClip ( _ ) if j < cigar_string_view . len ( ) - 1 => { bail ! ( ErrorKind UnexpectedCigarOperation ( " " to_owned ( ) ) ) ; } & Cigar :: HardClip ( _ ) => { j += 1 ; } } } Ok ( cigar_list ) }
Creates a vector of CigarPos, which contain each cigar operation and the reference position
and read position at the start of the operation
Creates a vector of CigarPos which contain each cigar operation and the reference position and read position at the start of the operation
A vector of CigarPos corresponding to the CIGAR string.
A vector of CigarPos corresponding to the CIGAR string .
refpos
u32
the starting reference position for the read
the starting reference position for the read
cigar_string_view
&CigarStringView
cigar string to create cigar position list for
cigar string to create cigar position list for