Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.Graphics.GenomeDiagram._LinearDrawer.LinearDrawer Class Reference
Inheritance diagram for Bio.Graphics.GenomeDiagram._LinearDrawer.LinearDrawer:
Inheritance graph
[legend]
Collaboration diagram for Bio.Graphics.GenomeDiagram._LinearDrawer.LinearDrawer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def draw
def init_fragments
def set_track_heights
def draw_test_tracks
def draw_track
def draw_tick
def draw_scale
def draw_greytrack
def draw_feature_set
def draw_feature
def draw_feature_location
def draw_cross_link
def get_feature_sigil
def draw_graph_set
def draw_line_graph
def draw_heat_graph
def draw_bar_graph
def canvas_location

Public Attributes

 fragments
 fragment_size
 track_size
 drawing
 drawn_tracks
 current_track_level
 fragment_height
 fragment_bases
 fragment_lines
 fragment_limits
 track_offsets

Detailed Description

LinearDrawer(AbstractDrawer)

    Inherits from:

    o AbstractDrawer

    Provides:

    Methods:

    o __init__(self, ...) Called on instantiation

    o set_page_size(self, pagesize, orientation)    Set the page size to the
                                                passed size and orientation

    o set_margins(self, x, y, xl, xr, yt, yb)   Set the drawable area of the
                                                page

    o set_bounds(self, start, end)  Set the bounds for the elements to be
                                    drawn

    o is_in_bounds(self, value)     Returns a boolean for whether the position
                                    is actually to be drawn

    o __len__(self)     Returns the length of sequence that will be drawn


    o draw(self)    Place the drawing elements on the diagram

    o init_fragments(self)  Calculate information
                            about sequence fragment locations on the drawing

    o set_track_heights(self)   Calculate information about the offset of
                                each track from the fragment base
                                
    o draw_test_tracks(self)    Add lines demarcating each track to the
                                drawing

    o draw_track(self, track)   Return the contents of the passed track as
                                drawing elements

    o draw_scale(self, track)   Return a scale for the passed track as
                                drawing elements

    o draw_tick(self, tickpos, ctr, ticklen, track, draw_label) Return a
                                tick line and possibly a label

    o draw_greytrack(self, track)   Return a grey background and superposed
                                    label for the passed track as drawing
                                    elements

    o draw_feature_set(self, set)   Return the features in the passed set as
                                    drawing elements

    o draw_feature(self, feature)   Return a single feature as drawing
                                    elements

    o get_feature_sigil(self, feature, x0, x1, fragment)    Return a single
                                    feature as its sigil in drawing elements

    o draw_graph_set(self, set)     Return the data in a set of graphs as
                                    drawing elements

    o draw_line_graph(self, graph)  Return the data in a graph as a line
                                    graph in drawing elements

    o draw_heat_graph(self, graph)  Return the data in a graph as a heat
                                    graph in drawing elements

    o draw_bar_graph(self, graph)   Return the data in a graph as a bar
                                    graph in drawing elements

    o canvas_location(self, base)   Return the fragment, and the offset from
                                    the left margin, of a passed position
                                    in the sequence, on the diagram.

    Attributes:

    o tracklines    Boolean for whether to draw lines dilineating tracks

    o pagesize      Tuple describing the size of the page in pixels

    o x0            Float X co-ord for leftmost point of drawable area

    o xlim          Float X co-ord for rightmost point of drawable area

    o y0            Float Y co-ord for lowest point of drawable area

    o ylim          Float Y co-ord for topmost point of drawable area

    o pagewidth     Float pixel width of drawable area

    o pageheight    Float pixel height of drawable area

    o xcenter       Float X co-ord of center of drawable area

    o ycenter       Float Y co-ord of center of drawable area

    o start         Int, base to start drawing from

    o end           Int, base to stop drawing at

    o length        Int, size of sequence to be drawn

    o fragments     Int, number of fragments into which to divide the
                    drawn sequence

    o fragment_size Float (0->1) the proportion of the fragment height to
                    draw in

    o track_size    Float (0->1) the proportion of the track height to
                    draw in

    o drawing       Drawing canvas

    o drawn_tracks  List of ints denoting which tracks are to be drawn

    o current_track_level   Int denoting which track is currently being
                            drawn

    o fragment_height   Float total fragment height in pixels

    o fragment_bases    Int total fragment length in bases

    o fragment_lines    Dictionary of top and bottom y-coords of fragment,
                        keyed by fragment number

    o fragment_limits   Dictionary of start and end bases of each fragment,
                        keyed by fragment number

    o track_offsets     Dictionary of number of pixels that each track top,
                        center and bottom is offset from the base of a
                        fragment, keyed by track
    
    o cross_track_links List of tuples each with four entries (track A,
                        feature A, track B, feature B) to be linked.

Definition at line 41 of file _LinearDrawer.py.


Constructor & Destructor Documentation

def Bio.Graphics.GenomeDiagram._LinearDrawer.LinearDrawer.__init__ (   self,
  parent = None,
  pagesize = 'A3',
  orientation = 'landscape',
  x = 0.05,
  y = 0.05,
  xl = None,
  xr = None,
  yt = None,
  yb = None,
  start = None,
  end = None,
  tracklines = 0,
  fragments = 10,
  fragment_size = 0.9,
  track_size = 0.75,
  cross_track_links = None 
)
__init__(self, parent, pagesize='A3', orientation='landscape',
     x=0.05, y=0.05, xl=None, xr=None, yt=None, yb=None,
     start=None, end=None, tracklines=0, fragments=10,
     fragment_size=0.9, track_size=0.75)

    o parent    Diagram object containing the data that the drawer
        draws

    o pagesize  String describing the ISO size of the image, or a tuple
        of pixels

    o orientation   String describing the required orientation of the
            final drawing ('landscape' or 'portrait')

    o x         Float (0->1) describing the relative size of the X
        margins to the page

    o y         Float (0->1) describing the relative size of the Y
        margins to the page

    o xl        Float (0->1) describing the relative size of the left X
        margin to the page (overrides x)

    o xl        Float (0->1) describing the relative size of the left X
        margin to the page (overrides x)

    o xr        Float (0->1) describing the relative size of the right X
        margin to the page (overrides x)

    o yt        Float (0->1) describing the relative size of the top Y
        margin to the page (overrides y)

    o yb        Float (0->1) describing the relative size of the lower Y
        margin to the page (overrides y)

    o start     Int, the position to begin drawing the diagram at

    o end       Int, the position to stop drawing the diagram at

    o tracklines    Boolean flag to show (or not) lines delineating tracks
            on the diagram            

    o fragments Int, the number of equal fragments into which the
        sequence should be divided for drawing

    o fragment_size Float(0->1) The proportion of the available height
            for the fragment that should be taken up in drawing
            
    o track_size    The proportion of the available track height that
            should be taken up in drawing

    o cross_track_links List of tuples each with four entries (track A,
                feature A, track B, feature B) to be linked.

Definition at line 183 of file _LinearDrawer.py.

