Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.Graphics.GenomeDiagram._Diagram.Diagram Class Reference

List of all members.

Public Member Functions

def __init__
def set_all_tracks
def draw
def write
def write_to_string
def add_track
def new_track
def del_track
def get_tracks
def move_track
def renumber_tracks
def get_levels
def get_drawn_levels
def range
def __getitem__
def __str__

Public Attributes

 tracks
 name
 format
 pagesize
 orientation
 x
 y
 xl
 xr
 yt
 yb
 start
 end
 tracklines
 fragments
 fragment_size
 track_size
 circular
 circle_core
 cross_track_links
 drawing

Detailed Description

Diagram

    Provides:

    Attributes:

    o name         String, identifier for the diagram

    o tracks       List of Track objects comprising the diagram 

    o format       String, format of the diagram (circular/linear)

    o pagesize     String, the pagesize of output

    o orientation  String, the page orientation (landscape/portrait)

    o x            Float, the proportion of the page to take up with even 
                          X margins

    o y            Float, the proportion of the page to take up with even 
                          Y margins

    o xl           Float, the proportion of the page to take up with the 
                          left X margin

    o xr           Float, the proportion of the page to take up with the 
                          right X margin

    o yt           Float, the proportion of the page to take up with the 
                          top Y margin

    o yb           Float, the proportion of the page to take up with the 
                          bottom Y margin

    o circle_core  Float, the proportion of the available radius to leave
                   empty at the center of a circular diagram (0 to 1).

    o start        Int, the base/aa position to start the diagram at

    o end          Int, the base/aa position to end the diagram at

    o tracklines   Boolean, True if track guidelines are to be drawn

    o fragments    Int, for a linear diagram, the number of equal divisions
                            into which the sequence is divided

    o fragment_size Float, the proportion of the space available to each 
                               fragment that should be used in drawing

    o track_size   Float, the proportion of the space available to each 
                              track that should be used in drawing

    o circular     Boolean, True if the genome/sequence to be drawn is, in 
                            reality, circular.  

    Methods:

    o __init__(self, name=None) Called on instantiation

    o draw(self, format='circular', ...) Instructs the package to draw
        the diagram

    o write(self, filename='test1.ps', output='PS') Writes the drawn
        diagram to a specified file, in a specified format.

    o add_track(self, track, track_level) Adds a Track object to the
        diagram, with instructions to place it at a particular level on
        the diagram

    o del_track(self, track_level) Removes the track that is to be drawn
        at a particular level on the diagram

    o get_tracks(self) Returns the list of Track objects to be drawn
        contained in the diagram

    o renumber_tracks(self, low=1) Renumbers all tracks consecutively,
        optionally from a passed lowest number

    o get_levels(self) Returns a list of levels currently occupied by
        Track objects

    o get_drawn_levels(self) Returns a list of levels currently occupied
        by Track objects that will be shown in the drawn diagram (i.e.
        are not hidden)

    o range(self) Returns the lowest- and highest-numbered positions
        contained within features in all tracks on the diagram as a tuple.

    o __getitem__(self, key) Returns the track contained at the level of
        the passed key

    o __str__(self) Returns a formatted string describing the diagram

Definition at line 56 of file _Diagram.py.


Constructor & Destructor Documentation

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.__init__ (   self,
  name = None,
  format = 'circular',
  pagesize = 'A3',
  orientation = 'landscape',
  x = 0.05,
  y = 0.05,
  xl = None,
  xr = None,
  yt = None,
  yb = None,
  start = None,
  end = None,
  tracklines = False,
  fragments = 10,
  fragment_size = 0.9,
  track_size = 0.75,
  circular = True,
  circle_core = 0.0 
)
__init__(self, name=None)

    o name  String describing the diagram

    o format    String: 'circular' or 'linear', depending on the sort of
        diagram required

    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, for linear diagrams, the number of sections into
        which to break the sequence being drawn

    o fragment_size     Float (0->1), for linear diagrams, describing 
                the proportion of space in a fragment to take
                up with tracks

    o track_size        Float (0->1) describing the proportion of space
                in a track to take up with sigils

    o circular  Boolean flag to indicate whether the sequence being
        drawn is circular

Definition at line 155 of file _Diagram.py.

