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
pub struct RandomBases {}
pub struct RandomAT {}
impl Iterator for RandomBases {
type Item = char;
fn next(&mut self) -> Option<Self::Item> {
use rand::Rng;
let mut rng = rand::thread_rng();
let between = rand::distributions::Uniform::from(0..4);
Some(match rng.sample(&between) {
0 => 'A',
1 => 'C',
2 => 'G',
_ => 'T',
})
}
}
impl Iterator for RandomAT {
type Item = char;
fn next(&mut self) -> Option<Self::Item> {
use rand::Rng;
let mut rng = rand::thread_rng();
if rng.gen() {
Some('A')
} else {
Some('T')
}
}
}
impl RandomBases {
pub fn new() -> Self {
RandomBases {}
}
}
impl RandomAT {
pub fn new() -> Self {
RandomAT {}
}
}
pub fn complement(base: char) -> char {
match base {
'A' | 'a' => 'T',
'T' | 't' => 'A',
'C' | 'c' => 'G',
'G' | 'g' => 'C',
_ => {
panic!("unexpected character");
}
}
}