00183 
00184                  fragment_size=0.9, track_size=0.75, cross_track_links=None):
00185         """ __init__(self, parent, pagesize='A3', orientation='landscape',
00186                      x=0.05, y=0.05, xl=None, xr=None, yt=None, yb=None,
00187                      start=None, end=None, tracklines=0, fragments=10,
00188                      fragment_size=0.9, track_size=0.75)
00189 
00190             o parent    Diagram object containing the data that the drawer
00191                         draws
00192 
00193             o pagesize  String describing the ISO size of the image, or a tuple
00194                         of pixels
00195 
00196             o orientation   String describing the required orientation of the
00197                             final drawing ('landscape' or 'portrait')
00198 
00199             o x         Float (0->1) describing the relative size of the X
00200                         margins to the page
00201 
00202             o y         Float (0->1) describing the relative size of the Y
00203                         margins to the page
00204 
00205             o xl        Float (0->1) describing the relative size of the left X
00206                         margin to the page (overrides x)
00207 
00208             o xl        Float (0->1) describing the relative size of the left X
00209                         margin to the page (overrides x)
00210 
00211             o xr        Float (0->1) describing the relative size of the right X
00212                         margin to the page (overrides x)
00213 
00214             o yt        Float (0->1) describing the relative size of the top Y
00215                         margin to the page (overrides y)
00216 
00217             o yb        Float (0->1) describing the relative size of the lower Y
00218                         margin to the page (overrides y)
00219 
00220             o start     Int, the position to begin drawing the diagram at
00221 
00222             o end       Int, the position to stop drawing the diagram at
00223 
00224             o tracklines    Boolean flag to show (or not) lines delineating tracks
00225                             on the diagram            
00226 
00227             o fragments Int, the number of equal fragments into which the
00228                         sequence should be divided for drawing
00229 
00230             o fragment_size Float(0->1) The proportion of the available height
00231                             for the fragment that should be taken up in drawing
00232                             
00233             o track_size    The proportion of the available track height that
00234                             should be taken up in drawing
00235 
00236             o cross_track_links List of tuples each with four entries (track A,
00237                                 feature A, track B, feature B) to be linked.
00238         """
00239         # Use the superclass' instantiation method
00240         AbstractDrawer.__init__(self, parent, pagesize, orientation,
00241                                   x, y, xl, xr, yt, yb, start, end,
00242                                   tracklines, cross_track_links)
00243 
00244         # Useful measurements on the page
00245         self.fragments = fragments
00246         self.fragment_size = fragment_size
00247         self.track_size = track_size
00248 

Here is the caller graph for this function:


Member Function Documentation

canvas_location(self, base) -> (int, float)

    o base      The base number on the genome sequence

    Returns the x-coordinate and fragment number of a base on the
    genome sequence, in the context of the current drawing setup

Definition at line 1331 of file _LinearDrawer.py.

01331 
01332     def canvas_location(self, base):
01333         """ canvas_location(self, base) -> (int, float)
01334 
01335             o base      The base number on the genome sequence
01336 
01337             Returns the x-coordinate and fragment number of a base on the
01338             genome sequence, in the context of the current drawing setup
01339         """
01340         base = int(base - self.start)   # number of bases we are from the start
01341         fragment = int(base / self.fragment_bases)
01342         if fragment < 1:    # First fragment
01343             base_offset = base
01344             fragment = 0
01345         elif fragment >= self.fragments:
01346             fragment = self.fragments-1
01347             base_offset = self.fragment_bases
01348         else:               # Calculate number of bases from start of fragment
01349             base_offset = base % self.fragment_bases
01350         assert fragment < self.fragments, (base, self.start, self.end, self.length, self.fragment_bases)
01351         # Calculate number of pixels from start of fragment
01352         x_offset = 1. * self.pagewidth * base_offset / self.fragment_bases
01353         return fragment, x_offset
01354         

Here is the call graph for this function:

Here is the caller graph for this function:

draw(self)

    Draw a linear diagram of the data in the parent Diagram object

Definition at line 249 of file _LinearDrawer.py.

00249 
00250     def draw(self):
00251         """ draw(self)
00252 
00253             Draw a linear diagram of the data in the parent Diagram object
00254         """
00255         # Instantiate the drawing canvas
00256         self.drawing = Drawing(self.pagesize[0], self.pagesize[1])
00257 
00258         feature_elements = []           # holds feature elements
00259         feature_labels = []             # holds feature labels
00260         greytrack_bgs = []              # holds track background
00261         greytrack_labels = []           # holds track foreground labels
00262         scale_axes = []                 # holds scale axes
00263         scale_labels = []               # holds scale axis labels
00264 
00265         # Get the tracks to be drawn
00266         self.drawn_tracks = self._parent.get_drawn_levels()
00267 
00268         # Set fragment and track sizes
00269         self.init_fragments()
00270         self.set_track_heights()
00271 
00272         # Go through each track in the parent (if it is to be drawn) one by
00273         # one and collate the data as drawing elements
00274         for track_level in self.drawn_tracks: # only use tracks to be drawn
00275             self.current_track_level = track_level      # establish track level
00276             track = self._parent[track_level]           # get the track at that level
00277             gbgs, glabels = self.draw_greytrack(track)  # get greytrack elements
00278             greytrack_bgs.append(gbgs)
00279             greytrack_labels.append(glabels)
00280             features, flabels = self.draw_track(track)  # get feature and graph elements
00281             feature_elements.append(features)
00282             feature_labels.append(flabels)
00283             if track.scale:
00284                 axes, slabels = self.draw_scale(track)      # get scale elements
00285                 scale_axes.append(axes)
00286                 scale_labels.append(slabels)
00287 
00288         feature_cross_links = []
00289         for cross_link_obj in self.cross_track_links:
00290             cross_link_elements = self.draw_cross_link(cross_link_obj)
00291             if cross_link_elements:
00292                 feature_cross_links.append(cross_link_elements)
00293 
00294         # Groups listed in order of addition to page (from back to front)
00295         # Draw track backgrounds
00296         # Draw feature cross track links
00297         # Draw features and graphs
00298         # Draw scale axes
00299         # Draw scale labels
00300         # Draw feature labels
00301         # Draw track labels
00302         element_groups = [greytrack_bgs, feature_cross_links,
00303                           feature_elements, scale_axes,
00304                           scale_labels, feature_labels, greytrack_labels]
00305         for element_group in element_groups:
00306             for element_list in element_group:
00307                 [self.drawing.add(element) for element in element_list]
00308             
00309         if self.tracklines:             # Draw test tracks over top of diagram
00310             self.draw_test_tracks()
00311 

draw_bar_graph(self, graph) -> [element, element,...]

    o graph     Graph object

    Returns a list of drawable elements for a bar graph of the passed
    Graph object

Definition at line 1243 of file _LinearDrawer.py.

01243 
01244     def draw_bar_graph(self, graph):
01245         """ draw_bar_graph(self, graph) -> [element, element,...]
01246 
01247             o graph     Graph object
01248 
01249             Returns a list of drawable elements for a bar graph of the passed
01250             Graph object
01251         """
01252         #print '\tdraw_bar_graph'
01253         # At each point contained in the graph data, we draw a vertical bar
01254         # from the track center to the height of the datapoint value (positive
01255         # values go up in one color, negative go down in the alternative
01256         # color).
01257         bar_elements = []   # Holds drawable elements for the graph
01258         
01259         # Set the number of pixels per unit for the data
01260         data_quartiles = graph.quartiles()
01261         minval, maxval = data_quartiles[0],data_quartiles[4]
01262         btm, ctr, top = self.track_offsets[self.current_track_level]
01263         trackheight = 0.5*(top-btm)
01264         datarange = maxval - minval
01265         if datarange == 0:
01266             datarange = trackheight
01267         data = graph[self.start:self.end]
01268         # midval is the value at which the x-axis is plotted, and is the
01269         # central ring in the track
01270         if graph.center is None:
01271             midval = (maxval + minval)/2.    
01272         else:
01273             midval = graph.center
01274 
01275         # Convert data into 'binned' blocks, covering half the distance to the
01276         # next data point on either side, accounting for the ends of fragments
01277         # and tracks
01278         start, end = self._current_track_start_end()
01279         data = intermediate_points(start, end, graph[start:end])
01280 
01281         if not data:
01282             return []
01283 
01284         # Whichever is the greatest difference: max-midval or min-midval, is
01285         # taken to specify the number of pixel units resolved along the
01286         # y-axis
01287         resolution = max((midval-minval), (maxval-midval))
01288         if resolution == 0:
01289             resolution = trackheight
01290         
01291         # Create elements for the bar graph based on newdata
01292         for pos0, pos1, val in data:
01293             fragment0, x0 = self.canvas_location(pos0)
01294             fragment1, x1 = self.canvas_location(pos1)
01295             x0, x1 = self.x0 + x0, self.x0 + x1     # account for margin
01296             barval = trackheight*(val-midval)/resolution
01297             if barval >=0:  # Different colors for bars that extend above...
01298                 barcolor = graph.poscolor
01299             else:           # ...or below the axis
01300                 barcolor = graph.negcolor
01301 
01302             # Draw bar
01303             if fragment0 == fragment1:  # Box is contiguous
01304                 if pos1 >= self.fragment_limits[fragment0][1]:
01305                     x1 = self.xlim
01306                 tctr = ctr + self.fragment_lines[fragment0][0]
01307                 barval += tctr                
01308                 bar_elements.append(draw_box((x0, tctr), (x1, barval),
01309                                              color=barcolor))
01310             else:   # Box is split over two or more fragments                       
01311                 fragment = fragment0
01312                 #if pos0 >= self.fragment_limits[fragment0][0]:
01313                 #    fragment += 1         
01314                 start = x0
01315                 while self.fragment_limits[fragment][1] < pos1:
01316                     tctr = ctr + self.fragment_lines[fragment][0]
01317                     thisbarval = barval + tctr
01318                     bar_elements.append(draw_box((start, tctr),
01319                                                  (self.xlim, thisbarval),
01320                                                  color=barcolor))
01321                     fragment += 1
01322                     start = self.x0
01323                 tctr = ctr + self.fragment_lines[fragment1][0]
01324                 barval += tctr
01325                 # Add the last part of the bar
01326                 bar_elements.append(draw_box((self.x0, tctr), (x1, barval),
01327                                              color=barcolor))
01328 
01329         return bar_elements
01330 
      

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 770 of file _LinearDrawer.py.