00155 
00156          track_size=0.75, circular=True, circle_core=0.0):
00157         """ __init__(self, name=None)
00158 
00159             o name  String describing the diagram
00160 
00161             o format    String: 'circular' or 'linear', depending on the sort of
00162                         diagram required
00163 
00164             o pagesize  String describing the ISO size of the image, or a tuple
00165                         of pixels
00166 
00167             o orientation   String describing the required orientation of the
00168                             final drawing ('landscape' or 'portrait')
00169 
00170             o x         Float (0->1) describing the relative size of the X
00171                         margins to the page
00172 
00173             o y         Float (0->1) describing the relative size of the Y
00174                         margins to the page
00175 
00176             o xl        Float (0->1) describing the relative size of the left X
00177                         margin to the page (overrides x)
00178 
00179             o xl        Float (0->1) describing the relative size of the left X
00180                         margin to the page (overrides x)
00181 
00182             o xr        Float (0->1) describing the relative size of the right X
00183                         margin to the page (overrides x)
00184 
00185             o yt        Float (0->1) describing the relative size of the top Y
00186                         margin to the page (overrides y)
00187 
00188             o yb        Float (0->1) describing the relative size of the lower Y
00189                         margin to the page (overrides y)
00190 
00191             o start     Int, the position to begin drawing the diagram at
00192 
00193 
00194             o end       Int, the position to stop drawing the diagram at
00195 
00196             o tracklines    Boolean flag to show (or not) lines delineating 
00197                         tracks on the diagram
00198 
00199             o fragments Int, for linear diagrams, the number of sections into
00200                         which to break the sequence being drawn
00201 
00202             o fragment_size     Float (0->1), for linear diagrams, describing 
00203                                 the proportion of space in a fragment to take
00204                                 up with tracks
00205 
00206             o track_size        Float (0->1) describing the proportion of space
00207                                 in a track to take up with sigils
00208 
00209             o circular  Boolean flag to indicate whether the sequence being
00210                         drawn is circular
00211                         
00212 
00213         """
00214         self.tracks = {}   # Holds all Track objects, keyed by level
00215         self.name = name    # Description of the diagram
00216         # Diagram page setup attributes
00217         self.format = format
00218         self.pagesize = pagesize
00219         self.orientation = orientation
00220         self.x = x
00221         self.y = y
00222         self.xl = xl
00223         self.xr = xr
00224         self.yt = yt
00225         self.yb = yb
00226         self.start = start
00227         self.end = end
00228         self.tracklines = tracklines
00229         self.fragments = fragments
00230         self.fragment_size = fragment_size
00231         self.track_size = track_size
00232         self.circular = circular
00233         self.circle_core = circle_core
00234         self.cross_track_links = []

Here is the caller graph for this function:


Member Function Documentation

__getitem__(self, key) -> Track

    o key       The id of a track in the diagram

    Return the Track object with the passed id

Definition at line 468 of file _Diagram.py.

00468 
00469     def __getitem__(self, key):
00470         """ __getitem__(self, key) -> Track
00471 
00472             o key       The id of a track in the diagram
00473 
00474             Return the Track object with the passed id
00475         """
00476         return self.tracks[key]

Here is the caller graph for this function:

__str__(self) -> ""

    Returns a formatted string with information about the diagram

Definition at line 477 of file _Diagram.py.

00477 
00478     def __str__(self):
00479         """ __str__(self) -> ""
00480 
00481             Returns a formatted string with information about the diagram
00482         """
00483         outstr = ["\n<%s: %s>" % (self.__class__, self.name)]
00484         outstr.append("%d tracks" % len(self.tracks))
00485         for level in self.get_levels():
00486             outstr.append("Track %d: %s\n" % (level, self.tracks[level]))
00487         outstr = '\n'.join(outstr)
00488         return outstr       
00489 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.add_track (   self,
  track,
  track_level 
)
add_track(self, track, track_level)

    o track         Track object to draw

    o track_level   Int, the level at which the track will be drawn
            (above an arbitrary baseline)

    Add a pre-existing Track to the diagram at a given level

Definition at line 328 of file _Diagram.py.

