-
Notifications
You must be signed in to change notification settings - Fork 2
/
fastqDemultiUserBarcode.py
75 lines (65 loc) · 1.86 KB
/
fastqDemultiUserBarcode.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
##################################
# #
# Last modified 02/08/2016 #
# #
# Georgi Marinov, Peng He #
# #
##################################
import sys
try:
import psyco
psyco.full()
except:
pass
def main(argv):
if len(argv) < 2:
print 'usage: python %s input outfilename barcodeSeq [-v]' % argv[0]
print '\tuse - for stdinout instead a input or output filename'
sys.exit(1)
inputfilename = argv[1]
outputfilename = argv[2]
barcodeSeq = argv[3]
if outputfilename == '-':
doStdOut = True
else:
doStdOut = False
outfile = open(outputfilename, 'w')
if inputfilename == '-':
input_stream = sys.stdin
else:
input_stream = open(inputfilename)
i=0
for line in input_stream:
i+=1
if i == 1:
if line.startswith('@'):
pass
else:
print 'fastq input is broken, exiting'
sys.exit(1)
line0 = line
continue
if i == 2:
line1 = line
continue
if i == 3:
if line.startswith('+'):
pass
else:
print 'fastq input is broken, exiting'
sys.exit(1)
line2 = line
continue
if i == 4:
line3 = line
i=0
if (line1.startswith(barcodeSeq) and '-v' not in argv) or (not line1.startswith(barcodeSeq) and '-v' in argv):
if doStdOut:
print line0 + line1 + line2 + line3.strip()
else:
outfile.write(line0 + line1 + line2 + line3.strip())
continue
if not doStdOut:
outfile.close()
if __name__ == '__main__':
main(sys.argv)