[gt-users] Using the AnnotationSketch module: output formats and default styles

Sascha Steinbiss steinbiss at zbh.uni-hamburg.de
Thu Apr 23 16:00:28 CEST 2009


James Casbon wrote:
> Hi,

Hi James,

> I have a couple of problems using AnnotationSketch, which I'm sure are
> easily solved.

Let's see what I can do.

> Firstly, how can you get a canvas object to output to a given format?
> For example, your example testdata/gtpython/sketch_simple.py will
> output PNG and testdata/gtpython/graphics_stuff.py will output SVG.
> But sketch_simple never creates the graphics object so you can't seem
> to tell it to use SVG as in the graphics_stuff example.

The answer is simple: The Python bindings are still not complete.
Currently, in the Python bindings the output format for the 
CanvasCairoFile (which is used in the sketch*.py scripts) is hard-coded 
to PNG. However, it should be straightforward to subclass the 
CanvasCairoFile class to produce CanvasCairoFile{PDF,PNG,PS,SVG} classes 
  for all output file formats supported by the Cairo drawing backend.
For an example, see the attached new version of 
gtpython/gt/annotationsketch/canvas.py.

Using these classes, you can also do the following:

   ...
   diagram = Diagram.from_index(feature_index, seqid, range, style)
   layout = Layout(diagram, 700, style)
   height = layout.get_height()
   canvas = CanvasCairoFilePNG(style, 700, height)
   layout.sketch(canvas)
   canvas.to_file(pngfile)
   canvas = CanvasCairoFilePDF(style, 700, height)
   layout.sketch(canvas)
   canvas.to_file(pdffile)
   ...

Any ideas about how to degrade gracefully in user code still 
instantiating CanvasCairoFile classes?

> Secondly, shouldn't style return default values when no value is
> present.  At the moment, you continually need to say:
> 
> bar_height = style.get_num('my element', 'bar_height') or
> style.get_num('format', 'bar_height')
> 
> (I'm guessing here format returns the default by looking at the examples)

During the layout process on the C side, for all parameters given in the 
format section of the example style file, the one in the format section 
is taken if no per-type value is present. However, this is not coded in 
the style class itself, but in the layout logic. The behaviour of 
returning None if no value is found is intentional because it leaves the 
decision about how to handle this case to the programmer. Of course, you 
are free to subclass the Style class and add a thin layer in your code, 
implementing the behaviour stated above.

> Thanks,
> James

Best regards,
Sascha

-- 
Sascha Steinbiss
Center for Bioinformatics
University of Hamburg
Bundesstr. 43
20146 Hamburg
Germany

Email:  steinbiss at zbh.uni-hamburg.de
URL:    http://www.zbh.uni-hamburg.de/steinbiss
Phone:  +49 (40) 42838 7322
FAX:    +49 (40) 42838 7312

-------------- next part --------------
A non-text attachment was scrubbed...
Name: canvas.py
Type: text/x-python
Size: 3708 bytes
Desc: not available
Url : http://genometools.org/pipermail/gt-users/attachments/20090423/f89a1fda/attachment.py 


More information about the gt-users mailing list