00328 
00329     def add_track(self, track, track_level):
00330         """ add_track(self, track, track_level)
00331 
00332             o track         Track object to draw
00333 
00334             o track_level   Int, the level at which the track will be drawn
00335                             (above an arbitrary baseline)
00336 
00337             Add a pre-existing Track to the diagram at a given level
00338         """
00339         if track is None:
00340             raise ValueError("Must specify track")
00341         if track_level not in self.tracks:     # No track at that level
00342             self.tracks[track_level] = track   # so just add it
00343         else:       # Already a track there, so shunt all higher tracks up one
00344             occupied_levels = self.get_levels() # Get list of occupied levels...
00345             occupied_levels.sort()              # ...sort it...
00346             occupied_levels.reverse()           # ...reverse it (highest first)
00347             for val in occupied_levels:
00348                 # If track value >= that to be added
00349                 if val >= track.track_level:
00350                     self.tracks[val+1] = self.tracks[val] # ...increment by 1
00351             self.tracks[track_level] = track   # And put the new track in
00352         self.tracks[track_level].track_level = track_level
00353                 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.del_track (   self,
  track_level 
)
del_track(self, track_level)

    o track_level   Int, the level of the track on the diagram to delete

    Remove the track at the passed level from the diagram

Definition at line 380 of file _Diagram.py.

00380 
00381     def del_track(self, track_level):
00382         """ del_track(self, track_level)
00383 
00384             o track_level   Int, the level of the track on the diagram to delete
00385 
00386             Remove the track at the passed level from the diagram
00387         """
00388         del self.tracks[track_level]
00389 

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.draw (   self,
  format = None,
  pagesize = None,
  orientation = None,
  x = None,
  y = None,
  xl = None,
  xr = None,
  yt = None,
  yb = None,
  start = None,
  end = None,
  tracklines = None,
  fragments = None,
  fragment_size = None,
  track_size = None,
  circular = None,
  circle_core = None,
  cross_track_links = None 
)
Draw the diagram, with passed parameters overriding existing attributes.

Definition at line 254 of file _Diagram.py.

00254 
00255              circle_core=None, cross_track_links=None):
00256         """Draw the diagram, with passed parameters overriding existing attributes.
00257         """
00258         # Pass the parameters to the drawer objects that will build the 
00259         # diagrams.  At the moment, we detect overrides with an or in the 
00260         # Instantiation arguments, but I suspect there's a neater way to do 
00261         # this.
00262         if format == 'linear':
00263             drawer = LinearDrawer(self, pagesize or self.pagesize, 
00264                                   orientation or self.orientation, 
00265                                   x or self.x, y or self.y, xl or self.xl, 
00266                                   xr or self.xr, yt or self.yt, 
00267                                   yb or self.yb, start or self.start, 
00268                                   end or self.end, 
00269                                   tracklines or self.tracklines,
00270                                   fragments or self.fragments, 
00271                                   fragment_size or self.fragment_size, 
00272                                   track_size or self.track_size,
00273                                   cross_track_links or self.cross_track_links)
00274         else:
00275             drawer = CircularDrawer(self, pagesize or self.pagesize, 
00276                                     orientation or self.orientation, 
00277                                     x or self.x, y or self.y, xl or self.xl, 
00278                                     xr or self.xr, yt or self.yt, 
00279                                     yb or self.yb, start or self.start, 
00280                                     end or self.end, 
00281                                     tracklines or self.tracklines,
00282                                     track_size or self.track_size,
00283                                     circular or self.circular,
00284                                     circle_core or self.circle_core,
00285                                     cross_track_links or self.cross_track_links)
00286         drawer.draw()   # Tell the drawer to complete the drawing
00287         self.drawing = drawer.drawing  # Get the completed drawing
        

Here is the caller graph for this function:

get_drawn_levels(self) -> [int, int, ...]

    Return a sorted list of levels occupied by tracks that are not
    explicitly hidden

Definition at line 443 of file _Diagram.py.

00443 
00444     def get_drawn_levels(self):
00445         """ get_drawn_levels(self) -> [int, int, ...]
00446 
00447             Return a sorted list of levels occupied by tracks that are not
00448             explicitly hidden
00449         """
00450         drawn_levels = [key for key in self.tracks.keys() if \
00451                         not self.tracks[key].hide] # get list of shown levels
00452         drawn_levels.sort()
00453         return drawn_levels
00454 

get_levels(self) -> [int, int, ...]

    Return a sorted list of levels occupied by tracks in the diagram

Definition at line 433 of file _Diagram.py.

00433 
00434     def get_levels(self):
00435         """ get_levels(self) -> [int, int, ...]
00436 
00437             Return a sorted list of levels occupied by tracks in the diagram
00438         """
00439         levels = self.tracks.keys()
00440         levels.sort()
00441         return levels
00442 

Here is the caller graph for this function:

get_tracks(self) -> list

    Returns a list of the tracks contained in the diagram

Definition at line 390 of file _Diagram.py.

