Bio.Graphics.BasicChromosome module

Draw representations of organism chromosomes with added information.

These classes are meant to model the drawing of pictures of chromosomes. This can be useful for lots of things, including displaying markers on a chromosome (ie. for genetic mapping) and showing syteny between two chromosomes.

The structure of these classes is intended to be a Composite, so that it will be easy to plug in and switch different parts without breaking the general drawing capabilities of the system. The relationship between classes is that everything derives from _ChromosomeComponent, which specifies the overall interface. The parts then are related so that an Organism contains Chromosomes, and these Chromosomes contain ChromosomeSegments. This representation differents from the canonical composite structure in that we don’t really have ‘leaf’ nodes here – all components can potentially hold sub-components.

Most of the time the ChromosomeSegment class is what you’ll want to customize for specific drawing tasks.

For providing drawing capabilities, these classes use reportlab:

This provides nice output in PDF, SVG and postscript. If you have reportlab’s renderPM module installed you can also use PNG etc.

class Bio.Graphics.BasicChromosome.Organism(output_format='pdf')

Bases: Bio.Graphics.BasicChromosome._ChromosomeComponent

Top level class for drawing chromosomes.

This class holds information about an organism and all of it’s chromosomes, and provides the top level object which could be used for drawing a chromosome representation of an organism.

Chromosomes should be added and removed from the Organism via the add and remove functions.

__init__(self, output_format='pdf')


draw(self, output_file, title)

Draw out the information for the Organism.

  • output_file – The name of a file specifying where the document should be saved, or a handle to be written to. The output format is set when creating the Organism object. Alternatively, output_file=None will return the drawing using the low-level ReportLab objects (for further processing, such as adding additional graphics, before writing).

  • title – The output title of the produced document.

class Bio.Graphics.BasicChromosome.Chromosome(chromosome_name)

Bases: Bio.Graphics.BasicChromosome._ChromosomeComponent

Class for drawing a chromosome of an organism.

This organizes the drawing of a single organisms chromosome. This class can be instantiated directly, but the draw method makes the most sense to be called in the context of an organism.

__init__(self, chromosome_name)

Initialize a Chromosome for drawing.

  • chromosome_name - The label for the chromosome.

  • start_x_position, end_x_position - The x positions on the page where the chromosome should be drawn. This allows multiple chromosomes to be drawn on a single page.

  • start_y_position, end_y_position - The y positions on the page where the chromosome should be contained.

Configuration Attributes:
  • title_size - The size of the chromosome title.

  • scale_num - A number of scale the drawing by. This is useful if you want to draw multiple chromosomes of different sizes at the same scale. If this is not set, then the chromosome drawing will be scaled by the number of segements in the chromosome (so each chromosome will be the exact same final size).


Return the scaled size of all subcomponents of this component.

draw(self, cur_drawing)

Draw a chromosome on the specified template.

Ideally, the x_position and y_*_position attributes should be set prior to drawing – otherwise we’re going to have some problems.

class Bio.Graphics.BasicChromosome.ChromosomeSegment

Bases: Bio.Graphics.BasicChromosome._ChromosomeComponent

Draw a segment of a chromosome.

This class provides the important configurable functionality of drawing a Chromosome. Each segment has some customization available here, or can be subclassed to define additional functionality. Most of the interesting drawing stuff is likely to happen at the ChromosomeSegment level.


Initialize a ChromosomeSegment.

  • start_x_position, end_x_position - Defines the x range we have to draw things in.

  • start_y_position, end_y_position - Defines the y range we have to draw things in.

Configuration Attributes:
  • scale - A scaling value for the component. By default this is set at 1 (ie – has the same scale as everything else). Higher values give more size to the component, smaller values give less.

  • fill_color - A color to fill in the segment with. Colors are available in reportlab.lib.colors

  • label - A label to place on the chromosome segment. This should be a text string specifying what is to be included in the label.

  • label_size - The size of the label.

  • chr_percent - The percentage of area that the chromosome segment takes up.

draw(self, cur_drawing)

Draw a chromosome segment.

Before drawing, the range we are drawing in needs to be set.

class Bio.Graphics.BasicChromosome.AnnotatedChromosomeSegment(bp_length, features, default_feature_color=Color(0, 0, 1, 1), name_qualifiers='gene', 'label', 'name', 'locus_tag', 'product')

Bases: Bio.Graphics.BasicChromosome.ChromosomeSegment

Annotated chromosome segment.

This is like the ChromosomeSegment, but accepts a list of features.

__init__(self, bp_length, features, default_feature_color=Color(0, 0, 1, 1), name_qualifiers='gene', 'label', 'name', 'locus_tag', 'product')


The features can either be SeqFeature objects, or tuples of values: start (int), end (int), strand (+1, -1, O or None), label (string), ReportLab color (string or object), and optional ReportLab fill color.

Note we require 0 <= start <= end <= bp_length, and within the vertical space allocated to this segmenet lines will be places according to the start/end coordinates (starting from the top).

Positive stand features are drawn on the right, negative on the left, otherwise all the way across.

We recommend using consisent units for all the segment’s scale values (e.g. their length in base pairs).

When providing features as SeqFeature objects, the default color is used, unless the feature’s qualifiers include an Artemis colour string (functionality also in GenomeDiagram). The caption also follows the GenomeDiagram approach and takes the first qualifier from the list or tuple specified in name_qualifiers.

Note additional attribute label_sep_percent controls the percentage of area that the chromosome segment takes up, by default half of the chr_percent attribute (half of 25%, thus 12.5%)

class Bio.Graphics.BasicChromosome.TelomereSegment(inverted=0)

Bases: Bio.Graphics.BasicChromosome.ChromosomeSegment

A segment that is located at the end of a linear chromosome.

This is just like a regular segment, but it draws the end of a chromosome which is represented by a half circle. This just overrides the _draw_segment class of ChromosomeSegment to provide that specialized drawing.

__init__(self, inverted=0)

Initialize a segment at the end of a chromosome.

See ChromosomeSegment for all of the attributes that can be customized in a TelomereSegments.

  • inverted – Whether or not the telomere should be inverted (ie. drawn on the bottom of a chromosome)

class Bio.Graphics.BasicChromosome.SpacerSegment

Bases: Bio.Graphics.BasicChromosome.ChromosomeSegment

A segment that is located at the end of a linear chromosome.

Doesn’t draw anything, just empty space which can be helpful for layout purposes (e.g. making room for feature labels).

draw(self, cur_diagram)

Draw nothing to the current diagram (dummy method).

The segment spacer has no actual image in the diagram, so this method therefore does nothing, but is defined to match the expected API of the other segment objects.