drawing Module

platform:Unix
synopsis:Define a lot of functions necessary to draw the logos.
drawing.draw_axis(output, length, x_coord, y_coord)[source]

Print the svg instructions to draw the axis to the output.

Parameters:
  • output (file) – Stream where to write.
  • length (float) – Number of positions in the logo.
  • x_coord (float) – x-coordinate where to write the axis in the svg.
  • y_coord (float) – y-coordinate where to write the axis in the svg.
drawing.draw_dense_letters(output, probabilities, width, xposition, yposition, step, previous_position_proba, index_letter)[source]

Print the svg instructions to draw the four nucleotides in the dense logo with respect to their probability of appearance at the current position, and return the y-coordinate position for the next box where to draw letters.

Parameters:
  • output (file) – Stream where to write.
  • probabilities (list of tuple (float, str)) – Probabilities of appearance of the four nucleotides. The given probabilities are given for A, C, G, and T in this order.
  • width (float) – Width of box containing the letters to draw.
  • xposition (float) – x-coordinate of the bottom left corner of the box containing the letters to draw.
  • yposition (float) – y-coordinate of the bottom left corner of the box containing the letters to draw.
  • step (float) – Distance between two boxes containing the letters for the same position (it is a dense logo!).
  • previous_position_proba (dict) – Probabilities of getting ACGT at the previous position of the motif.
  • index_letter (int) – Index of the letter in the alphabet from A:0, C:1, G:2, T:3 (i.e. -1<index_letter<4).
Returns:

The y-coordinate for the next box where to draw letters.

Return type:

float

drawing.draw_ellipse(output, x_center, y_center, x_radius, y_radius, colour=(0, 0, 0), opacity=1.0)[source]

Print the svg instructions to draw an ellipse to the output.

Parameters:
  • output (file) – Stream where to write.
  • x_center (float) – x-coordinate of the center of the ellipse.
  • y_center (float) – y-coordinate of the center of the ellipse.
  • x_radius (float) – Radius of the ellipse on the x-axis.
  • y_radius (float) – Radius of the ellipse on the y-ayis.
  • colour (tuple (int, int, int)) – Color of the ellipse (default: black). The colour is given in RGB.
  • opacity (float) – Opacity of the ellipse (default: 1.0)
Note:

Look at the ellipse statement of an svg file for more information.

drawing.draw_frame(output, header_width, header_height, axis_length, axis_width, axis_height)[source]

Print the svg instructions to draw the frame of the logo (i.e. Y- and X-axis).

Parameters:
  • output (file) – Stream where to write.
  • header_width (float) – Width of the svg.
  • header_height (float) – Height of the svg.
  • axis_length (float) – number of positions in the motif.
  • axis_width (float) – Width of the logo x-axis.
  • axis_height (float) – Height of the logo y-axis.
drawing.draw_left_letters(output)[source]

Print the big four nucleotides on the left side of the svg to the output.

Parameters:output (file) – Stream where to write.
drawing.draw_letter_a(output, x_coord, y_coord, width, height, colour=(178, 34, 34), opacity=1.0)[source]

Print the svg instructions to draw the letter ‘A’ to the output.

Parameters:
  • output (file) – Stream where to write.
  • x_coord (float) – x-coordinate of the bottom left corner of the box containing the ‘A’.
  • y_coord (float) – y-coordinate of the bottom left corner ot the box containing the ‘A’.
  • width (float) – Width of the box containing the ‘A’.
  • height (float) – Height of the box containing the ‘A’.
  • colour (tuple (int, int, int)) – Color of the ‘A’ (default: black). The colour is given in RGB.
  • opacity (float) – Opacity of the ‘A’ (default: 1.0)
Note:

The ‘A’ is drawn by creating a red polygon giving the shape and a white internal triangle above to make the bar in the middle of the ‘A’ appear.

drawing.draw_letter_c(output, x_coord, y_coord, width, height, colour=(0, 0, 128), opacity=1.0)[source]

Print the svg instructions to draw the letter ‘C’ to the output.

Parameters:
  • output (file) – Stream where to write.
  • x_coord (float) – x-coordinate of the bottom left corner of the box containing the ‘C’.
  • y_coord (float) – y-coordinate of the bottom left corner ot the box containing the ‘C’.
  • width (float) – Width of the box containing the ‘C’.
  • height (float) – Height of the box containing the ‘C’.
  • colour (tuple (int, int, int)) – Color of the box containing the ‘C’ (default: black). The colour is given in RGB.
  • opacity (float) – Opacity of the box containing the ‘C’ (default: 1.0)
Note:

The ‘C’ is drawn by creating the surrounding ellipse with the right colour and then superposing an smaller white ellipse and a white rectangle on the right side of the ellipe to create the ‘C’.

drawing.draw_letter_g(output, x_coord, y_coord, width, height, colour=(255, 165, 0), opacity=1.0)[source]

Print the svg instructions to draw the letter ‘G’ to the output.

Parameters:
  • output (file) – Stream where to write.
  • x_coord (float) – x-coordinate of the bottom left corner of the box containing the ‘G’.
  • y_coord (float) – y-coordinate of the bottom left corner ot the box containing the ‘G’.
  • width (float) – Width of the box containing the ‘G’.
  • height (float) – Height of the box containing the ‘G’.
  • colour (tuple (int, int, int)) – Color of the box containing the ‘G’ (default: black). The colour is given in RGB.
  • opacity (float) – Opacity of the box containing the ‘G’ (default: 1.0)
