2
__author__ = "Jesse Zaneveld"
3
__copyright__ = "Copyright 2007-2010, The Cogent Project"
4
__credits__ = ["Jesse Zaneveld", "Rob Knight"]
7
__maintainer__ = "Jesse Zaneveld"
8
__email__ = "zaneveld@gmail.com"
12
Parser for kegg .pos files
14
Currently this is quite bare-bones, and primarily useful
15
for associating the species name with the results, which is
16
essential if combining multiple .pos files into a single
20
def parse_pos_file(fname):
21
"""Opens fname, extracts pos fields and prepends filename"""
22
curr_file = open(fname,"U")
23
for line in parse_pos_lines(curr_file,fname):
26
def parse_pos_lines(lines, file_name):
27
"""Parse lines from a KEGG .pos file, yielding tab-
30
file name -- the file name, for deriving the
31
species for the pos file (this is not available within
32
the pos file, but important for mapping to other KEGG
35
species_name = file_name.split('/')[-1].rsplit('.',1)[0]
37
yield species_name + '\t' + line[:-1] + "\n"
39
if __name__ == '__main__':
42
for result_line in parse_pos_file(filename):