00770 
00771     def draw_cross_link(self, cross_link):
00772         startA = cross_link.startA
00773         startB = cross_link.startB
00774         endA = cross_link.endA
00775         endB = cross_link.endB
00776            
00777         if not self.is_in_bounds(startA) \
00778         and not self.is_in_bounds(endA):
00779             return None
00780         if not self.is_in_bounds(startB) \
00781         and not self.is_in_bounds(endB):
00782             return None
00783 
00784         if startA < self.start: startA = self.start
00785         if startB < self.start: startB = self.start
00786         if self.end < endA: endA = self.end
00787         if self.end < endB: endB = self.end
00788 
00789         trackobjA = cross_link._trackA(self._parent.tracks.values())
00790         trackobjB = cross_link._trackB(self._parent.tracks.values())
00791         assert trackobjA is not None
00792         assert trackobjB is not None
00793         if trackobjA == trackobjB: raise NotImplementedError()
00794 
00795         if trackobjA.start is not None:
00796             if endA < trackobjA.start:
00797                 return
00798             startA = max(startA, trackobjA.start)
00799         if trackobjA.end is not None:
00800             if trackobjA.end < startA:
00801                 return
00802             endA = min(endA, trackobjA.end)
00803         if trackobjB.start is not None:
00804             if endB < trackobjB.start:
00805                 return
00806             startB = max(startB, trackobjB.start)
00807         if trackobjB.end is not None:
00808             if trackobjB.end < startB:
00809                 return
00810             endB = min(endB, trackobjB.end)
00811 
00812         for track_level in self._parent.get_drawn_levels():
00813             track = self._parent[track_level]
00814             if track == trackobjA:
00815                 trackA = track_level
00816             if track == trackobjB:
00817                 trackB = track_level
00818         if trackA == trackB: raise NotImplementedError()
00819 
00820         if cross_link.color == colors.white and border is None:   # Force black border on 
00821             strokecolor = colors.black                 # white boxes with
00822         elif cross_link.border is None:                           # undefined border, else
00823             strokecolor = cross_link.color                        # use fill color
00824         if cross_link.border:
00825             if not isinstance(cross_link.border, colors.Color):
00826                 raise ValueError("Invalid border color %s" % repr(cross_link.border))
00827             strokecolor = cross_link.border
00828         else:
00829             #e.g. False
00830             strokecolor = None
00831 
00832         allowed_fragments = self.fragment_limits.keys()
00833 
00834         start_fragmentA, start_offsetA = self.canvas_location(startA)
00835         end_fragmentA, end_offsetA = self.canvas_location(endA)
00836         if start_fragmentA not in allowed_fragments \
00837         or end_fragmentA not in allowed_fragments:
00838             return
00839 
00840         start_fragmentB, start_offsetB = self.canvas_location(startB)
00841         end_fragmentB, end_offsetB = self.canvas_location(endB)
00842         if start_fragmentB not in allowed_fragments \
00843         or end_fragmentB not in allowed_fragments:
00844             return
00845 
00846         #TODO - Better drawing of flips when split between fragments
00847 
00848         answer = []
00849         for fragment in range(min(start_fragmentA, start_fragmentB),
00850                               max(end_fragmentA, end_fragmentB)+1):
00851             btmA, ctrA, topA = self.track_offsets[trackA]
00852             btmA += self.fragment_lines[fragment][0]
00853             ctrA += self.fragment_lines[fragment][0]
00854             topA += self.fragment_lines[fragment][0]
00855     
00856             btmB, ctrB, topB = self.track_offsets[trackB]
00857             btmB += self.fragment_lines[fragment][0]
00858             ctrB += self.fragment_lines[fragment][0]
00859             topB += self.fragment_lines[fragment][0]
00860     
00861             if self.fragment_limits[fragment][1] < endA:
00862                 xAe = self.x0 + self.pagewidth
00863                 crop_rightA = True
00864             else:
00865                 xAe = self.x0 + end_offsetA
00866                 crop_rightA = False
00867             if self.fragment_limits[fragment][1] < endB:
00868                 xBe = self.x0 + self.pagewidth
00869                 crop_rightB = True
00870             else:
00871                 xBe = self.x0 + end_offsetB
00872                 crop_rightB = False
00873 
00874             if fragment < start_fragmentA:
00875                 xAs = self.x0 + self.pagewidth
00876                 xAe = xAs
00877                 crop_leftA = False
00878             elif fragment == start_fragmentA:
00879                 xAs = self.x0 + start_offsetA
00880                 crop_leftA = False
00881             else:
00882                 xAs = self.x0
00883                 crop_leftA = True
00884 
00885             if fragment < start_fragmentB:
00886                 xBs = self.x0 + self.pagewidth
00887                 xBe = xBs
00888                 crop_leftB = False
00889             elif fragment == start_fragmentB:
00890                 xBs = self.x0 + start_offsetB
00891                 crop_leftB = False
00892             else:
00893                 xBs = self.x0
00894                 crop_leftB = True
00895 
00896             if ctrA < ctrB:
00897                 yA = topA
00898                 yB = btmB
00899             else:
00900                 yA = btmA
00901                 yB = topB
00902 
00903             if fragment < start_fragmentB or end_fragmentB < fragment:
00904                 if cross_link.flip:
00905                     #Just draw A as a triangle to left/right
00906                     if fragment < start_fragmentB:
00907                         extra = [self.x0 + self.pagewidth, 0.5 * (yA + yB)]
00908                     else:
00909                         extra = [self.x0 , 0.5 * (yA + yB)]
00910                 else:
00911                     if fragment < start_fragmentB:
00912                         extra = [self.x0 + self.pagewidth, 0.7*yA + 0.3*yB,
00913                                  self.x0 + self.pagewidth, 0.3*yA + 0.7*yB]
00914                     else:
00915                         extra = [self.x0 , 0.3*yA + 0.7*yB,
00916                                  self.x0 , 0.7*yA + 0.3*yB]
00917                 answer.append(Polygon([xAs, yA, xAe, yA] + extra,
00918                                strokeColor=strokecolor,
00919                                fillColor=cross_link.color,
00920                                #default is mitre/miter which can stick out too much:
00921                                strokeLineJoin=1, #1=round
00922                                strokewidth=0))
00923             elif fragment < start_fragmentA or end_fragmentA < fragment:
00924                 if cross_link.flip:
00925                     #Just draw B as a triangle to left
00926                     if fragment < start_fragmentA:
00927                         extra = [self.x0 + self.pagewidth, 0.5 * (yA + yB)]
00928                     else:
00929                         extra = [self.x0 , 0.5 * (yA + yB)]
00930                 else:
00931                     if fragment < start_fragmentA:
00932                         extra = [self.x0 + self.pagewidth, 0.3*yA + 0.7*yB,
00933                                  self.x0 + self.pagewidth, 0.7*yA + 0.3*yB]
00934                     else:
00935                         extra = [self.x0 , 0.7*yA + 0.3*yB,
00936                                  self.x0 , 0.3*yA + 0.7*yB]
00937                 answer.append(Polygon([xBs, yB, xBe, yB] + extra,
00938                                strokeColor=strokecolor,
00939                                fillColor=cross_link.color,
00940                                #default is mitre/miter which can stick out too much:
00941                                strokeLineJoin=1, #1=round
00942                                strokewidth=0))
00943             elif cross_link.flip and ((crop_leftA and not crop_rightA) or \
00944                                     (crop_leftB and not crop_rightB)):
00945                 #On left end of fragment... force "crossing" to margin
00946                 answer.append(Polygon([xAs, yA, xAe, yA,
00947                                        self.x0, 0.5 * (yA + yB),
00948                                        xBe, yB, xBs, yB],
00949                                strokeColor=strokecolor,
00950                                fillColor=cross_link.color,
00951                                #default is mitre/miter which can stick out too much:
00952                                strokeLineJoin=1, #1=round
00953                                strokewidth=0))
00954             elif cross_link.flip and ((crop_rightA and not crop_leftA) or \
00955                                       (crop_rightB and not crop_leftB)):
00956                 #On right end... force "crossing" to margin
00957                 answer.append(Polygon([xAs, yA, xAe, yA,
00958                                        xBe, yB, xBs, yB,
00959                                        self.x0 + self.pagewidth, 0.5 * (yA + yB)],
00960                                strokeColor=strokecolor,
00961                                fillColor=cross_link.color,
00962                                #default is mitre/miter which can stick out too much:
00963                                strokeLineJoin=1, #1=round
00964                                strokewidth=0))
00965             elif cross_link.flip:
00966                 answer.append(Polygon([xAs, yA, xAe, yA, xBs, yB, xBe, yB],
00967                                strokeColor=strokecolor,
00968                                fillColor=cross_link.color,
00969                                #default is mitre/miter which can stick out too much:
00970                                strokeLineJoin=1, #1=round
00971                                strokewidth=0))
00972             else:
00973                 answer.append(Polygon([xAs, yA, xAe, yA, xBe, yB, xBs, yB],
00974                                strokeColor=strokecolor,
00975                                fillColor=cross_link.color,
00976                                #default is mitre/miter which can stick out too much:
00977                                strokeLineJoin=1, #1=round
00978                                strokewidth=0))
00979         return answer

