Back to index

python-biopython  1.60
Classes | Functions
Bio.SwissProt.KeyWList Namespace Reference

Classes

class  Record

Functions

def parse

Function Documentation

def Bio.SwissProt.KeyWList.parse (   handle)

Definition at line 47 of file KeyWList.py.

00047 
00048 def parse(handle):
00049     record = Record()
00050     # First, skip the header - look for start of a record
00051     for line in handle:
00052         if line.startswith("ID   "):
00053             # Looks like there was no header
00054             record["ID"] = line[5:].strip()
00055             break
00056         if line.startswith("IC   "):
00057             # Looks like there was no header
00058             record["IC"] = line[5:].strip()
00059             break
00060     # Now parse the records
00061     for line in handle:
00062         if line.startswith("-------------------------------------"):
00063             # We have reached the footer
00064             break
00065         key = line[:2]
00066         if key=="//":
00067             record["DE"] = " ".join(record["DE"])
00068             record["SY"] = " ".join(record["SY"])
00069             yield record
00070             record = Record()
00071         elif line[2:5]=="   ":
00072             value = line[5:].strip()
00073             if key in ("ID", "IC", "AC", "CA"):
00074                 record[key] = value
00075             elif key in ("DE", "SY", "GO", "HI", "WW"):
00076                 record[key].append(value)
00077             else:
00078                 print "Ignoring: %s" % line.strip()
00079     # Read the footer and throw it away
00080     for line in handle:
00081         pass