noodles_sam/alignment/record/cigar/op/
kind.rs

1//! Alignment record CIGAR operation kind.
2
3/// An alignment record CIGAR operation kind.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum Kind {
6    /// An alignment match (`M`).
7    Match,
8    /// An insertion into the reference (`I`).
9    Insertion,
10    /// A deletion from the reference (`D`).
11    Deletion,
12    /// A skipped region from the reference (`N`).
13    Skip,
14    /// A soft clip (`S`).
15    SoftClip,
16    /// A hard clip (`H`).
17    HardClip,
18    /// Padding (`P`).
19    Pad,
20    /// A sequence match (`=`).
21    SequenceMatch,
22    /// A sequence mismatch (`X`).
23    SequenceMismatch,
24}
25
26impl Kind {
27    /// Returns whether the operation kind causes the alignment to consume the read.
28    ///
29    /// # Examples
30    ///
31    /// ```
32    /// use noodles_sam::alignment::record::cigar::op::Kind;
33    /// assert!(Kind::Match.consumes_read());
34    /// assert!(Kind::Insertion.consumes_read());
35    /// assert!(!Kind::Deletion.consumes_read());
36    /// ```
37    pub fn consumes_read(&self) -> bool {
38        matches!(
39            self,
40            Self::Match
41                | Self::Insertion
42                | Self::SoftClip
43                | Self::SequenceMatch
44                | Self::SequenceMismatch
45        )
46    }
47
48    /// Returns whether the operation kind causes the alignment to consume the reference.
49    ///
50    /// # Examples
51    ///
52    /// ```
53    /// use noodles_sam::alignment::record::cigar::op::Kind;
54    /// assert!(Kind::Match.consumes_reference());
55    /// assert!(!Kind::Insertion.consumes_reference());
56    /// assert!(Kind::Deletion.consumes_reference());
57    /// ```
58    pub fn consumes_reference(&self) -> bool {
59        matches!(
60            self,
61            Self::Match
62                | Self::Deletion
63                | Self::Skip
64                | Self::SequenceMatch
65                | Self::SequenceMismatch
66        )
67    }
68}
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn test_consumes_read() {
76        assert!(Kind::Match.consumes_read());
77        assert!(Kind::Insertion.consumes_read());
78        assert!(!Kind::Deletion.consumes_read());
79        assert!(!Kind::Skip.consumes_read());
80        assert!(Kind::SoftClip.consumes_read());
81        assert!(!Kind::HardClip.consumes_read());
82        assert!(!Kind::Pad.consumes_read());
83        assert!(Kind::SequenceMatch.consumes_read());
84        assert!(Kind::SequenceMismatch.consumes_read());
85    }
86
87    #[test]
88    fn test_consumes_reference() {
89        assert!(Kind::Match.consumes_reference());
90        assert!(!Kind::Insertion.consumes_reference());
91        assert!(Kind::Deletion.consumes_reference());
92        assert!(Kind::Skip.consumes_reference());
93        assert!(!Kind::SoftClip.consumes_reference());
94        assert!(!Kind::HardClip.consumes_reference());
95        assert!(!Kind::Pad.consumes_reference());
96        assert!(Kind::SequenceMatch.consumes_reference());
97        assert!(Kind::SequenceMismatch.consumes_reference());
98    }
99}