1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use codons::{CODONS, REV_CODONS};
use monster::incubation::{SliceDropFirst, SliceDropLast};
pub fn rev_nucleotide_shift_left_two(mut amino_seq: &[u8]) -> String {
// fn rev_nucleotide_shift_left_two does the following:
// Reverses all elements in the Array.
// Removes element at position '0'
// Removes elemtne at position '0'
// Then we check to see if the vector is a multiple of three
// IF the vector is not a multiple of three we remove from the end
// of the vector a single element then check until the vector is a multiple of three.
// Then we convert our stream of nucleotides into groups of three
// We then convert our groups of three into utf8 encoded String
// We then use a phf to convert our utf8 encoded Strings into corrosponding
// u8 Amino Acid encoding,
// We then push the results of the Amino Acid encoding to a vector.
// We push() a newline to the end of the String to assist with file encoding.
let mut done = String::with_capacity(amino_seq.len() / 3 + 2);;
done.push('\n');
// Shift sequence two elements to the right
amino_seq = amino_seq.drop_last(2);
rev_trim_and_map(&amino_seq, &mut done);
done.push('\n');
done
}
pub fn rev_nucleotide_shift_left_one(mut amino_seq: &[u8]) -> String {
// fn rev_nucleotide_shift_left_one does the following:
// Reverses all elements in the Array.
// Removes element at position '0'
// Then we check to see if the vector is a multiple of three
// IF the vector is not a multiple of three we remove from the end
// of the vector a single element then check until the vector is a multiple of three.
// Then we convert our stream of nucleotides into groups of three
// We then convert our groups of three into utf8 encoded String
// We then use a phf to convert our utf8 encoded Strings into corrosponding
// u8 Amino Acid encoding,
// We then push the results of the Amino Acid encoding to a vector.
// We push() a newline to the end of the String to assist with file encoding.
let mut done = String::new();
done.push('\n');
// Shift elements to the right once
amino_seq = amino_seq.drop_last(1);
rev_trim_and_map(&amino_seq, &mut done);
done.push('\n');
done
}
pub fn rev_no_move(amino_seq: &[u8]) -> String {
// fn rev_no_move does the following:
// Reverses all elements in the Array.
// Then we check to see if the vector is a multiple of three
// IF the vector is not a multiple of three we remove from the end
// of the vector a single element then check until the vector is a multiple of three.
// Then we convert our stream of nucleotides into groups of three
// We then convert our groups of three into utf8 encoded String
// We then use a phf to convert our utf8 encoded Strings into corrosponding
// u8 Amino Acid encoding,
// We then push the results of the Amino Acid encoding to a vector.
// We push() a newline to the end of the String to assist with file encoding.
let mut done = String::with_capacity(amino_seq.len() / 3 + 2);;
done.push('\n');
rev_trim_and_map(&amino_seq, &mut done);
done.push('\n');
done
}
pub fn nucleotide_shift_left_two(mut amino_seq: &[u8]) -> String {
// fn nucleotide_shift_left_two does the following:
// Removes element at position '0'
// Removes elemtne at position '0'
// Then we check to see if the vector is a multiple of three
// IF the vector is not a multiple of three we remove from the end
// of the vector a single element then check until the vector is a multiple of three.
// Then we convert our stream of nucleotides into groups of three
// We then convert our groups of three into utf8 encoded String
// We then use a phf to convert our utf8 encoded Strings into corrosponding
// u8 Amino Acid encoding,
// We then push the results of the Amino Acid encoding to a vector.
// We push() a newline to the end of the String to assist with file encoding.
let mut done = String::with_capacity(amino_seq.len() / 3 + 2);;
// Shift elements to the left twice
amino_seq = amino_seq.drop_first(2);
trim_and_map(&amino_seq, &mut done);
done.push('\n');
done
}
pub fn nucleotide_shift_left_one(mut amino_seq: &[u8]) -> String {
// fn nucleotide_shift_left_one does the following:
// Removes elemtne at position '0'
// Then we check to see if the vector is a multiple of three
// IF the vector is not a multiple of three we remove from the end
// of the vector a single element then check until the vector is a multiple of three.
// Then we convert our stream of nucleotides into groups of three
// We then convert our groups of three into utf8 encoded String
// We then use a phf to convert our utf8 encoded Strings into corrosponding
// u8 Amino Acid encoding,
// We then push the results of the Amino Acid encoding to a vector.
// We push() a newline to the end of the String to assist with file encoding.
let mut done = String::with_capacity(amino_seq.len() / 3 + 2);;
done.push('\n');
// Shift elements to the left once
amino_seq = amino_seq.drop_first(1);
trim_and_map(amino_seq, &mut done);
done.push('\n');
done
}
pub fn no_move<'a>(amino_seq: &[u8]) -> String {
// fn no_move does the following:
// Then we check to see if the vector is a multiple of three
// IF the vector is not a multiple of three we remove from the end
// of the vector a single element then check until the vector is a multiple of three.
// Then we convert our stream of nucleotides into groups of three
// We then convert our groups of three into utf8 encoded String
// We then use a phf to convert our utf8 encoded Strings into corrosponding
// u8 Amino Acid encoding,
// We then push the results of the Amino Acid encoding to a vector.
// We push() a newline to the end of the String to assist with file encoding.
let mut done = String::with_capacity(amino_seq.len() / 3 + 2);;
done.push('\n');
trim_and_map(amino_seq, &mut done);
done.push('\n');
done
}
fn trim_and_map(mut amino_seq: &[u8], done: &mut String) {
// Trim elements from the end until the length is a multiple of 3
amino_seq = amino_seq.drop_last(amino_seq.len() % 3);
debug_assert!(amino_seq.len() % 3 == 0);
for aminos in amino_seq.chunks(3) {
debug_assert!(aminos.len() == 3);
match CODONS.get(aminos) {
Some(&p) => done.push(p),
None => println!("Done!"),
}
}
}
fn rev_trim_and_map(mut amino_seq: &[u8], done: &mut String) {
// Trim elements from the beginning until the length is a multiple of 3
amino_seq = amino_seq.drop_first(amino_seq.len() % 3);
debug_assert!(amino_seq.len() % 3 == 0);
for aminos in amino_seq.chunks(3).rev() {
debug_assert!(aminos.len() == 3);
match REV_CODONS.get(aminos) {
Some(&p) => done.push(p),
None => println!("Done!"),
}
}
}