Note:

The ‘G’ is drawn by creating a ‘C’ and then adding the two other rectangles.

drawing.draw_letter_t(output, x_coord, y_coord, width, height, colour=(0, 100, 0), opacity=1.0)[source]

Print the svg instructions to draw the letter ‘T’ to the output.

Parameters:
  • output (file) – Stream where to write.
  • x_coord (float) – x-coordinate of the bottom left corner of the box containing the ‘T’.
  • y_coord (float) – y-coordinate of the bottom left corner ot the box containing the ‘T’.
  • width (float) – Width of the box containing the ‘T’.
  • height (float) – Height of the box containing the ‘T’.
  • colour (tuple (int, int, int)) – Color of the box containing the ‘T’ (default: black). The colour is given in RGB.
  • opacity (float) – Opacity of the box containing the ‘T’ (default: 1.0)
Note:

The ‘T’ is drawn by using two rectangles.

Print the svg instructions to draw the logo to the output.

Parameters:
  • output (file) – Stream where to write the svg instruction to draw the logo.
  • tffm (TFFM) – TFFM from which to draw the logo.
  • logo_type (Enum) – Kind of logo to draw (either LOGO_TYPE.SUMMARY or LOGO_TYPE.DENSE)
Todo:

raise an error if the logo type is wrong.

drawing.draw_logo_letters(output, tffm, logo_type, xposition=90.0, width=50.0, step=10.0)[source]

Print the svg instructions to draw the letters of the logo and return the information content to be printed.

Parameters:
  • output (file) – Stream where to write the svg instruction to draw the logo.
  • tffm (TFFM) – The TFFM for which drawing the logo.
  • logo_type (str) – Kind of logo to draw (either ‘summary’ or ‘dense’)
  • xposition (float) – x-coordinate where to start the logo (default: 90.)
  • width – Width of the logo.
  • step (float) – Distance between two boxes containing letters in the logo.
Note:

The computation of the information content is done within the drawing since it follows the same algorithm computing the emission probabilities. So we do not call the get_information_content method for an algorithmic improvement.

drawing.draw_polygon(output, pts, colour=(0, 0, 0), opacity=1.0)[source]

Print the svg instructions to draw an polygon to the output.

Parameters:
  • output (file) – Stream where to write.
  • pts (list of tuple (float, float)) – Coordinates of the points defining the polygon. For each point in the list, its coordinates are given by the couple (x-coordinate, y-coordinate).
  • colour (tuple (int, int, int)) – Color of the polygon (default: black). The colour is given in RGB.
  • opacity (float) – Opacity of the polygon (default: 1.0)
Note:

Look at the polygon statement of an svg file for more information.

drawing.draw_rectangle(output, x_coord, y_coord, height, width, colour=(0, 0, 0), opacity=1.0)[source]

Print the svg instructions to draw an rectangle to the output.

Parameters:
  • output (file) – Stream where to write.
  • x_coord (float) – x-coordinate of the bottom-left corner of the rectangle.
  • y_coord (float) – y-coordinate of the bottom-left corner of the rectangle.
  • height (float) – Height of the rectangle.
  • width (float) – Width of the rectangle.
  • colour (tuple (int, int, int)) – Color of the rectangle (default: black). The colour is given in RGB.
  • opacity (float) – Opacity of the rectangle (default: 1.0)
Note:

Look at the rectangle statement of an svg file for more information.

drawing.draw_summary_letters(output, probabilities, width, xposition, yposition, step, entropy)[source]

Print the svg instruction to writh the ACGT letters at the current position and return the x-coordinate and y-coordinate for the box containing the letters at the next position.

Parameters:
  • output (file) – Stream where to write.
  • probabilities (list of tuple (float, str)) – Probabilities of appearance of the four nucleotides. The given probabilities are given for A, C, G, and T in this order.
  • width (float) – Width of box containing the letters to draw.
  • xposition (float) – x-coordinate of the bottom left corner of the box containing the letters to draw.
  • yposition (float) – y-coordinate of the bottom left corner of the box containing the letters to draw.
  • step (float) – Distance between two boxes containing the letters for the same position (it is a dense logo!).
  • entropy (float) – Entropy of the current position to determine the height of the letters.
Returns:

The coordinates (x, y) of the box that will be drawn with letters at the next position.

Return type:

tuple (float, float).

drawing.draw_y_axis(output, x_coord=80, y_coord=120)[source]

Print the svg instructions to draw the axis to the output.

Parameters:
  • output (file) – Stream where to write.
  • x_coord (float) – x-coordinate where to start (bottom) the Y-axis in the svg.
  • y_coord (float) – y-coordinate where to start (bottom) the Y-axis in the svg.

Print the footer of the svg to the output.

Parameters:output (file) – Stream where to write.
drawing.print_header(output, height, width)[source]

Print the header of the svg to the output.

Parameters:
  • output (file) – Stream where to write.
  • height (int) – Height of the final svg.
  • width (int) – Width of the final svg.
drawing.print_ic(output, length, information_content, x_coord, y_coord)[source]

Print the information content underneath the logo.

Parameters:
  • output (file) – Stream where to write.
  • length (int) – Number of positions in the logo.
  • information_content (float) – Value of the information content.
  • x_coord (float) – x-coordinate where to write the information content value in the svg.
  • y_coord (float) – y-coordinate where to write the information content value in the svg.

Module author: Anthony Mathelier <amathelier@cmmt.ubc.ca>

Previous topic

hit Module

Next topic

utils Module

This Page