00390 
00391     def get_tracks(self):
00392         """ get_tracks(self) -> list
00393 
00394             Returns a list of the tracks contained in the diagram
00395         """
00396         return self.tracks.values()
00397 

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.move_track (   self,
  from_level,
  to_level 
)
move_track(self, from_level, to_level)

    o from_level    Int, the level at which the track to be moved is
            found

    o to_level      Int, the level to move the track to

    Moves a track from one level on the diagram to another

Definition at line 398 of file _Diagram.py.

00398 
00399     def move_track(self, from_level, to_level):
00400         """ move_track(self, from_level, to_level)
00401 
00402             o from_level    Int, the level at which the track to be moved is
00403                             found
00404 
00405             o to_level      Int, the level to move the track to
00406 
00407             Moves a track from one level on the diagram to another
00408         """
00409         aux = self.tracks[from_level]
00410         del self.tracks[from_level]
00411         self.add_track(aux, to_level)
00412 

Here is the call graph for this function:

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.new_track (   self,
  track_level,
  args 
)
new_track(self, track_level) -> Track

    o track_level   Int, the level at which the track will be drawn
            (above an arbitrary baseline)

    Add a new Track to the diagram at a given level and returns it for
    further user manipulation.

Definition at line 354 of file _Diagram.py.

00354 
00355     def new_track(self, track_level, **args):
00356         """ new_track(self, track_level) -> Track
00357 
00358             o track_level   Int, the level at which the track will be drawn
00359                             (above an arbitrary baseline)
00360 
00361             Add a new Track to the diagram at a given level and returns it for
00362             further user manipulation.
00363         """
00364         newtrack = Track()
00365         for key in args:
00366             setattr(newtrack, key, args[key])
00367         if track_level not in self.tracks:        # No track at that level
00368             self.tracks[track_level] = newtrack   # so just add it
00369         else:       # Already a track there, so shunt all higher tracks up one
00370             occupied_levels = self.get_levels() # Get list of occupied levels...
00371             occupied_levels.sort()              # ...sort it...
00372             occupied_levels.reverse()           # ...reverse (highest first)...
00373             for val in occupied_levels:     
00374                 if val >= track_level:        # Track value >= that to be added
00375                     self.tracks[val+1] = self.tracks[val] # ..increment by 1
00376             self.tracks[track_level] = newtrack   # And put the new track in
00377         self.tracks[track_level].track_level = track_level
00378         return newtrack
00379 
            

Here is the call graph for this function:

range(self) -> (int, int)

    Returns the lowest and highest base (or mark) numbers containd in
    track features as a tuple

Definition at line 455 of file _Diagram.py.

00455 
00456     def range(self):
00457         """ range(self) -> (int, int)
00458 
00459             Returns the lowest and highest base (or mark) numbers containd in
00460             track features as a tuple
00461         """
00462         lows, highs = [], []
00463         for track in self.tracks.values(): # Get ranges for each track
00464             low, high = track.range()
00465             lows.append(low)
00466             highs.append(high)
00467         return (min(lows), max(highs))      # Return extremes from all tracks

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.renumber_tracks (   self,
  low = 1,
  step = 1 
)
renumber_tracks(self, low=1, step=1)

    o low       Int, the track number to start from

    o step      Int, the track interval for separation of tracks

    Reassigns all the tracks to run consecutively from the lowest
    value (low)

Definition at line 413 of file _Diagram.py.

00413 
00414     def renumber_tracks(self, low=1, step=1):
00415         """ renumber_tracks(self, low=1, step=1)
00416 
00417             o low       Int, the track number to start from
00418 
00419             o step      Int, the track interval for separation of tracks
00420 
00421             Reassigns all the tracks to run consecutively from the lowest
00422             value (low)
00423         """
00424         track = low                 # Start numbering from here
00425         levels = self.get_levels()  # 
00426 
00427         conversion = {}             # Holds new set of levels
00428         for level in levels:        # Starting at low...
00429             conversion[track] = self.tracks[level] # Add old tracks to new set
00430             conversion[track].track_level = track
00431             track += step                           # step interval
00432         self.tracks = conversion   # Replace old set of levels with new set

Here is the call graph for this function:

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.set_all_tracks (   self,
  attr,
  value 
)
set_all_tracks(self, attr, value)

    o attr      An attribute of the Track class

    o value     The value to set that attribute

    Set the passed attribute of all tracks in the set to the
    passed value

