pub enum Difference {
Match(usize),
Mismatch(u8),
Insertion(Vec<u8>),
Deletion(usize),
End,
}Expand description
An operation in a difference string describing an alignment between a query sequence and a target sequence.
This implementation supports the following operations:
=: A match given as the matching sequence.:: A match given as the match length.*: A mismatch given as the target base and the query base.+: An insertion given as the inserted sequence.-: A deletion given as the deleted sequence.
The operations do not store target bases, as the query sequence can be reconstructed without that information.
Operation ~ (intron length and splice signal) is not supported yet.
Parsing is based on bytes rather than characters to avoid unnecessary UTF-8 validation.
§Examples
use gbz_base::Difference;
let with_gaps = b":48-CAT:44+GATTACA:51";
let ops = Difference::parse(with_gaps);
assert!(ops.is_ok());
let ops = ops.unwrap();
assert_eq!(ops.len(), 5);
assert_eq!(ops[0], Difference::Match(48));
assert_eq!(ops[1], Difference::Deletion(3));
assert_eq!(ops[2], Difference::Match(44));
assert_eq!(ops[3], Difference::Insertion(b"GATTACA".to_vec()));
assert_eq!(ops[4], Difference::Match(51));Variants§
Match(usize)
A match of the given length.
Mismatch(u8)
Mismatch represented as the query base.
Insertion(Vec<u8>)
Insertion to the reference represented as the inserted sequence.
Deletion(usize)
Deletion from the reference represented as deletion length.
End
Marker for the end of a sequence when concatenating multiple difference strings.
Implementations§
Source§impl Difference
impl Difference
Sourcepub const UNKNOWN_BASE: u8 = b'X'
pub const UNKNOWN_BASE: u8 = b'X'
Symbol used as a substitute for an unknown base.
Sourcepub fn parse(difference_string: &[u8]) -> Result<Vec<Self>, String>
pub fn parse(difference_string: &[u8]) -> Result<Vec<Self>, String>
Parses a difference string and returns it as a vector of operations.
Returns an error if the difference string is invalid.
Sourcepub fn parse_normalized(difference_string: &[u8]) -> Result<Vec<Self>, String>
pub fn parse_normalized(difference_string: &[u8]) -> Result<Vec<Self>, String>
Parses a difference string and returns it as a normalized vector of operations.
The operations are merged and empty operations are removed. Returns an error if the difference string is invalid.
Sourcepub fn stats(difference_string: &[Self]) -> (usize, usize, usize, usize)
pub fn stats(difference_string: &[Self]) -> (usize, usize, usize, usize)
Calculates various statistics from a sequence of operations.
The return value is (query length, target length, matches, edits).
Sourcepub fn target_len(&self) -> usize
pub fn target_len(&self) -> usize
Returns the length of the operation in the target sequence.
Sourcepub fn try_merge(&mut self, op: &Self) -> bool
pub fn try_merge(&mut self, op: &Self) -> bool
Merges the given operation into this operation if they can be merged.
Returns true if the operations were merged.
Trait Implementations§
Source§impl Clone for Difference
impl Clone for Difference
Source§fn clone(&self) -> Difference
fn clone(&self) -> Difference
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more