File: _CrossLink.py

package info (click to toggle)
python-biopython 1.68%2Bdfsg-3~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 46,856 kB
  • sloc: python: 160,306; xml: 93,216; ansic: 9,118; sql: 1,208; makefile: 155; sh: 63
file content (96 lines) | stat: -rw-r--r-- 3,184 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Copyright 2011 by Peter Cock.  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.
################################################################################

"""Genome Diagram Feature cross-link module
"""

from reportlab.lib import colors


class CrossLink(object):
    """Hold information for drawing a cross link between features.
    """
    def __init__(self, featureA, featureB,
                 color=colors.lightgreen, border=None, flip=False):
        """Create a new cross link.

        Arguments featureA and featureB should GenomeDiagram feature objects,
        or 3-tuples (track object, start, end), and currently must be on
        different tracks.

        The color and border arguments should be ReportLab colour objects, or
        for border use a boolean False for no border, otherwise it defaults to
        the same as the main colour.

        The flip argument draws an inverted cross link, useful for showing a
        mapping where one sequence has been reversed. It is conventional to
        also use a different colour (e.g. red for simple links, blue for any
        flipped links).
        """
        # Initialise attributes
        self.featureA = featureA
        self.featureB = featureB
        self.color = color            # default color to draw the feature
        self.border = border
        self.flip = flip

    @property
    def startA(self):
        try:
            return self.featureA.start
        except AttributeError:
            track, start, end = self.featureA
            return start

    @property
    def endA(self):
        try:
            return self.featureA.end
        except AttributeError:
            track, start, end = self.featureA
            return end

    def _trackA(self, tracks):
        try:
            track, start, end = self.featureA
            assert track in tracks
            return track
        except Exception:  # TODO: ValueError?
            for track in tracks:
                for feature_set in track.get_sets():
                    if hasattr(feature_set, "features"):
                        if self.featureA in feature_set.features.values():
                            return track
            return None

    @property
    def startB(self):
        try:
            return self.featureB.start
        except AttributeError:
            track, start, end = self.featureB
            return start

    @property
    def endB(self):
        try:
            return self.featureB.end
        except AttributeError:
            track, start, end = self.featureB
            return end

    def _trackB(self, tracks):
        try:
            track, start, end = self.featureB
            assert track in tracks
            return track
        except:
            for track in tracks:
                for feature_set in track.get_sets():
                    if hasattr(feature_set, "features"):
                        if self.featureB in feature_set.features.values():
                            return track
            return None