Using pygr-draw with 'group'-style annotations

First, import the necessary components, load the genome/FASTA database in, and pick a sequence:

>>> from pygr import seqdb
>>> genome = seqdb.BlastDB('example.fa')
>>> sequence_name = 'chrI'

Now, import pygr_draw and the AnnotationGroup class:

>>> import pygr_draw
>>> from pygr_draw import AnnotationGroup

Instantiate the sequence picture class; in this case, use a BitmapSequencePicture to produce a PNG. You can also use PDFSequencePicture to create PDFs, with otherwise identical code.

>>> picture_class = pygr_draw.BitmapSequencePicture
>>> colors = picture_class.colors

Build a more complex set of "group" annotations, like those for genes with multiple exons:

>>> annotations2 = {}
>>> annotations2['gene1'] = AnnotationGroup('gene1', sequence_name,
...                                        ((50, 100),
...                                         (200, 300),
...                                         (3500, 4200)),
...                                        color=colors.red)
>>> annotations2['gene2'] = AnnotationGroup('gene2', sequence_name,
...                                        ((200, 422),
...                                          (1502, 1646),
...                                         (3000, 3712)),
...                                        color=colors.blue)

Convert the annotations into an NLMSA annotations map:

>>> annotations_map = pygr_draw.create_annotation_map(annotations2, genome)

Draw:

>>> p = pygr_draw.draw_annotation_maps(genome[sequence_name],
...                                    (annotations_map,),
...                                    picture_class=picture_class)

Save image:

>>> image = p.finalize()
>>> open('group-example.png', 'w').write(image)
group-example.png