/// Calculate the bam cigar from the alignment struct. x is the target string
/// and y is the reference. `hard_clip` controls how unaligned read bases are encoded in the
/// cigar string. Set to true to use the hard clip (`H`) code, or false to use soft clip
/// (`S`) code. See the [SAM spec](https://samtools.github.io/hts-specs/SAMv1.pdf) for more details.
Calculate the bam cigar from the alignment struct. x is the target string
and y is the reference. `hard_clip` controls how unaligned read bases are encoded in the
cigar string. Set to true to use the hard clip (`H`) code, or false to use soft clip
(`S`) code. See the [SAM spec] for more details.
Calculate the bam cigar from the alignment struct . x is the target string and y is the reference . ` hard_clip ` controls how unaligned read bases are encoded in the cigar string . Set to true to use the hard clip ( ` H ` ) code or false to use soft clip ( ` S ` ) code . See the [ SAM spec ] for more details .
pub fn from_alignment(alignment: &Alignment, hard_clip: bool) -> Self {
        match alignment.mode {
            AlignmentMode::Global => {
                panic!(" Bam cigar fn not supported for Global Alignment mode")
            }
            AlignmentMode::Local => panic!(" Bam cigar fn not supported for Local Alignment mode"),
            _ => {}
        }
        let mut cigar = Vec::new();
        if alignment.operations.is_empty() {
            return CigarString(cigar);
        }
        let add_op = |op: AlignmentOperation, length: u32, cigar: &mut Vec<Cigar>| match op {
            AlignmentOperation::Del => cigar.push(Cigar::Del(length)),
            AlignmentOperation::Ins => cigar.push(Cigar::Ins(length)),
            AlignmentOperation::Subst => cigar.push(Cigar::Diff(length)),
            AlignmentOperation::Match => cigar.push(Cigar::Equal(length)),
            _ => {}
        };
        if alignment.xstart > 0 {
            cigar.push(if hard_clip {
                Cigar::HardClip(alignment.xstart as u32)
            } else {
                Cigar::SoftClip(alignment.xstart as u32)
            });
        }
        let mut last = alignment.operations[0];
        let mut k = 1u32;
        for &op in alignment.operations[1..].iter() {
            if op == last {
                k += 1;
            } else {
                add_op(last, k, &mut cigar);
                k = 1;
            }
            last = op;
        }
        add_op(last, k, &mut cigar);
        if alignment.xlen > alignment.xend {
            cigar.push(if hard_clip {
                Cigar::HardClip((alignment.xlen - alignment.xend) as u32)
            } else {
                Cigar::SoftClip((alignment.xlen - alignment.xend) as u32)
            });
        }
        CigarString(cigar)
    }
pub fn from_alignment ( alignment : & Alignment , hard_clip : bool ) -> Self { match alignment . mode { AlignmentMode :: Global => { panic ! ( " " ) } AlignmentMode :: Local => panic ! ( " " ) , _ => { } } let mut cigar = Vec :: new ( ) ; if alignment . operations . is_empty ( ) { return CigarString ( cigar ) ; } let add_op = | op : AlignmentOperation , length : u32 , cigar : & mut Vec < Cigar > | match op { AlignmentOperation :: Del => cigar . push ( Cigar :: Del ( length ) ) , AlignmentOperation :: Ins => cigar . push ( Cigar :: Ins ( length ) ) , AlignmentOperation :: Subst => cigar . push ( Cigar :: Diff ( length ) ) , AlignmentOperation :: Match => cigar . push ( Cigar :: Equal ( length ) ) , _ => { } } ; if alignment . xstart > 0 { cigar . push ( if hard_clip { Cigar :: HardClip ( alignment . xstart as u32 ) } else { Cigar :: SoftClip ( alignment . xstart as u32 ) } ) ; } let mut last = alignment . operations [ 0 ] ; let mut k = 1u32 ; for & op in alignment . operations [ 1 .. ] . iter ( ) { if op == last { k += 1 ; } else { add_op ( last , k , & mut cigar ) ; k = 1 ; } last = op ; } add_op ( last , k , & mut cigar ) ; if alignment . xlen > alignment . xend { cigar . push ( if hard_clip { Cigar :: HardClip ( ( alignment . xlen - alignment . xend ) as u32 ) } else { Cigar :: SoftClip ( ( alignment . xlen - alignment . xend ) as u32 ) } ) ; } CigarString ( cigar ) }
Calculate the bam cigar from the alignment struct.
Calculate the bam cigar from the alignment struct .
alignment
&Alignment
hard_clip
bool