-
Notifications
You must be signed in to change notification settings - Fork 2
/
fastaMinLength.py
52 lines (45 loc) · 1.51 KB
/
fastaMinLength.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
##################################
# #
# Last modified 03/21/2014 #
# #
# Georgi Marinov #
# #
##################################
import sys
import string
def main(argv):
if len(argv) < 4:
print 'usage: python %s fasta minLength blocksize outputfilename' % argv[0]
sys.exit(1)
fasta = argv[1]
minLenSequence = int(argv[2])
blocksize = int(argv[3])
outfilename = argv[4]
outfile = open(outfilename, 'w')
inputdatafile = open(fasta)
ID=''
for line in inputdatafile:
if line[0]=='>':
if ID == '':
ID = line.strip().split('>')[1]
else:
sequence = ''.join(sequence)
if len(sequence) < minLenSequence:
pass
else:
outfile.write('>' + ID + '\n')
for i in range(0,len(sequence),blocksize):
outfile.write(sequence[i:min(i+blocksize, len(sequence))] + '\n')
ID = line.strip().split('>')[1]
sequence=[]
else:
sequence.append(line.strip())
sequence = ''.join(sequence)
if len(sequence) < minLenSequence:
pass
else:
outfile.write('>' + ID + '\n')
for i in range(0,len(sequence),blocksize):
outfile.write(sequence[i:min(i+blocksize, len(sequence))] + '\n')
if __name__ == '__main__':
main(sys.argv)