Here is the call graph for this function:

draw_feature(self, feature, parent_feature=None) -> ([element, element,...], [element, element,...])

    o feature           Feature containing location info

    Returns tuple of (list of elements describing single feature, list
    of labels for those elements)

Definition at line 688 of file _LinearDrawer.py.

00688 
00689     def draw_feature(self, feature):
00690         """ draw_feature(self, feature, parent_feature=None) -> ([element, element,...], [element, element,...])
00691 
00692             o feature           Feature containing location info
00693 
00694             Returns tuple of (list of elements describing single feature, list
00695             of labels for those elements)
00696         """
00697         if feature.hide:        # Feature hidden, don't draw it...
00698             return [], []
00699         
00700         feature_elements = []   # Holds diagram elements belonging to the feature
00701         label_elements = []     # Holds labels belonging to the feature
00702 
00703         start, end = self._current_track_start_end()
00704         # A single feature may be split into subfeatures, so loop over them
00705         for locstart, locend in feature.locations:
00706             if locend < start:
00707                 continue
00708             locstart = max(locstart, start)
00709             if end < locstart:
00710                 continue
00711             locend = min(locend, end)
00712             feature_boxes = self.draw_feature_location(feature, locstart, locend)
00713             for box, label in feature_boxes:
00714                 feature_elements.append(box)
00715                 if label is not None:
00716                     label_elements.append(label)
00717             
00718         return feature_elements, label_elements

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._LinearDrawer.LinearDrawer.draw_feature_location (   self,
  feature,
  locstart,
  locend 
)

Definition at line 719 of file _LinearDrawer.py.

00719 
00720     def draw_feature_location(self, feature, locstart, locend):
00721         feature_boxes = []
00722         # Get start and end positions for feature/subfeatures
00723         start_fragment, start_offset = self.canvas_location(locstart)
00724         end_fragment, end_offset = self.canvas_location(locend)
00725             #print "start_fragment, start_offset", start_fragment, start_offset
00726             #print "end_fragment, end_offset", end_fragment, end_offset
00727             #print "start, end", locstart, locend
00728 
00729         # Note that there is a strange situation where a feature may be in
00730         # several parts, and one or more of those parts may end up being
00731         # drawn on a non-existent fragment.  So we check that the start and
00732         # end fragments do actually exist in terms of the drawing
00733         allowed_fragments = self.fragment_limits.keys()
00734         if start_fragment in allowed_fragments and end_fragment in allowed_fragments:
00735             
00736             #print feature.name, feature.start, feature.end, start_offset, end_offset
00737             if start_fragment == end_fragment:  # Feature is found on one fragment
00738                 feature_box, label = self.get_feature_sigil(feature, start_offset,
00739                                                             end_offset, start_fragment)
00740                 feature_boxes.append((feature_box, label))
00741                 #feature_elements.append(feature_box)
00742                 #if label is not None:   # There is a label for the feature
00743                 #    label_elements.append(label)                        
00744             else: # Feature is split over two or more fragments
00745                 fragment = start_fragment
00746                 start = start_offset
00747                 # The bit that runs up to the end of the first fragment,
00748                 # and any bits that subsequently span whole fragments
00749                 while self.fragment_limits[fragment][1] < locend:
00750                     #print fragment, self.fragment_limits[fragment][1], locend
00751                     feature_box, label = self.get_feature_sigil(feature, start,
00752                                                                 self.pagewidth,
00753                                                                 fragment)
00754                     
00755                     fragment += 1   # move to next fragment
00756                     start = 0       # start next sigil from start of fragment
00757                     feature_boxes.append((feature_box, label))
00758                     #feature_elements.append(feature_box)
00759                     #if label is not None:   # There's a label for the feature
00760                     #    label_elements.append(label)
00761                 # The last bit of the feature
00762                 #print locend, self.end, fragment
00763                 #print self.fragment_bases, self.length
00764                 feature_box, label = self.get_feature_sigil(feature, 0,
00765                                                             end_offset, fragment)
00766                 feature_boxes.append((feature_box, label))
00767         #if locstart > locend:
00768         #    print locstart, locend, feature.strand, feature_boxes, feature.name
00769         return feature_boxes

Here is the call graph for this function:

Here is the caller graph for this function:

draw_feature_set(self, set) -> ([element, element,...], [element, element,...])

    o set       FeatureSet object

    Returns a tuple (list of elements describing features, list of
    labels for elements)

Definition at line 667 of file _LinearDrawer.py.

00667 
00668     def draw_feature_set(self, set):
00669         """ draw_feature_set(self, set) -> ([element, element,...], [element, element,...])
00670 
00671             o set       FeatureSet object
00672 
00673             Returns a tuple (list of elements describing features, list of
00674             labels for elements)
00675         """
00676         #print 'draw feature set'
00677         feature_elements = []   # Holds diagram elements belonging to the features
00678         label_elements = []     # Holds diagram elements belonging to feature labels 
00679 
00680         # Collect all the elements for the feature set
00681         for feature in set.get_features():
00682             if self.is_in_bounds(feature.start) or self.is_in_bounds(feature.end):
00683                 features, labels = self.draw_feature(feature)   # get elements and labels
00684                 feature_elements += features
00685                 label_elements += labels
00686 
00687         return feature_elements, label_elements

