Back to index

python-biopython  1.60
Classes | Functions
Bio.Graphics.GenomeDiagram._AbstractDrawer Namespace Reference

Classes

class  AbstractDrawer
 CLASSES. More...

Functions

def page_sizes
 METHODS.
def draw_box
def draw_polygon
def draw_arrow
def angle2trig
def intermediate_points

Function Documentation

angle2trig(angle)

    o theta     Angle in degrees, counter clockwise from horizontal

    Returns a representation of the passed angle in a format suitable
    for ReportLab rotations (i.e. cos(theta), sin(theta), -sin(theta),
    cos(theta) tuple)

Definition at line 247 of file _AbstractDrawer.py.

00247 
00248 def angle2trig(theta):
00249     """ angle2trig(angle)
00250 
00251         o theta     Angle in degrees, counter clockwise from horizontal
00252 
00253         Returns a representation of the passed angle in a format suitable
00254         for ReportLab rotations (i.e. cos(theta), sin(theta), -sin(theta),
00255         cos(theta) tuple)
00256     """
00257     c = cos(theta * pi / 180)
00258     s = sin(theta * pi / 180)
00259     return(c, s, -s, c)         # Vector for rotating point around an origin
00260 

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._AbstractDrawer.draw_arrow (   point1,
  point2,
  color = colors.lightgreen,
  border = None,
  shaft_height_ratio = 0.4,
  head_length_ratio = 0.5,
  orientation = 'right',
  colour = None,
  kwargs 
)
Returns a closed path object representing an arrow enclosed by the
    box with corners at {point1=(x1,y1), point2=(x2,y2)}, a shaft height
    given by shaft_height_ratio (relative to box height), a head length
    given by head_length_ratio (also relative to box height), and
    an orientation that may be 'left' or 'right'.

Definition at line 174 of file _AbstractDrawer.py.

00174 
00175                colour=None, **kwargs):
00176     """ Returns a closed path object representing an arrow enclosed by the
00177         box with corners at {point1=(x1,y1), point2=(x2,y2)}, a shaft height
00178         given by shaft_height_ratio (relative to box height), a head length
00179         given by head_length_ratio (also relative to box height), and
00180         an orientation that may be 'left' or 'right'.
00181     """
00182     x1, y1 = point1
00183     x2, y2 = point2
00184     
00185     if shaft_height_ratio < 0 or 1 < shaft_height_ratio:
00186         raise ValueError("Arrow shaft height ratio should be in range 0 to 1")
00187     if head_length_ratio < 0:
00188         raise ValueError("Arrow head length ratio should be positive")
00189 
00190     #Let the UK spelling (colour) override the USA spelling (color)
00191     if colour is not None:
00192         color = colour
00193         del colour
00194 
00195     if color == colors.white and border is None:   # Force black border on 
00196         strokecolor = colors.black                 # white boxes with
00197     elif border is None:                           # undefined border, else
00198         strokecolor = color                        # use fill colour
00199     elif border:
00200         strokecolor = border
00201     else:
00202         #e.g. False
00203         strokecolor = None
00204 
00205     # Depending on the orientation, we define the bottom left (x1, y1) and
00206     # top right (x2, y2) coordinates differently, but still draw the box
00207     # using the same relative co-ordinates:
00208     xmin, ymin = min(x1, x2), min(y1, y2)
00209     xmax, ymax = max(x1, x2), max(y1, y2)
00210     if orientation == 'right':
00211         x1, x2, y1, y2 = xmin, xmax, ymin, ymax
00212     elif orientation == 'left':
00213         x1, x2, y1, y2 = xmax, xmin, ymin, ymax
00214     else:
00215         raise ValueError("Invalid orientation %s, should be 'left' or 'right'" \
00216                          % repr(orientation))
00217 
00218     # We define boxheight and boxwidth accordingly, and calculate the shaft
00219     # height from these.  We also ensure that the maximum head length is
00220     # the width of the box enclosure
00221     boxheight = y2-y1
00222     boxwidth = x2-x1
00223     shaftheight = boxheight*shaft_height_ratio
00224     headlength = min(abs(boxheight)*head_length_ratio, abs(boxwidth))
00225     if boxwidth < 0:
00226         headlength *= -1 #reverse it
00227 
00228 
00229     shafttop = 0.5*(boxheight+shaftheight)
00230     shaftbase = boxheight-shafttop
00231     headbase = boxwidth-headlength
00232     midheight = 0.5*boxheight
00233     return Polygon([x1, y1+shafttop,
00234                     x1+headbase, y1+shafttop,
00235                     x1+headbase, y2,
00236                     x2, y1+midheight,
00237                     x1+headbase, y1,
00238                     x1+headbase, y1+shaftbase,
00239                     x1, y1+shaftbase],
00240                    strokeColor=strokecolor,
00241                    #strokeWidth=max(1, int(boxheight/40.)),
00242                    strokeWidth=1,
00243                    #default is mitre/miter which can stick out too much:
00244                    strokeLineJoin=1, #1=round
00245                    fillColor=color,
00246                    **kwargs)

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._AbstractDrawer.draw_box (   point1,
  point2,
  color = colors.lightgreen,
  border = None,
  colour = None,
  kwargs 
)
draw_box(self, (x1, y1), (x2, y2), (x3, y3), (x4, y4),
          color=colors.lightgreen)

    o point1, point2 Co-ordinates for opposite corners of the box
                     (x,y tuples)
    
    o color /colour       The color for the box
                          (colour takes priority over color)
                          
    o border              Border color for the box

    Returns a closed path object, beginning at (x1,y1) going round
    the four points in order, and filling with the passed color.            

