pub fn add_alignment(&mut self, aln: &Alignment, seq: Vec<u64>, seq_str: Option<&String>, seq_minim_pos: Option<&Vec<usize>>) {
        let debug = false;
        let mut prev: NodeIndex<usize> = NodeIndex::new(0);
        let mut prev_i = 0;
        let mut i: usize = aln.ystart;
        for op in aln.operations.iter() {
            match op {
                AlignmentOperation::Match(None) => {
                    i += 1;
                }
                AlignmentOperation::Match(Some((_, p))) => {
                    let node = NodeIndex::new(*p);
                    let between_minims = String::from(&seq_str.unwrap()[seq_minim_pos.unwrap()[prev_i] as usize..seq_minim_pos.unwrap()[i] as usize]);
                    if debug {
                        println!("Weight : {}", self.graph.raw_nodes()[*p].weight);
                        println!("Node : {:?}", seq[i]);
                    }
                    if seq[i] != self.graph.raw_nodes()[*p].weight {
                        if debug {println!("node added");}
                        let node = self.graph.add_node(seq[i]);
                        self.graph.add_edge(prev, node, (1, between_minims));
                        //let edge = self.graph.find_edge(prev, node).unwrap(); 
                        // Rayan: I don't see the point of that above line
                        prev = node;
                        prev_i = i;
                    } else {
                        // increment node weight
                        match self.graph.find_edge(prev, node) {
                            Some(edge) => {
                                if debug {println!("edge incremented");}
                                self.graph.edge_weight_mut(edge).unwrap().0 += 1;
                            }
                            None => {
                                if debug {println!("edge added");}
                                // where the previous node was newly added
                                self.graph.add_edge(prev, node, (1, between_minims));
                                //let edge = self.graph.find_edge(prev, node).unwrap();
                                //println!("Edge added {:?}", (self.node_index[&prev], self.node_index[&node]));
                            }
                        }
                        prev = node;
                        prev_i = i;
                    }
                    i += 1;
                }
                AlignmentOperation::Ins(None) => {
                    i += 1;
                }
               AlignmentOperation::Ins(Some(_)) => {
                    let node = self.graph.add_node(seq[i]);
                    let between_minims = String::from(&seq_str.unwrap()[seq_minim_pos.unwrap()[prev_i] as usize..seq_minim_pos.unwrap()[i] as usize]);
                    self.graph.add_edge(prev, node, (1, between_minims));
                    //let edge = self.graph.find_edge(prev, node).unwrap();
                    prev = node;
                    prev_i = i;
                    i += 1;
                }
                AlignmentOperation::Del(_) => {} // we should only have to skip over deleted nodes
            }
        }
    }
/// 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: Vec<u64>, seq_str: Option<&String>, seq_minim_pos: Option<&Vec<usize>>) {
        let debug = false;
        let mut prev: NodeIndex<usize> = NodeIndex::new(0);
        let mut prev_i = 0;
        let mut i: usize = aln.ystart;
        for op in aln.operations.iter() {
            match op {
                AlignmentOperation::Match(None) => {
                    i += 1;
                }
                AlignmentOperation::Match(Some((_, p))) => {
                    let node = NodeIndex::new(*p);
                    let between_minims = String::from(&seq_str.unwrap()[seq_minim_pos.unwrap()[prev_i] as usize..seq_minim_pos.unwrap()[i] as usize]);
                    if debug {
                        println!("Weight : {}", self.graph.raw_nodes()[*p].weight);
                        println!("Node : {:?}", seq[i]);
                    }
                    if seq[i] != self.graph.raw_nodes()[*p].weight {
                        if debug {println!("node added");}
                        let node = self.graph.add_node(seq[i]);
                        self.graph.add_edge(prev, node, (1, between_minims));
                        //let edge = self.graph.find_edge(prev, node).unwrap(); 
                        // Rayan: I don't see the point of that above line
                        prev = node;
                        prev_i = i;
                    } else {
                        // increment node weight
                        match self.graph.find_edge(prev, node) {
                            Some(edge) => {
                                if debug {println!("edge incremented");}
                                self.graph.edge_weight_mut(edge).unwrap().0 += 1;
                            }
                            None => {
                                if debug {println!("edge added");}
                                // where the previous node was newly added
                                self.graph.add_edge(prev, node, (1, between_minims));
                                //let edge = self.graph.find_edge(prev, node).unwrap();
                                //println!("Edge added {:?}", (self.node_index[&prev], self.node_index[&node]));
                            }
                        }
                        prev = node;
                        prev_i = i;
                    }
                    i += 1;
                }
                AlignmentOperation::Ins(None) => {
                    i += 1;
                }
               AlignmentOperation::Ins(Some(_)) => {
                    let node = self.graph.add_node(seq[i]);
                    let between_minims = String::from(&seq_str.unwrap()[seq_minim_pos.unwrap()[prev_i] as usize..seq_minim_pos.unwrap()[i] as usize]);
                    self.graph.add_edge(prev, node, (1, between_minims));
                    //let edge = self.graph.find_edge(prev, node).unwrap();
                    prev = node;
                    prev_i = i;
                    i += 1;
                }
                AlignmentOperation::Del(_) => {} // we should only have to skip over deleted nodes
            }
        }
    }