Here is the call graph for this function:

Here is the caller graph for this function:

draw_graph_set(self, set) -> ([element, element,...], [element, element,...])

    o set       GraphSet object

    Returns tuple (list of graph elements, list of graph labels)

Definition at line 1076 of file _LinearDrawer.py.

01076 
01077     def draw_graph_set(self, set):
01078         """ draw_graph_set(self, set) -> ([element, element,...], [element, element,...])
01079 
01080             o set       GraphSet object
01081 
01082             Returns tuple (list of graph elements, list of graph labels)
01083         """
01084         #print 'draw graph set'
01085         elements = []   # Holds graph elements
01086 
01087         # Distribution dictionary for how to draw the graph
01088         style_methods = {'line': self.draw_line_graph,
01089                          'heat': self.draw_heat_graph,
01090                          'bar': self.draw_bar_graph
01091                          }
01092 
01093         for graph in set.get_graphs():
01094             elements += style_methods[graph.style](graph)
01095 
01096         return elements, []
01097 

Here is the call graph for this function:

Here is the caller graph for this function:

draw_greytrack(self) -> ([element, element,...], [element, element,...])

    o track     Track object

    Put in a grey background to the current track in all fragments,
    if track specifies that we should

Definition at line 607 of file _LinearDrawer.py.

00607 
00608     def draw_greytrack(self, track):
00609         """ draw_greytrack(self) -> ([element, element,...], [element, element,...])
00610 
00611             o track     Track object
00612 
00613             Put in a grey background to the current track in all fragments,
00614             if track specifies that we should
00615         """        
00616         greytrack_bgs = []      # Holds grey track backgrounds
00617         greytrack_labels = []   # Holds grey foreground labels
00618 
00619         if not track.greytrack: # No greytrack required, return early
00620             return [], []
00621 
00622         # Get track location
00623         btm, ctr, top = self.track_offsets[self.current_track_level]
00624 
00625         start, end = self._current_track_start_end()
00626         start_fragment, start_offset = self.canvas_location(start)
00627         end_fragment, end_offset = self.canvas_location(end)
00628 
00629         # Add greytrack to all fragments for this track
00630         for fragment in range(start_fragment, end_fragment+1):
00631             tbtm = btm + self.fragment_lines[fragment][0]
00632             tctr = ctr + self.fragment_lines[fragment][0]
00633             ttop = top + self.fragment_lines[fragment][0]
00634             if fragment == start_fragment:
00635                 x1 = self.x0 + start_offset
00636             else:
00637                 x1 = self.x0
00638             if fragment == end_fragment:
00639                 x2 = self.x0 + end_offset
00640             else:
00641                 x2 = self.xlim
00642             box = draw_box((x1, tbtm), (x2, ttop),  # Grey track bg
00643                            colors.Color(0.96,0.96, 0.96))       # is just a box
00644             greytrack_bgs.append(box)
00645 
00646             if track.greytrack_labels:  # If labels are required
00647                 labelstep = (self.pagewidth)/track.greytrack_labels # how far apart should they be?
00648                 label = String(0, 0, track.name,    # label contents
00649                                fontName=track.greytrack_font,
00650                                fontSize=track.greytrack_fontsize,
00651                                fillColor=track.greytrack_fontcolor)
00652                 # Create a new labelgroup at each position the label is required
00653                 for x in range(int(self.x0), int(self.xlim), int(labelstep)):
00654                     if fragment == start_fragment and x < start_offset:
00655                         continue
00656                     if fragment == end_fragment and end_offset < x + label.getBounds()[2]:
00657                         continue
00658                     labelgroup = Group(label)
00659                     rotation = angle2trig(track.greytrack_font_rotation)
00660                     labelgroup.transform = (rotation[0], rotation[1], rotation[2],
00661                                             rotation[3], x, tbtm)
00662                     if not self.xlim-x <= labelstep:    # Don't overlap the end of the track
00663                         greytrack_labels.append(labelgroup)
00664 
00665         return greytrack_bgs, greytrack_labels
00666 

Here is the call graph for this function:

draw_heat_graph(self, graph) -> [element, element,...]

    o graph     Graph object

    Returns a list of drawable elements for the heat graph

Definition at line 1165 of file _LinearDrawer.py.

01165 
01166     def draw_heat_graph(self, graph):
01167         """ draw_heat_graph(self, graph) -> [element, element,...]
01168 
01169             o graph     Graph object
01170 
01171             Returns a list of drawable elements for the heat graph
01172         """
01173         #print '\tdraw_heat_graph'
01174         # At each point contained in the graph data, we draw a box that is the
01175         # full height of the track, extending from the midpoint between the
01176         # previous and current data points to the midpoint between the current
01177         # and next data points
01178         heat_elements = []  # Holds drawable elements for the graph
01179 
01180         # Get graph data and information
01181         data_quartiles = graph.quartiles()
01182         minval, maxval = data_quartiles[0],data_quartiles[4]
01183         midval = (maxval + minval)/2.    # mid is the value at the X-axis
01184         btm, ctr, top = self.track_offsets[self.current_track_level]
01185         trackheight = (top-btm)
01186         
01187         start, end = self._current_track_start_end()
01188         data = intermediate_points(start, end, graph[start:end])
01189 
01190         if not data:
01191             return []
01192 
01193         # Create elements on the graph, indicating a large positive value by
01194         # the graph's poscolor, and a large negative value by the graph's
01195         # negcolor attributes
01196         for pos0, pos1, val in data:
01197             #assert start <= pos0 <= pos1 <= end
01198             fragment0, x0 = self.canvas_location(pos0)
01199             fragment1, x1 = self.canvas_location(pos1)
01200             x0, x1 = self.x0 + x0, self.x0 + x1     # account for margin
01201             #print 'x1 before:', x1
01202             
01203             # Calculate the heat color, based on the differential between
01204             # the value and the median value
01205             heat = colors.linearlyInterpolatedColor(graph.poscolor,
01206                                                     graph.negcolor,
01207                                                     maxval, minval, val)
01208             
01209             # Draw heat box
01210             if fragment0 == fragment1:  # Box is contiguous on one fragment
01211                 if pos1 >= self.fragment_limits[fragment0][1]:
01212                     x1 = self.xlim
01213                 ttop = top + self.fragment_lines[fragment0][0]
01214                 tbtm = btm + self.fragment_lines[fragment0][0]
01215                 #print 'equal', pos0, pos1, val
01216                 #print pos0, pos1, fragment0, fragment1
01217                 heat_elements.append(draw_box((x0, tbtm), (x1, ttop),
01218                                               color=heat, border=None))
01219             else:   # box is split over two or more fragments
01220                 #if pos0 >= self.fragment_limits[fragment0][0]:
01221                 #    fragment0 += 1
01222                 fragment = fragment0
01223                 start_x = x0
01224                 while self.fragment_limits[fragment][1] <= pos1:
01225                     #print pos0, self.fragment_limits[fragment][1], pos1
01226                     ttop = top + self.fragment_lines[fragment][0]
01227                     tbtm = btm + self.fragment_lines[fragment][0]
01228                     heat_elements.append(draw_box((start_x, tbtm),
01229                                                   (self.xlim, ttop),
01230                                                   color=heat,
01231                                                   border=None))
01232                     fragment += 1
01233                     start_x = self.x0
01234                 ttop = top + self.fragment_lines[fragment][0]
01235                 tbtm = btm + self.fragment_lines[fragment][0]
01236                 # Add the last part of the bar
01237                 #print 'x1 after:', x1, '\n'
01238                 heat_elements.append(draw_box((self.x0, tbtm), (x1, ttop),
01239                                               color=heat, border=None))                    
01240 
01241         return heat_elements
01242 

Here is the call graph for this function:

Here is the caller graph for this function:

draw_line_graph(self, graph) -> [element, element,...]

    o graph     Graph object

    Returns a line graph as a list of drawable elements 

