-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastaSeqLinearizer.py
34 lines (28 loc) · 1.04 KB
/
FastaSeqLinearizer.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
#!/usr/bin/python3
#This is a script to linerarize multi-line FASTA sequences. It will change the format into one-line header with one-line sequences below
#Input: Any FASTA.
#Output: FASTA with one-line header and one-line sequences below
#Version: Y.H.S, 2020-05-21
import sys
def FastaSeqLinearizer():
fi=open(sys.argv[1],'r')
fo=open(sys.argv[2],'w')
Seq=""
lines=fi.readlines()
for line in lines:
if line[0] == '>':
fo.writelines(Seq)
if Seq!="": fo.writelines("\n")
fo.writelines(line)
Seq=""
else:
Seq=Seq+line.strip()
if line is lines[-1]:
fo.writelines(Seq+"\n")
fi.close()
fo.close()
if len(sys.argv) != 3:
print("This is a script to linerarize multi-line FASTA sequences. It will output one-line header with one-line sequence below")
print("Usage: [FastaSeqLinearizer.py] [Fasta Input] [Fasta Output]")
else:
FastaSeqLinearizer()