-
-
Notifications
You must be signed in to change notification settings - Fork 467
/
regexdna.zep
62 lines (52 loc) · 1.64 KB
/
regexdna.zep
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
62
namespace Stub;
/**
* RegexDNA
*
* @see https://www.haskell.org/haskellwiki/Shootout/Regex_DNA
*/
class RegexDNA
{
public function process(var path)
{
var variants, vIUB, vIUBnew, stuffToRemove, contents, initialLength,
regex, codeLength, discard = null;
let variants = [
"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"
];
let vIUB = [], vIUBnew = [],
vIUB[] = "/B/S", vIUBnew[] = "(c|g|t)",
vIUB[] = "/D/S", vIUBnew[] = "(a|g|t)",
vIUB[] = "/H/S", vIUBnew[] = "(a|c|t)",
vIUB[] = "/K/S", vIUBnew[] = "(g|t)",
vIUB[] = "/M/S", vIUBnew[] = "(a|c)",
vIUB[] = "/N/S", vIUBnew[] = "(a|c|g|t)",
vIUB[] = "/R/S", vIUBnew[] = "(a|g)",
vIUB[] = "/S/S", vIUBnew[] = "(c|g)",
vIUB[] = "/V/S", vIUBnew[] = "(a|c|g)",
vIUB[] = "/W/S", vIUBnew[] = "(a|t)",
vIUB[] = "/Y/S", vIUBnew[] = "(c|t)";
let stuffToRemove = "^>.*$|\n",
discard = null;
// Read in file
let contents = file_get_contents(path),
initialLength = strlen(contents);
// Remove things
let contents = preg_replace("/" . stuffToRemove . "/mS", "", contents),
codeLength = strlen(contents);
// Do regexp counts
for regex in variants {
echo regex , " " , preg_match_all("/" . regex . "/iS", contents, discard), '\n';
}
// Do replacements
let contents = preg_replace(vIUB, vIUBnew, contents);
echo '\n', initialLength, '\n', codeLength, '\n', strlen(contents), '\n';
}
}