-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathremoveShortContigs.py
More file actions
executable file
·39 lines (34 loc) · 1005 Bytes
/
removeShortContigs.py
File metadata and controls
executable file
·39 lines (34 loc) · 1005 Bytes
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
#1/usr/bin/python
'''usage: python removeShortContigs.py path/to/infile/ path/to/outfile/ cutoff'''
import sys
infasta = open(sys.argv[1], 'r')
cutoff = int(sys.argv[3])
outfasta = open(sys.argv[2], 'w')
def get_next_fasta (fileObject):
'''usage: for header, seq in get_next_fasta(fileObject):
'''
header = ''
seq = ''
#The following for loop gets the header of the first fasta
#record. Skips any leading junk in the file
for line in fileObject:
if line.startswith('>'):
header = line.strip()
break
for line in fileObject:
if line.startswith('>'):
yield header, seq
header = line.strip()
seq = ''
else:
seq += line.strip()
#yield the last entry
if header:
yield header, seq
for header, seq in get_next_fasta(infasta):
if len(seq) >= cutoff:
outfasta.write("%s\n%s\n" %(header, seq) )
else:
pass
infasta.close()
outfasta.close()