Definition at line 86 of file _AbstractDrawer.py.

00086 
00087              **kwargs):
00088     """ draw_box(self, (x1, y1), (x2, y2), (x3, y3), (x4, y4),
00089               color=colors.lightgreen)
00090 
00091         o point1, point2 Co-ordinates for opposite corners of the box
00092                          (x,y tuples)
00093         
00094         o color /colour       The color for the box
00095                               (colour takes priority over color)
00096                               
00097         o border              Border color for the box
00098 
00099         Returns a closed path object, beginning at (x1,y1) going round
00100         the four points in order, and filling with the passed color.            
00101     """
00102     x1, y1 = point1
00103     x2, y2 = point2
00104 
00105     #Let the UK spelling (colour) override the USA spelling (color)
00106     if colour is not None:
00107         color = colour
00108         del colour
00109 
00110     if not isinstance(color, colors.Color):
00111         raise ValueError("Invalid color %s" % repr(color))
00112     
00113     if color == colors.white and border is None:   # Force black border on 
00114         strokecolor = colors.black                 # white boxes with
00115     elif border is None:                           # undefined border, else
00116         strokecolor = color                        # use fill color
00117     elif border:
00118         if not isinstance(border, colors.Color):
00119             raise ValueError("Invalid border color %s" % repr(border))
00120         strokecolor = border
00121     else:
00122         #e.g. False
00123         strokecolor = None
00124 
00125     x1, y1, x2, y2 = min(x1, x2), min(y1, y2), max(x1, x2), max(y1, y2)
00126     return Polygon([x1, y1, x2, y1, x2, y2, x1, y2],
00127                    strokeColor=strokecolor,
00128                    fillColor=color,
00129                    strokewidth=0,
00130                    **kwargs)
00131 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._AbstractDrawer.draw_polygon (   list_of_points,
  color = colors.lightgreen,
  border = None,
  colour = None,
  kwargs 
)
draw_polygon(self, (x1, y1), (x2, y2), (x3, y3), (x4, y4)
          colour=colors.lightgreen)

    o list_of_point = list of (x,y) tuples for the corner coordinates
    
    o colour              The colour for the box

    Returns a closed path object, beginning at (x1,y1) going round
    the four points in order, and filling with the passed colour.          

Definition at line 134 of file _AbstractDrawer.py.

