File: testing.py

package info (click to toggle)
trinculo 0.96%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 580 kB
  • sloc: cpp: 2,930; python: 372; sh: 46; makefile: 6
file content (240 lines) | stat: -rw-r--r-- 9,524 bytes parent folder | download | duplicates (2)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import hashlib
import subprocess
import os
import tempfile

devnull = open(os.devnull, 'w')

binpath="./bin/"
examplepath="./examples/"
trinculo = binpath + "/trinculo"

tmpdir=tempfile.mkdtemp()

print "Testing trinculo (v0.95)"
print "Test files are written to: " + tmpdir
print "1. Testing frequentist association (plink)...",

test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--out", tmpdir + "/1"],stdout=devnull, stderr=devnull)

stoptest=False
if test1 != 0:
    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
    stoptest=True 

if not stoptest:
    test2 = os.path.isfile(tmpdir + "/1" + ".log") and os.path.isfile(tmpdir + "/1" + ".assoc.multinom")
    if not test2:
        print "FAILED (trinuculo failed to produce expected files)"
        stoptest=True
if not stoptest:
    test3 = hashlib.md5(file(tmpdir + '/1.assoc.multinom').read()).digest()
    if test3 != '\x1dg(d\xde\xccM\xcdHM\x11\xdd\xee\xfa\x02\xc6':
        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/1.assoc.multinom)'
        stoptest=True

if not stoptest:
    print "PASSED"


print "2. Testing frequentist association (dosage)...",

test1 = subprocess.call([trinculo,"multinom","--dosage", examplepath + "/genotypes.dose","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--out", tmpdir + "/2"],stdout=devnull, stderr=devnull)

stoptest=False
if test1 != 0:
    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
    stoptest=True 

if not stoptest:
    test2 = os.path.isfile(tmpdir + "/2" + ".log") and os.path.isfile(tmpdir + "/2" + ".assoc.multinom")
    if not test2:
        print "FAILED (trinuculo failed to produce expected files)"
        stoptest=True

if not stoptest:
    test3 = hashlib.md5(file(tmpdir + '/2.assoc.multinom').read()).digest()
    if test3 != '=6\xd0\xb3\xd8\x15SW\x8f\xf9\x86\x13\x99\x90S\xba':
        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/2.assoc.multinom)'
        stoptest=True

if not stoptest:
    print "PASSED"
  
print "3. Testing frequentist association (covariates)...",

test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--out", tmpdir + "/3"],stdout=devnull, stderr=devnull)

stoptest=False
if test1 != 0:
    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
    stoptest=True

if not stoptest:
    test2 = os.path.isfile(tmpdir + "/3" + ".log") and os.path.isfile(tmpdir + "/3" + ".assoc.multinom")
    if not test2:
        print "FAILED (trinuculo failed to produce expected files)"
        stoptest=True

if not stoptest:
    test3 = hashlib.md5(file(tmpdir + '/3.assoc.multinom').read()).digest()
    if test3 != '\x16\x03\xb7\xaaD~M\x04\xba\xff\xc5\xef\xfd{r7':
        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/3.assoc.multinom)'
        stoptest=True

if not stoptest:
    print "PASSED"


print "4. Testing frequentist association (conditioning)...",

condfile=tempfile.mkstemp()
file(condfile[1],"w").write("SNP1")

test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--condition",condfile[1],"--out", tmpdir + "/4"],stdout=devnull, stderr=devnull)

stoptest=False
if test1 != 0:
    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
    stoptest=True

if not stoptest:
    test2 = os.path.isfile(tmpdir + "/4" + ".log") and os.path.isfile(tmpdir + "/4" + ".assoc.multinom")
    if not test2:
        print "FAILED (trinuculo failed to produce expected files)"
        stoptest=True

if not stoptest:
    test3 = hashlib.md5(file(tmpdir + '/4.assoc.multinom').read()).digest()
    if test3 != ":\x03'\x9be=\x08\xbas\xea\xc7\xf2_N\xe3\x02":
        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/4.assoc.multinom)'
        stoptest=True

if not stoptest:
    print "PASSED"


print "5. Testing Bayesian association...",

test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--normalize","--defaultprior","--out", tmpdir + "/5"],stdout=devnull, stderr=devnull)

stoptest=False
if test1 != 0:
    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
    stoptest=True

