forked from brianpenghe/fastq-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splitfastqintolanes.py
54 lines (46 loc) · 1.32 KB
/
splitfastqintolanes.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
##################################
# #
# Last modified 07/06/2011 #
# #
# Georgi Marinov #
# #
##################################
import sys
import string
import random
from sets import Set
def main(argv):
if len(argv) < 2:
print 'usage: python %s fastq outfileprefix' % argv[0]
sys.exit(1)
input = argv[1]
outprefix = argv[2]
OutfileDict={}
lineslist = open(input)
i=0
j=0
for line in lineslist:
i+=1
if i==1:
j+=1
if j % 1000000 == 0:
print j, 'reads processed'
fields = line.strip().split('@')[1].split(':')
lane=fields[0]+'_s_'+fields[1]
if OutfileDict.has_key(lane):
pass
else:
OutfileDict[lane]=open(outprefix+'_'+lane+'.fastq','w')
print outprefix+'_'+lane+'.fastq'
OutfileDict[lane].write(line)
if i==2:
OutfileDict[lane].write(line)
if i==3:
OutfileDict[lane].write(line)
if i==4:
OutfileDict[lane].write(line)
i=0
for lane in OutfileDict.keys():
OutfileDict[lane].close()
if __name__ == '__main__':
main(sys.argv)