Mercurial > repos > yating-l > ucsc_trix_index_generator
comparison extractHeaders.py @ 0:3de4fbd488a1 draft default tip
planemo upload commit 81955d80a45c04ad4874f19f43c36ca608b3735e
author | yating-l |
---|---|
date | Wed, 16 May 2018 17:33:35 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3de4fbd488a1 |
---|---|
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) |