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