00134 
00135                  **kwargs):
00136     """ draw_polygon(self, (x1, y1), (x2, y2), (x3, y3), (x4, y4)
00137               colour=colors.lightgreen)
00138 
00139         o list_of_point = list of (x,y) tuples for the corner coordinates
00140         
00141         o colour              The colour for the box
00142 
00143         Returns a closed path object, beginning at (x1,y1) going round
00144         the four points in order, and filling with the passed colour.          
00145     """
00146     #Let the UK spelling (colour) override the USA spelling (color)
00147     if colour is not None:
00148         color = colour
00149         del colour
00150 
00151     if color == colors.white and border is None:   # Force black border on 
00152         strokecolor = colors.black                 # white boxes with
00153     elif border is None:                           # undefined border, else
00154         strokecolor = color                        # use fill colour
00155     elif border:
00156         strokecolor = border
00157     else:
00158         #e.g. False
00159         strokecolor = None
00160 
00161     xy_list = []
00162     for (x,y) in list_of_points:
00163         xy_list.append(x)
00164         xy_list.append(y)
00165 
00166     return Polygon(xy_list,
00167                    strokeColor=strokecolor,
00168                    fillColor=color,
00169                    strokewidth=0,
00170                    **kwargs)
00171 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._AbstractDrawer.intermediate_points (   start,
  end,
  graph_data 
)
intermediate_points(start, end, graph_data)

    o graph_data

    o start

    o end

    Returns a list of (start, end, value) tuples describing the passed
    graph data as 'bins' between position midpoints.

Definition at line 261 of file _AbstractDrawer.py.

00261 
00262 def intermediate_points(start, end, graph_data):
00263     """ intermediate_points(start, end, graph_data)
00264 
00265         o graph_data
00266 
00267         o start
00268 
00269         o end
00270 
00271         Returns a list of (start, end, value) tuples describing the passed
00272         graph data as 'bins' between position midpoints.
00273     """
00274     #print start, end, len(graph_data)
00275     newdata = []    # data in form (X0, X1, val)
00276     # add first block
00277     newdata.append((start, graph_data[0][0]+(graph_data[1][0]-graph_data[0][0])/2.,
00278                     graph_data[0][1]))
00279     # add middle set
00280     for index in xrange(1, len(graph_data)-1):
00281         lastxval, lastyval = graph_data[index-1]
00282         xval, yval = graph_data[index]
00283         nextxval, nextyval = graph_data[index+1]
00284         newdata.append( (lastxval+(xval-lastxval)/2.,
00285                          xval+(nextxval-xval)/2., yval) )
00286     # add last block
00287     newdata.append( (xval+(nextxval-xval)/2.,
00288                          end, graph_data[-1][1]) )
00289     #print newdata[-1]
00290     #print newdata
00291     return newdata

Here is the caller graph for this function:

METHODS.

Utility method to translate strings to ISO page sizes

page_sizes(size)

    o size        A string representing a standard page size

    Returns a ReportLab pagesize when passed a valid size string

Definition at line 53 of file _AbstractDrawer.py.

00053 
00054 def page_sizes(size):
00055     """ page_sizes(size)
00056 
00057         o size        A string representing a standard page size
00058 
00059         Returns a ReportLab pagesize when passed a valid size string
00060     """
00061     sizes = {'A0': pagesizes.A0,    # ReportLab pagesizes, keyed by ISO string
00062              'A1': pagesizes.A1,
00063              'A2': pagesizes.A2,
00064              'A3': pagesizes.A3,
00065              'A4': pagesizes.A4,
00066              'A5': pagesizes.A5,
00067              'A6': pagesizes.A6,
00068              'B0': pagesizes.B0,
00069              'B1': pagesizes.B1,
00070              'B2': pagesizes.B2,
00071              'B3': pagesizes.B3,
00072              'B4': pagesizes.B4,
00073              'B5': pagesizes.B5,
00074              'B6': pagesizes.B6,
00075              'ELEVENSEVENTEEN': pagesizes.ELEVENSEVENTEEN,
00076              'LEGAL': pagesizes.LEGAL,
00077              'LETTER': pagesizes.LETTER
00078              }
00079     try:
00080         return sizes[size]
00081     except:
00082         raise ValueError, "%s not in list of page sizes" % size
00083 

Here is the call graph for this function:

Here is the caller graph for this function: