Back to index

python-biopython  1.60
Dom.py
Go to the documentation of this file.
00001 # Copyright 2000 by Jeffrey Chang.  All rights reserved.
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 
00006 # Gavin E. Crooks 2001-11-07:
00007 #     Interface and comments modified to reflect changes to the SCOP
00008 #     module, and to SCOP itself.
00009 
00010 """ Handle the SCOP DOMain file.
00011 
00012 The DOM file has been officially deprecated. For more information see
00013 the SCOP"release notes.":http://scop.berkeley.edu/release-notes-1.55.html 
00014 The DOM files for older releases can be found 
00015 "elsewhere at SCOP.":http://scop.mrc-lmb.cam.ac.uk/scop/parse/
00016 """
00017 
00018 
00019 from Residues import Residues
00020 
00021 class Record(object):
00022     """Holds information for one SCOP domain.
00023 
00024     sid -- The SCOP ID of the entry, e.g. d1anu1
00025 
00026     residues -- The domain definition as a Residues object
00027 
00028     hierarchy -- A string specifying where this domain is in the hierarchy.
00029     """
00030     def __init__(self, line=None):
00031         self.sid = ''
00032         self.residues = []
00033         self.hierarchy = ''
00034         if line:
00035             self._process(line)
00036 
00037     def _process(self, line):
00038         """Parses DOM records.
00039     
00040         Records consist of 4 tab deliminated fields;
00041         sid, pdbid, residues, hierarchy
00042         """
00043         #For example ::
00044         #
00045         #d1sctg_ 1sct    g:      1.001.001.001.001.001
00046         #d1scth_ 1sct    h:      1.001.001.001.001.001
00047         #d1flp__ 1flp    -       1.001.001.001.001.002
00048         #d1moh__ 1moh    -       1.001.001.001.001.002
00049 
00050         line = line.rstrip()  # no trailing whitespace
00051         columns = line.split("\t")  # separate the tab-delineated cols
00052         if len(columns) != 4:
00053             raise ValueError("I don't understand the format of %s" % line)
00054         self.sid, pdbid, res, self.hierarchy = columns
00055         self.residues = Residues(res)
00056         self.residues.pdbid =pdbid
00057 
00058 
00059     def __str__(self):
00060         s = []
00061         s.append(self.sid)
00062         s.append(str(self.residues).replace(" ","\t") )
00063         s.append(self.hierarchy)
00064         return "\t".join(s) + "\n"
00065 
00066 
00067 def parse(handle):
00068     """Iterates over a DOM file, returning a Dom record for each line
00069     in the file.
00070 
00071     Arguments:
00072         
00073         handle -- file-like object.
00074     """ 
00075     for line in handle:
00076         if line.startswith('#'):
00077             continue
00078         yield Record(line)