if not stoptest:
    test2 = os.path.isfile(tmpdir + "/5" + ".log") and os.path.isfile(tmpdir + "/5" + ".assoc.multinom")
    if not test2:
        print "FAILED (trinuculo failed to produce expected files)"
        stoptest=True

if not stoptest:
    test3 = hashlib.md5(file(tmpdir + '/5.assoc.multinom').read()).digest()
    if test3 != 'A~\x85\x00Zy^OsG_\xa9\xa7\xc5\r\xe3':
        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/5.assoc.multinom)'
        stoptest=True

if not stoptest:
    print "PASSED"


print "6. Testing Bayesian association (prior file)...",

test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--normalize","--priors",examplepath + "/priors.txt","--out", tmpdir + "/6"],stdout=devnull, stderr=devnull)

stoptest=False
if test1 != 0:
    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
    stoptest=True

if not stoptest:
    test2 = os.path.isfile(tmpdir + "/6" + ".log") and os.path.isfile(tmpdir + "/6" + ".assoc.multinom")
    if not test2:
        print "FAILED (trinuculo failed to produce expected files)"
        stoptest=True

if not stoptest:
    test3 = hashlib.md5(file(tmpdir + '/6.assoc.multinom').read()).digest()
    if test3 != 'A~\x85\x00Zy^OsG_\xa9\xa7\xc5\r\xe3':
        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/6.assoc.multinom)'
        stoptest=True

if not stoptest:
    print "PASSED"



print "7. Testing Bayesian model selection...",

test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--normalize","--defaultprior","--select","--out", tmpdir + "/7"],stdout=devnull, stderr=devnull)

stoptest=False
if test1 != 0:
    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
    stoptest=True

if not stoptest:
    test2 = os.path.isfile(tmpdir + "/7" + ".log") and os.path.isfile(tmpdir + "/7" + ".assoc.multinom") and os.path.isfile(tmpdir + "/7" + ".select.multinom")
    if not test2:
        print "FAILED (trinuculo failed to produce expected files)"
        stoptest=True

if not stoptest:
    test3 = hashlib.md5(file(tmpdir + '/7.select.multinom').read()).digest()
    if test3 != "9\xb9\xfa\xdf\x02'\xdcx\x82U\xce\xcf\xecx\x06!":
        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/7.select.multinom)'
        stoptest=True

if not stoptest:
    print "PASSED"

print "8. Testing Bayesian model selection (empirical prior)...",

test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--normalize","--empiricalprior","--select","--out", tmpdir + "/8"],stdout=devnull, stderr=devnull)

stoptest=False
if test1 != 0:
    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
    stoptest=True

if not stoptest:
    test2 = os.path.isfile(tmpdir + "/8" + ".log") and os.path.isfile(tmpdir + "/8" + ".assoc.multinom") and os.path.isfile(tmpdir + "/8" + ".select.multinom") and os.path.isfile(tmpdir + "/8" + ".prior")
    if not test2:
        print "FAILED (trinuculo failed to produce expected files)"
        stoptest=True

if not stoptest:
    test3 = hashlib.md5(file(tmpdir + '/8.select.multinom').read()).digest()
    if test3 != '\x89_3\xf2\xef\x96\x1e\xac\x8dy\xc8\xbf\x14\x1f\xfa%':
        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/8.select.multinom)'
        stoptest=True

if not stoptest:
    print "PASSED"

print "9. Testing ordinal regression...",



test1 = subprocess.call([trinculo,"ordinal","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Order","--covar", examplepath + "/pcs.txt","--out", tmpdir + "/9"],stdout=devnull, stderr=devnull)

stoptest=False
if test1 != 0:
    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
    stoptest=True

if not stoptest:
    test2 = os.path.isfile(tmpdir + "/9" + ".log") and os.path.isfile(tmpdir + "/9" + ".assoc.ordinal")
    if not test2:
        print "FAILED (trinuculo failed to produce expected files)"
        stoptest=True

if not stoptest:
    test3 = hashlib.md5(file(tmpdir + '/9.assoc.ordinal').read()).digest()
    if test3 != '\xbd\xab\xad\x10\xd3\xea\xd8r\x9f*~V\xf8\xb5\x9b\x9c':
        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/9.assoc.ordinal)'
        stoptest=True

if not stoptest:
    print "PASSED"