Created
September 4, 2014 18:13
-
-
Save brson/fd4d620d6aac03b5db21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The Computer Language Benchmarks Game | |
http://benchmarksgame.alioth.debian.org/ | |
contributed by Alexey Zolotov | |
without openmp, without assert | |
*/ | |
#include <re2.h> | |
#include <iostream> | |
#include <stdio.h> | |
using namespace re2; | |
using namespace std; | |
#define BUFSIZE 1024 | |
int main(void) | |
{ | |
string str, out; | |
int len1, len2; | |
int read_size; | |
char *buf; | |
string pattern1[] = { | |
"agggtaaa|tttaccct", | |
"[cgt]gggtaaa|tttaccc[acg]", | |
"a[act]ggtaaa|tttacc[agt]t", | |
"ag[act]gtaaa|tttac[agt]ct", | |
"agg[act]taaa|ttta[agt]cct", | |
"aggg[acg]aaa|ttt[cgt]ccct", | |
"agggt[cgt]aa|tt[acg]accct", | |
"agggta[cgt]a|t[acg]taccct", | |
"agggtaa[cgt]|[acg]ttaccct" | |
}; | |
string pattern2[] = { | |
"B", "(c|g|t)", "D", "(a|g|t)", "H", "(a|c|t)", "K", "(g|t)", | |
"M", "(a|c)", "N", "(a|c|g|t)", "R", "(a|g)", "S", "(c|g)", | |
"V", "(a|c|g)", "W", "(a|t)", "Y", "(c|t)" | |
}; | |
fseek(stdin, 0, SEEK_END); | |
read_size = ftell(stdin); | |
buf = new char[read_size]; | |
rewind(stdin); | |
read_size = fread(buf, 1, read_size, stdin); | |
str.append(buf, read_size); | |
delete [] buf; | |
len1 = str.length(); | |
RE2::GlobalReplace(&str, ">.*\n|\n", ""); | |
len2 = str.length(); | |
out = str; | |
{ | |
for (int i = 0; i < (int)(sizeof(pattern1) / sizeof(string)); i++) { | |
int count = 0; | |
RE2 pat(pattern1[i]); | |
StringPiece piece = str; | |
while (RE2::FindAndConsume(&piece, pat)) { | |
count++; | |
} | |
cout << pattern1[i] << " " << count << endl; | |
} | |
for (int i = 0; i < (int)(sizeof(pattern2) / sizeof(string)); i += 2) { | |
RE2::GlobalReplace(&out, pattern2[i], pattern2[i + 1]); | |
} | |
} | |
cout << endl; | |
cout << len1 << endl; | |
cout << len2 << endl; | |
cout << out.length() << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment