-
Notifications
You must be signed in to change notification settings - Fork 2
/
renameFastq.py
55 lines (48 loc) · 1.35 KB
/
renameFastq.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 12/03/2014 #
# #
# Georgi Marinov #
# #
##################################
import sys
def main(argv):
if len(argv) < 3:
print 'usage: python %s fastq string newstring' % argv[0]
print '\tUse - for stdin; the script will print to stdout by default'
print '\tIf you want to replace spaces, use _space_ as the string character'
sys.exit(1)
fastq = argv[1]
oldstring = argv[2]
if oldstring == '_space_':
oldstring = ' '
newstring = argv[3]
i=0
pos=1
if fastq == '-':
input_stream = sys.stdin
else:
input_stream = open(fastq)
for line in input_stream:
i+=1
if pos==1 and line.startswith('@'):
print line.strip().replace(oldstring,newstring)
pos=2
continue
if pos==1 and line[0] != '@':
print 'fastq broken'
sys.exit(1)
if pos==2:
print line.strip()
pos=3
continue
if pos==3:
print line.strip()
pos=4
continue
if pos==4:
print line.strip()
pos=1
continue
if __name__ == '__main__':
main(sys.argv)