Definition at line 235 of file _Diagram.py.

00235 
00236     def set_all_tracks(self, attr, value):
00237         """ set_all_tracks(self, attr, value)
00238 
00239             o attr      An attribute of the Track class
00240 
00241             o value     The value to set that attribute
00242 
00243             Set the passed attribute of all tracks in the set to the
00244             passed value
00245         """
00246         for track in self.tracks.values():
00247             if hasattr(track, attr):          # If the feature has the attribute
00248                 if getattr(track, attr) != value:
00249                     setattr(track, attr, value)   # set it to the passed value     

Here is the call graph for this function:

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.write (   self,
  filename = 'test1.ps',
  output = 'PS',
  dpi = 72 
)
write(self, filename='test1.ps', output='PS', dpi=72)

    o filename      String indicating the name of the output file,
            or a handle to write to.

    o output        String indicating output format, one of PS, PDF,
            SVG, or provided the ReportLab renderPM module is
            installed, one of the bitmap formats JPG, BMP,
            GIF, PNG, TIFF or TIFF.  The format can be given
            in upper or lower case.

    o dpi           Resolution (dots per inch) for bitmap formats.

    Write the completed drawing out to a file in a prescribed format

    No return value.

Definition at line 288 of file _Diagram.py.

00288 
00289     def write(self, filename='test1.ps', output='PS', dpi=72):
00290         """ write(self, filename='test1.ps', output='PS', dpi=72)
00291 
00292             o filename      String indicating the name of the output file,
00293                             or a handle to write to.
00294 
00295             o output        String indicating output format, one of PS, PDF,
00296                             SVG, or provided the ReportLab renderPM module is
00297                             installed, one of the bitmap formats JPG, BMP,
00298                             GIF, PNG, TIFF or TIFF.  The format can be given
00299                             in upper or lower case.
00300 
00301             o dpi           Resolution (dots per inch) for bitmap formats.
00302 
00303             Write the completed drawing out to a file in a prescribed format
00304 
00305             No return value.
00306         """
00307         return _write(self.drawing, filename, output, dpi=dpi)
        

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Graphics.GenomeDiagram._Diagram.Diagram.write_to_string (   self,
  output = 'PS',
  dpi = 72 
)
write(self, output='PS')

    o output        String indicating output format, one of PS, PDF,
            SVG, JPG, BMP, GIF, PNG, TIFF or TIFF (as
            specified for the write method).

    o dpi           Resolution (dots per inch) for bitmap formats.

    Return the completed drawing as a string in a prescribed format

Definition at line 308 of file _Diagram.py.

00308 
00309     def write_to_string(self, output='PS', dpi=72):
00310         """ write(self, output='PS')
00311 
00312             o output        String indicating output format, one of PS, PDF,
00313                             SVG, JPG, BMP, GIF, PNG, TIFF or TIFF (as
00314                             specified for the write method).
00315 
00316             o dpi           Resolution (dots per inch) for bitmap formats.
00317 
00318             Return the completed drawing as a string in a prescribed format
00319         """
00320         #The ReportLab drawToString method, which this function used to call,
00321         #just uses a cStringIO or StringIO handle with the drawToFile method.
00322         #In order to put all our complicated file format specific code in one
00323         #place we'll just use a StringIO handle here:
00324         from StringIO import StringIO
00325         handle = StringIO()
00326         self.write(handle, output, dpi)
00327         return handle.getvalue()

Here is the call graph for this function:


Member Data Documentation

Definition at line 232 of file _Diagram.py.

Definition at line 231 of file _Diagram.py.

Definition at line 233 of file _Diagram.py.

Definition at line 286 of file _Diagram.py.

Definition at line 226 of file _Diagram.py.

Definition at line 216 of file _Diagram.py.

Definition at line 229 of file _Diagram.py.

Definition at line 228 of file _Diagram.py.

Definition at line 214 of file _Diagram.py.

Definition at line 218 of file _Diagram.py.

Definition at line 217 of file _Diagram.py.

Definition at line 225 of file _Diagram.py.

Definition at line 230 of file _Diagram.py.

Definition at line 227 of file _Diagram.py.

Definition at line 213 of file _Diagram.py.

Definition at line 219 of file _Diagram.py.

Definition at line 221 of file _Diagram.py.

Definition at line 222 of file _Diagram.py.

Definition at line 220 of file _Diagram.py.

Definition at line 224 of file _Diagram.py.

Definition at line 223 of file _Diagram.py.


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