ppgg/data_structures/InternalRep/
instruction.rs

1use std::mem::needs_drop;
2
3// load the modules and crates 
4use crate::data_structures::mutation_ds::*; 
5use serde::{Deserialize, Serialize};
6
7/// A simple for an instruction
8#[derive(Debug,Clone,Serialize,Deserialize,PartialEq)]
9pub struct Instruction
10{
11    code:char,
12    s_state:bool,
13    pos_ref:usize,
14    pos_res:usize,
15    len:usize,
16    data:Vec<char>
17}
18impl Instruction
19{
20    /// create a new instruction where code is the instruction code, pos, is the position code,
21    /// len is the length of the instruction and finally, data is the data associated with the 
22    /// instruction, for example, the sequence of an insertion and/or a deletion. 
23    /// The meaning of each code is as follow: 
24    /// Missense ->	    M
25    /// *Missense ->    N
26    /// frameshift ->	F
27    /// *frameshift	->  R
28    /// stop_gained ->	G
29    /// Stop_lost ->	L
30    /// inframe_insertion ->    I	
31    /// *inframe_insertion ->	J
32    /// inframe_deletion -> 	D
33    /// *inframe_deletion ->	C
34    /// *missense&inframe_altering  ->	    K
35    /// *frameshift&stop_retained ->	    Q
36    /// *stop_gained&inframe_altering ->	A
37    /// frameshift&stop_retained ->     	B
38    /// inframe_deletion&stop_retained ->	P
39    /// inframe_insertion&stop_retained	->  Z
40    /// stop_gained&inframe_altering -> 	T
41    /// stop_lost&frameshift ->             W
42    /// missense&inframe_altering ->        Y
43    /// start_lost&splice_region ->         U
44    /// ```rust
45    /// // load the modules 
46    /// use ppgg_rust::data_structures::InternalRep::instruction::Instruction; 
47    /// // define some example data 
48    /// let code = 'M'; 
49    /// let s_state = false; 
50    /// let pos_ref= 5 as usize; 
51    /// let pos_res= 5 as usize; 
52    /// let len = 1 as usize;
53    /// let data= vec!['K']; 
54    /// // create an instance 
55    /// instance = Instruction::new(code,s_state,pos_ref,pos_res,len,data);  
56    /// // print it out 
57    /// println!("The instance data are: {}", instance); 
58    /// ```
59    pub fn new(code:char, s_state:bool, pos_ref:usize, pos_res:usize, len:usize, data:Vec<char>)->Self
60    {
61        Instruction{code, s_state, pos_ref, pos_res, len, data}
62    }
63    /// ## Summary 
64    /// this is going to be the main translator of the language, it takes as input the mutation type 
65    /// an returns an instruction Representing the interpreted code 
66    pub fn from_mutation(mutation:&Mutation, vec_mut:&Vec<Mutation>)->Self
67    {
68        match &mutation.mut_type
69        {
70            MutationType::MisSense=>Instruction::interpret_missense(mutation,vec_mut), 
71            MutationType::SMisSense=>Instruction::interpret_s_missense(mutation,vec_mut),
72            MutationType::FrameShift=>Instruction::interpret_frameshift(mutation,vec_mut),
73            MutationType::SFrameShift=>Instruction::interpret_s_frameshift(mutation,vec_mut),
74            MutationType::InframeInsertion=>Instruction::interpret_inframe_insertion(mutation,vec_mut),
75            MutationType::SInframeInsertion=>Instruction::interpret_s_inframe_insertion(mutation,vec_mut),
76            MutationType::InframeDeletion=>Instruction::interpret_inframe_deletion(mutation, vec_mut),
77            MutationType::SInframeDeletion=>Instruction::interpret_s_inframe_deletion(mutation, vec_mut),
78            MutationType::StartLost=>Instruction::interpret_start_lost(mutation,vec_mut),
79            MutationType::StopLost=>Instruction::interpret_stop_lost(mutation,vec_mut),
80            MutationType::StopGained=>Instruction::interpret_stop_gained(mutation,vec_mut),
81            MutationType::SStopGained=>Instruction::interpret_s_stop_gained(mutation,vec_mut), 
82            MutationType::SMisSenseAndInframeAltering=>Instruction::interpret_s_missense_and_inframe_altering(mutation,vec_mut), 
83            MutationType::SFrameShiftAndStopRetained=>Instruction::interpret_s_frameshift_and_stop_retained(mutation,vec_mut),
84            MutationType::SStopGainedAndInframeAltering=>Instruction::interpret_s_stop_gained_and_inframe_altering(mutation,vec_mut), 
85            MutationType::FrameShiftAndStopRetained=>Instruction::interpret_frameshift_and_stop_retained(mutation, vec_mut), 
86            MutationType::InframeDeletionAndStopRetained=>Instruction::interpret_inframe_deletion_and_stop_retained(mutation,vec_mut),
87            MutationType::InframeInsertionAndStopRetained=>Instruction::interpret_inframe_insertion_and_stop_retained(mutation),
88            MutationType::StopGainedAndInframeAltering=>Instruction::interpret_stop_gained_and_inframe_altering(mutation,vec_mut),
89            MutationType::StopLostAndFrameShift=>Instruction::interpret_stop_lost_and_frameshift(mutation,vec_mut), 
90            MutationType::MissenseAndInframeAltering=>Instruction::interpret_missense_and_inframe_altering(mutation,vec_mut),
91            MutationType::StartLostAndSpliceRegion=>Instruction::interpret_start_lost_and_splice_region(mutation,vec_mut),        
92        }
93    }
94    /// ## Summary 
95    /// return the code of the instruction
96    pub fn get_code(&self)->char
97    {
98        self.code
99    }
100    /// ## Summary 
101    /// return the position of the instruction in the reference code 
102    pub fn get_position_ref(&self)->usize
103    {
104        self.pos_ref
105    }
106    /// ## Summary 
107    /// return the position of the instruction in the result code 
108    pub fn get_position_res(&self)->usize
109    {
110        self.pos_res
111    }
112    /// ## Summary 
113    /// return the length of the instruction
114    pub fn get_length(&self)->usize
115    {
116        self.len
117    }
118    /// ## Summary 
119    /// return a copy of the associated data 
120    pub fn get_data(&self)->Vec<char>
121    {
122        self.data.clone()
123    }
124    /// ## Summary 
125    /// return the asterisk state of the associated data
126    pub fn get_s_state(&self)->bool
127    {
128        self.s_state
129    }
130    /// ## Summary 
131    /// update the code of the instruction, takes a code as a char and updates the instance code  
132    pub fn update_code(&mut self, code:char)
133    {
134        self.code=code;
135    }
136    /// ## Summary 
137    /// Update the asterisk state or the s state of the instance, takes a flag as an s_state and updates the instance code  
138    pub fn update_s_state(&mut self,s_state:bool)
139    {
140        self.s_state=s_state; 
141    }
142    /// ## Summary 
143    /// Update the starting position of the instruction, takes a new usize and update the instruction start position
144    pub fn update_start_pos(&mut self, start_pos:usize)
145    {
146        self.pos_res=start_pos; 
147    }
148    /// ## Summary 
149    /// Generate an empty, i.e. phi instruction
150    fn generate_phi_instruction()->Self
151    {
152        let code='E'; 
153        let len=0;
154        let pos_ref=0;
155        let pos_res=0;
156        let data=Vec::new(); 
157        let s_state=false;
158        Instruction{code, s_state, pos_ref, pos_res, len, data}
159    }
160    /// ## Summary 
161    /// generate an instruction from a missense mutation 
162    /// ## Example 
163    /// ```rust
164    /// // load instruction and mutation into scope
165    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
166    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
167    /// // let's create a vector of mutation that represent the collection of mutations 
168    /// let mut vec_mut = Vec::new(); 
169    /// // create a mutation instance  
170    /// let test_case=vec!["missense".to_string(),"ENST00000484547".to_string(), "32Q>32R".to_string()];
171    /// let test_mutation=Mutation::new(test_case).unwrap();
172    /// // push a cloned version of the mutation to the instruction set 
173    /// vec_mut.push(test_mutation.clone()); 
174    /// // create an instruction
175    /// let ins=Instruction::interpret_missense(&test_mutation, &vec_mut); 
176    /// println!("The instruction is: {:#?}", ins); 
177    /// assert_eq!(ins.get_code(),'M'); 
178    /// assert_eq!(ins.get_s_state(),false); 
179    /// assert_eq!(ins.get_position_ref(),31); 
180    /// assert_eq!(ins.get_position_res(),31); 
181    /// assert_eq!(ins.get_length(),1); 
182    /// assert_eq!(ins.get_data().len(),1); 
183    /// assert_eq!(ins.get_data()[0],'R'); 
184    /// ```
185    fn interpret_missense(mutation:&Mutation,_vec_mut:&Vec<Mutation>)->Self
186    {   
187        let code='M'; 
188        //println!("Mutation is: {:?}",&mutation);
189        let pos_ref=mutation.mut_info.ref_aa_position as usize; // the position of the reference 
190        let pos_res=mutation.mut_info.mut_aa_position as usize; // the position of the result 
191        let data= match &mutation.mut_info.mut_aa
192        {
193            MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
194            MutatedString::EndSequence(seq_str)=>
195            {
196                let mut data=seq_str.chars().collect::<Vec<char>>();
197                data.remove(data.len()-1);   
198                data
199            }
200            MutatedString::NotSeq =>panic!("Something went wrong, interpreting: {:#?}, failed",&mutation)
201        }; 
202        let len=1;
203        let s_state=false;
204        Instruction{code, s_state, pos_ref, pos_res, len, data}
205    }
206    /// ## Summary 
207    /// Generate an instruction from an asterisk missense mutation, i.e. *missense 
208    /// ## Example 
209    /// ```rust
210    /// // load instruction and mutation into scope
211    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
212    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
213    /// // let's create a vector of mutations that represent the collection of mutations 
214    /// let mut vec_mut = Vec::new(); 
215    /// // create a mutation instance  
216    /// let test_case=vec!["*missense".to_string(),"ENST00000484547".to_string(), "32Q>32R".to_string()];
217    /// let test_mutation=Mutation::new(test_case).unwrap();
218    /// // push a cloned version of the mutation to the instruction set 
219    /// vec_mut.push(test_mutation.clone()); 
220    /// // create an instruction
221    /// let ins=Instruction::interpret_s_missense(&test_mutation, &vec_mut); 
222    /// println!("The instruction is: {:#?}", ins); 
223    /// ```
224    fn interpret_s_missense(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
225    {
226        match Instruction::validate_s_state(mutation,vec_mut)
227        {
228            true=>
229            {
230                let mut n_inst=Instruction::interpret_missense(mutation,vec_mut);
231                n_inst.update_code('N'); 
232                n_inst.update_s_state(true); 
233                n_inst
234            },
235            false=>
236            {
237                Instruction::generate_phi_instruction()
238            }
239        }
240    }
241    // ## Summary 
242    /// generate an instruction from a inframe insertion mutation
243    /// ## Example 
244    /// ```rust
245    /// // load instruction and mutation into scope
246    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
247    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
248    /// // let's create a vector of mutation that represent the collection of mutations 
249    /// let mut vec_mut = Vec::new(); 
250    /// // create a mutation instance  
251    /// let test_case=vec!["inframe_insertion".to_string(),"ENST00000484547".to_string(), "125Y>125YRR".to_string()];
252    /// let test_mutation=Mutation::new(test_case).unwrap();
253    /// // push a cloned version of the mutation to the instruction set 
254    /// vec_mut.push(test_mutation.clone()); 
255    /// // create an instruction
256    /// let ins=Instruction::interpret_inframe_insertion(&test_mutation, &vec_mut); 
257    /// println!("The instruction is: {:#?}", ins); 
258    /// ```
259    fn interpret_inframe_insertion(mutation:&Mutation,_vec_mut:&Vec<Mutation>)->Self
260    {
261        let code='I'; 
262        let pos_ref=mutation.mut_info.ref_aa_position as usize; // the position of the reference 
263        let pos_res=mutation.mut_info.mut_aa_position as usize; // the position of the result 
264        // check the correctness of the reference sequence 
265        match &mutation.mut_info.ref_aa
266        {
267            MutatedString::Sequence(seq_str)=>
268            {
269                let mut_str = seq_str.chars().collect::<Vec<char>>(); 
270                if mut_str.len() != 1 
271                {
272                    let code='2';
273                    let pos_res=mutation.mut_info.ref_aa_position as usize;
274                    let pos_ref=mutation.mut_info.mut_aa_position as usize; 
275                    let data= match &mutation.mut_info.mut_aa
276                    {
277                        MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
278                        MutatedString::EndSequence(seq_str)=>
279                        {
280                            let mut data=seq_str.chars().collect::<Vec<char>>();
281                            data.remove(data.len()-1);   
282                            data
283                        }
284                        MutatedString::NotSeq => return Instruction::interpret_stop_gained(mutation,_vec_mut)
285                    };
286                    let ref_seq=match &mutation.mut_info.ref_aa
287                    {
288                    MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
289                    MutatedString::EndSequence(seq_str)=>
290                    {
291                        let mut data=seq_str.chars().collect::<Vec<char>>();
292                        data.remove(data.len()-1);   
293                        data
294                    }
295                    MutatedString::NotSeq => return Instruction::interpret_stop_lost(mutation,_vec_mut)
296                    };
297                    if data.len()!=ref_seq.len()
298                    {
299                        let code='3';
300                        let pos_res=mutation.mut_info.ref_aa_position as usize;
301                        let pos_ref=mutation.mut_info.mut_aa_position as usize; 
302                        let len=ref_seq.len(); 
303                        let s_state=false; 
304                        return Instruction::new(code, s_state, pos_ref, pos_res, len, data) 
305                    }
306                    let len=data.len(); 
307                    let s_state=false;
308                    return Instruction::new(code, s_state, pos_ref, pos_res, len, data) 
309                } // this is an 2 instruction                  
310            }
311            MutatedString::EndSequence(_)=>
312            {
313                return Instruction::interpret_frameshift(mutation, _vec_mut); // interpret the mutation as a frame shift 
314            },
315            MutatedString::NotSeq =>panic!("In interpreting an inframe insertion the reference amino acids was just an asterisk,\
316             please check your input and contact the developer at h.elabd@ikmb.uni-kiel.de or at the project webpage: https://github.com/ikmb/ppg")
317        };
318        let data= match &mutation.mut_info.mut_aa
319        {
320            MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
321            MutatedString::EndSequence(_)=>
322            {
323                return Instruction::interpret_frameshift(mutation, _vec_mut)
324            }
325            MutatedString::NotSeq =>return Instruction::interpret_stop_gained(mutation, _vec_mut)
326        }; 
327        let len=data.len();
328        let s_state=false;
329        Instruction{code, s_state, pos_ref,pos_res,len, data}
330    }
331    // ## Summary 
332    /// generate an instruction from a asterisk inframe insertion, i.e. *inframe_insertion 
333    /// ## Example 
334    /// ```rust
335    /// // load instruction and mutation into scope
336    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
337    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
338    /// // let's create a vector of mutation that represent the collection of mutations 
339    /// let mut vec_mut = Vec::new(); 
340    /// // create a mutation instance  
341    /// let test_case=vec!["*inframe_insertion".to_string(),"ENST00000484547".to_string(), "125Y>125YRR".to_string()];
342    /// let test_mutation=Mutation::new(test_case).unwrap();
343    /// // push a cloned version of the mutation to the instruction set 
344    /// vec_mut.push(test_mutation.clone()); 
345    /// // create an instruction
346    /// let ins=Instruction::interpret_s_inframe_insertion(&test_mutation, &vec_mut); 
347    /// println!("The instruction is: {:#?}", ins); 
348    /// ```
349    fn interpret_s_inframe_insertion(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
350    {
351        match Instruction::validate_s_state(mutation,vec_mut)
352        {
353            true=>
354            {
355                let mut n_inst=Instruction::interpret_inframe_insertion(mutation,vec_mut);
356                match n_inst.get_code()
357                {
358                    'I'=>
359                    {
360                        n_inst.update_code('J'); 
361                        n_inst.update_s_state(true); 
362                        n_inst
363                    },
364                    _=>n_inst
365                }    
366            }
367            false=>
368            {
369                Instruction::generate_phi_instruction()
370            }
371        }
372    }
373    // ## Summary 
374    /// generate an instruction from an inframe deletion
375    /// ## Example 
376    /// ```rust
377    /// // load instruction and mutation into scope
378    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
379    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
380    /// // let's create a vector of mutation that represent the collection of mutations 
381    /// let mut vec_mut = Vec::new(); 
382    /// // create a mutation instance  
383    /// let test_case=vec!["inframe_deletion".to_string(),"ENST00000506382".to_string(), "115SL>115S".to_string()];
384    /// let test_mutation=Mutation::new(test_case).unwrap();
385    /// // push a cloned version of the mutation to the instruction set 
386    /// vec_mut.push(test_mutation.clone()); 
387    /// // create an instruction
388    /// let ins=Instruction::interpret_inframe_deletion(&test_mutation, &vec_mut); 
389    /// println!("The instruction is: {:#?}", ins); 
390    /// ```
391    fn interpret_inframe_deletion(mutation:&Mutation,_vec_mut:&Vec<Mutation>)->Self
392    {
393        
394        let code='D'; 
395        let pos_ref=mutation.mut_info.ref_aa_position as usize; // the position of the reference 
396        let pos_res=mutation.mut_info.mut_aa_position as usize; // the position of the result 
397        let len = match &mutation.mut_info.ref_aa
398        {
399            MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>().len(),
400            MutatedString::EndSequence(seq_str)=>
401            {
402                let mut data=seq_str.chars().collect::<Vec<char>>();
403                data.remove(data.len()-1);   
404                data.len()
405            }
406            MutatedString::NotSeq => return Instruction::interpret_stop_gained(mutation, _vec_mut)
407        }; 
408        let data=match &mutation.mut_info.mut_aa
409        {
410            MutatedString::Sequence(seq_str)=>
411            {
412                let mut_str=seq_str.chars().collect::<Vec<char>>();
413                if mut_str.len()==1
414                {
415                    mut_str // this is the normal sane case where a stretch of amino acids is replaced 
416                }
417                else 
418                {
419                    let code='2';
420                    let pos_res=mutation.mut_info.ref_aa_position as usize;
421                    let pos_ref=mutation.mut_info.mut_aa_position as usize; 
422                    let data= match &mutation.mut_info.mut_aa
423                    {
424                        MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
425                        MutatedString::EndSequence(seq_str)=>
426                        {
427                            let mut data=seq_str.chars().collect::<Vec<char>>();
428                            data.remove(data.len()-1);   
429                            data
430                        }
431                        MutatedString::NotSeq => panic!("Something went wrong, interpreting: {:#?}, failed",&mutation)
432                    };
433                    let ref_seq=match &mutation.mut_info.ref_aa
434                    {
435                    MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
436                    MutatedString::EndSequence(seq_str)=>
437                    {
438                        let mut data=seq_str.chars().collect::<Vec<char>>();
439                        data.remove(data.len()-1);   
440                        data
441                    }
442                    MutatedString::NotSeq => panic!("Something went wrong, interpreting: {:#?}, failed",&mutation)
443                    };
444                    if data.len()!=ref_seq.len()
445                    {
446                        let code='3';
447                        let pos_res=mutation.mut_info.ref_aa_position as usize;
448                        let pos_ref=mutation.mut_info.mut_aa_position as usize; 
449                        let len=ref_seq.len(); 
450                        let s_state=false; 
451                        return Instruction::new(code, s_state, pos_ref, pos_res, len, data) 
452                    }
453                    let len=data.len(); 
454                    let s_state=false;
455                    return Instruction::new(code, s_state, pos_ref, pos_res, len, data) 
456                } // this is an 2 instruction  
457            },
458            MutatedString::EndSequence(seq_str)=>
459            {
460                let mut data=seq_str.chars().collect::<Vec<char>>();
461                data.remove(data.len()-1);   
462                if data.len()==1
463                {
464                    data // this is also the sane case where we have a stretch of amino acids that will be replaced with one amino acid
465                }
466                else
467                {
468                    return Instruction::interpret_frameshift(mutation, _vec_mut); // interpret the mutation as a frame shift 
469                }
470            }
471            MutatedString::NotSeq => return Instruction::interpret_stop_gained(mutation, _vec_mut)
472        }; 
473        // the length of deletion is 1.
474        let s_state=false;
475        Instruction::new(code, s_state, pos_ref, pos_res, len - data.len(), data)
476    }
477    // ## Summary 
478    /// generates an instruction from an asterisk inframe deletion, i.e. *inframe_deletion
479    /// ## Example 
480    /// ```rust
481    /// // load instruction and mutation into scope
482    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
483    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
484    /// // let's create a vector of mutation that represent the collection of mutations 
485    /// let mut vec_mut = Vec::new(); 
486    /// // create a mutation instance  
487    /// let test_case=vec!["*inframe_deletion".to_string(),"ENST00000506382".to_string(), "115SL>115S".to_string()];
488    /// let test_mutation=Mutation::new(test_case).unwrap();
489    /// // push a cloned version of the mutation to the instruction set 
490    /// vec_mut.push(test_mutation.clone()); 
491    /// // create an instruction
492    /// let ins=Instruction::interpret_s_inframe_insertion(&test_mutation, &vec_mut); 
493    /// println!("The instruction is: {:#?}", ins); 
494    /// ```
495    fn interpret_s_inframe_deletion(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
496    {
497        match Instruction::validate_s_state(mutation,vec_mut)
498        {
499            true=>
500            {
501                let mut n_inst=Instruction::interpret_inframe_deletion(mutation,vec_mut);
502                n_inst.update_code('C'); 
503                n_inst.update_s_state(true); 
504                n_inst
505            },
506            false=>
507            {
508                Instruction::generate_phi_instruction()
509            }
510        }
511    }
512    // ## Summary 
513    /// generates an instruction from a frameshift alteration
514    /// ## Example 
515    /// ```rust
516    /// // load instruction and mutation into scope
517    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
518    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
519    /// // let's create a vector of mutation that represent the collection of mutations 
520    /// let mut vec_mut = Vec::new(); 
521    /// // create a mutation instance  
522    /// let test_case=vec!["frameshift".to_string(),"ENST00000510017".to_string(), "40VGLHFWTM*>40VDSTFGQC".to_string()];
523    /// let test_mutation = Mutation::new(test_case).unwrap();
524    /// // push a cloned version of the mutation to the instruction set 
525    /// vec_mut.push(test_mutation.clone()); 
526    /// // create an instruction
527    /// let ins=Instruction::interpret_frameshift(&test_mutation, &vec_mut); 
528    /// println!("The instruction is: {:#?}", ins); 
529    /// ```
530    fn interpret_frameshift(mutation:&Mutation, _vec_mut:&Vec<Mutation>)->Self
531    {
532        let code='F'; 
533        let pos_ref=mutation.mut_info.ref_aa_position as usize; // the position of the reference 
534        let pos_res=mutation.mut_info.mut_aa_position as usize; // the position of the result 
535        let data= match &mutation.mut_info.mut_aa
536        {
537            MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
538            MutatedString::EndSequence(seq_str)=>
539            {
540                let mut data=seq_str.chars().collect::<Vec<char>>();
541                data.remove(data.len()-1);   
542                data
543            }
544            MutatedString::NotSeq => return Instruction::generate_phi_instruction()
545        }; 
546        let len=data.len();// Because we have the first amino acid in the mutated sequences already, for example, 115SL>115S
547        // the length of deletion is 1.
548        let s_state=false;
549        Instruction{code, s_state, pos_ref, pos_res, len, data}
550    }
551    // ## Summary 
552    /// generates an instruction from an *frameshift mutation
553    /// ## Example 
554    /// ```rust
555    /// // load instruction and mutation into scope
556    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
557    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
558    /// // let's create a vector of mutation that represent the collection of mutations 
559    /// let mut vec_mut = Vec::new(); 
560    /// // create a mutation instance  
561    /// let test_case=vec!["*frameshift".to_string(),"ENST00000510017".to_string(), "40VGLHFWTM*>40VDSTFGQC".to_string()];
562    /// let test_mutation = Mutation::new(test_case).unwrap();
563    /// // push a cloned version of the mutation to the instruction set 
564    /// vec_mut.push(test_mutation.clone()); 
565    /// // create an instruction
566    /// let ins=Instruction::interpret_s_frameshift(&test_mutation, &vec_mut); 
567    /// println!("The instruction is: {:#?}", ins); 
568    /// ```
569    fn interpret_s_frameshift(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
570    {
571        match Instruction::validate_s_state(mutation,vec_mut)
572        {
573            true=>
574            {
575                match mutation.mut_info.mut_aa
576                {
577                    MutatedString::NotSeq=>return Instruction::interpret_stop_gained(mutation, vec_mut),
578                    _=>
579                    {
580                        let mut n_inst=Instruction::interpret_frameshift(mutation,vec_mut);
581                        n_inst.update_code('R'); 
582                        n_inst.update_s_state(true); 
583                        n_inst
584                    }
585                }
586            },
587            false =>
588            {
589                Instruction::generate_phi_instruction()
590            }
591        }
592    }
593    // ## Summary 
594    /// generates an instruction from a stop_gained mutation
595    /// ## Example 
596    /// ```rust
597    /// // load instruction and mutation into scope
598    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
599    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
600    /// // let's create a vector of mutation that represent the collection of mutations 
601    /// let mut vec_mut = Vec::new(); 
602    /// // create a mutation instance  
603    /// let test_case=vec!["stop_gained".to_string(),"ENST00000313766".to_string(), "217E>217*".to_string()];
604    /// let test_mutation = Mutation::new(test_case).unwrap();
605    /// // push a cloned version of the mutation to the instruction set 
606    /// vec_mut.push(test_mutation.clone()); 
607    /// // create an instruction
608    /// let ins=Instruction::interpret_stop_gained(&test_mutation, &vec_mut); 
609    /// println!("The instruction is: {:#?}", ins); 
610    /// ```
611    fn interpret_stop_gained(mutation:&Mutation, _vec_mut:&Vec<Mutation>)->Self
612    {
613        let code='G'; 
614        let pos_ref=mutation.mut_info.ref_aa_position as usize; // the position of the reference 
615        let pos_res=mutation.mut_info.mut_aa_position as usize; // the position of the result 
616        let len=0;
617        let data=Vec::new(); 
618        let s_state=false;
619        Instruction{code, s_state, pos_ref, pos_res, len, data}
620    }
621    // ## Summary 
622    /// generates an instruction from an asterisk *stop_gained mutation, i.e. *stop_gained
623    /// ## Example 
624    /// ```rust
625    /// // load instruction and mutation into scope
626    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
627    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
628    /// // let's create a vector of mutation that represent the collection of mutations 
629    /// let mut vec_mut = Vec::new(); 
630    /// // create a mutation instance  
631    /// let test_case=vec!["*stop_gained".to_string(),"ENST00000313766".to_string(), "217E>217*".to_string()];
632    /// let test_mutation = Mutation::new(test_case).unwrap();
633    /// // push a cloned version of the mutation to the instruction set 
634    /// vec_mut.push(test_mutation.clone()); 
635    /// // create an instruction
636    /// let ins=Instruction::interpret_s_stop_gained(&test_mutation, &vec_mut); 
637    /// println!("The instruction is: {:#?}", ins); 
638    /// ```
639    fn interpret_s_stop_gained(mutation:&Mutation, vec_mut:&Vec<Mutation>)->Self
640    {
641        match Instruction::validate_s_state(mutation,vec_mut)
642        {
643            true=>
644            {
645                let mut n_inst=Instruction::interpret_stop_gained(mutation,vec_mut);
646                n_inst.update_code('X'); 
647                n_inst.update_s_state(true); 
648                n_inst
649            },
650            false=>
651            {
652                Instruction::generate_phi_instruction()
653            }
654        }
655    }
656    // ## Summary 
657    /// generates an instruction from a stop_lost mutations, i.e. stop_lost
658    /// ## Example 
659    /// ```rust
660    /// // load instruction and mutation into scope
661    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
662    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
663    /// // let's create a vector of mutation that represent the collection of mutations 
664    /// let mut vec_mut = Vec::new(); 
665    /// // create a mutation instance  
666    /// let test_case=vec!["stop_lost".to_string(),"ENST00000650310".to_string(), "489*>489S".to_string()];
667    /// let test_mutation = Mutation::new(test_case).unwrap();
668    /// // push a cloned version of the mutation to the instruction set 
669    /// vec_mut.push(test_mutation.clone()); 
670    /// // create an instruction
671    /// let ins=Instruction::interpret_stop_lost(&test_mutation, &vec_mut); 
672    /// println!("The instruction is: {:#?}", ins); 
673    /// ```
674    fn interpret_stop_lost(mutation:&Mutation, _vec_mut:&Vec<Mutation>)->Self
675    {
676        let code='L'; 
677        let pos_ref=mutation.mut_info.ref_aa_position as usize; // the position of the reference 
678        let pos_res=mutation.mut_info.mut_aa_position as usize; // the position of the result 
679        let data= match &mutation.mut_info.mut_aa
680        {
681            MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
682            MutatedString::EndSequence(seq_str)=>
683            {
684                let mut data=seq_str.chars().collect::<Vec<char>>();
685                data.remove(data.len()-1);   
686                data
687            }
688            MutatedString::NotSeq => panic!("Something went wrong, interpreting: {:#?}, failed",&mutation)
689        }; 
690        let len=data.len();
691        let s_state=false;
692        Instruction{code, s_state, pos_ref, pos_res, len, data}
693    }
694    // ## Summary 
695    /// generates an instruction from a start_lost mutation or alteration
696    /// ## Example 
697    /// ```rust
698    /// // load instruction and mutation into scope
699    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
700    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
701    /// // let's create a vector of mutation that represent the collection of mutations 
702    /// let mut vec_mut = Vec::new(); 
703    /// // create a mutation instance  
704    /// let test_case=vec!["start_lost".to_string(),"ENST00000275358".to_string(), "1M>1K".to_string()];
705    /// let test_mutation = Mutation::new(test_case).unwrap();
706    /// // push a cloned version of the mutation to the instruction set 
707    /// vec_mut.push(test_mutation.clone()); 
708    /// // create an instruction
709    /// let ins=Instruction::interpret_start_lost(&test_mutation, &vec_mut); 
710    /// println!("The instruction is: {:#?}", ins); 
711    /// ``` 
712    fn interpret_start_lost(_mutation:&Mutation, _vec_mut:&Vec<Mutation>)->Self
713    {
714        let code='0'; 
715        let len=0;
716        let pos_ref=0;
717        let pos_res=0;
718        let data=Vec::new(); 
719        let s_state=false;
720        Instruction{code, s_state, pos_ref, pos_res, len, data}
721    }
722    // ## Summary 
723    /// generates an instruction from an asterisk missense & inframe_altering mutation which is semantically equivalent to a frame shift 
724    /// ## Example 
725    /// ```rust
726    /// // load instruction and mutation into scope
727    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
728    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
729    /// // let's create a vector of mutation that represent the collection of mutations 
730    /// let mut vec_mut = Vec::new(); 
731    /// // create a mutation instance  
732    /// let test_case=vec!["*missense&inframe_altering".to_string(),"ENST00000326303".to_string(), "188LAY>188LQS".to_string()];
733    /// let test_mutation = Mutation::new(test_case).unwrap();
734    /// // push a cloned version of the mutation to the instruction set 
735    /// vec_mut.push(test_mutation.clone()); 
736    /// // create an instruction
737    /// let ins=Instruction::interpret_s_missense_and_inframe_altering(&test_mutation, &vec_mut); 
738    /// println!("The instruction is: {:#?}", ins); 
739    /// ``` 
740    fn interpret_s_missense_and_inframe_altering(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
741    {
742        let mut n_inst=Instruction::interpret_s_frameshift(mutation,vec_mut);
743        match n_inst.get_code()
744        {
745            'E'=>n_inst,
746            _=>{n_inst.update_code('K'); n_inst}
747        }
748    }
749    // ## Summary 
750    /// generates an instruction from an asterisk frameshift & stop_retained which can be semantically equivalent to an *frameshift
751    /// ## Example 
752    /// ```rust
753    /// // load instruction and mutation into scope
754    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
755    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
756    /// // let's create a vector of mutation that represent the collection of mutations 
757    /// let mut vec_mut = Vec::new(); 
758    /// // create a mutation instance  
759    /// let test_case=vec!["*frameshift&stop_retained".to_string(),"ENST00000438700".to_string(),
760    /// "308GSLGMGQLLLRAKAMRLLYYLKTEDPEYDVQSKQWLTHLLDQFTNIKNILALKKIEVVHFTSLSRQLEFEATSVTVIPVFHLAYILIILFAVTSCFRFDCIRNKMCVAAFGVISAFLAVVSGFGLLLHIGVPFVIIVANSPFLILGVGVDDMFIMISAWHKTNLADDIRERMSNVYSKAAVSITITTITNILALYTGIMSSFRSVQCFCIYTGMTLLFCYFYNITCFGAFMALDGKREVVCLCWLKKADPKWPSFKKFCCFPFGSVPDEHGTDIHPISLFFRDYFGPFLTRSESKYFVVFIYVLYIISSIYGCFHVQEGLDLRNLASDDSYITPYFNVEENYFSDYGPRVMVIVTKKVDYWDKDVRQKLENCTKIFEKNVYVDKNLTEFWLDAYVQYLKGNSQDPNEKNTFMNNIPDFLSNFPNFQHDINISSSNEIISSRGFIQTTDVSSSAKKKILLF*>308GQPRNGPVTPAGQSHAAAVLPEDRGP*".to_string()];
761    /// let test_mutation = Mutation::new(test_case).unwrap();
762    /// // push a cloned version of the mutation to the instruction set 
763    /// vec_mut.push(test_mutation.clone()); 
764    /// // create an instruction
765    /// let ins=Instruction::interpret_s_frameshift_and_stop_retained(&test_mutation, &vec_mut); 
766    /// println!("The instruction is: {:#?}", ins); 
767    /// ``` 
768    fn interpret_s_frameshift_and_stop_retained(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
769    {
770        match mutation.mut_info.mut_aa
771        {
772            MutatedString::NotSeq=>
773            {
774                match Instruction::validate_s_state(mutation,vec_mut)
775                {
776                    true=>
777                    {
778                        let pos_ref=mutation.mut_info.ref_aa_position as usize; 
779                        let pos_res=mutation.mut_info.mut_aa_position as usize; 
780                        let code='Q'; 
781                        let len=0; 
782                        let data:Vec<char>=Vec::new(); 
783                        let s_state=true;
784                        return Instruction::new(code, s_state, pos_ref, pos_res, len, data)
785                    },
786                    false =>
787                    {
788                        Instruction::generate_phi_instruction()
789                    }
790                }
791            },
792            _=>
793            {
794                Instruction::interpret_s_frameshift(mutation,vec_mut)
795            }
796        }
797    }
798    // ## Summary 
799    /// generates an instruction from an asterisk stop-gained & inframe altering which is semantically equivalent to an asterisk stop-gained
800    /// ## Example 
801    /// ```rust
802    /// // load instruction and mutation into scope
803    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
804    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
805    /// // let's create a vector of mutation that represent the collection of mutations 
806    /// let mut vec_mut = Vec::new(); 
807    /// // create a mutation instance  
808    /// let test_case=vec!["*stop_gained&inframe_altering".to_string(),"ENST00000275358".to_string(), 
809    /// "1273KEEDDKNAQGRKRHVKPTSGNAFTICKYPCGKSRECVAPNICKCKPGYIGSNCQTALCDPDCKNHGKCIKPNICQCLPGHGGATCDEEHCNPPCQHGGTCLAGNLCTCPYGFVGPRCETMVCNRHCENGGQCLTPDICQC>1273".to_string()];
810    /// let test_mutation = Mutation::new(test_case).unwrap();
811    /// // push a cloned version of the mutation to the instruction set 
812    /// vec_mut.push(test_mutation.clone()); 
813    /// // create an instruction
814    /// let ins=Instruction::interpret_s_stop_gained_and_inframe_altering(&test_mutation, &vec_mut); 
815    /// println!("The instruction is: {:#?}", ins); 
816    /// ``` 
817    fn interpret_s_stop_gained_and_inframe_altering(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
818    {
819        let mut n_inst=Instruction::interpret_s_stop_gained(mutation,vec_mut);
820        match n_inst.get_code()
821        {
822            'E'=>n_inst,
823            _=>{n_inst.update_code('A'); n_inst}
824        }
825    }
826    // ## Summary 
827    /// generates an instruction from frameshift and stop-retained alternation which is semantically equivalent to a frameshift
828    /// ## Example 
829    /// ```rust
830    /// // load instruction and mutation into scope
831    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
832    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
833    /// // let's create a vector of mutation that represent the collection of mutations 
834    /// let mut vec_mut = Vec::new(); 
835    /// // create a mutation instance  
836    /// let test_case=vec!["frameshift&stop_retained".to_string(),"ENST00000381329".to_string(), "733S*>733*".to_string()];
837    /// let test_mutation = Mutation::new(test_case).unwrap();
838    /// // push a cloned version of the mutation to the instruction set 
839    /// vec_mut.push(test_mutation.clone()); 
840    /// // create an instruction
841    /// let ins=Instruction::interpret_s_missense_and_inframe_altering(&test_mutation, &vec_mut); 
842    /// println!("The instruction is: {:#?}", ins); 
843    /// ``` 
844    fn interpret_frameshift_and_stop_retained(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
845    {
846        let mut n_inst=Instruction::interpret_frameshift(mutation,vec_mut);
847        match n_inst.get_code()
848        {
849            'E'=>n_inst,
850            _=>{n_inst.update_code('B'); n_inst}
851        }
852    }
853    // ## Summary 
854    /// generates an instruction from an inframe_deletion and stop-retained which is semantically equivalent to a stop_gained
855    /// ## Example 
856    /// ```rust
857    /// // load instruction and mutation into scope
858    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
859    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
860    /// // let's create a vector of mutation that represent the collection of mutations 
861    /// let mut vec_mut = Vec::new(); 
862    /// // create a mutation instance  
863    /// let test_case=vec!["inframe_deletion&stop_retained".to_string(),"ENST00000381329".to_string(), "90SL*>90*".to_string()];
864    /// let test_mutation = Mutation::new(test_case).unwrap();
865    /// // push a cloned version of the mutation to the instruction set 
866    /// vec_mut.push(test_mutation.clone()); 
867    /// // create an instruction
868    /// let ins=Instruction::interpret_inframe_deletion_and_stop_retained(&test_mutation, &vec_mut); 
869    /// println!("The instruction is: {:#?}", ins); 
870    /// ``` 
871    fn interpret_inframe_deletion_and_stop_retained(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
872    {        
873        let mut n_inst=Instruction::interpret_stop_gained(mutation,vec_mut);
874        match n_inst.get_code()
875        {
876            'E'=>n_inst,
877            _=>
878            {
879                n_inst.update_code('P');
880                match &mutation.mut_info.ref_aa
881                {
882                    MutatedString::EndSequence(seq)=>
883                    {
884                        n_inst.len=seq.len()-1 as usize;
885                    },
886                    _=>()
887                }
888                n_inst
889            }
890        }
891    }
892    // ## Summary 
893    /// generates an instruction from an inframe_insertion and stop_retained which is semantically equivalent to a phi-Instruction
894    /// ## Example 
895    /// ```rust
896    /// // load instruction and mutation into scope
897    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
898    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
899    /// // let's create a vector of mutation that represent the collection of mutations 
900    /// let mut vec_mut = Vec::new(); 
901    /// // create a mutation instance  
902    /// let test_case=vec!["inframe_insertion&stop_retained".to_string(),"ENST00000551483".to_string(), "192*>192*".to_string()];
903    /// let test_mutation = Mutation::new(test_case).unwrap();
904    /// // push a cloned version of the mutation to the instruction set 
905    /// vec_mut.push(test_mutation.clone()); 
906    /// // create an instruction
907    /// let ins=Instruction::interpret_inframe_insertion_and_stop_retained(&test_mutation, &vec_mut); 
908    /// println!("The instruction is: {:#?}", ins); 
909    /// ```   
910    fn interpret_inframe_insertion_and_stop_retained(mutation:&Mutation)->Self
911    {
912        let mut n_inst=Instruction::generate_phi_instruction();
913        match n_inst.get_code()
914        {
915            'E'=>n_inst,
916            _=>
917            {
918                n_inst.update_code('Z');
919                n_inst.update_start_pos(mutation.mut_info.mut_aa_position as usize);
920                n_inst
921            }
922        }
923    }
924    // ## Summary 
925    /// generates an instruction from a stop_gained and stop_retained which is semantically equivalent to a phi-Instruction, i.e. an empty instruction  
926    /// ## Example 
927    /// ```rust
928    /// // load instruction and mutation into scope
929    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
930    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
931    /// // let's create a vector of mutation that represent the collection of mutations 
932    /// let mut vec_mut = Vec::new(); 
933    /// // create a mutation instance  
934    /// let test_case=vec!["inframe_insertion&stop_retained".to_string(),"ENST00000551483".to_string(), "192*>192*".to_string()];
935    /// let test_mutation = Mutation::new(test_case).unwrap();
936    /// // push a cloned version of the mutation to the instruction set 
937    /// vec_mut.push(test_mutation.clone()); 
938    /// // create an instruction
939    /// let ins=Instruction::interpret_inframe_insertion_and_stop_retained(&test_mutation, &vec_mut); 
940    /// println!("The instruction is: {:#?}", ins); 
941    /// ```   
942    fn interpret_stop_gained_and_inframe_altering(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
943    {
944        let mut n_inst=Instruction::interpret_stop_gained(mutation,vec_mut);
945        match n_inst.get_code()
946        {
947            'E'=>n_inst,
948            _=>{n_inst.update_code('T'); n_inst}
949        }
950    }
951    // ## Summary 
952    /// generates an instruction from a stop_lost and a frameshift which is semantically equivalent to a stop-lost
953    /// ## Example 
954    /// ```rust
955    /// // load instruction and mutation into scope
956    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
957    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
958    /// // let's create a vector of mutation that represent the collection of mutations 
959    /// let mut vec_mut = Vec::new(); 
960    /// // create a mutation instance  
961    /// let test_case=vec!["stop_gained&inframe_altering".to_string(),"ENST00000328942".to_string(), "22LESVQCWIGIPFCAIYLIAMIGNSLLLSIIKSERSLHEPLYIFLGMLGATDIALASSIMPKMLGIFWFNVPEIYFDSCLLQMWFIHTLQGIESGILVAMALDRYVAICYPLRHANIFTHQLVIQIGTMVVLRAAILVAPCLVLIKCRFQFYHTTVISHSYCEHMAIVKLAAANVQVNKIYGLFVAFTVAGFDLTFITLSYIQIFITVFRLPQKEARFKAFNTCIAHICVFLQFYLLAFFSFFTHRFGS>22*".to_string()];
962    /// let test_mutation = Mutation::new(test_case).unwrap();
963    /// // push a cloned version of the mutation to the instruction set 
964    /// vec_mut.push(test_mutation.clone()); 
965    /// // create an instruction
966    /// let ins=Instruction::interpret_stop_lost_and_frameshift(&test_mutation, &vec_mut); 
967    /// println!("The instruction is: {:#?}", ins); 
968    /// ```  
969    fn interpret_stop_lost_and_frameshift(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
970    {
971        match &mutation.mut_info.ref_aa
972        {
973            MutatedString::NotSeq=>Instruction::interpret_stop_lost(mutation,vec_mut),
974            _=>Instruction::interpret_frameshift(mutation,vec_mut)   
975        }
976    }
977    // ## Summary 
978    /// generates an instruction from a missense and an inframe altering which can be semantically equivalent to a frameshift, '2' or '3' depending on the context
979    /// ## Example 
980    /// ```rust
981    /// // load instruction and mutation into scope
982    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
983    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
984    /// // let's create a vector of mutation that represent the collection of mutations 
985    /// let mut vec_mut = Vec::new(); 
986    /// // create a mutation instance  
987    /// let test_case=vec!["missense&inframe_altering".to_string(),"ENST00000328942".to_string(), "22LKM>22LKM".to_string()];
988    /// let test_mutation = Mutation::new(test_case).unwrap();
989    /// // push a cloned version of the mutation to the instruction set 
990    /// vec_mut.push(test_mutation.clone()); 
991    /// // create an instruction
992    /// let ins=Instruction::interpret_missense_and_inframe_altering(&test_mutation, &vec_mut); 
993    /// println!("The instruction is: {:#?}", ins); 
994    /// ```  
995    fn interpret_missense_and_inframe_altering(mutation:&Mutation,vec_mut:&Vec<Mutation>)->Self
996    {
997        match mutation.mut_info.mut_aa
998        {
999            MutatedString::NotSeq=>
1000            {
1001                let mut n_inst=Instruction::interpret_frameshift(mutation,vec_mut);
1002                match n_inst.get_code()
1003                {
1004                    'E'=>n_inst,
1005                    _=>{n_inst.update_code('Y'); n_inst}
1006                }
1007            },
1008            _=>
1009            {
1010                let code='2';
1011                let pos_res=mutation.mut_info.ref_aa_position as usize;
1012                let pos_ref=mutation.mut_info.mut_aa_position as usize; 
1013                let data= match &mutation.mut_info.mut_aa
1014                {
1015                    MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
1016                    MutatedString::EndSequence(seq_str)=>
1017                    {
1018                        let mut data=seq_str.chars().collect::<Vec<char>>();
1019                        data.remove(data.len()-1);   
1020                        data
1021                    }
1022                    MutatedString::NotSeq => panic!("Something went wrong, interpreting: {:#?}, failed",&mutation)
1023                };
1024                let ref_seq=match &mutation.mut_info.ref_aa
1025                {
1026                    MutatedString::Sequence(seq_str)=>seq_str.chars().collect::<Vec<char>>(),
1027                    MutatedString::EndSequence(seq_str)=>
1028                    {
1029                        let mut data=seq_str.chars().collect::<Vec<char>>();
1030                        data.remove(data.len()-1);   
1031                        data
1032                    }
1033                    MutatedString::NotSeq => panic!("Something went wrong, interpreting: {:#?}, failed",&mutation)
1034                };
1035                if data.len()!=ref_seq.len()
1036                {
1037                    let code='3';
1038                    let pos_res=mutation.mut_info.ref_aa_position as usize;
1039                    let pos_ref=mutation.mut_info.mut_aa_position as usize; 
1040                    let len=ref_seq.len(); 
1041                    let s_state=false; 
1042                    return Instruction::new(code, s_state, pos_ref, pos_res, len, data) 
1043                }
1044                let len=data.len(); 
1045                let s_state=false;
1046                Instruction::new(code, s_state, pos_ref, pos_res, len, data) 
1047            }
1048        }
1049    } 
1050    // ## Summary 
1051    /// generates an instruction from a start_lost and splice_region mutation which is semantically equivalent to a start_lost 
1052    /// ## Example 
1053    /// ```rust
1054    /// // load instruction and mutation into scope
1055    /// use ppgg_rust::data_structures::internalRep::instruction::Instruction; 
1056    /// use ppgg_rust::data_structures::mutational_ds::Mutation; 
1057    /// // let's create a vector of mutation that represent the collection of mutations 
1058    /// let mut vec_mut = Vec::new(); 
1059    /// // create a mutation instance  
1060    /// let test_case=vec!["start_lost&splice_region".to_string(),"ENST00000375110".to_string(), "1M>1I".to_string()];
1061    /// let test_mutation = Mutation::new(test_case).unwrap();
1062    /// // push a cloned version of the mutation to the instruction set 
1063    /// vec_mut.push(test_mutation.clone()); 
1064    /// // create an instruction
1065    /// let ins=Instruction::interpret_start_lost_and_splice_region(&test_mutation, &vec_mut); 
1066    /// println!("The instruction is: {:#?}", ins); 
1067    /// ```  
1068    fn interpret_start_lost_and_splice_region(mutation:&Mutation, vec_mut:&Vec<Mutation>)->Self
1069    {
1070        let mut n_inst=Instruction::interpret_start_lost(mutation,vec_mut);
1071        n_inst.update_code('U');
1072        n_inst
1073    }
1074    // ## Summary 
1075    /// validate an input asterisk-based instruction, true if the provided instruction is not precedent by  
1076    /// a frameshift, stop_gained or *stop_gained or an inframe_insertion and deletion with * as a mutated amino acid
1077    fn validate_s_state(mutation:&Mutation,vec_mut:&Vec<Mutation>)->bool
1078    {
1079        let index=vec_mut.iter()
1080                .position(|elem|elem==mutation).unwrap(); 
1081        let mut state=true; 
1082        for mutation in vec_mut[..index].iter()
1083        { 
1084            if mutation.mut_type == MutationType::StopGained || mutation.mut_type == MutationType::FrameShift || mutation.mut_type==MutationType::SStopGained
1085            {
1086                state=false;
1087                 break;
1088            }
1089            else if mutation.mut_type == MutationType::InframeInsertion || mutation.mut_type == MutationType::InframeDeletion
1090            {
1091                match mutation.mut_info.mut_aa 
1092                {
1093                    MutatedString::NotSeq=>{state=false; break;},
1094                    MutatedString::EndSequence(_)=>{state=false; break;}
1095                    _=>(),
1096                }
1097            }
1098        }
1099        state
1100    }
1101}
1102#[cfg(test)]
1103pub mod test_instructions
1104{
1105    use super::*; 
1106    #[test]
1107    pub fn test_interpretion_of_missense_mut()
1108    {
1109        let test_case=vec!["missense".to_string(),"ENST00000484547".to_string(), "32Q>32R".to_string()];
1110        let test_mutation=Mutation::new(test_case).unwrap();
1111        let ins=Instruction::interpret_missense(&test_mutation); 
1112        assert_eq!(ins.get_code(),'M'); 
1113        assert_eq!(ins.get_s_state(),false); 
1114        assert_eq!(ins.get_position(),31); 
1115        assert_eq!(ins.get_length(),1); 
1116        assert_eq!(ins.get_data().len(),1); 
1117        assert_eq!(ins.get_data()[0],'R'); 
1118    }
1119    #[test]
1120    pub fn test_interpretion_of_missense_mut2()
1121    {
1122        let test_case=vec!["*missense".to_string(),"ENST00000484547".to_string(), "32Q>32R".to_string()];
1123        let test_mutation=Mutation::new(test_case).unwrap();
1124        let ins=Instruction::interpret_s_missense(&test_mutation); 
1125        assert_eq!(ins.get_code(),'N'); 
1126        assert_eq!(ins.get_s_state(),true); 
1127        assert_eq!(ins.get_position(),31); 
1128        assert_eq!(ins.get_length(),1); 
1129        assert_eq!(ins.get_data().len(),1); 
1130        assert_eq!(ins.get_data()[0],'R'); 
1131    }
1132    #[test]
1133    #[should_panic]
1134    pub  fn test_interpretion_of_missense_mut3()
1135    {
1136        let test_case=vec!["*missense".to_string(),"ENST00000484547".to_string(), "32Q>32*".to_string()];
1137        let test_mutation=Mutation::new(test_case).unwrap();
1138        let ins=Instruction::interpret_s_missense(&test_mutation); 
1139        assert_eq!(ins.get_code(),'N'); 
1140        assert_eq!(ins.get_s_state(),true); 
1141        assert_eq!(ins.get_position(),31); 
1142        assert_eq!(ins.get_length(),1); 
1143        assert_eq!(ins.get_data().len(),1); 
1144        assert_eq!(ins.get_data()[0],'R'); 
1145    }
1146    #[test]
1147    #[should_panic]
1148    pub  fn test_interpretion_of_missense_mut4()
1149    {
1150        let test_case=vec!["*missense".to_string(),"ENST00000484547".to_string(), "3200>32M".to_string()];
1151        let test_mutation=Mutation::new(test_case).unwrap();
1152        let ins=Instruction::interpret_missense(&test_mutation); 
1153        assert_eq!(ins.get_code(),'M'); 
1154        assert_eq!(ins.get_s_state(),true); 
1155        assert_eq!(ins.get_position(),31); 
1156        assert_eq!(ins.get_length(),1); 
1157        assert_eq!(ins.get_data().len(),1); 
1158        assert_eq!(ins.get_data()[0],'M'); 
1159    }
1160    #[test]
1161    pub  fn test_interpretion_of_inframe_insertion_mut1()
1162    {
1163        // 125Y>125YRR   
1164        let test_case=vec!["inframe_insertion".to_string(),"ENST00000484547".to_string(), "125Y>125YRR".to_string()];
1165        let test_mutation=Mutation::new(test_case).unwrap();
1166        println!("{:#?}",&test_mutation);
1167        let ins=Instruction::interpret_inframe_insertion(&test_mutation); 
1168        assert_eq!(ins.get_code(),'I'); 
1169        assert_eq!(ins.get_s_state(),false); 
1170        assert_eq!(ins.get_position(),124); 
1171        assert_eq!(ins.get_length(),3); 
1172        assert_eq!(ins.get_data().len(),3); 
1173        assert_eq!(ins.get_data()[0],'Y'); 
1174        assert_eq!(ins.get_data()[1],'R'); 
1175        assert_eq!(ins.get_data()[2],'R'); 
1176    }
1177    #[test]
1178    pub  fn test_interpretion_of_s_inframe_insertion_mut2()
1179    {
1180        // 125Y>125YRR   
1181        let test_case=vec!["*inframe_insertion".to_string(),"ENST00000484547".to_string(), "125Y>125YRR".to_string()];
1182        let test_mutation=Mutation::new(test_case).unwrap();
1183        println!("{:#?}",&test_mutation);
1184        let ins=Instruction::interpret_s_inframe_insertion(&test_mutation); 
1185        assert_eq!(ins.get_code(),'J'); 
1186        assert_eq!(ins.get_s_state(),true); 
1187        assert_eq!(ins.get_position(),124); 
1188        assert_eq!(ins.get_length(),3); 
1189        assert_eq!(ins.get_data().len(),3); 
1190        assert_eq!(ins.get_data()[0],'Y'); 
1191        assert_eq!(ins.get_data()[1],'R'); 
1192        assert_eq!(ins.get_data()[2],'R'); 
1193    }
1194    #[test]
1195    pub fn test_interpretion_of_inframe_deletion()
1196    {
1197        let test_case=vec!["inframe_deletion".to_string(),"ENST00000506382".to_string(), "115SL>115S".to_string()];
1198        let test_mutation=Mutation::new(test_case).unwrap();
1199        println!("{:#?}",&test_mutation);  
1200        let ins=Instruction::interpret_inframe_deletion(&test_mutation); 
1201        println!("{:#?}",&ins);  
1202        assert_eq!(ins.get_code(),'D'); 
1203        assert_eq!(ins.get_s_state(),false); 
1204        assert_eq!(ins.get_position(),114); 
1205        assert_eq!(ins.get_length(),1); 
1206        assert_eq!(ins.get_data().len(),1); 
1207    }
1208    #[test]
1209    pub fn test_interpretion_of_s_inframe_deletion()
1210    {
1211        let test_case=vec!["*inframe_deletion".to_string(),"ENST00000506382".to_string(), "115SL>115S".to_string()];
1212        let test_mutation=Mutation::new(test_case).unwrap();
1213        println!("{:#?}",&test_mutation);  
1214        let ins=Instruction::interpret_s_inframe_deletion(&test_mutation);
1215        println!("{:#?}",&ins); 
1216        assert_eq!(ins.get_code(),'C'); 
1217        assert_eq!(ins.get_s_state(),true); 
1218        assert_eq!(ins.get_position(),114); 
1219        assert_eq!(ins.get_length(),1); 
1220        assert_eq!(ins.get_data().len(),1); 
1221    }
1222    #[test]
1223    pub fn test_interpretion_of_frameshift()
1224    {
1225        let test_case=vec!["frameshift".to_string(),"ENST00000510017".to_string(), "40VGLHFWTM*>40VDSTFGQC".to_string()];
1226        let test_mutation=Mutation::new(test_case).unwrap();
1227        println!("{:#?}",&test_mutation);  
1228        let ins=Instruction::interpret_frameshift(&test_mutation); 
1229        println!("{:#?}",&ins); 
1230        assert_eq!(ins.get_code(),'F'); 
1231        assert_eq!(ins.get_s_state(),false); 
1232        assert_eq!(ins.get_position(),39); 
1233        assert_eq!(ins.get_length(),8); 
1234        assert_eq!(*ins.get_data(),['V','D','S','T','F','G','Q','C']); 
1235    }
1236    #[test]
1237    pub fn test_interpretion_of_s_frameshift()
1238    {
1239        let test_case=vec!["*frameshift".to_string(),"ENST00000510017".to_string(), "40VGLHFWTM*>40VDSTFGQC".to_string()];
1240        let test_mutation=Mutation::new(test_case).unwrap();
1241        println!("{:#?}",&test_mutation);  
1242        let ins=Instruction::interpret_s_frameshift(&test_mutation); 
1243        println!("{:#?}",&ins); 
1244        assert_eq!(ins.get_code(),'R'); 
1245        assert_eq!(ins.get_s_state(),true); 
1246        assert_eq!(ins.get_position(),39); 
1247        assert_eq!(ins.get_length(),8); 
1248        assert_eq!(*ins.get_data(),['V','D','S','T','F','G','Q','C']); 
1249    }
1250    #[test]
1251    pub fn test_interpretion_of_stop_gained()
1252    {
1253        let test_case=vec!["stop_gained".to_string(),"ENST00000313766".to_string(), "217E>217*".to_string()];
1254        let test_mutation=Mutation::new(test_case).unwrap();
1255        println!("{:#?}",&test_mutation);  
1256        let ins=Instruction::interpret_stop_gained(&test_mutation); 
1257        println!("{:#?}",&ins); 
1258        assert_eq!(ins.get_code(),'G'); 
1259        assert_eq!(ins.get_s_state(),false); 
1260        assert_eq!(ins.get_position(),216); 
1261        assert_eq!(ins.get_length(),0); 
1262        assert_eq!(ins.get_data().len(),0); 
1263    }
1264    #[test]
1265    pub fn test_interpretion_of_stop_lost()
1266    {
1267        let test_case=vec!["stop_lost".to_string(),"ENST00000650310".to_string(), "489*>489S".to_string()];
1268        let test_mutation=Mutation::new(test_case).unwrap();
1269        println!("{:#?}",&test_mutation);  
1270        let ins=Instruction::interpret_stop_lost(&test_mutation); 
1271        println!("{:#?}",&ins); 
1272        assert_eq!(ins.get_code(),'L'); 
1273        assert_eq!(ins.get_s_state(),false); 
1274        assert_eq!(ins.get_position(),488); 
1275        assert_eq!(ins.get_length(),1);
1276        assert_eq!(ins.get_data().len(),1);
1277        assert_eq!(*ins.get_data(),['S']);
1278    }
1279    #[test]
1280    pub fn test_interpretion_of_start_lost()
1281    {
1282        let test_case=vec!["start_lost".to_string(),"ENST00000275358".to_string(), "1M>1K".to_string()];
1283        let test_mutation=Mutation::new(test_case).unwrap();
1284        println!("{:#?}",&test_mutation);  
1285        let ins=Instruction::interpret_start_lost(&test_mutation); 
1286        println!("{:#?}",&ins); 
1287        assert_eq!(ins.get_code(),'0'); 
1288        assert_eq!(ins.get_s_state(),false); 
1289        assert_eq!(ins.get_position(),0); 
1290        assert_eq!(ins.get_length(),0);
1291        assert_eq!(ins.get_data().len(),0);
1292    }
1293    #[test]
1294    pub fn test_interpretion_of_s_stop_gained()
1295    {
1296        let test_case=vec!["*stop_gained".to_string(),"ENST00000313766".to_string(), "217E>217*".to_string()];
1297        let test_mutation=Mutation::new(test_case).unwrap();
1298        println!("{:#?}",&test_mutation);  
1299        let ins=Instruction::interpret_s_stop_gained(&test_mutation); 
1300        println!("{:#?}",&ins); 
1301        assert_eq!(ins.get_code(),'X'); 
1302        assert_eq!(ins.get_s_state(),true); 
1303        assert_eq!(ins.get_position(),216); 
1304        assert_eq!(ins.get_length(),0); 
1305        assert_eq!(ins.get_data().len(),0); 
1306    }
1307    #[test]
1308    pub fn test_interpret_s_missense_and_inframe_altering()
1309    {
1310        let test_case=vec!["*missense&inframe_altering".to_string(),"ENST00000326303".to_string(), "188LAY>188LQS".to_string()];
1311        let test_mutation=Mutation::new(test_case).unwrap();
1312        println!("{:#?}",&test_mutation);  
1313        let ins=Instruction::interpret_s_missense_and_inframe_altering(&test_mutation); 
1314        println!("{:#?}",&ins); 
1315        assert_eq!(ins.get_code(),'K'); 
1316        assert_eq!(ins.get_s_state(),true); 
1317        assert_eq!(ins.get_position(),187); 
1318        assert_eq!(ins.get_length(),3); 
1319        assert_eq!(ins.get_data().len(),3); 
1320        assert_eq!(*ins.get_data(),['L','Q','S']); 
1321    }
1322    #[test]
1323    pub fn test_interpret_s_frameshift_and_stop_retained()
1324    {
1325        let test_case=vec!["*frameshift&stop_retained".to_string(),"ENST00000438700".to_string(), "308GSLGMGQLLLRAKAMRLLYYLKTEDPEYDVQSKQWLTHLLDQFTNIKNILALKKIEVVHFTSLSRQLEFEATSVTVIPVFHLAYILIILFAVTSCFRFDCIRNKMCVAAFGVISAFLAVVSGFGLLLHIGVPFVIIVANSPFLILGVGVDDMFIMISAWHKTNLADDIRERMSNVYSKAAVSITITTITNILALYTGIMSSFRSVQCFCIYTGMTLLFCYFYNITCFGAFMALDGKREVVCLCWLKKADPKWPSFKKFCCFPFGSVPDEHGTDIHPISLFFRDYFGPFLTRSESKYFVVFIYVLYIISSIYGCFHVQEGLDLRNLASDDSYITPYFNVEENYFSDYGPRVMVIVTKKVDYWDKDVRQKLENCTKIFEKNVYVDKNLTEFWLDAYVQYLKGNSQDPNEKNTFMNNIPDFLSNFPNFQHDINISSSNEIISSRGFIQTTDVSSSAKKKILLF*>308GQPRNGPVTPAGQSHAAAVLPEDRGP*".to_string()];
1326        let test_mutation=Mutation::new(test_case).unwrap();
1327        println!("{:#?}",&test_mutation);  
1328        let ins=Instruction::interpret_s_frameshift_and_stop_retained(&test_mutation); 
1329        println!("{:#?}",&ins); 
1330        assert_eq!(ins.get_code(),'Q'); 
1331        assert_eq!(ins.get_s_state(),true); 
1332        assert_eq!(ins.get_position(),307); 
1333        assert_eq!(*ins.get_data(),[
1334            'G','Q','P','R','N','G','P','V','T',
1335            'P','A','G','Q','S','H','A','A','A','V','L','P','E','D','R','G','P',]); 
1336    }
1337    #[test]
1338    pub fn test_interpret_s_stop_gained_and_inframe_altering()
1339    {
1340        let test_case=vec!["*stop_gained&inframe_altering".to_string(),"ENST00000275358".to_string(), "1273KEEDDKNAQGRKRHVKPTSGNAFTICKYPCGKSRECVAPNICKCKPGYIGSNCQTALCDPDCKNHGKCIKPNICQCLPGHGGATCDEEHCNPPCQHGGTCLAGNLCTCPYGFVGPRCETMVCNRHCENGGQCLTPDICQC>1273".to_string()];
1341        let test_mutation=Mutation::new(test_case).unwrap();
1342        println!("{:#?}",&test_mutation);  
1343        let ins=Instruction::interpret_s_stop_gained_and_inframe_altering(&test_mutation); 
1344        println!("{:#?}",&ins); 
1345        assert_eq!(ins.get_code(),'A'); 
1346        assert_eq!(ins.get_s_state(),true); 
1347        assert_eq!(ins.get_position(),1272); 
1348
1349    }
1350    #[test]
1351    pub fn test_interpret_frameshift_and_stop_retained()
1352    {
1353        let test_case=vec!["frameshift&stop_retained".to_string(),"ENST00000381329".to_string(), "65IEREFENLYIENLELRREIDTLNERLAAEGQAIDGAELSKGQLKTKASHSTSQLSQKLKTTYKASTSKIVSSFKTTTSRAACQLVKEYIGHRDGIWDVSVAKTQPVVLGTASADHTALLWSIETGKCLVKYAGHVGSVNSIKFHPSEQLALTASGDQTAHIWRYAVQLPTPQPVADTSVSTFPYL*>65IENLKTFISKT*".to_string()];
1354        let test_mutation=Mutation::new(test_case).unwrap();
1355        println!("{:#?}",&test_mutation);  
1356        let ins=Instruction::interpret_frameshift_and_stop_retained(&test_mutation); 
1357        println!("{:#?}",&ins); 
1358        assert_eq!(ins.get_code(),'B'); 
1359        assert_eq!(ins.get_s_state(),false); 
1360        assert_eq!(ins.get_position(),64); 
1361        assert_eq!(*ins.get_data(),['I','E','N','L','K','T','F','I','S','K','T']);
1362    }
1363    #[test]
1364    pub fn test_inframe_deletion_and_stop_retained()
1365    {
1366        let test_case=vec!["frameshift&stop_retained".to_string(),"ENST00000381329".to_string(), "733S*>733*".to_string()];
1367        let test_mutation=Mutation::new(test_case).unwrap();
1368        println!("{:#?}",&test_mutation);  
1369        let ins=Instruction::interpret_inframe_deletion_and_stop_retained(&test_mutation); 
1370        println!("{:#?}",&ins); 
1371        assert_eq!(ins.get_code(),'P'); 
1372        assert_eq!(ins.get_s_state(),false); 
1373        assert_eq!(ins.get_length(),0);
1374        assert_eq!(ins.get_position(),732); 
1375    }
1376    #[test]
1377    pub fn test_interpret_inframe_insertion_and_stop_retained()
1378    {
1379        let test_case=vec!["inframe_insertion&stop_retained".to_string(),"ENST00000551483".to_string(), "192*>192*".to_string()];
1380        let test_mutation=Mutation::new(test_case).unwrap();
1381        println!("{:#?}",&test_mutation);  
1382        let ins=Instruction::interpret_inframe_insertion_and_stop_retained(&test_mutation); 
1383        println!("{:#?}",&ins); 
1384        assert_eq!(ins.get_code(),'Z'); 
1385        assert_eq!(ins.get_s_state(),false); 
1386        assert_eq!(ins.get_length(),0);
1387        assert_eq!(ins.get_position(),191); 
1388    }
1389    #[test]
1390    pub fn test_stop_gained_inframe_altering()
1391    {
1392        let test_case=vec!["stop_gained&inframe_altering".to_string(),"ENST00000328942".to_string(), "22LESVQCWIGIPFCAIYLIAMIGNSLLLSIIKSERSLHEPLYIFLGMLGATDIALASSIMPKMLGIFWFNVPEIYFDSCLLQMWFIHTLQGIESGILVAMALDRYVAICYPLRHANIFTHQLVIQIGTMVVLRAAILVAPCLVLIKCRFQFYHTTVISHSYCEHMAIVKLAAANVQVNKIYGLFVAFTVAGFDLTFITLSYIQIFITVFRLPQKEARFKAFNTCIAHICVFLQFYLLAFFSFFTHRFGS>22*".to_string()];
1393        let test_mutation=Mutation::new(test_case).unwrap();
1394        println!("{:#?}",&test_mutation);  
1395        let ins=Instruction::interpret_stop_gained_and_inframe_altering(&test_mutation); 
1396        println!("{:#?}",&ins); 
1397        assert_eq!(ins.get_code(),'T'); 
1398        assert_eq!(ins.get_s_state(),false); 
1399        assert_eq!(ins.get_position(),21); 
1400    }
1401    #[test]
1402    pub fn test_stop_lost_and_frameshift()
1403    {
1404        let test_case=vec!["stop_lost&frameshift".to_string(),"ENST00000398786".to_string(), "134*>134N".to_string()];
1405        let test_mutation=Mutation::new(test_case).unwrap();
1406        println!("{:#?}",&test_mutation);  
1407        let ins=Instruction::interpret_stop_lost_and_frameshift(&test_mutation); 
1408        println!("{:#?}",&ins); 
1409        assert_eq!(ins.get_code(),'W'); 
1410        assert_eq!(ins.get_s_state(),false); 
1411        assert_eq!(ins.get_position(),133); 
1412        assert_eq!(*ins.get_data(),['N']);  
1413    }
1414    #[test]
1415    pub fn test_interpret_start_lost_and_splice_region()
1416    {
1417        let test_case=vec!["start_lost&splice_region".to_string(),"ENST00000375110".to_string(), "1M>1I".to_string()];
1418        let test_mutation=Mutation::new(test_case).unwrap();
1419        println!("{:#?}",&test_mutation);  
1420        let ins=Instruction::interpret_start_lost_and_splice_region(&test_mutation); 
1421        println!("{:#?}",&ins); 
1422        assert_eq!(ins.get_code(),'U'); 
1423        assert_eq!(ins.get_s_state(),false); 
1424        assert_eq!(ins.get_position(),0); 
1425    }
1426}