Back to index

python-biopython  1.60
_CrossLink.py
Go to the documentation of this file.
00001 # Copyright 2011 by Peter Cock.  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 
00007 """Genome Diagram Feature cross-link module
00008 """
00009 
00010 from reportlab.lib import colors
00011 
00012 class CrossLink(object):
00013     """Hold information for drawing a cross link between features.
00014     """
00015     def __init__(self, featureA, featureB,
00016                  color=colors.lightgreen, border=None, flip=False):
00017         """Create a new cross link.
00018         
00019         Arguments featureA and featureB should GenomeDiagram feature objects,
00020         or 3-tuples (track object, start, end), and currently must be on
00021         different tracks.
00022         
00023         The color and border arguments should be ReportLab colour objects, or
00024         for border use a boolean False for no border, otherwise it defaults to
00025         the same as the main colour.
00026         
00027         The flip argument draws an inverted cross link, useful for showing a
00028         mapping where one sequence has been reversed. It is conventional to
00029         also use a different colour (e.g. red for simple links, blue for any
00030         flipped links).
00031         """
00032         # Initialise attributes
00033         self.featureA = featureA
00034         self.featureB = featureB
00035         self.color = color            # default color to draw the feature
00036         self.border = border
00037         self.flip = flip
00038 
00039     @property
00040     def startA(self):
00041         try:
00042             return self.featureA.start
00043         except AttributeError:
00044             track, start, end = self.featureA
00045             return start
00046 
00047     @property
00048     def endA(self):
00049         try:
00050             return self.featureA.end
00051         except AttributeError:
00052             track, start, end = self.featureA
00053             return end
00054     
00055     def _trackA(self, tracks):
00056         try:
00057             track, start, end = self.featureA
00058             assert track in tracks
00059             return track
00060         except:
00061             for track in tracks:
00062                 for feature_set in track.get_sets():
00063                     if hasattr(feature_set, "features"):
00064                         if self.featureA in feature_set.features.values():
00065                             return track
00066             return None
00067 
00068     @property
00069     def startB(self):
00070         try:
00071             return self.featureB.start
00072         except AttributeError:
00073             track, start, end = self.featureB
00074             return start
00075 
00076     @property
00077     def endB(self):
00078         try:
00079             return self.featureB.end
00080         except AttributeError:
00081             track, start, end = self.featureB
00082             return end
00083     
00084     def _trackB(self, tracks):
00085         try:
00086             track, start, end = self.featureB
00087             assert track in tracks
00088             return track
00089         except:
00090             for track in tracks:
00091                 for feature_set in track.get_sets():
00092                     if hasattr(feature_set, "features"):
00093                         if self.featureB in feature_set.features.values():
00094                             return track
00095             return None