[BioPython] Generating Figures in Python

Dinu Gherman gherman@darwin.in-berlin.de
Wed, 11 Apr 2001 16:21:33 +0200


Andrew Dalke wrote:
> 
> I've also been playing around with reportlab.  I have
> this idea to use it to generate automated reports from,
> say, a Genbank record, with the graphics added to show
> where the features are.

That would be quite interesting! Please let me know when
someone does that, so we can put at least a prominent link
on our site! Maybe even include a demo into the distribu-
tion (some HUGO data - or Lassa fever? - might be cool! ;-).

> BTW, Dinu Gherman is one of the reportlab developers,
> worked at EMBL, AND is a biopython reader, so I think
> we have inside help with this sort of thing.

Sure!

> What I was having trouble with, btw, was figuring out
> what to do when the sequence became too long for the width
> of a page (assuming you wanted to see letters) or when
> the annotations were too many for the height of a page.
> I could think of many things to do, like use the concept
> of "flowables" in Platypus, but there is little documentation
> on how that works (Dinu pointed out to me at the Python
> conference that my ideas garnered from reading the source
> wasn' correct) and little experience from real life to
> know what people want as a result.

Let me add to this that we're about to deliver a first 
iteration of a graphics/chart package, containing mostly
fairly general charts (bar, pie, line, etc.). This is paid
for by a large customer in the financial industry, but will 
be entirely OpenSource (in fact, it's already in CVS, al-
most finished). If nothing else, it could be a useful 
source for inspiration for other kinds of charts. 

As an aside: there will be soon a bitmap renderer based on
libart, that will add to further platform-independance of
the (e.g. chart) output (although I'm not exactly sure about 
its legal status). And, one day, we also consider SVG...

Concerning charts spanning multiple pages: I see no real
difficulties here! Just make sure the chart is a Flowable
and provides the methods for being split. 

> But I do urge others to give it a try.  As Brad says,
> reportlab is quite powerful and easy to use.

Thanks! We know the docmentation leaves considerable room
for improvement, but my general advice here is: try it and
if it doesn't work ask about it on this list if the docs
are not specific enough:

  reportlab-users@yahoogroups.com

If Andrew did that, he would have noticed there was no
problem at all with his concern (single paragraphs spanning 
multiple pages) as I found out myself during IPC9 simply
be writing a test case (in test_platypus_paragraphs.py in 
reportlab/test ;-) The crucial bit looks like this:

class ParagraphSplitTestCase(unittest.TestCase):
    "Test multi-page splitting of paragraphs (eyeball-test)."
    
    def test1(self):
        "This makes one long multi-page paragraph."

        # Build story.
        story = []
        styleSheet = getSampleStyleSheet()
        bt = styleSheet['BodyText']

        phrase = 'This should be a paragraph spanning at least three
pages. '
        description = phrase * 250
        story.append(Paragraph(description, bt))

        doc = MyDocTemplate('test_paragraphs_splitting.pdf')
        doc.multiBuild0(story)

Have fun,

Dinu

--
Dinu C. Gherman
ReportLab Consultant - http://www.reportlab.com
................................................................
"The only possible values [for quality] are 'excellent' and 'in-
sanely excellent', depending on whether lives are at stake or 
not. Otherwise you don't enjoy your work, you don't work well, 
and the project goes down the drain." 
                    (Kent Beck, "Extreme Programming Explained")