0
|
1 #!/usr/bin/python
|
|
2 """ Extract headers from Fasta file and write the headers to a Tabular file """
|
|
3
|
|
4 import sys
|
|
5
|
|
6 def extractHeaders(fasta_file, tab_file):
|
|
7
|
|
8 with open(tab_file, 'w') as out:
|
|
9 with open(fasta_file, 'r') as f:
|
|
10 lines = f.readlines()
|
|
11 for l in lines:
|
|
12 if '>' in l:
|
|
13 l = l.split()
|
|
14 name = l[0].replace('>', '').rstrip()
|
|
15 desc = ''.join(l[1:]).rstrip()
|
|
16 out.write(name + '\t' + desc + '\n')
|
|
17
|
|
18
|
|
19
|
|
20 def main(argv):
|
|
21 input_file = argv[1]
|
|
22 output_file = argv[2]
|
|
23 extractHeaders(input_file, output_file)
|
|
24
|
|
25 if __name__ == "__main__":
|
|
26 main(sys.argv)
|