1
2
3
4
5
6 """
7 This module provides code to work with the keywlist.txt file from
8 SwissProt.
9 http://www.expasy.ch/sprot/sprot-top.html
10
11
12 Classes:
13 ListParser Parses a keywlist.txt file into a list of keywords.
14
15 _Scanner Scans the keywlist.txt file.
16 _ListConsumer Consumes keywlist data to a list.
17
18
19 Functions:
20 extract_keywords Return the keywords from a keywlist.txt file.
21
22 """
23
24 from types import *
25
26 from Bio import File
27 from Bio.ParserSupport import *
28
30 """Parses keywlist.txt data into a list of keywords.
31
32 """
36
40
41
43 """Scan the keywlist.txt file included with the SwissProt distribution.
44
45 Tested with:
46 Release 37
47 Release 38
48 """
49
50 - def feed(self, handle, consumer):
51 """feed(self, handle, consumer)
52
53 Feed in the keywlist.txt file for scanning. handle is a file-like
54 object that contains keyword information. consumer is a
55 Consumer object that will receive events as the report is scanned.
56
57 """
58 if isinstance(handle, File.UndoHandle):
59 uhandle = handle
60 else:
61 uhandle = File.UndoHandle(handle)
62
63 self._scan_header(uhandle, consumer)
64 self._scan_keywords(uhandle, consumer)
65 self._scan_footer(uhandle, consumer)
66
68 consumer.start_header()
69
70 read_and_call(uhandle, consumer.noevent, start='----')
71 read_and_call(uhandle, consumer.noevent, blank=1)
72 read_and_call(uhandle, consumer.noevent, contains="SWISS-PROT")
73 read_and_call(uhandle, consumer.noevent, contains="Release")
74 read_and_call(uhandle, consumer.noevent, blank=1)
75 read_and_call(uhandle, consumer.noevent, start='----')
76
77 read_and_call(uhandle, consumer.noevent, blank=1)
78 read_and_call(uhandle, consumer.noevent, start='List of keywords')
79 read_and_call(uhandle, consumer.noevent, blank=1)
80 read_and_call(uhandle, consumer.noevent, start='----')
81
82 while 1:
83 if attempt_read_and_call(uhandle, consumer.noevent, start='----'):
84 break
85 read_and_call(uhandle, consumer.noevent, blank=0)
86
87 read_and_call(uhandle, consumer.noevent, start='Document name')
88 read_and_call(uhandle, consumer.noevent, start='----')
89 read_and_call(uhandle, consumer.noevent, blank=1)
90
91 consumer.end_header()
92
110
121
123 """Consumer that converts a keywlist.txt file into a list of keywords.
124
125 Members:
126 keywords List of keywords.
127
128 """
131
134
137
139 """extract_keywords(keywlist_handle) -> list of keywords
140
141 Return the keywords from a keywlist.txt file.
142
143 """
144 if type(keywlist_handle) is not FileType and \
145 type(keywlist_handle) is not InstanceType:
146 raise ValueError, "I expected a file handle or file-like object"
147 return ListParser().parse(keywlist_handle)
148