/// Incorporate a new sequence into a graph from an alignment
///
/// # Arguments
///
/// * `aln` - The alignment of the new sequence to the graph
/// * `seq` - The sequence being incorporated
Incorporate a new sequence into a graph from an alignment
Incorporate a new sequence into a graph from an alignment
pub fn add_alignment(&mut self, aln: &Alignment, seq: TextSlice) {
        let mut prev: NodeIndex<usize> = NodeIndex::new(0);
        let mut i: usize = 0;
        for op in aln.operations.iter() {
            match op {
                AlignmentOperation::Match(None) => {
                    i += 1;
                }
                AlignmentOperation::Match(Some((_, p))) => {
                    let node = NodeIndex::new(*p);
                    if (seq[i] != self.graph.raw_nodes()[*p].weight) && (seq[i] != b'X') {
                        let node = self.graph.add_node(seq[i]);
                        self.graph.add_edge(prev, node, 1);
                        prev = node;
                    } else {
                        // increment node weight
                        match self.graph.find_edge(prev, node) {
                            Some(edge) => {
                                *self.graph.edge_weight_mut(edge).unwrap() += 1;
                            }
                            None => {
                                // where the previous node was newly added
                                self.graph.add_edge(prev, node, 1);
                            }
                        }
                        prev = NodeIndex::new(*p);
                    }
                    i += 1;
                }
                AlignmentOperation::Ins(None) => {
                    i += 1;
                }
                AlignmentOperation::Ins(Some(_)) => {
                    let node = self.graph.add_node(seq[i]);
                    self.graph.add_edge(prev, node, 1);
                    prev = node;
                    i += 1;
                }
                AlignmentOperation::Del(_) => {} // we should only have to skip over deleted nodes
            }
        }
    }
pub fn add_alignment ( & mut self , aln : & Alignment , seq : TextSlice ) { let mut prev : NodeIndex < usize > = NodeIndex :: new ( 0 ) ; let mut i : usize = 0 ; for op in aln . operations . iter ( ) { match op { AlignmentOperation :: Match ( None ) => { i += 1 ; } AlignmentOperation :: Match ( Some ( ( _ , p ) ) ) => { let node = NodeIndex :: new ( * p ) ; if ( seq [ i ] != self . graph . raw_nodes ( ) [ * p ] . weight ) && ( seq [ i ] != b'X' ) { let node = self . graph . add_node ( seq [ i ] ) ; self . graph . add_edge ( prev , node , 1 ) ; prev = node ; } else { // increment node weight match self . graph . find_edge ( prev , node ) { Some ( edge ) => { * self . graph . edge_weight_mut ( edge ) . unwrap ( ) += 1 ; } None => { // where the previous node was newly added self . graph . add_edge ( prev , node , 1 ) ; } } prev = NodeIndex :: new ( * p ) ; } i += 1 ; } AlignmentOperation :: Ins ( None ) => { i += 1 ; } AlignmentOperation :: Ins ( Some ( _ ) ) => { let node = self . graph . add_node ( seq [ i ] ) ; self . graph . add_edge ( prev , node , 1 ) ; prev = node ; i += 1 ; } AlignmentOperation :: Del ( _ ) => { } // we should only have to skip over deleted nodes } } }
Incorporate a new sequence into a graph from an alignment
Incorporate a new sequence into a graph from an alignment
&mut self
aln
&Alignment
seq
TextSlice