1
2
3
4
5
6 import string
7 """A parser for the NCBI blastpgp version 2.2.5 output format. Currently only supports
8 the '-m 9' option, (table w/ annotations).
9 Returns a BlastTableRec instance
10 """
11
13 - def __init__(self,in_rec):
14 bt_fields = in_rec.split()
15 self.qid = bt_fields[0].split('|')
16 self.sid = bt_fields[1].split('|')
17 self.pid = string.atof(bt_fields[2])
18 self.ali_len = string.atoi(bt_fields[3])
19 self.mis = string.atoi(bt_fields[4])
20 self.gaps = string.atoi(bt_fields[5])
21 self.q_bounds = (string.atoi(bt_fields[6]), string.atoi(bt_fields[7]))
22 self.s_bounds = (string.atoi(bt_fields[8]), string.atoi(bt_fields[9]))
23 self.e_value = string.atof(bt_fields[10])
24 self.bit_score = string.atof(bt_fields[11])
25
28 self.program = None
29 self.version = None
30 self.date = None
31 self.iteration = None
32 self.query = None
33 self.database = None
34 self.entries = []
35 - def add_entry(self, entry):
36 self.entries.append(entry)
37
38 reader_keywords = {'BLASTP': 'version',
39 'Iteration': 'iteration',
40 'Query': 'query',
41 'Database': 'database',
42 'Fields': 'fields'}
54 self.table_record = BlastTableRec()
55 self._n += 1
56 inline = self._lookahead
57 if not inline:
58 return None
59 while inline:
60 if inline[0] == '#':
61 if self._in_header:
62 self._in_header = self._consume_header(inline)
63 else:
64 break
65 else:
66 self._consume_entry(inline)
67 self._in_header = 0
68
69 inline = self.handle.readline()
70 self._lookahead = inline
71 self._in_header = 1
72 return self.table_record
73
74 - def _consume_entry(self, inline):
75 current_entry = BlastTableEntry(inline)
76 self.table_record.add_entry(current_entry)
90 self.table_record.iteration = string.atoi(inline.split()[2])
91 return 1
93 self.table_record.query = inline.split()[2:]
94 return 1
100 - def _Parse(self, method_name, inline):
101 return getattr(self,method_name)(inline)
102