-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.pl
153 lines (134 loc) · 3.67 KB
/
process.pl
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
`mkdir generated`;
$chainLength="1000000";
foreach $f (glob("data/*.nex")) {
$n = 0;
print STDERR "Processing $f\n";
open(FIN, $f) or die "cannot open $f";
while (($s = <FIN>) && ($s !~ /matrix/)) {}
while (($s = <FIN>) && ($s !~ /^\s*$/)) {
@s = split('\s+', $s);
if ($#s != 2) {
print STDERR "Expected two words, not $#s $s[1]\n";
}
$taxon[$n] = $s[1];
$seq[$n] = $s[2];
$n++;
}
$f =~ s/data\///;
$f =~ s/testHKY(.*).nex/$1/;
generate1();
generate2();
close FIN;
}
open(FOUT,">generated/_experiment.sh");
print FOUT "#!/bin/bash\n";
print FOUT "mkdir singleThread\n";
print FOUT "cd singleThread\n";
print FOUT "mkdir singleThread/test_xml\n";
doWith(1);
print FOUT "cd ..\n";
print FOUT "mkdir doubleThread\n";
print FOUT "cd doubleThread\n";
print FOUT "mkdir doubleThread/test_xml\n";
doWith(2);
print FOUT "cd ..\n";
print FOUT "mkdir fourThread\n";
print FOUT "cd fourThread\n";
print FOUT "mkdir fourThread/test_xml\n";
doWith(4);
print FOUT "cd ..\n";
print FOUT "mkdir GPU\n";
print FOUT "cd GPU\n";
print FOUT "mkdir GPU/test_xml\n";
doGPU();
print FOUT "cd ..\n";
close FOUT;
sub doWith {
$threads = shift;
print FOUT "echo \"\" >times1.dat\n";
print FOUT "echo \"\" >times2.dat\n";
foreach $f (sort(glob("generated/*_1_*.xml"))) {
print FOUT "echo $f\n";
print FOUT "/usr/bin/time ../beast1 -overwrite -beagle_instances $threads -threads $threads ../$f >/dev/null 2>> times1.dat\n";
print FOUT "printf \"\\n\"\n";
$f =~ s/_1_/_2_/;
print FOUT "echo $f\n";
print FOUT "/usr/bin/time ../beast2 -overwrite -instances $threads -threads $threads ../$f >/dev/null 2>> times2.dat\n";
print FOUT "printf \"\\n\"\n";
}
}
sub doGPU {
$threads = shift;
print FOUT "echo \"\" >times1.dat\n";
foreach $f (sort(glob("generated/*_1_*.xml"))) {
print FOUT "echo $f\n";
print FOUT "/usr/bin/time ../beast1 -overwrite -beagle_GPU -beagle_order 1 ../$f >/dev/null 2>> times1.dat\n";
print FOUT "printf \"\\n\"\n";
$f =~ s/_1_/_2_/;
print FOUT "echo $f\n";
print FOUT "/usr/bin/time ../beast2 -overwrite -beagle_GPU ../$f >/dev/null 2>> times2.dat\n";
print FOUT "printf \"\\n\"\n";
}
}
sub generate1 {
merge1("xml/GTR_1.xml");
merge1("xml/GTRI_1.xml");
merge1("xml/GTRG_1.xml");
merge1("xml/GTRGI_1.xml");
}
sub merge1 {
$src = shift;
$type_ = $src;
$type_ =~ s/.xml/_/;
$target = $src;
$target =~ s/xml\///;
$target =~ s/.xml/_$f.xml/;
open (FIN, $src) or die "cannot open file $src" or die "cannot read $src";
open (FOUT, ">generated/_$target") or die "Cannot write generated/_$target" ;
$taxa = '';
$seqs = '';
for ($i = 0; $i < $n; $i++) {
$taxa .= "<taxon id=\"$taxon[$i]\"/>\n";
$seqs .= "<sequence>\n<taxon idref=\"$taxon[$i]\"/>\n$seq[$i]\n</sequence>\n";
}
while ($s = <FIN>) {
$s =~ s/fileName="test/fileName="test_$type_$f/;
$s =~ s/#taxa#/$taxa/;
$s =~ s/#seqs"/$seqs/;
$s =~ s/chainLength="1000000"/chainLength="$chainLength"/;
print FOUT $s;
}
close FOUT;
close FIN;
}
sub generate2 {
merge2("xml/GTR_2.xml");
merge2("xml/GTRI_2.xml");
merge2("xml/GTRG_2.xml");
merge2("xml/GTRGI_2.xml");
}
sub merge2 {
$src = shift;
$type_ = $src;
$type_ =~ s/.xml/_/;
$target = $src;
$target =~ s/.xml/_$f.xml/;
$target =~ s/xml\///;
open (FIN, $src) or die "cannot open file $src";
open (FOUT, ">generated/_$target");
$s = <FIN>;
print FOUT $s;
print FOUT " <data id=\"test\" name=\"alignment\"\n";
for ($i = 0; $i < $n; $i++) {
print FOUT " $taxon[$i]=\"$seq[$i]\"\n";
}
print FOUT "/>\n";
while ($s = <FIN>) {
$s =~ s/fileName="test/fileName="test_$type_$f/;
$s =~ s/fileName="tree/fileName="test_$type_$f/;
$s =~ s/chainLength="1000000"/chainLength="$chainLength"/;
print FOUT $s;
}
close FOUT;
close FIN;
}