plasmidcanvas.plasmid
Module Contents
Classes
Circular object representing a plasmid object on which to plot Features onto. |
- class plasmidcanvas.plasmid.Plasmid(name: str, base_pairs: int)
Circular object representing a plasmid object on which to plot Features onto.
Creates a Plasmid object with a given name and number of base pairs
- Parameters:
name (str) – The name of the plasmid e.g. pBR322
base_pairs (int) – The number of base pairs in the plasmid
- Raises:
ValueError – If the number of base pairs is negative
Examples
Creating a Plasmid:
from plasmidcanvas.plasmid import Plasmid myplasmid = Plasmid("pBR322", 4361)
- SUPPORTED_MARKER_STYLES = ['auto', 'n_markers', 'none']
- SUPPORTED_TICK_STYLES = ['auto', 'none']
- name: str
- base_pairs: int
- plot() matplotlib.figure.Figure
Plots all features added to the Plasmid object onto a matplotlib Figure.
Note
Unless you are working in an interactive environment, e.g. Jupyter, it is recommended to use save_to_file() to view your plasmid instead.
- Returns:
figure – A matplotlib figure object with the plasmid and its features plotted onto it
- Return type:
Figure
Example
Obtaining a plasmid Figure:
from plasmidcanvas.plasmid import Plasmid myplasmid = Plasmid("pBR322", 4361) figure = myplasmid.plot() proceed to view or work with figure...
- save_to_file(filename: str) None
Plots the plasmid by calling Plasmid.plot() and saves the figure to an image with a given filename.
- Parameters:
filename (str) –
- filename or path to save the figure to. e.g.
“myplasmid.png” would save it to the working directory. “build/myplasmid.png” would save the same image inside the “build” folder.
A file extention should be included in the filename. Any matplotlib supported file extention is supported. e.g. png, pdf, ps, eps and svg.
Examples
To save a plasmid to a png:
from plasmidcanvas.plasmid import Plasmid myplasmid = Plasmid("pBR322", 4361) myplasmid.savefig("figure.png")
- add_feature(feature: plasmidcanvas.feature.Feature) None
Adds a feature to the Plasmid object. All features to be plotted must be created and then added to the plasmid this way. See the example below.
- Parameters:
feature (Feature) – A Feature object to add to the plasmid. e.g RectangleFeature, ArrowFeature, SinglePairLabel, RestrictionSite etc. See the documentation for plasmidcanvas.feature to see the availble Feature types and their usage.
- Raises:
ValueError – If the feature lies out of bounds of the Plasmid’s base pair range
Note
This does not render the feature, that only happens when Plasmid.plot() or Plasmid.save_to_file() is ran. Therefore, plasmid wide and feature specific customisations can be made after the feature is added if you wish.
Examples
Adding an Arrow Featue:
from plasmidcanvas.plasmid import Plasmid from plasmidcanvas.feature import ArrowFeature, RectangleFeature, RestrictionSite myplasmid = Plasmid("pBR322", 4361) myplasmid.savefig("figure.png") arrow = ArrowFeature(1000, 2000) # Optional feature customisation here myplasmid.add_feature(arrow) # Save plasmid out myplasmid.save_to_file("figure.png")
- get_features() MutableSequence[plasmidcanvas.feature.Feature]
Get the features associated with the plasmid.
- Returns:
features – The features associated with the plasmid.
- Return type:
MutableSequence[Feature]
- get_base_pairs() int
Get the number of base pairs in the plasmid.
- Returns:
base_pairs – The number of base pairs in the plasmid.
- Return type:
int
- set_base_pairs(base_pairs) None
Set the number of base pairs in the plasmid.
- Parameters:
base_pairs (int) – The number of base pairs to set the plasmid to.
- get_name() str
Get the name of the plasmid.
- Returns:
name – The name of the plasmid.
- Return type:
str
- set_name(name: str) None
Set the name of the plasmid.
- Parameters:
name (str) – The name to set for the plasmid.
- get_color() str
Get the color of the plasmid circle.
- Returns:
color – The color of the plasmid circle.
- Return type:
str
- set_color(color: str) None
Set the color of the plasmid circle.
- Parameters:
color (str) – The color to set for the plasmid circle. Use words e.g “red” or hex values e.g. “#FFFFFF”
- get_center() tuple[float, float]
Get the center coordinates of the plasmid.
- Returns:
center – The (x, y) coordinates of the center of the plasmid.
- Return type:
tuple[float, float]
- set_center(center: tuple[float, float]) None
Set the center coordinates of the plasmid.
- Parameters:
center (tuple[float, float]) – The (x, y) coordinates to set as the center of the plasmid.
- get_plasmid_line_width_sf() float
Get the scale factor for the plasmid circle line width.
- Returns:
line_width_sf – The scale factor for the plasmid circle line width.
- Return type:
float
- set_plasmid_line_width_sf(line_width_sf: float) None
Set the scale factor for the plasmid circle line width.
- Parameters:
line_width_sf (float) – The scale factor to set for the plasmid circle line width. e.g. 1.5 makes the plasmid circle 1.5 times as thick as the default
- get_plasmid_line_width() float
Get the plasmid line width.
- Returns:
plasmid_line_width – The plasmid line width.
- Return type:
float
- set_plasmid_line_width(plasmid_line_width: float) None
Set the plasmid line width.
- Parameters:
plasmid_line_width (float) – The plasmid line width to set.
Note
Either use set_plasmid_line_width or set_plasmid_line_width_sf. Increasing both values could create a very thick plasmid circle!
- get_marker_style() str
Get the style of markers for the plasmid.
- Returns:
marker_style – The style of markers used for the plasmid.
- Return type:
str
- set_marker_style(marker_style: str) None
Set the style of markers for the plasmid.
- Parameters:
marker_style (str) – The style of markers to set for the plasmid. Currently supported styles
“auto” (default) - Automatically apply markers at a reasonable marker interval based on the plasmid size
“n_markers” - Place n equidistant markers around the circle. The default is 16, unless changed with Plasmid.set_number_of_markers()
“none” - No markers added to the circle
- Raises:
ValueError – If the given marker_style is not in Plasmid.SUPPORTED_MARKER_STYLES, as listed above.
- get_marker_distance_sf() float
Get the scale factor for the distance between the circle and the marker text.
- Returns:
marker_distance_sf – The scale factor for the marker distance.
- Return type:
float
- set_marker_distance_sf(marker_distance_sf) None
Set the scale factor for the distance between the circle and the marker text.
- Parameters:
marker_distance_sf (float) – The scale factor to set for the marker distance.
Examples
This value is small by default (1.03). It is advised to alter this by applying a to the existing scale factor to achieve reliable increases.:
myplasmid.set_marker_distance(myplasmid.get_marker_distance_sf() * 1.5)
- get_number_of_markers() int
Get the number of markers on the plasmid. Only used when the plasmid’s marker style is “n_markers”.
- Returns:
number_of_markers – The number of markers on the plasmid.
- Return type:
int
- set_number_of_markers(number_of_markers: int) None
Set the number of markers to produce around the plasmid when the plasmid’s marker style is “n_markers”.
- Parameters:
number_of_markers (int) – The number of markers to place around the plasmid when using n_marker style.
- get_tick_style() str
Get the style of tick placement on the plasmid.
- Returns:
tick_style – The style of ticks used for the plasmid.
- Return type:
str
- set_tick_style(tick_style: str) None
Set the style of tick placement on the plasmid.
- Parameters:
tick_style (str) – The style of ticks to set for the plasmid.
Currently supported:
“auto” (default) - Automatically draw on ticks at a reasonable marker interval based on the plasmid size
“none” - No ticks are drawn around the circle
- Raises:
ValueError – If the given tick_style is not in Plasmid.SUPPORTED_TICK_STYLES, as listed above.
- get_tick_color() str
Get the color of ticks for the plasmid.
- Returns:
tick_color – The color of ticks used for the plasmid.
- Return type:
str
- set_tick_color(tick_color: str) None
Set the color of ticks for the plasmid.
- Parameters:
tick_color (str) – The color of ticks to set for the plasmid. Use words e.g “red” or hex values e.g. “#FFFFFF”
- get_feature_label_font_size() int
Get the override font size of feature labels for the plasmid. This font size will be applied to any labels / features that have not already had their font size changed manually.
- Returns:
feature_label_font_size – The font size of feature labels used for the plasmid. Given as a pt value.
- Return type:
int
- set_feature_label_font_size(feature_label_font_size: int) None
Set the font size of feature labels for the plasmid. This font size will be applied to any labels / features that have not already had their font size changed manually.
- Parameters:
feature_label_font_size (int) – The font size of feature labels to set for the plasmid. Given as a pt value.