Definition at line 1098 of file _LinearDrawer.py.

01098 
01099     def draw_line_graph(self, graph):
01100         """ draw_line_graph(self, graph) -> [element, element,...]
01101 
01102             o graph     Graph object
01103 
01104             Returns a line graph as a list of drawable elements 
01105         """
01106         #print '\tdraw_line_graph'
01107         line_elements = []                  # Holds drawable elements
01108 
01109         # Get graph data
01110         data_quartiles = graph.quartiles()
01111         minval, maxval = data_quartiles[0],data_quartiles[4]
01112         btm, ctr, top = self.track_offsets[self.current_track_level]
01113         trackheight = 0.5*(top-btm)
01114         datarange = maxval - minval
01115         if datarange == 0:
01116             datarange = trackheight
01117         
01118         start, end = self._current_track_start_end()
01119         data = graph[start:end]
01120 
01121         # midval is the value at which the x-axis is plotted, and is the
01122         # central ring in the track
01123         if graph.center is None:
01124             midval = (maxval + minval)/2.    
01125         else:
01126             midval = graph.center
01127         # Whichever is the greatest difference: max-midval or min-midval, is
01128         # taken to specify the number of pixel units resolved along the
01129         # y-axis
01130         resolution = max((midval-minval), (maxval-midval))
01131 
01132         # Start from first data point
01133         pos, val = data[0]
01134         lastfrag, lastx = self.canvas_location(pos)
01135         lastx += self.x0        # Start xy co-ords
01136         lasty = trackheight*(val-midval)/resolution + \
01137                 self.fragment_lines[lastfrag][0] + ctr
01138         lastval = val
01139         # Add a series of lines linking consecutive data points
01140         for pos, val in data:   
01141             frag, x = self.canvas_location(pos)
01142             x += self.x0        # next xy co-ords
01143             y = trackheight*(val-midval)/resolution + \
01144                 self.fragment_lines[frag][0] + ctr
01145             if frag == lastfrag:    # Points on the same fragment: draw the line
01146                 line_elements.append(Line(lastx, lasty, x, y,
01147                                           strokeColor = graph.poscolor,
01148                                           strokeWidth = graph.linewidth))
01149             else:   # Points not on the same fragment, so interpolate
01150                 tempval = 1.*(val-lastval)/(x-lastx)
01151                 tempy = trackheight*(val-midval)/resolution + \
01152                         self.fragment_lines[lastfrag][0] + ctr
01153                 line_elements.append(Line(lastx, lasty, self.xlim, tempy,
01154                                           strokeColor = graph.poscolor,
01155                                           strokeWidth = graph.linewidth))
01156                 tempy = trackheight*(val-midval)/resolution + \
01157                         self.fragment_lines[frag][0] + ctr
01158                 line_elements.append(Line(self.x0, tempy, x, y,
01159                                           strokeColor = graph.poscolor,
01160                                           strokeWidth = graph.linewidth))
01161             lastfrag, lastx, lasty, lastval = frag, x, y, val
01162             
01163         return line_elements
01164 

Here is the call graph for this function:

Here is the caller graph for this function:

draw_scale(self, track) -> ([element, element,...], [element, element,...])

    o track     Track object

    Returns a tuple of (list of elements in the scale, list of labels
    in the scale)

Definition at line 476 of file _LinearDrawer.py.

