forked from aakechin/NGS-PrimerPlex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
351 lines (337 loc) · 12.9 KB
/
test.py
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# This script performs some tests of NGS-PrimerPlex:
# - Extracting regions
# - Primer design with all possible features
# + blast
# + SNPs
# + embedded
# + draft primers
# + draft primers with embedded
# + embedded for internal primers
# + anchored PCR
# - Adding adapters
import os
import argparse
import sys
import subprocess as sp
thisDir=os.path.dirname(os.path.realpath(__file__))+os.sep
# Section of reading arguments
parser=argparse.ArgumentParser(description='This script performs some tests of NGS-PrimerPlex')
parser.add_argument('--refDir','-ref',
dest='refDir',type=str,
help="directory with reference files. It is required only if you don't use it in docker",
required=False)
parser.add_argument('--reference-genome','-wgref',
dest='wholeGenomeRef',type=str,
help="file with INDEXED whole-genome reference sequence. "
"It is required only if you don't use it in docker",
required=False)
parser.add_argument('--dbsnp-vcf','-dbsnp',
dest='dbSnpVcfFile',type=str,
help='VCF-file (may be gzipped) with dbSNP variations. '
"It is required only if you don't use it in docker or "
"are not going to use this feature",
required=False)
args=parser.parse_args()
print('\n### Global testing of almost all functions of NGS-PrimerPlex started (11 tests)! ###')
print('\n# 1. Testing extraction of genome regions... #')
cmd=['python3',thisDir+'getGeneRegions.py',
'-glf',thisDir+os.sep.join(['test',
'test_gene.txt']),
'-rf',thisDir+os.sep.join(['test',
'test_gene.regions.csv'])]
if args.refDir:
cmd.extend(['-ref',args.refDir])
else:
cmd.extend(['-ref','/hg19'])
if args.wholeGenomeRef:
cmd.extend(['-wgref',args.wholeGenomeRef])
else:
cmd.extend(['-wgref','/hg19/ucsc.hg19.fasta'])
process=sp.Popen(cmd,shell=False,
stdout=sp.PIPE,stderr=sp.STDOUT,
universal_newlines=True)
out=[]
for c in iter(process.stdout.readline,''):
out.append(str(c))
if 'NGS-PrimerPlex finished!' in '\n'.join(out):
print('Finished successfully!')
else:
print('ERROR! This test was finished with error!')
print('\n'.join(out))
exit(1)
print('\n# 2. Testing primer design with blast, SNPs, and adapter sequences... #')
cmd=['python3',thisDir+'NGS_primerplex.py',
'-regions',thisDir+os.sep.join(['test',
'test_gene.regions.csv']),
'-th','2','-run','test',
'-blast','-snps',
'-ad1','ctctctatgggcagtcggtgatt',
'-ad2','ctgcgtgtctccgactcag',
'-returnvariantsnum','1']
if args.wholeGenomeRef:
cmd.extend(['-ref',args.wholeGenomeRef])
else:
cmd.extend(['-ref','/hg19/ucsc.hg19.fasta'])
if args.dbSnpVcfFile:
cmd.extend(['-snps','-dbsnp',args.dbSnpVcfFile])
elif os.path.exists('/hg19/common_all_20180423_hg19.vcf.gz'):
cmd.extend(['-snps','-dbsnp','/hg19/common_all_20180423_hg19.vcf.gz'])
process=sp.Popen(cmd,shell=False,
stdout=sp.PIPE,stderr=sp.STDOUT,
universal_newlines=True)
out=[]
for c in iter(process.stdout.readline,''):
out.append(str(c))
if 'NGS-PrimerPlex finished!' in '\n'.join(out):
print('Finished successfully!')
else:
print('ERROR! This test was finished with error!')
print('\n'.join(out))
exit(2)
print('\n# 3. Testing converting to draft-primers... #')
cmd=['python3',thisDir+'convertToDraftFile.py',
'-in',thisDir+os.sep.join(['test',
'test_gene.regions_NGS_primerplex_test_primers_combination_1_info.xls']),
'-out',thisDir+os.sep.join(['test',
'test_gene.regions_NGS_primerplex_test_primers_combination_1_info.draft.xls'])]
process=sp.Popen(cmd,shell=False,
stdout=sp.PIPE,stderr=sp.STDOUT,
universal_newlines=True)
out=[]
for c in iter(process.stdout.readline,''):
## sys.stdout.write("\r"+str(c))
out.append(str(c))
## sys.stdout.flush()
if 'NGS-PrimerPlex finished!' in '\n'.join(out):
print('Finished successfully!')
else:
print('ERROR! This test was finished with error!')
print('\n'.join(out))
exit(3)
print('\n# 4. Testing primer design with draft-primers... #')
cmd=['python3',thisDir+'NGS_primerplex.py',
'-regions',thisDir+os.sep.join(['test',
'test_gene.regions.csv']),
'-th','2','-run','test',
'-blast','-snps',
'-ad1','ctctctatgggcagtcggtgatt',
'-ad2','ctgcgtgtctccgactcag',
'-returnvariantsnum','1',
'-draft',thisDir+os.sep.join(['test',
'test_gene.regions_NGS_primerplex_all_draft_primers.xls'])]
if args.wholeGenomeRef:
cmd.extend(['-ref',args.wholeGenomeRef])
else:
cmd.extend(['-ref','/hg19/ucsc.hg19.fasta'])
if args.dbSnpVcfFile:
cmd.extend(['-snps','-dbsnp',args.dbSnpVcfFile])
elif os.path.exists('/hg19/common_all_20180423_hg19.vcf.gz'):
cmd.extend(['-snps','-dbsnp','/hg19/common_all_20180423_hg19.vcf.gz'])
process=sp.Popen(cmd,shell=False,
stdout=sp.PIPE,stderr=sp.STDOUT,
universal_newlines=True)
out=[]
for c in iter(process.stdout.readline,''):
out.append(str(c))
if 'NGS-PrimerPlex finished!' in '\n'.join(out):
print('Finished successfully!')
else:
print('ERROR! This test was finished with error!')
print('\n'.join(out))
exit(4)
print('\n# 5. Testing primer design for embedded PCR... #')
cmd=['python3',thisDir+'NGS_primerplex.py',
'-regions',thisDir+os.sep.join(['test',
'test_gene.regions.csv']),
'-th','2','-run','test',
'-blast','-snps',
'-ad1','ctctctatgggcagtcggtgatt',
'-ad2','ctgcgtgtctccgactcag',
'-returnvariantsnum','1',
'-embedded']
if args.wholeGenomeRef:
cmd.extend(['-ref',args.wholeGenomeRef])
else:
cmd.extend(['-ref','/hg19/ucsc.hg19.fasta'])
if args.dbSnpVcfFile:
cmd.extend(['-snps','-dbsnp',args.dbSnpVcfFile])
elif os.path.exists('/hg19/common_all_20180423_hg19.vcf.gz'):
cmd.extend(['-snps','-dbsnp','/hg19/common_all_20180423_hg19.vcf.gz'])
process=sp.Popen(cmd,shell=False,
stdout=sp.PIPE,stderr=sp.STDOUT,
universal_newlines=True)
out=[]
for c in iter(process.stdout.readline,''):
out.append(str(c))
if 'NGS-PrimerPlex finished!' in '\n'.join(out):
print('Finished successfully!')
else:
print('ERROR! This test was finished with error!')
print('\n'.join(out))
exit(5)
print('\n# 6. Testing primer design for embedded PCR with draft-primers... #')
cmd=['python3',thisDir+'NGS_primerplex.py',
'-regions',thisDir+os.sep.join(['test',
'test_gene.regions.csv']),
'-th','2','-run','test',
'-blast','-snps',
'-ad1','ctctctatgggcagtcggtgatt',
'-ad2','ctgcgtgtctccgactcag',
'-returnvariantsnum','1',
'-embedded',
'-draft',thisDir+os.sep.join(['test',
'test_gene.regions_NGS_primerplex_all_draft_primers.xls'])]
if args.wholeGenomeRef:
cmd.extend(['-ref',args.wholeGenomeRef])
else:
cmd.extend(['-ref','/hg19/ucsc.hg19.fasta'])
if args.dbSnpVcfFile:
cmd.extend(['-snps','-dbsnp',args.dbSnpVcfFile])
elif os.path.exists('/hg19/common_all_20180423_hg19.vcf.gz'):
cmd.extend(['-snps','-dbsnp','/hg19/common_all_20180423_hg19.vcf.gz'])
process=sp.Popen(cmd,shell=False,
stdout=sp.PIPE,stderr=sp.STDOUT,
universal_newlines=True)
out=[]
for c in iter(process.stdout.readline,''):
out.append(str(c))
if 'NGS-PrimerPlex finished!' in '\n'.join(out):
print('Finished successfully!')
else:
print('ERROR! This test was finished with error!')
print('\n'.join(out))
exit(6)
print('\n# 7. Testing primer design for embedded PCR with given internal primers... #')
cmd=['python3',thisDir+'NGS_primerplex.py',
'-regions',thisDir+os.sep.join(['test',
'test_gene.regions.csv']),
'-th','2','-run','test',
'-blast','-snps',
'-ad1','ctctctatgggcagtcggtgatt',
'-ad2','ctgcgtgtctccgactcag',
'-returnvariantsnum','1',
'-embedded',
'-primers',thisDir+os.sep.join(['test',
'test_gene.regions_NGS_primerplex_test_primers_combination_1_info.xls'])]
if args.wholeGenomeRef:
cmd.extend(['-ref',args.wholeGenomeRef])
else:
cmd.extend(['-ref','/hg19/ucsc.hg19.fasta'])
if args.dbSnpVcfFile:
cmd.extend(['-snps','-dbsnp',args.dbSnpVcfFile])
elif os.path.exists('/hg19/common_all_20180423_hg19.vcf.gz'):
cmd.extend(['-snps','-dbsnp','/hg19/common_all_20180423_hg19.vcf.gz'])
process=sp.Popen(cmd,shell=False,
stdout=sp.PIPE,stderr=sp.STDOUT,
universal_newlines=True)
out=[]
for c in iter(process.stdout.readline,''):
out.append(str(c))
if 'NGS-PrimerPlex finished!' in '\n'.join(out):
print('Finished successfully!')
else:
print('ERROR! This test was finished with error!')
print('\n'.join(out))
exit(7)
print('\n# 8. Testing primer design for embedded anchored PCR... #')
cmd=['python3',thisDir+'NGS_primerplex.py',
'-regions',thisDir+os.sep.join(['test',
'test_gene.regions_anchored.csv']),
'-th','2','-run','test',
'-blast','-snps',
'-ad1','ctctctatgggcagtcggtgatt',
'-ad2','ctgcgtgtctccgactcag',
'-returnvariantsnum','1',
'-embedded']
if args.wholeGenomeRef:
cmd.extend(['-ref',args.wholeGenomeRef])
else:
cmd.extend(['-ref','/hg19/ucsc.hg19.fasta'])
if args.dbSnpVcfFile:
cmd.extend(['-snps','-dbsnp',args.dbSnpVcfFile])
elif os.path.exists('/hg19/common_all_20180423_hg19.vcf.gz'):
cmd.extend(['-snps','-dbsnp','/hg19/common_all_20180423_hg19.vcf.gz'])
process=sp.Popen(cmd,shell=False,
stdout=sp.PIPE,stderr=sp.STDOUT,
universal_newlines=True)
out=[]
for c in iter(process.stdout.readline,''):
out.append(str(c))
if 'NGS-PrimerPlex finished!' in '\n'.join(out):
print('Finished successfully!')
else:
print('ERROR! This test was finished with error!')
print('\n'.join(out))
exit(8)
##print('\n# 9. Testing extraction of genome regions for A. thaliana... #')
##cmd=['python3',thisDir+'getGeneRegions.py',
## '-glf',thisDir+os.sep.join(['test',
## 'test_gene_arabidopsis.txt']),
## '-rf',thisDir+os.sep.join(['test',
## 'test_gene_arabidopsis.regions.csv'])]
##if args.refDir:
## cmd.extend(['-ref',args.refDir])
##else:
## cmd.extend(['-ref','/hg19'])
##if args.wholeGenomeRef:
## cmd.extend(['-wgref',args.wholeGenomeRef])
##else:
## cmd.extend(['-wgref','/hg19/ucsc.hg19.fasta'])
##process=sp.Popen(cmd,shell=False,
## stdout=sp.PIPE,stderr=sp.STDOUT,
## universal_newlines=True)
##out=[]
##for c in iter(process.stdout.readline,''):
## out.append(str(c))
##if 'NGS-PrimerPlex finished!' in '\n'.join(out):
## print('Finished successfully!')
##else:
## print('ERROR! This test was finished with error!')
## print('\n'.join(out))
## exit(1)
##
##print('\n# 10. Testing primer design for A. thaliana... #')
##cmd=['python3',thisDir+'NGS_primerplex.py',
## '-regions',thisDir+os.sep.join(['test',
## 'test_gene_arabidopsis.regions.csv']),
## '-th','2','-run','test',
## '-blast',
## '-ad1','ctctctatgggcagtcggtgatt',
## '-ad2','ctgcgtgtctccgactcag',
## '-returnvariantsnum','1']
##if args.wholeGenomeRef:
## cmd.extend(['-ref',args.wholeGenomeRef])
##else:
## cmd.extend(['-ref','/hg19/ucsc.hg19.fasta'])
##if args.dbSnpVcfFile:
## cmd.extend(['-snps','-dbsnp',args.dbSnpVcfFile])
##elif os.path.exists('/hg19/common_all_20180423_hg19.vcf.gz'):
## cmd.extend(['-snps','-dbsnp','/hg19/common_all_20180423_hg19.vcf.gz'])
##process=sp.Popen(cmd,shell=False,
## stdout=sp.PIPE,stderr=sp.STDOUT,
## universal_newlines=True)
##out=[]
##for c in iter(process.stdout.readline,''):
## out.append(str(c))
##if 'NGS-PrimerPlex finished!' in '\n'.join(out):
## print('Finished successfully!')
##else:
## print('ERROR! This test was finished with error!')
## print('\n'.join(out))
## exit(10)
print('\n# 9. Testing addition of adapter sequences... #')
cmd=['python3',thisDir+'addSeqToPrimers.py',
'-in',thisDir+os.sep.join(['test',
'test_gene.regions_NGS_primerplex_test_primers_combination_1_info.xls'])]
process=sp.Popen(cmd,shell=False,
stdout=sp.PIPE,stderr=sp.STDOUT,
universal_newlines=True)
out=[]
for c in iter(process.stdout.readline,''):
out.append(str(c))
if 'NGS-PrimerPlex finished!' in '\n'.join(out):
print('Finished successfully!')
else:
print('ERROR! This test was finished with error!')
print('\n'.join(out))
exit(9)