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