-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeFasta1line.py
executable file
·58 lines (43 loc) · 1.08 KB
/
makeFasta1line.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
55
56
57
58
#!/usr/bin/python3
author__ = "Sunandan Mukherjee"
email__ = "[email protected]"
'''
Name
====
makeFasta1line.py
Description
===========
Convert multiline fasta format to one line fasta.
E.g
>sample protein
ADFPPALLFPPGNSLFKKALWALCITRH
KLLADDESCPAM
to
>sample protein
ADFPPALLFPPGNSLFKKALWALCITRHKLLADDESCPAM
Dependencies
============
python version 3.0 or above
'''
import sys
def make1line(in_name, out_name):
with open(in_name) as f_input, open(out_name, 'w') as f_output:
block = []
for line in f_input:
if line.startswith('>'):
if block:
f_output.write(''.join(block) + '\n')
block = []
f_output.write(line)
else:
block.append(line.strip())
if block:
f_output.write(''.join(block) + '\n')
f_input.close()
f_output.close()
def main():
infile = sys.argv[1]
outfile = sys.argv[2]
make1line(infile, outfile)
if __name__ == "__main__":
main()