1
2
3
4
5
6
7 """Bio.Graphics offers several graphical outputs, all using ReportLab."""
8
9
10 try:
11 import reportlab as r
12 del r
13 except ImportError:
14 from Bio import MissingPythonDependencyError
15 raise MissingPythonDependencyError(
16 "Please install ReportLab if you want "
17 "to use Bio.Graphics. You can find ReportLab at "
18 "http://www.reportlab.org/downloads.html")
19
20
21
22
23
24 -def _write(drawing, output_file, format, dpi=72):
25 """Helper function to standardize output to files (PRIVATE).
26
27 Writes the provided drawing out to a file in a prescribed format.
28
29 drawing - suitable ReportLab drawing object.
30 output_file - a handle to write to, or a filename to write to.
31 format - String indicating output format, one of PS, PDF, SVG,
32 or provided the ReportLab renderPM module is installed,
33 one of the bitmap formats JPG, BMP, GIF, PNG, TIFF or TIFF.
34 The format can be given in any case.
35 dpi - Resolution (dots per inch) for bitmap formats.
36
37 No return value.
38 """
39 from reportlab.graphics import renderPS, renderPDF, renderSVG
40 try:
41 from reportlab.graphics import renderPM
42 except ImportError:
43
44
45
46 renderPM=None
47
48 formatdict = {'PS': renderPS, 'EPS': renderPS,
49
50
51 'PDF': renderPDF,
52 'SVG': renderSVG,
53 'JPG': renderPM,
54 'BMP': renderPM,
55 'GIF': renderPM,
56 'PNG': renderPM,
57 'TIFF': renderPM,
58 'TIF': renderPM
59 }
60 try:
61
62
63 drawmethod = formatdict[format.upper()]
64 except (KeyError,AttributeError):
65 raise ValueError("Output format should be one of %s"
66 % ", ".join(formatdict))
67
68 if drawmethod is None:
69
70
71 from Bio import MissingPythonDependencyError
72 raise MissingPythonDependencyError(
73 "Please install ReportLab's renderPM module")
74
75 if drawmethod == renderPM:
76
77 return drawmethod.drawToFile(drawing, output_file,
78 format, dpi=dpi)
79 else:
80 return drawmethod.drawToFile(drawing, output_file)
81