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