Back to index

python-biopython  1.60
Namespaces | Functions
Bio.Graphics Namespace Reference

Namespaces

namespace  BasicChromosome
namespace  Comparative
namespace  DisplayRepresentation
namespace  Distribution
namespace  GenomeDiagram

Functions

def _write

Function Documentation

def Bio.Graphics._write (   drawing,
  output_file,
  format,
  dpi = 72 
) [private]
Helper function to standize output to files (PRIVATE).

Writes the provided drawing out to a file in a prescribed format.

drawing - suitable ReportLab drawing object.
output_file - a handle to write to, or a filename to write to.
format - 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 any case.
dpi - Resolution (dots per inch) for bitmap formats.

No return value.

Definition at line 23 of file __init__.py.

00023 
00024 def _write(drawing, output_file, format, dpi=72):
00025     """Helper function to standize output to files (PRIVATE).
00026 
00027     Writes the provided drawing out to a file in a prescribed format.
00028 
00029     drawing - suitable ReportLab drawing object.
00030     output_file - a handle to write to, or a filename to write to.
00031     format - String indicating output format, one of PS, PDF, SVG,
00032              or provided the ReportLab renderPM module is installed,
00033              one of the bitmap formats JPG, BMP, GIF, PNG, TIFF or TIFF.
00034              The format can be given in any case.
00035     dpi - Resolution (dots per inch) for bitmap formats.
00036 
00037     No return value.
00038     """
00039     from reportlab.graphics import renderPS, renderPDF, renderSVG
00040     try:
00041         from reportlab.graphics import renderPM
00042     except ImportError:
00043         #This is an optional part of ReportLab, so may not be installed.
00044         #We'll raise a missing dependency error if rendering to a
00045         #bitmap format is attempted.
00046         renderPM=None
00047 
00048     formatdict = {'PS': renderPS, 'EPS': renderPS,
00049                   # not sure which you actually get, PS or EPS, but
00050                   # GenomeDiagram used PS while other modules used EPS.
00051                   'PDF': renderPDF,
00052                   'SVG': renderSVG,
00053                   'JPG': renderPM,
00054                   'BMP': renderPM,
00055                   'GIF': renderPM,
00056                   'PNG': renderPM,
00057                   'TIFF': renderPM,
00058                   'TIF': renderPM
00059                  }
00060     try:
00061         #If output is not a string, then .upper() will trigger
00062         #an attribute error...
00063         drawmethod = formatdict[format.upper()] # select drawing method
00064     except (KeyError,AttributeError):
00065         raise ValueError("Output format should be one of %s" \
00066                          % ", ".join(formatdict))
00067 
00068     if drawmethod is None:
00069         #i.e. We wanted renderPM but it isn't installed
00070         #See the import at the top of the function.
00071         from Bio import MissingPythonDependencyError
00072         raise MissingPythonDependencyError(
00073             "Please install ReportLab's renderPM module")
00074 
00075     if drawmethod == renderPM:
00076         #This has a different API to the other render objects
00077         return drawmethod.drawToFile(drawing, output_file,
00078                                      format, dpi=dpi)
00079     else:
00080         return drawmethod.drawToFile(drawing, output_file)

Here is the caller graph for this function: