1 // The Computer Language Benchmarks Game
2 // https://benchmarksgame-team.pages.debian.net/benchmarksgame/
3 //
4 // contributed by the Rust Project Developers
5 // contributed by TeXitoi
6 // contributed by BurntSushi
7 
8 extern crate regex;
9 
10 use std::io::{self, Read};
11 
12 macro_rules! regex {
13     ($re:expr) => {
14         ::regex::Regex::new($re).unwrap()
15     };
16 }
17 
main()18 fn main() {
19     let mut seq = String::with_capacity(50 * (1 << 20));
20     io::stdin().read_to_string(&mut seq).unwrap();
21     let ilen = seq.len();
22 
23     seq = regex!(">[^\n]*\n|\n").replace_all(&seq, "").into_owned();
24     let clen = seq.len();
25 
26     let variants = vec![
27         regex!("agggtaaa|tttaccct"),
28         regex!("[cgt]gggtaaa|tttaccc[acg]"),
29         regex!("a[act]ggtaaa|tttacc[agt]t"),
30         regex!("ag[act]gtaaa|tttac[agt]ct"),
31         regex!("agg[act]taaa|ttta[agt]cct"),
32         regex!("aggg[acg]aaa|ttt[cgt]ccct"),
33         regex!("agggt[cgt]aa|tt[acg]accct"),
34         regex!("agggta[cgt]a|t[acg]taccct"),
35         regex!("agggtaa[cgt]|[acg]ttaccct"),
36     ];
37     for re in variants {
38         println!("{} {}", re.to_string(), re.find_iter(&seq).count());
39     }
40 
41     let substs = vec![
42         (regex!("B"), "(c|g|t)"),
43         (regex!("D"), "(a|g|t)"),
44         (regex!("H"), "(a|c|t)"),
45         (regex!("K"), "(g|t)"),
46         (regex!("M"), "(a|c)"),
47         (regex!("N"), "(a|c|g|t)"),
48         (regex!("R"), "(a|g)"),
49         (regex!("S"), "(c|g)"),
50         (regex!("V"), "(a|c|g)"),
51         (regex!("W"), "(a|t)"),
52         (regex!("Y"), "(c|t)"),
53     ];
54     let mut seq = seq;
55     for (re, replacement) in substs {
56         seq = re.replace_all(&seq, replacement).into_owned();
57     }
58     println!("\n{}\n{}\n{}", ilen, clen, seq.len());
59 }
60