00476 
00477     def draw_scale(self, track):
00478         """ draw_scale(self, track) -> ([element, element,...], [element, element,...])
00479 
00480             o track     Track object
00481 
00482             Returns a tuple of (list of elements in the scale, list of labels
00483             in the scale)
00484         """
00485         scale_elements = []     # Holds axes and ticks
00486         scale_labels = []       # Holds labels
00487 
00488         if not track.scale:     # No scale required, exit early
00489             return [], []
00490 
00491         # Get track location
00492         btm, ctr, top = self.track_offsets[self.current_track_level]
00493         trackheight = (top-ctr)
00494 
00495         # For each fragment, draw the scale for this track
00496         start, end = self._current_track_start_end()
00497         start_f, start_x = self.canvas_location(start)
00498         end_f, end_x = self.canvas_location(end)
00499 
00500         for fragment in range(start_f, end_f+1):
00501             tbtm = btm + self.fragment_lines[fragment][0]
00502             tctr = ctr + self.fragment_lines[fragment][0]
00503             ttop = top + self.fragment_lines[fragment][0]
00504             # X-axis
00505             if fragment == start_f:
00506                 x_left = start_x
00507             else:
00508                 x_left = 0
00509             if fragment == end_f:
00510                 x_right = end_x
00511                 # Y-axis end marker
00512                 scale_elements.append(Line(self.x0+x_right, tbtm, self.x0+x_right, ttop,
00513                                            strokeColor=track.scale_color))
00514             else:
00515                 x_right = self.xlim - self.x0
00516             scale_elements.append(Line(self.x0+x_left, tctr, self.x0+x_right, tctr,
00517                                    strokeColor=track.scale_color))
00518             # Y-axis start marker
00519             scale_elements.append(Line(self.x0+x_left, tbtm, self.x0+x_left, ttop,
00520                                        strokeColor=track.scale_color))
00521 
00522         start, end = self._current_track_start_end()
00523         if track.scale_ticks:   # Ticks are required on the scale
00524             # Draw large ticks
00525             #I want the ticks to be consistently positioned relative to
00526             #the start of the sequence (position 0), not relative to the
00527             #current viewpoint (self.start and self.end)
00528 
00529             ticklen = track.scale_largeticks * trackheight
00530             tickiterval = int(track.scale_largetick_interval)
00531             #Note that we could just start the list of ticks using
00532             #range(0,self.end,tickinterval) and the filter out the
00533             #ones before self.start - but this seems wasteful.
00534             #Using tickiterval * (self.start//tickiterval) is a shortcut.
00535             for tickpos in range(tickiterval * (self.start//tickiterval),
00536                                  int(self.end), tickiterval):
00537                 if tickpos <= start or end <= tickpos:
00538                     continue
00539                 tick, label = self.draw_tick(tickpos, ctr, ticklen,
00540                                              track,
00541                                              track.scale_largetick_labels)
00542                 scale_elements.append(tick)
00543                 if label is not None:   # If there's a label, add it
00544                     scale_labels.append(label)
00545             # Draw small ticks
00546             ticklen = track.scale_smallticks * trackheight
00547             tickiterval = int(track.scale_smalltick_interval)
00548             for tickpos in range(tickiterval * (self.start//tickiterval),
00549                                  int(self.end), tickiterval):
00550                 if tickpos <= start or end <= tickpos:
00551                     continue
00552                 tick, label = self.draw_tick(tickpos, ctr, ticklen,
00553                                              track,
00554                                              track.scale_smalltick_labels)
00555                 scale_elements.append(tick)
00556                 if label is not None:   # If there's a label, add it
00557                     scale_labels.append(label)
00558 
00559         # Check to see if the track contains a graph - if it does, get the
00560         # minimum and maximum values, and put them on the scale Y-axis
00561         if track.axis_labels:
00562             for set in track.get_sets():            # Check all sets...
00563                 if set.__class__ is GraphSet:     # ...for a graph set
00564                     graph_label_min = []
00565                     graph_label_mid = []                    
00566                     graph_label_max = []
00567                     for graph in set.get_graphs():
00568                         quartiles = graph.quartiles()
00569                         minval, maxval = quartiles[0], quartiles[4]
00570                         if graph.center is None:
00571                             midval = (maxval + minval)/2.
00572                             graph_label_min.append("%.3f" % minval)
00573                             graph_label_max.append("%.3f" % maxval)
00574                         else:
00575                             diff = max((graph.center-minval),
00576                                        (maxval-graph.center))
00577                             minval = graph.center-diff
00578                             maxval = graph.center+diff
00579                             midval = graph.center
00580                             graph_label_mid.append("%.3f" % midval)
00581                             graph_label_min.append("%.3f" % minval)
00582                             graph_label_max.append("%.3f" % maxval)
00583                     for fragment in range(start_f, end_f+1):  # Add to all used fragment axes
00584                         tbtm = btm + self.fragment_lines[fragment][0]
00585                         tctr = ctr + self.fragment_lines[fragment][0]
00586                         ttop = top + self.fragment_lines[fragment][0]
00587                         if fragment == start_f:
00588                             x_left = start_x
00589                         else:
00590                             x_left = 0
00591                         for val, pos in [(";".join(graph_label_min), tbtm),
00592                                          (";".join(graph_label_max), ttop),
00593                                          (";".join(graph_label_mid), tctr)]:
00594                             label = String(0, 0, val,
00595                                            fontName=track.scale_font,
00596                                            fontSize=track.scale_fontsize,
00597                                            fillColor=track.scale_color)
00598                             labelgroup = Group(label)
00599                             rotation = angle2trig(track.scale_fontangle)
00600                             labelgroup.transform = (rotation[0], rotation[1], rotation[2],
00601                                                     rotation[3], self.x0 + x_left, pos)
00602                             scale_labels.append(labelgroup)
00603 
00604         return scale_elements, scale_labels
00605         
00606         

Here is the call graph for this function:

draw_test_tracks(self)

    Draw red lines indicating the top and bottom of each fragment,
    and blue ones indicating tracks to be drawn.

Definition at line 377 of file _LinearDrawer.py.

00377 
00378     def draw_test_tracks(self):
00379         """ draw_test_tracks(self)
00380 
00381             Draw red lines indicating the top and bottom of each fragment,
00382             and blue ones indicating tracks to be drawn.
00383         """
00384         # Add lines for each fragment
00385         for fbtm, ftop in self.fragment_lines.values():
00386             self.drawing.add(Line(self.x0, ftop, self.xlim, ftop,
00387                                   strokeColor=colors.red))  # top line
00388             self.drawing.add(Line(self.x0, fbtm, self.xlim, fbtm,
00389                                   strokeColor=colors.red))  # bottom line
00390 
00391             # Add track lines for this fragment - but only for drawn tracks
00392             for track in self.drawn_tracks:
00393                 trackbtm = fbtm + self.track_offsets[track][0]
00394                 trackctr = fbtm + self.track_offsets[track][1]
00395                 tracktop = fbtm + self.track_offsets[track][2]
00396                 self.drawing.add(Line(self.x0, tracktop, self.xlim, tracktop,
00397                                       strokeColor=colors.blue))  # top line
00398                 self.drawing.add(Line(self.x0, trackctr, self.xlim, trackctr,
00399                                       strokeColor=colors.green))  # center line
00400                 self.drawing.add(Line(self.x0, trackbtm, self.xlim, trackbtm,
00401                                       strokeColor=colors.blue))  # bottom line

def Bio.Graphics.GenomeDiagram._LinearDrawer.LinearDrawer.draw_tick (   self,
  tickpos,
  ctr,
  ticklen,
  track,
  draw_label 
)
draw_tick(self, tickpos, ctr, ticklen) -> (element, element)

    o tickpos   Int, position of the tick on the sequence

    o ctr       Float, Y co-ord of the center of the track

    o ticklen   How long to draw the tick

    o track     Track, the track the tick is drawn on

    o draw_label    Boolean, write the tick label?

    Returns a drawing element that is the tick on the scale

Definition at line 425 of file _LinearDrawer.py.

00425 
00426     def draw_tick(self, tickpos, ctr, ticklen, track, draw_label):
00427         """ draw_tick(self, tickpos, ctr, ticklen) -> (element, element)
00428 
00429             o tickpos   Int, position of the tick on the sequence
00430 
00431             o ctr       Float, Y co-ord of the center of the track
00432 
00433             o ticklen   How long to draw the tick
00434 
00435             o track     Track, the track the tick is drawn on
00436 
00437             o draw_label    Boolean, write the tick label?
00438 
00439             Returns a drawing element that is the tick on the scale
00440         """
00441         assert self.start <= tickpos and tickpos <= self.end, \
00442                "Tick at %i, but showing %i to %i" \
00443                % (tickpos, self.start, self.end)
00444         assert (track.start is None or track.start <= tickpos) and \
00445                (track.end is None or tickpos <= track.end), \
00446                "Tick at %i, but showing %r to %r for track" \
00447                % (tickpos, track.start, track.end)
00448         fragment, tickx = self.canvas_location(tickpos) # Tick co-ordinates
00449         assert fragment >=0, \
00450                "Fragment %i, tickpos %i" % (fragment, tickpos)
00451         tctr = ctr + self.fragment_lines[fragment][0]   # Center line of the track
00452         tickx += self.x0                # Tick X co-ord
00453         ticktop = tctr + ticklen        # Y co-ord of tick top
00454         tick = Line(tickx, tctr, tickx, ticktop, strokeColor=track.scale_color)
00455         if draw_label: # Put tick position on as label
00456             if track.scale_format == 'SInt':
00457                 if tickpos >= 1000000:
00458                     tickstring = str(tickpos//1000000) + " Mbp"
00459                 elif tickpos >= 1000:
00460                     tickstring = str(tickpos//1000) + " Kbp"
00461                 else:
00462                     tickstring = str(tickpos)
00463             else:
00464                 tickstring = str(tickpos)
00465             label = String(0, 0, tickstring,  # Make label string
00466                    fontName=track.scale_font,
00467                    fontSize=track.scale_fontsize,
00468                    fillColor=track.scale_color)
00469             labelgroup = Group(label)
00470             rotation = angle2trig(track.scale_fontangle)
00471             labelgroup.transform = (rotation[0], rotation[1], rotation[2],
00472                                     rotation[3], tickx, ticktop)
00473         else:
00474             labelgroup = None
00475         return tick, labelgroup

Here is the call graph for this function:

Here is the caller graph for this function:

draw_track(self, track) -> ([element, element,...], [element, element,...])

    o track     Track object

    Returns a tuple (list of elements in the track, list of labels in
    the track)

Definition at line 402 of file _LinearDrawer.py.

00402 
00403     def draw_track(self, track):
00404         """ draw_track(self, track) -> ([element, element,...], [element, element,...])
00405 
00406             o track     Track object
00407 
00408             Returns a tuple (list of elements in the track, list of labels in
00409             the track)
00410         """
00411         track_elements = []     # Holds elements from features and graphs
00412         track_labels = []       # Holds labels from features and graphs
00413         
00414         # Distribution dictionary for dealing with different set types
00415         set_methods = {FeatureSet: self.draw_feature_set,
00416                        GraphSet: self.draw_graph_set
00417                        }
00418         
00419         for set in track.get_sets():        # Draw the feature or graph sets
00420             elements, labels = set_methods[set.__class__](set)
00421             track_elements += elements
00422             track_labels += labels
00423         return track_elements, track_labels
00424         

Here is the call graph for this function:

def Bio.Graphics.GenomeDiagram._LinearDrawer.LinearDrawer.get_feature_sigil (   self,
  feature,
  x0,
  x1,
  fragment,
  kwargs 
)
get_feature_sigil(self, feature, x0, x1, fragment) -> (element, element, element)

    o feature       Feature object

    o x0            Start X co-ordinate on diagram

    o x1            End X co-ordinate on diagram

    o fragment      The fragment on which the feature appears

    Returns a drawable indicator of the feature, and any required label
    for it

Definition at line 980 of file _LinearDrawer.py.

00980 
00981     def get_feature_sigil(self, feature, x0, x1, fragment, **kwargs):
00982         """ get_feature_sigil(self, feature, x0, x1, fragment) -> (element, element, element)
00983 
00984             o feature       Feature object
00985 
00986             o x0            Start X co-ordinate on diagram
00987 
00988             o x1            End X co-ordinate on diagram
00989 
00990             o fragment      The fragment on which the feature appears
00991 
00992             Returns a drawable indicator of the feature, and any required label
00993             for it
00994         """
00995         # Establish co-ordinates for drawing
00996         x0, x1 = self.x0 + x0, self.x0 + x1
00997         btm, ctr, top = self.track_offsets[self.current_track_level]
00998         try:
00999             btm += self.fragment_lines[fragment][0]
01000             ctr += self.fragment_lines[fragment][0]
01001             top += self.fragment_lines[fragment][0]
01002         except:     # Only called if the method screws up big time
01003             print "We've got a screw-up"
01004             print self.start, self.end
01005             print self.fragment_bases
01006             print x0, x1
01007             for locstart, locend in feature.locations:
01008                 print self.canvas_location(locstart)
01009                 print self.canvas_location(locend)
01010             print 'FEATURE\n', feature
01011             1/0
01012 
01013         # Distribution dictionary for various ways of drawing the feature
01014         # Each method takes the corners of a containing box and a color
01015         # as argument
01016         draw_methods = {'BOX': draw_box,
01017                         'ARROW': draw_arrow,
01018                         }
01019         method = draw_methods[feature.sigil]
01020         kwargs['head_length_ratio'] = feature.arrowhead_length
01021         kwargs['shaft_height_ratio'] = feature.arrowshaft_height
01022 
01023         #Support for clickable links... needs ReportLab 2.4 or later
01024         #which added support for links in SVG output.
01025         if hasattr(feature, "url") :
01026             kwargs["hrefURL"] = feature.url
01027             kwargs["hrefTitle"] = feature.name
01028 
01029         strand = feature.strand
01030         
01031         # Get sigil for the feature, location dependent on the feature strand
01032         if strand == 1:
01033             sigil = method((x0, ctr), (x1, top), color=feature.color,
01034                            border=feature.border,
01035                            orientation='right', **kwargs)
01036         elif strand == -1:
01037             sigil = method((x1, btm), (x0, ctr), color=feature.color,
01038                            border=feature.border,
01039                            orientation='left', **kwargs)
01040         else:
01041             sigil = method((x0, btm), (x1, top), color=feature.color,
01042                            border=feature.border,
01043                            **kwargs)
01044         if feature.label:   # Feature requires a label
01045             label = String(0, 0, feature.name,
01046                            fontName=feature.label_font,
01047                            fontSize=feature.label_size,
01048                            fillColor=feature.label_color)
01049             labelgroup = Group(label)
01050             # Feature is on top, or covers both strands (location affects
01051             # the height and rotation of the label)
01052             if feature.strand in (0, 1):    
01053                 rotation = angle2trig(feature.label_angle)
01054                 if feature.label_position in ('start', "5'", 'left'):
01055                     pos = x0
01056                 elif feature.label_position in ('middle', 'center', 'centre'):
01057                     pos = (x1 + x0)/2.
01058                 else:
01059                     pos = x1
01060                 labelgroup.transform = (rotation[0], rotation[1], rotation[2],
01061                                         rotation[3], pos, top)
01062             else:   # Feature on bottom strand
01063                 rotation = angle2trig(feature.label_angle + 180)                        
01064                 if feature.label_position in ('start', "5'", 'left'):
01065                     pos = x1
01066                 elif feature.label_position in ('middle', 'center', 'centre'):
01067                     pos = (x1 + x0)/2.
01068                 else:
01069                     pos = x0
01070                 labelgroup.transform = (rotation[0], rotation[1], rotation[2],
01071                                         rotation[3], pos, btm)
01072         else:
01073             labelgroup = None
01074         return sigil, labelgroup
01075 
                

Here is the call graph for this function:

Here is the caller graph for this function:

init_fragments(self)

    Initialises useful values for calculating the positioning of
    diagram elements

Definition at line 312 of file _LinearDrawer.py.

00312 
00313     def init_fragments(self):
00314         """ init_fragments(self)
00315 
00316             Initialises useful values for calculating the positioning of
00317             diagram elements
00318         """
00319         # Set basic heights, lengths etc
00320         self.fragment_height = 1.*self.pageheight/self.fragments     # total fragment height in pixels
00321         self.fragment_bases = ceil(1.*self.length/self.fragments)    # fragment length in bases
00322 
00323         # Key fragment base and top lines by fragment number
00324         self.fragment_lines = {}    # Holds bottom and top line locations of fragments, keyed by fragment number
00325         fragment_crop = (1-self.fragment_size)/2    # No of pixels to crop the fragment
00326         fragy = self.ylim           # Holder for current absolute fragment base
00327         for fragment in range(self.fragments):
00328             fragtop = fragy-fragment_crop * self.fragment_height     # top - crop
00329             fragbtm = fragy-(1-fragment_crop) * self.fragment_height # bottom + crop
00330             self.fragment_lines[fragment] = (fragbtm, fragtop)
00331             fragy -= self.fragment_height                   # next fragment base
00332 
00333         # Key base starts and ends for each fragment by fragment number
00334         self.fragment_limits = {}   # Holds first and last base positions in a fragment
00335         fragment_step = self.fragment_bases  # bases per fragment
00336         fragment_count = 0
00337         # Add start and end positions for each fragment to dictionary
00338         for marker in range(int(self.start), int(self.end), int(fragment_step)):
00339             self.fragment_limits[fragment_count] = (marker, marker+fragment_step)
00340             fragment_count += 1
00341 

set_track_heights(self)

    Since tracks may not be of identical heights, the bottom and top
    offsets of each track relative to the fragment top and bottom is
    stored in a dictionary - self.track_offsets, keyed by track number

Definition at line 342 of file _LinearDrawer.py.

00342 
00343     def set_track_heights(self):
00344         """ set_track_heights(self)
00345 
00346             Since tracks may not be of identical heights, the bottom and top
00347             offsets of each track relative to the fragment top and bottom is
00348             stored in a dictionary - self.track_offsets, keyed by track number
00349         """
00350         bot_track = min(min(self.drawn_tracks), 1)
00351         top_track = max(self.drawn_tracks)     # The 'highest' track number to draw
00352 
00353         trackunit_sum = 0           # Total number of 'units' for the tracks
00354         trackunits = {}             # The start and end units for each track, keyed by track number
00355         heightholder = 0            # placeholder variable
00356         for track in range(bot_track, top_track+1): # for all track numbers to 'draw'
00357             try:
00358                 trackheight = self._parent[track].height    # Get track height
00359             except:
00360                 trackheight = 1                             # ...or default to 1
00361             trackunit_sum += trackheight    # increment total track unit height
00362             trackunits[track] = (heightholder, heightholder+trackheight)
00363             heightholder += trackheight     # move to next height
00364         trackunit_height = 1.*self.fragment_height*self.fragment_size/trackunit_sum
00365 
00366         # Calculate top and bottom offsets for each track, relative to fragment
00367         # base
00368         track_offsets = {}      # The offsets from fragment base for each track
00369         track_crop = trackunit_height*(1-self.track_size)/2.    # 'step back' in pixels
00370         assert track_crop >= 0
00371         for track in trackunits:
00372             top = trackunits[track][1]*trackunit_height - track_crop  # top offset
00373             btm = trackunits[track][0]*trackunit_height + track_crop  # bottom offset
00374             ctr = btm+(top-btm)/2.                          # center offset
00375             track_offsets[track] = (btm, ctr, top)          
00376         self.track_offsets = track_offsets


Member Data Documentation

Definition at line 274 of file _LinearDrawer.py.

Definition at line 255 of file _LinearDrawer.py.

Definition at line 265 of file _LinearDrawer.py.

Definition at line 320 of file _LinearDrawer.py.

Definition at line 319 of file _LinearDrawer.py.

Definition at line 333 of file _LinearDrawer.py.

Definition at line 323 of file _LinearDrawer.py.

Definition at line 245 of file _LinearDrawer.py.

Definition at line 244 of file _LinearDrawer.py.

Definition at line 375 of file _LinearDrawer.py.

Definition at line 246 of file _LinearDrawer.py.


The documentation for this class was generated from the following file: