예제 #1
0
def bc_chromosome_draw_label(self, cur_drawing, label_name):
    """Monkeypatch to Bio.Graphics.BasicChromosome.Chromosome._draw_label.

    Draw a label for the chromosome. Mod: above the chromosome, not below.
    """
    # Center on chromosome image
    x_position = 0.5 * (self.start_x_position + self.end_x_position)
    # Place at the bottom of the diagram?
    y_position = self.start_y_position + 0.1 * inch  # was: self.end_y_position
    label_string = BC.String(x_position, y_position, label_name)
    label_string.fontName = 'Times-BoldItalic'
    label_string.fontSize = self.title_size
    label_string.textAnchor = 'middle'
    cur_drawing.add(label_string)
예제 #2
0
def bc_organism_draw(org, title, wrap=12):
    """Modified copy of Bio.Graphics.BasicChromosome.Organism.draw.

    Instead of stacking chromosomes horizontally (along the x-axis), stack rows
    vertically, then proceed with the chromosomes within each row.

    Parameters
    ----------
    org :
        The chromosome diagram object being modified.
    title : str
        The output title of the produced document.
    wrap : int
        Maximum number of chromosomes per row; the remainder will be wrapped to
        the next row(s).
    """
    margin_top = 1.25 * inch
    margin_bottom = 0.1 * inch
    margin_side = 0.5 * inch

    width, height = org.page_size
    cur_drawing = BC.Drawing(width, height)

    # Draw the title text
    title_string = BC.String(width / 2, height - margin_top + .5 * inch, title)
    title_string.fontName = 'Helvetica-Bold'
    title_string.fontSize = org.title_size
    title_string.textAnchor = "middle"
    cur_drawing.add(title_string)

    # Layout subcomponents (individual chromosomes), wrapping into rows
    if len(org._sub_components) > 0:
        nrows = math.ceil(len(org._sub_components) / wrap)
        x_pos_change = (width - 2 * margin_side) / wrap
        y_pos_change = (height - margin_top - margin_bottom) / nrows

    cur_x_pos = margin_side
    cur_row = 0
    for i, sub_component in enumerate(org._sub_components):
        if i % wrap == 0 and i != 0:
            cur_row += 1
            cur_x_pos = margin_side
        # Set the page coordinates of the chromosome drawing
        sub_component.start_x_position = cur_x_pos + 0.05 * x_pos_change
        sub_component.end_x_position = cur_x_pos + 0.95 * x_pos_change
        sub_component.start_y_position = (height - margin_top -
                                          y_pos_change * cur_row)
        sub_component.end_y_position = (margin_bottom + y_pos_change *
                                        (nrows - cur_row - 1))
        # Render the chromosome drawing
        sub_component.draw(cur_drawing)
        # Update the locations for the next chromosome
        cur_x_pos += x_pos_change

    # Draw a legend
    # (Rect coordinates are: left, bottom, width, height)
    # Bounding box -- near-bottom, center
    cur_drawing.add(
        BC.Rect(width / 2 - .8 * inch,
                .5 * inch,
                1.6 * inch,
                .4 * inch,
                fillColor=colors.white))
    # Red box & label -- in left half of bounding box
    cur_drawing.add(
        BC.Rect(width / 2 - .7 * inch,
                .6 * inch,
                .2 * inch,
                .2 * inch,
                fillColor=colors.Color(.8, .2, .2)))
    cur_drawing.add(
        BC.String(width / 2 - .42 * inch,
                  .65 * inch,
                  "Gain",
                  fontName='Helvetica',
                  fontSize=12))
    # Blue box & label -- in right half of bounding box
    cur_drawing.add(
        BC.Rect(width / 2 + .07 * inch,
                .6 * inch,
                .2 * inch,
                .2 * inch,
                fillColor=colors.Color(.2, .2, .8)))
    cur_drawing.add(
        BC.String(width / 2 + .35 * inch,
                  .65 * inch,
                  "Loss",
                  fontName='Helvetica',
                  fontSize=12))

    # Let the caller take care of writing to the file...
    return cur_drawing