pub fn add_alignment ( & mut self , aln : & Alignment , seq : Vec < u64 > , seq_str : Option < & String > , seq_minim_pos : Option < & Vec < usize > > ) { let debug = false ; let mut prev : NodeIndex < usize > = NodeIndex :: new ( 0 ) ; let mut prev_i = 0 ; let mut i : usize = aln . ystart ; for op in aln . operations . iter ( ) { match op { AlignmentOperation :: Match ( None ) => { i += 1 ; } AlignmentOperation :: Match ( Some ( ( _ , p ) ) ) => { let node = NodeIndex :: new ( * p ) ; let between_minims = String :: from ( & seq_str . unwrap ( ) [ seq_minim_pos . unwrap ( ) [ prev_i ] as usize .. seq_minim_pos . unwrap ( ) [ i ] as usize ] ) ; if debug { println ! ( " " self graph raw_nodes ( ) [ p ] weight ) ; println ! ( " " seq [ i ] ) ; } if seq [ i ] != self . graph . raw_nodes ( ) [ * p ] . weight { if debug { println ! ( " " ) ; } let node = self . graph . add_node ( seq [ i ] ) ; self . graph . add_edge ( prev , node , ( 1 , between_minims ) ) ; //let edge = self.graph.find_edge(prev, node).unwrap();  // Rayan: I don't see the point of that above line prev = node ; prev_i = i ; } else { // increment node weight match self . graph . find_edge ( prev , node ) { Some ( edge ) => { if debug { println ! ( " " ) ; } self . graph . edge_weight_mut ( edge ) . unwrap ( ) . 0 += 1 ; } None => { if debug { println ! ( " " ) ; } // where the previous node was newly added self . graph . add_edge ( prev , node , ( 1 , between_minims ) ) ; //let edge = self.graph.find_edge(prev, node).unwrap(); //println!("Edge added {:?}", (self.node_index[&prev], self.node_index[&node])); } } prev = node ; prev_i = i ; } i += 1 ; } AlignmentOperation :: Ins ( None ) => { i += 1 ; } AlignmentOperation :: Ins ( Some ( _ ) ) => { let node = self . graph . add_node ( seq [ i ] ) ; let between_minims = String :: from ( & seq_str . unwrap ( ) [ seq_minim_pos . unwrap ( ) [ prev_i ] as usize .. seq_minim_pos . unwrap ( ) [ i ] as usize ] ) ; self . graph . add_edge ( prev , node , ( 1 , between_minims ) ) ; //let edge = self.graph.find_edge(prev, node).unwrap(); prev = node ; prev_i = i ; 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
Vec<u64>
seq_str
Option<&String>
seq_minim_pos
Option<&Vec<usize>>
&mut self
aln
&Alignment
seq
Vec<u64>
seq_str
Option<&String>
seq_minim_pos
Option<&Vec<usize>>