File: Dom.py

package info (click to toggle)
python-biopython 1.68%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 46,860 kB
  • ctags: 13,237
  • sloc: python: 160,306; xml: 93,216; ansic: 9,118; sql: 1,208; makefile: 155; sh: 63
file content (76 lines) | stat: -rw-r--r-- 2,356 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2000 by Jeffrey Chang.  All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.

# Gavin E. Crooks 2001-11-07:
#     Interface and comments modified to reflect changes to the SCOP
#     module, and to SCOP itself.

""" Handle the SCOP DOMain file.

The DOM file has been officially deprecated. For more information see
the SCOP"release notes.":http://scop.berkeley.edu/release-notes-1.55.html
The DOM files for older releases can be found
"elsewhere at SCOP.":http://scop.mrc-lmb.cam.ac.uk/scop/parse/
"""

from .Residues import Residues


class Record(object):
    """Holds information for one SCOP domain.

    Attribues:

     - sid - The SCOP ID of the entry, e.g. d1anu1
     - residues - The domain definition as a Residues object
     - hierarchy - A string specifying where this domain is in the hierarchy.
    """
    def __init__(self, line=None):
        self.sid = ''
        self.residues = []
        self.hierarchy = ''
        if line:
            self._process(line)

    def _process(self, line):
        """Parses DOM records.

        Records consist of 4 tab deliminated fields;
        sid, pdbid, residues, hierarchy
        """
        # For example ::
        #
        # d1sctg_ 1sct    g:      1.001.001.001.001.001
        # d1scth_ 1sct    h:      1.001.001.001.001.001
        # d1flp__ 1flp    -       1.001.001.001.001.002
        # d1moh__ 1moh    -       1.001.001.001.001.002

        line = line.rstrip()  # no trailing whitespace
        columns = line.split("\t")  # separate the tab-delineated cols
        if len(columns) != 4:
            raise ValueError("I don't understand the format of %s" % line)
        self.sid, pdbid, res, self.hierarchy = columns
        self.residues = Residues(res)
        self.residues.pdbid = pdbid

    def __str__(self):
        s = []
        s.append(self.sid)
        s.append(str(self.residues).replace(" ", "\t"))
        s.append(self.hierarchy)
        return "\t".join(s) + "\n"


def parse(handle):
    """Iterates over a DOM file as a Dom record for each line.

    Arguments:

     - handle -- file-like object.
    """
    for line in handle:
        if line.startswith('#'):
            continue
        yield Record(line)