Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support feature label_position of start/end on circular diagrams

  • Loading branch information...
commit 6b1e57494c32ad208a1c43895ae9805d69985343 1 parent 7b0b9e1
@peterjc peterjc authored
View
18 Bio/Graphics/GenomeDiagram/_CircularDrawer.py
@@ -407,10 +407,26 @@ def get_feature_sigil(self, feature, locstart, locend, **kwargs):
fontSize=feature.label_size,
fillColor=feature.label_color)
labelgroup = Group(label)
- if feature.label_position in ('middle', 'center', 'centre'):
+ if feature.label_position in ('start', "5'", 'left'):
+ # Position the label at the feature's start
+ if feature.strand != -1:
+ label_angle = startangle + 0.5 * pi # Make text radial
+ sinval, cosval = startsin, startcos
+ else:
+ label_angle = endangle + 0.5 * pi # Make text radial
+ sinval, cosval = endsin, endcos
+ elif feature.label_position in ('middle', 'center', 'centre'):
# Position the label at the feature's midpoint
label_angle = midangle + 0.5 * pi # Make text radial
sinval, cosval = midsin, midcos
+ elif feature.label_position in ('end', "3'", 'right'):
+ # Position the label at the feature's end
+ if feature.strand != -1:
+ label_angle = endangle + 0.5 * pi # Make text radial
+ sinval, cosval = endsin, endcos
+ else:
+ label_angle = startangle + 0.5 * pi # Make text radial
+ sinval, cosval = startsin, startcos
elif startangle < pi:
# Default to placing the label the bottom of the feature
# as drawn on the page, meaning feature end on left half
View
6 Bio/Graphics/GenomeDiagram/_Feature.py
@@ -90,7 +90,9 @@ class Feature(object):
feature label in degrees (default = 45, linear only)
o label_position String, 'start', 'end' or 'middle' denoting where
- to place the feature label (linear only)
+ to place the feature label. Leave as None for the default
+ which is 'start' for linear diagrams, and at the bottom of
+ the feature as drawn on circular diagrams.
o locations List of tuples of (start, end) ints describing where the
feature and any subfeatures start and end
@@ -145,7 +147,7 @@ def __init__(self, parent=None, feature_id=None, feature=None,
self.label_size = 6
self.label_color = colors.black
self.label_angle = 45
- self.label_position = 'start'
+ self.label_position = None #Expect 'start', 'middle', or 'end' (plus aliases)
if feature is not None:
self.set_feature(feature)
View
14 Bio/Graphics/GenomeDiagram/_LinearDrawer.py
@@ -1032,22 +1032,24 @@ def get_feature_sigil(self, feature, x0, x1, fragment, **kwargs):
# the height and rotation of the label)
if feature.strand in (0, 1):
rotation = angle2trig(feature.label_angle)
- if feature.label_position in ('start', "5'", 'left'):
- pos = x0
+ if feature.label_position in ('end', "3'", 'right'):
+ pos = x1
elif feature.label_position in ('middle', 'center', 'centre'):
pos = (x1 + x0)/2.
else:
- pos = x1
+ # Default to start, i.e. 'start', "5'", 'left'
+ pos = x0
labelgroup.transform = (rotation[0], rotation[1], rotation[2],
rotation[3], pos, top)
else: # Feature on bottom strand
rotation = angle2trig(feature.label_angle + 180)
- if feature.label_position in ('start', "5'", 'left'):
- pos = x1
+ if feature.label_position in ('end', "3'", 'right'):
+ pos = x0
elif feature.label_position in ('middle', 'center', 'centre'):
pos = (x1 + x0)/2.
else:
- pos = x0
+ # Default to start, i.e. 'start', "5'", 'left'
+ pos = x1
labelgroup.transform = (rotation[0], rotation[1], rotation[2],
rotation[3], pos, btm)
else:
Please sign in to comment.
Something went wrong with that request. Please try again.