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