forked from brianpenghe/fastq-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shufflefastqReads.py
68 lines (57 loc) · 1.51 KB
/
shufflefastqReads.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
##################################
# #
# Last modified 08/12/2014 #
# #
# Georgi Marinov #
# #
##################################
import sys
import string
import random
def main(argv):
if len(argv) < 1:
print 'usage: python %s inputfilename' % argv[0]
print '\tuse - for stdin; the script will print to stdout by default'
sys.exit(1)
inputfilename = argv[1]
ReadList = []
if inputfilename == '-':
listoflines = sys.stdin
else:
listoflines = open(inputfilename)
i=1
for line in listoflines:
if line == '':
break
if i==1:
if line[0]=='@':
ID = line.strip()
i = 2
else:
print 'fastq file broken'
sys.exit(1)
continue
if i==2:
i = 3
sequence = line.strip()
continue
if i==3:
if line[0]=='+':
i = 4
else:
print 'fastq file broken'
sys.exit(1)
continue
if i==4:
i = 1
scores = line.strip()
ReadList.append((ID,sequence,scores))
continue
random.shuffle(ReadList)
for (ID,sequence,scores) in ReadList:
print ID
print sequence
print '+'
print scores
if __name__ == '__main__':
main(sys.argv)