Package Bio :: Package SwissProt :: Module KeyWList
[hide private]
[frames] | no frames]

Source Code for Module Bio.SwissProt.KeyWList

 1  # Copyright 1999 by Jeffrey Chang.  All rights reserved. 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 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   
21   
22 -class Record(dict):
23 """ 24 This record stores the information of one keyword or category in the 25 keywlist.txt as a Python dictionary. The keys in this dictionary are 26 the line codes that can appear in the keywlist.txt file: 27 28 --------- --------------------------- ---------------------- 29 Line code Content Occurrence in an entry 30 --------- --------------------------- ---------------------- 31 ID Identifier (keyword) Once; starts a keyword entry 32 IC Identifier (category) Once; starts a category entry 33 AC Accession (KW-xxxx) Once 34 DE Definition Once or more 35 SY Synonyms Optional; once or more 36 GO Gene ontology (GO) mapping Optional; once or more 37 HI Hierarchy Optional; once or more 38 WW Relevant WWW site Optional; once or more 39 CA Category Once per keyword entry; absent 40 in category entries 41 """
42 - def __init__(self):
43 dict.__init__(self) 44 for keyword in ("DE", "SY", "GO", "HI", "WW"): 45 self[keyword] = []
46
47 -def parse(handle):
48 # First, skip the header 49 for line in handle: 50 if line.startswith("______________________________________"): 51 break 52 # Now parse the records 53 record = Record() 54 for line in handle: 55 if line.startswith("-------------------------------------"): 56 # We have reached the footer 57 break 58 key = line[:2] 59 if key=="//": 60 record["DE"] = " ".join(record["DE"]) 61 record["SY"] = " ".join(record["SY"]) 62 yield record 63 record = Record() 64 else: 65 value = line[5:].strip() 66 if key in ("ID", "IC", "AC", "CA"): 67 record[key] = value 68 elif key in ("DE", "SY", "GO", "HI", "WW"): 69 record[key].append(value) 70 # Read the footer and throw it away 71 for line in handle: 72 pass
73