Welcome to plasmidcanvas’s documentation!

What is plasmidcanvas?

plasmidcanvas is a Python graphics package designed for producing customised plasmid maps.

Top level overview of plasmidcanvas’ current features as of v1.0.0

  • Directional arrows and rectangles to represent features of a plasmid.

  • Support for restriction sites.

  • Support for arbitrary labels.

  • Support for overlapping features by automatically moving features inwards.

  • Support for base pair “ticks”.

  • Two types of plasmid base pair tick labels:
    • auto - The circle is automatically labelled using the most suitable tick intervals.

    • n_labels - The circle is given n labels, evenly spaced around the plasmid circle.

  • Two types of feature labels:
    • off-circle - A label is placed outside the plasmid circle, pointing at the base pair / feature of interest.

    • on-circle (curved text) - A label is placed on a feature and curves around the circle with the feature.

  • Plasmids can be saved to a variety of filetypes e.g. png, pdf, ps, eps and svg.

Bugs, feature requests and contributing

## How Can I Contribute? If you are a user who would like to contribute to the project, please refer to the CONTRIBUTING.md document.

### Reporting Bugs

If you encounter a bug or unexpected behavior, please search the [existing issues](https://github.com/th0mr/plasmidcanvas/issues) to see if it has already been reported. If not, please [open a new issue](https://github.com/th0mr/plasmidcanvas/issues/new) and provide a clear description of the problem along with steps to reproduce it.

### Requesting Features

If you have a feature request or an enhancement idea, please search the [existing issues](https://github.com/th0mr/plasmidcanvas/issues) to see if it has already been requested. If not, please [open a new issue](https://github.com/th0mr/plasmidcanvas/issues/new) and describe the feature or enhancement you’d like to see.

Alternatively, if you want to send me an email please contact thom.robinson@york.ac.uk. I am always happy to talk about this project.

Prerequisites

  • Python 3.9 or higher is installed

Installation

1 - Open a command prompt with admin privilages and run pip install plasmidcanvas

2 - You now have the package installed! If you want to double check it has installed correctly then run pip list to verify plasmidcanvas is in the list

Usage

This document contains example usage of the package through tutorials, options and example. However we advise that users take a look at the api documentation for more detail on how methods work and their parameters. See API Reference on the sidebar

Tutorial

These steps run through creating a basic, unstyled plasmid map. These examples can be extended using the techniques shown here and in the “Customising your plasmid map” section later on.

1 - Import all of ``plasmidcanvas.plasmid`` and ``plasmidcanvas.feature`` into a new Python file

from plasmidcanvas.plasmid import *
from plasmidcanvas.feature import *

2 - Create a new Plasmid object, passing through a name and a number of base pairs.

# Creates a plasmid that is 2500 base pairs long and is called called "my_plasmid"
plasmid = Plasmid("my_plasmid", "2500")

3 - Create and add the plasmid’s features to the plasmid

At the moment only RectangleFeature and ArrowFeature can be used to represent multi-pair features. Note that these features will automatically be labelled with their name and their base-pair range.

# Creates a rectangle to represent a feature called "some_gene", spanning from bp (basepair) 500 to bp 1000
some_gene = RectangleFeature("some_gene", 500, 1000)
plasmid.add_feature(some_gene)

# Creates a clockwise arrow to represent a feature called "another_gene" spanning from bp 2000 to 2300
another_gene = ArrowFeature("another_gene", 2000, 2300)
plasmid.add_feature(another_gene)

# Creates a counter-clockwise arrow from bp 300  to bp 400 to represent "ori"
ori = ArrowFeature("ori", 300, 400)
plasmid.add_feature(ori)

4 - Add any restriction sites or additional labels you want.

RestrictionSite takes a name and a base pair and formats a label at that base pair location with the text {name} ({basepair}) SinglePairLabel works the same, except whatever text it is given will be exactly what is displayed on the label, allowing you to add an arbitrary label.

# Creates a restriction site, this will create a label with the text "AbcD (900)" at bp 900
abcd = RestrictionSite("AbcD", 900)
plasmid.add_feature(abcd)

# Creates a label to mark where something might be
label = SinglePairLabel("Some extra label", 1500)
plasmid.add_feature(label)

5 - Save the plasmid out to a file, giving it a filename. Note that the extension on the filename will determine the filetype. Currently this is only tested for .png and .pdf but any matplotlib supported filetype should work.

plasmid.save_to_file("example_plasmid.png")

6 - Run your script and view the file example_plasmid.png It should be in the same directory as your Python script. However, you may notice it looks a little bit boring… See the section below focuses on customising your map to avoid this.

Customising your plasmid map

Below are some examples of how you can customise your plasmid maps and its features at a fine grained level.

Changing the color of a feature

ori = ArrowFeature("ori", 2534, 3122, direction=-1)
ori.set_color("green")
plasmid.add_feature(ori)

Changing the font color or font size of a label or restriction site

This example also applies for RestrictionSite objects.

# Creates a label to mark where something might be
label = SinglePairLabel("Some label", 1500)
# Sets the labels font color to red
label.set_font_color("red")
# Set the font size to 10pt
label.set_font_size(10)
plasmid.add_feature(label)

Changing the color or length of a label or restriction site

This example also applies for RestrictionSite objects.

# Creates a label to mark where something might be
label = SinglePairLabel("Some label", 1500)
# Scale factor to increase the line length by
label.set_line_length_sf(1.25)
# Set the line color to red
label.set_line_color("red")
plasmid.add_feature(label)

Changing the width of a rectangle feature

Note - The same should be possible for ArrowFeature objects in the future

rct = ArrowFeature("rectangle", 2534, 3122)
# Makes the width of the arrow 1.25 times wider than the width of the plasmid circle
rct.set_line_width_scale_factor(1.25)
plasmid.add_feature(ori)

Changing the plasmid line width

The following code can be used to make the plasmid line width wider or thinner. Note that this will increase in line width will be passed down to all features at render time.

plasmid = Plasmid("myplasmid", 5000)
# Create a new line width that is 1.25x larger than before
new_line_width = plasmid.get_plasmid_line_width() * 1.25
plasmid.set_plasmid_line_width(new_line_width)

Or, apply a scale factor to the line width

plasmid = Plasmid("myplasmid", 5000)
# Create a new line width that is 1.25x larger than before
new_line_width_sf = plasmid.get_plasmid_line_width_sf() * 1.25
plasmid.set_plasmid_line_width_sf(new_line_width_sf)

Changing the base pair tick marker style for a Plasmid

There are two types of plasmid base pair tick labels
  • auto - (default) The circle is automatically labeled using the most suitible tick intervals.

  • n_labels - The circle is given n labels, evenly spaced around the plasmid circle.

Auto is the default label style, n_labels can be used as below. If unspecified n=16.

plasmid = Plasmid("myplasmid", 5000)
plasmid.set_marker_style("n_labels")
# By default n=16, to change this do:
plasmid.set_number_of_markers(8)

Changing the distance of marker text from the circle

This may lead to some text clipping into labels, but the option is here if you need to change this.

plasmid = Plasmid("myplasmid", 5000)
# Sets the markers 1.25x the distance away from the circle when compared to the default
plasmid.set_marker_distance_sf(1.25)

Using on-circle labelling (curved text)

To swap a label to use on-circle labelling, a new style array must be passed to the feature. If your feature is too small to fit the label on, it wont be placed.

Note - it is possible to have both on-cirlce and off-circle styles by passing in [“on-circle”, “off-circle”]

ori = ArrowFeature("ori", 2534, 3122, direction=-1)
ori.set_label_styles(["on-circle"])
plasmid.add_feature(ori)

Chaning font size for all labels

If you wish to easily change the font size on all labels associated with the Plasmid and its Features, it can be set with Plasmid.set_label_font_size()

Note - You can still alter the size of any specific label manually, e.g. label.set_font_size() and that wont be overridden by this setting i.e. any manually changed label size wont have the global font size applied to it.

plasmid = Plasmid("myplasmid", 5000)
# Accepts a pt value
plasmid.set_label_font_size(5)

Example 1 - Creating a map of pBR322

The following code shows a concrete example of producing a basic, unstyled map of pBR322

# An example showing how to build pBR322 in plasmidcanvas

from plasmidcanvas.plasmid import Plasmid
from plasmidcanvas.feature import ArrowFeature, RectangleFeature, RestrictionSite

plasmid = Plasmid("pBR322", 4361)

# Adding features
tcr = ArrowFeature("TcR", 86, 1276)
plasmid.add_feature(tcr)

bom = RectangleFeature("bom", 2208,2348)
plasmid.add_feature(bom)

ori = ArrowFeature("ori", 2534, 3122, direction=-1)
plasmid.add_feature(ori)

ampr = ArrowFeature("ampr", 3293, 4153, direction=-1)
plasmid.add_feature(ampr)

ampr_promoter = ArrowFeature("ampr promoter", 4154, 4258, direction=-1)
plasmid.add_feature(ampr_promoter)

# Add a couple of restriction sites to the plasmid
restriction_site_1 = RestrictionSite("BamHI", 375)
restriction_site_2 = RestrictionSite("BfuAI - BspMI", 1054)
restriction_site_3 = RestrictionSite("Bpu10I", 1581)
restriction_site_4 = RestrictionSite("AflIII - PciI", 2473)
restriction_site_5 = RestrictionSite("AhdI", 3366)

# Add the sites to the plasmid
plasmid.add_feature(restriction_site_1)
plasmid.add_feature(restriction_site_2)
plasmid.add_feature(restriction_site_3)
plasmid.add_feature(restriction_site_4)
plasmid.add_feature(restriction_site_5)

plasmid.save_to_file("pBR322_basic.png")

This produces the following map as a png in your script’s directory

_images/pBR322_basic.png

Example 2 - Demonstrating overlapping features on pBR322

This is an example to show how overlapping features look in plasmidcanvas

from plasmidcanvas.plasmid import Plasmid
from plasmidcanvas.feature import ArrowFeature, RectangleFeature, RestrictionSite

plasmid = Plasmid("pBR322", 4361)

# Adding an arrow
# for pBR322 this is TcR
tcr = ArrowFeature("TcR", 86,1276)
# # # Customise the thinkness of the line relative to the thickness of the plasmid circle
# # tcr.set_line_width_scale_factor(1.0)
plasmid.add_feature(tcr)

# # Add rop protein for pBR322
rop = ArrowFeature("rop", 1915,2106)
plasmid.add_feature(rop)

# # Add a rectangle, base of mobility for pBR322
bom = RectangleFeature("bom", 2208,2348)
plasmid.add_feature(bom)

# # Add ori
ori = ArrowFeature("ori", 2534, 3122, -1)
ori.set_color("orange")
plasmid.add_feature(ori)

# # Add ampr - technically this arrow should have a portion segmented for its signal sequence
ampr = ArrowFeature("ampr", 3293, 4153, -1)
ampr.set_color("red")
plasmid.add_feature(ampr)

# # Add ampr promoter as an arrow
ampr_promoter = ArrowFeature("ampr promoter", 4154, 4258, -1)
ampr_promoter.set_color("darkred")
plasmid.add_feature(ampr_promoter)

overlapping = ArrowFeature("overlapping feature", 3500, 4300)
overlapping.set_color("darkblue")
plasmid.add_feature(overlapping)

overlapping = ArrowFeature("overlapping feature2", 3366, 3440)
overlapping.set_color("darkgreen")
plasmid.add_feature(overlapping)

overlapping = ArrowFeature("overlapping feature3", 3400, 3800)
overlapping.set_color("darkgreen")
plasmid.add_feature(overlapping)

overlapping = ArrowFeature("overlapping feature4", 2900, 3100)
overlapping.set_color("darkgreen")
plasmid.add_feature(overlapping)

overlapping = ArrowFeature("overlapping feature5", 3600, 3700)
overlapping.set_color("darkgreen")
plasmid.add_feature(overlapping)

overlapping = RectangleFeature("overlapping feature6", 2600, 3200)
overlapping.set_color("darkgreen")
plasmid.add_feature(overlapping)

plasmid.save_to_file("myplasmid.png")
_images/pBR322_overlapping.png

Example 3 - pBR322 with curved text, mixed labels and more

from plasmidcanvas.plasmid import Plasmid
from plasmidcanvas.feature import ArrowFeature, RectangleFeature, RestrictionSite

# Define a plasmid of X base pairs long, with a name
plasmid = Plasmid("pBR322", 4361)
plasmid.set_marker_style("auto")
plasmid.set_feature_label_font_size(7)
plasmid.set_plasmid_line_width_sf(1.25)

# Adding tcr
tcr = ArrowFeature("tcr", 86,1276)
plasmid.add_feature(tcr)

# Add rop protein for pBR322
rop = ArrowFeature("rop", 1915,2106)
rop.set_line_width_scale_factor(1.5)
rop.set_color("purple")
plasmid.add_feature(rop)

# Add a rectangle, base of mobility for pBR322
bom = RectangleFeature("bom", 2208,2348)
plasmid.add_feature(bom)

# Add ori
ori = ArrowFeature("ori", 2534, 3122, -1)
ori.set_color("orange")
plasmid.add_feature(ori)

# # Add ampr
ampr = ArrowFeature("ampr", 3293, 4153, -1)
ampr.set_color("red")
plasmid.add_feature(ampr)

for feature in plasmid.get_features():
    feature.set_label_styles(["on-circle"])

# # Add ampr promoter as an arrow
ampr_promoter = ArrowFeature("ampr promoter", 4154, 4258, -1)
ampr_promoter.set_color("darkred")

ampr_promoter.set_line_width_scale_factor(0.75)
plasmid.add_feature(ampr_promoter)

# Add the sites to the plasmid
plasmid.add_feature(RestrictionSite("BamHI", 375))
plasmid.add_feature(RestrictionSite("BfuAI - BspMI", 1054))
plasmid.add_feature(RestrictionSite("Bpu10I", 1581))
plasmid.add_feature(RestrictionSite("AflIII - PciI", 2473))
plasmid.add_feature(RestrictionSite("AhdI", 3366))

# Plot the plasmid
plasmid.save_to_file("myplasmid.png")
_images/pBR322_curved.png

API Reference

This page contains auto-generated API reference documentation [1].

plasmidcanvas

Submodules

plasmidcanvas.feature
Module Contents
Classes

Feature

Abstract base class representing a feature

MultiPairFeature

An abstract Feauture type that spans multiple base pairs

SinglePairFeature

An abstract Feature class representing a Feature that relates to only a single base pair

LabelBase

A base class for labels.

SinglePairLabel

A class representing a label associated with a single base pair feature on a plasmid. Inheriting from both SinglePairLabel and LabelBase.

RestrictionSite

A class representing a restriction site on a plasmid as an extention of SinglePairLabel.

CurvedMultiPairLabel

A class representing a curved label associated with multiple base pairs on a plasmid.

RectangleFeature

A class representing a curved rectangular feature associated with multiple base pairs on a plasmid.

DirectionalMultiPairFeature

An abstract class representing a directional feature associated with multiple base pairs on a plasmid.

ArrowFeature

A class representing a curved arrow feature associated with multiple base pairs on a plasmid.

class plasmidcanvas.feature.Feature(name: str)

Abstract base class representing a feature

Initializes the Feature object.

Parameters:

name (str) – The name of the feature.

name: str
color: str
get_name() str

Get the name of the feature.

Returns:

The name of the feature.

Return type:

str

set_name(name: str)

Set the name of the feature.

Parameters:

name (str) – The name to set for the feature.

get_color() str

Get the color of the feature.

Returns:

The color of the feature.

Return type:

str

set_color(color: str) None

Set the color of the feature.

Parameters:

color (str) – The color to set for the feature. Use words e.g “red” or hex values e.g. “#FFFFFF”

class plasmidcanvas.feature.MultiPairFeature(name: str, start_pair: int, end_pair: int)

Bases: Feature

Inheritance diagram of plasmidcanvas.feature.MultiPairFeature

An abstract Feauture type that spans multiple base pairs

Initializes the MultiPairFeature object.

Parameters:
  • name (str) – The name of the feature.

  • start_pair (int) – The starting base pair of the feature.

  • end_pair (int) – The ending base pair of the feature.

start_pair: int
end_pair: int
SUPPORTED_LABEL_STYLES = ['on-circle', 'off-circle']
label_style = ['off-circle']
length() int

Calculates and returns the length of the feature. i.e. end_pair - start_pair

Returns:

The length of the feature.

Return type:

int

get_start_pair() int

Get the starting base pair of the feature.

Returns:

The starting base pair.

Return type:

int

set_start_pairs(start_pair: int) None

Set the starting base pair of the feature.

Parameters:

start_pair – The starting base pair to set.

get_end_pair() int

Get the ending base pair of the feature.

Returns:

The ending base pair.

Return type:

int

set_end_pairs(end_pair) None

Set the ending base pair of the feature.

Parameters:

end_pair – The ending base pair to set.

get_orbit() int

Get the orbit of the feature.

Returns:

The orbit value of the feature.

Return type:

int

set_orbit(orbit: int) None

Set the orbit of the feature. Mostly used internally for overlapping features, but can be used to force features into an orbit. The higher the orbit, the closer to the center of the plasmid the feature is placed. i.e orbit = 0 is the default, orbit = 4 circles four times the width of a feature closer to the center.

Parameters:

orbit (int) – The orbit value to set.

get_label_font_size() int

Get the font size of the labels associated with the feature.

Returns:

The font size of the labels.

Return type:

int

set_label_font_size(font_size: int) None

Set the font size of the labels associated with the feature.

Parameters:

font_size (int) – The font size to set.

get_label_styles() list[str]

Get the list of label styles associated with the feature.

Returns:

label_style – The list of label styles.

Return type:

list[str]

set_label_styles(label_styles: list[str])

Set the list of label styles associated with the feature.

Parameters:

label_styles (list[str]) – The list of label styles to set. Currently supported styles

“on-circle” - The label is applied onto the feature using curved text. (The base pair location is not included in this labelling)

“off-circle” - A label is placed off the circle with the name and bp range, connected by a small line

Note

A plasmid can have both, one or none of the label styles applied at the same time

Raises:

ValueError – If the given label_style is not in MultiPairFeature.SUPPORTED_LABEL_STYLES as listed above.

class plasmidcanvas.feature.SinglePairFeature(name: str, base_pair: int)

Bases: Feature

Inheritance diagram of plasmidcanvas.feature.SinglePairFeature

An abstract Feature class representing a Feature that relates to only a single base pair

Initializes the SinglePairFeature object.

Parameters:
  • name (str) – The name of the feature.

  • base_pair (int) – The base pair associated with the feature.

base_pair: int
get_base_pair() int

Get the base pair associated with the feature.

Returns:

The base pair.

Return type:

int

set_base_pair(base_pair) None

Set the base pair associated with the feature.

Parameters:

base_pair – The base pair to set.

class plasmidcanvas.feature.LabelBase(name: str)

A base class for labels.

Initializes the LabelBase object.

Parameters:

name (str) – The name of the label.

DEFAULT_FONT_SIZE: int
DEFAULT_FONT_COLOR: str = 'black'
label_text: str = 'UntitledLabel'
font_color: str
font_size: int
get_font_color() str

Get the color of the label font.

Returns:

The color of the label font.

Return type:

str

set_font_color(font_color: str) None

Set the color of the label font.

Parameters:

font_color (str) – The color of the label font.

set_label_text(label_text: str) None

Set the text of the label.

Parameters:

label_text (str) – The text of the label.

get_label_text() str

Get the text of the label.

Returns:

label_text – The text of the label.

Return type:

str

get_font_size() int

Get the size of the label font.

Returns:

font_size – The size of the label font.

Return type:

int

set_font_size(font_size: int) None

Set the size of the label font.

Parameters:

font_size (int) – The size of the label font.

class plasmidcanvas.feature.SinglePairLabel(name: str, base_pair: int)

Bases: SinglePairFeature, LabelBase

Inheritance diagram of plasmidcanvas.feature.SinglePairLabel

A class representing a label associated with a single base pair feature on a plasmid. Inheriting from both SinglePairLabel and LabelBase.

Initializes the SinglePairLabel object.

Parameters:
  • name (str) – The name of the label.

  • base_pair (int) – The base pair associated with the label.

line_length_sf: float
line_color: str
get_line_color() str

Get the color of the line connecting the label to the feature.

Returns:

The color of the line.

Return type:

str

set_line_color(line_color: str) None

Set the color of the line connecting the label to the feature.

Parameters:

line_color (str) – The color of the line.

get_line_length_sf() float

Get the scale factor for the length of the line connecting the label to the feature.

Returns:

The scale factor for the line length.

Return type:

float

set_line_length_sf(line_length_sf: float) None

Set the scale factor for the length of the line connecting the label to the feature.

Parameters:

line_length_sf (float) – The scale factor for the line length.

class plasmidcanvas.feature.RestrictionSite(text: str, base_pair: int)

Bases: SinglePairLabel

Inheritance diagram of plasmidcanvas.feature.RestrictionSite

A class representing a restriction site on a plasmid as an extention of SinglePairLabel.

Initializes the RestrictionSite object. Creating a label in the format “<text> (<base_pair>)”. For more control over the label text, use SinglePairLabel.

Parameters:
  • text (str) – The text to display on the restiction site. e.g. “BspMI”, “BfuAI, BspMI”, “Multiple Cloning Site”

  • base_pair (int) – The base pair position of the restriction site.

class plasmidcanvas.feature.CurvedMultiPairLabel(name: str, start_pair: int, end_pair: int)

Bases: MultiPairFeature, LabelBase

Inheritance diagram of plasmidcanvas.feature.CurvedMultiPairLabel

A class representing a curved label associated with multiple base pairs on a plasmid.

Initializes the CurvedMultiPairLabel object.

Parameters:
  • name (str) – The name of the curved label.

  • start_pair (int) – The starting base pair position of the label.

  • end_pair (int) – The ending base pair position of the label.

SUPPORTED_CURVE_ALIGNMENTS: list[str] = ['bottom', 'top']
set_curve_alignment(curve_align: str) None

Sets the alignment of the curved label. i.e. does the text follow the bottom or top of the curve? (use bottom for curves in the bottom half of the circle and top for the top half)

Parameters:

curve_align (str) – The alignment of the curved label (‘bottom’ or ‘top’).

get_curve_alignment() str

Returns the alignment of the curved label.

Returns:

The alignment of the curved label.

Return type:

str

class plasmidcanvas.feature.RectangleFeature(name: str, start_pair: int, end_pair: int)

Bases: MultiPairFeature

Inheritance diagram of plasmidcanvas.feature.RectangleFeature

A class representing a curved rectangular feature associated with multiple base pairs on a plasmid.

Initializes the MultiPairFeature object.

Parameters:
  • name (str) – The name of the feature.

  • start_pair (int) – The starting base pair of the feature.

  • end_pair (int) – The ending base pair of the feature.

line_width_scale_factor: float = 1
get_line_width_scale_factor() float

Returns the scale factor for the width of the rectangle.

Returns:

The scale factor for the width of the rectangle.

Return type:

float

set_line_width_scale_factor(sf: float) None

Sets the scale factor for the width of the rectangle.

Parameters:

sf (float) – The scale factor for the width of the rectangle.

class plasmidcanvas.feature.DirectionalMultiPairFeature(name: str, start_pair: int, end_pair: int, direction: int = 1)

Bases: MultiPairFeature

Inheritance diagram of plasmidcanvas.feature.DirectionalMultiPairFeature

An abstract class representing a directional feature associated with multiple base pairs on a plasmid.

Initializes a directional multi-pair feature.

Parameters:
  • name (str) – The name of the feature.

  • start_pair (int) – The start base pair.

  • end_pair (int) – The end base pair.

  • direction (int, optional) – The direction of the feature, either 1 for clockwise or -1 for anti-clockwise (default is 1).

direction: int = 1
get_direction() int

Returns the direction of the feature.

Returns:

The direction of the feature. (1 for clockwise or -1 for anti-clockwise)

Return type:

int

set_direction(direction: int) None

Sets the direction of the feature.

Parameters:

direction (int) – The direction of the feature, either 1 for clockwise or -1 for anti-clockwise.

Raises:

ValueError – If direction is neither 1 or -1.

class plasmidcanvas.feature.ArrowFeature(name: str, start_pair: int, end_pair: int, direction: int = 1)

Bases: DirectionalMultiPairFeature

Inheritance diagram of plasmidcanvas.feature.ArrowFeature

A class representing a curved arrow feature associated with multiple base pairs on a plasmid.

Initializes a directional multi-pair feature.

Parameters:
  • name (str) – The name of the feature.

  • start_pair (int) – The start base pair.

  • end_pair (int) – The end base pair.

  • direction (int, optional) – The direction of the feature, either 1 for clockwise or -1 for anti-clockwise (default is 1).

line_width_scale_factor: float = 1
get_line_width_scale_factor() float

Returns the scale factor for the width of the arrow.

Returns:

The scale factor for the width of the arrow.

Return type:

float

set_line_width_scale_factor(sf: float) None

Sets the scale factor for the width of the arrow.

Parameters:

sf (float) – The scale factor to set.

plasmidcanvas.plasmid
Module Contents
Classes

Plasmid

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.