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 Record Stores the information about one keyword or one category
14 in the keywlist.txt file.
15
16 Functions:
17 parse Parses the keywlist.txt file and returns an iterator to
18 the records it contains.
19
20 DEPRECATED:
21
22 Classes:
23 ListParser Parses a keywlist.txt file into a list of keywords.
24
25 _Scanner Scans the keywlist.txt file.
26 _ListConsumer Consumes keywlist data to a list.
27
28
29 Functions:
30 extract_keywords Return the keywords from a keywlist.txt file.
31
32 """
33
34
36 """
37 This record stores the information of one keyword or category in the
38 keywlist.txt as a Python dictionary. The keys in this dictionary are
39 the line codes that can appear in the keywlist.txt file:
40
41 --------- --------------------------- ----------------------
42 Line code Content Occurrence in an entry
43 --------- --------------------------- ----------------------
44 ID Identifier (keyword) Once; starts a keyword entry
45 IC Identifier (category) Once; starts a category entry
46 AC Accession (KW-xxxx) Once
47 DE Definition Once or more
48 SY Synonyms Optional; once or more
49 GO Gene ontology (GO) mapping Optional; once or more
50 HI Hierarchy Optional; once or more
51 WW Relevant WWW site Optional; once or more
52 CA Category Once per keyword entry; absent
53 in category entries
54 """
59
86
87
88
89
90 from types import *
91
92 from Bio import File
93 from Bio.ParserSupport import *
94
96 """Parses keywlist.txt data into a list of keywords.
97
98 """
100 import warnings
101 warnings.warn("Bio.SwissProt.KeyWList.ListParser is deprecated. Please use the function Bio.SwissProt.KeyWList.parse instead to parse the keywlist.txt file. In case of any problems, please contact the Biopython developers (biopython-dev@biopython.org).",
102 DeprecationWarning)
103 self._scanner = _Scanner()
104 self._consumer = _ListConsumer()
105
106 - def parse(self, handle):
109
110
112 """Scan the keywlist.txt file included with the SwissProt distribution.
113
114 Tested with:
115 Release 37
116 Release 38
117 """
118
120 import warnings
121 warnings.warn("Bio.SwissProt.KeyWList._Scanner is deprecated. Please use the function Bio.SwissProt.KeyWList.parse instead to parse the keywlist.txt file. In case of any problems, please contact the Biopython developers (biopython-dev@biopython.org).",
122 DeprecationWarning)
123
124 - def feed(self, handle, consumer):
125 """feed(self, handle, consumer)
126
127 Feed in the keywlist.txt file for scanning. handle is a file-like
128 object that contains keyword information. consumer is a
129 Consumer object that will receive events as the report is scanned.
130
131 """
132 if isinstance(handle, File.UndoHandle):
133 uhandle = handle
134 else:
135 uhandle = File.UndoHandle(handle)
136
137 self._scan_header(uhandle, consumer)
138 self._scan_keywords(uhandle, consumer)
139 self._scan_footer(uhandle, consumer)
140
142 consumer.start_header()
143
144 read_and_call(uhandle, consumer.noevent, start='----')
145 read_and_call(uhandle, consumer.noevent, blank=1)
146 read_and_call(uhandle, consumer.noevent, contains="SWISS-PROT")
147 read_and_call(uhandle, consumer.noevent, contains="Release")
148 read_and_call(uhandle, consumer.noevent, blank=1)
149 read_and_call(uhandle, consumer.noevent, start='----')
150
151 read_and_call(uhandle, consumer.noevent, blank=1)
152 read_and_call(uhandle, consumer.noevent, start='List of keywords')
153 read_and_call(uhandle, consumer.noevent, blank=1)
154 read_and_call(uhandle, consumer.noevent, start='----')
155
156 while 1:
157 if attempt_read_and_call(uhandle, consumer.noevent, start='----'):
158 break
159 read_and_call(uhandle, consumer.noevent, blank=0)
160
161 read_and_call(uhandle, consumer.noevent, start='Document name')
162 read_and_call(uhandle, consumer.noevent, start='----')
163 read_and_call(uhandle, consumer.noevent, blank=1)
164
165 consumer.end_header()
166
184
195
197 """Consumer that converts a keywlist.txt file into a list of keywords.
198
199 Members:
200 keywords List of keywords.
201
202 """
204 import warnings
205 warnings.warn("Bio.SwissProt.KeyWList._ListConsumer is deprecated. Please use the function Bio.SwissProt.KeyWList.parse instead to parse the keywlist.txt file. In case of any problems, please contact the Biopython developers (biopython-dev@biopython.org).",
206 DeprecationWarning)
207 self.keywords = None
208
211
214
216 """extract_keywords(keywlist_handle) -> list of keywords
217
218 Return the keywords from a keywlist.txt file.
219
220 """
221 import warnings
222 warnings.warn("Bio.SwissProt.KeyWList.extract_keywords is deprecated. Please use the function Bio.SwissProt.KeyWList.parse instead to parse the keywlist.txt file. In case of any problems, please contact the Biopython developers (biopython-dev@biopython.org).",
223 DeprecationWarning)
224 if type(keywlist_handle) is not FileType and \
225 type(keywlist_handle) is not InstanceType:
226 raise ValueError("I expected a file handle or file-like object")
227 return ListParser().parse(keywlist_handle)
228