-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfq2fa.py
executable file
·49 lines (38 loc) · 866 Bytes
/
fq2fa.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
#!/usr/bin/python
'''
convert fastq to fasta
assumes every four lines start with sequence line
and then have 3 ignoreable lines
'''
import sys
if len(sys.argv) != 3:
print 'usage: fq2fa.py inputfile outputfile\n - means stdin/out'
exit()
if sys.argv[1] == '-':
fin = sys.stdin
else:
fin = open(sys.argv[1],'rb')
if sys.argv[2] == '-':
fout = sys.stdout
else:
fout = open(sys.argv[2],'wb')
while True:
#description line
line = fin.readline()
if line == '': break
assert line.startswith('@')
fout.write('>' + line[1:])
#sequence line
line = fin.readline()
assert line != ''
try:
fout.write(line)
except:
exit()
#skip next two lines
line = fin.readline()
assert line != ''
line = fin.readline()
assert line != ''
fin.close()
fout.close()