Lab module

PCR module

This part of the lab module is used for simulating and calculating PCR reactions.

constrain.lab.PCR.Q5_NEB_PCR_program(amplicon)[source]

Simple PCR program designed to give a quick visual representations.

Parameters:

amplicon (pydna.amplicon) – pydna amplicon object

Returns:

schematic representation of a Q5 program

Return type:

str

constrain.lab.PCR.amplicon_by_name(name: str, amplicons_lst: list)[source]

Returns amplicon with specified name

Parameters:
  • name (str) –

  • amplicons_lst (list) –

Returns:

amplicon

Return type:

pydna.amplicon

constrain.lab.PCR.calculate_elongation_time(amplicon)[source]

Determines elongation time for an amplicon and add the elongation time to the amplicon annotations

Parameters:

amplicon (pydna.amplicon) –

Return type:

Adds the elongation time to the amplicon annotations

Notes

The amplicon needs to have a dict called proc_speed shown as follows: amplicon.annotations[“proc_speed”] This dict within the annotations can be made with the function proc_speed.

constrain.lab.PCR.calculate_processing_speed(amplicon)[source]

Determines process speed based on the which polymerase is used.

Parameters:

amplicon (pydna.amplicon) –

Return type:

Adds annotations to the amplicon object dependent on which polymerase was used

Notes

The amplicon needs to have the following dict incorporated: amplicon.annotations[“polymerase”]

constrain.lab.PCR.calculate_required_thermal_cyclers(amplicons: list, polymerase: str, elong_time_max_diff=15)[source]

Determines the number of thermalcyclers that is needed based on elongation time differences

Parameters:
  • amplicons (list) – of pydna.amplicon objects

  • polymerase (str) –

Returns:

dataframe of grouped amplicons

Return type:

pd.DataFrame

constrain.lab.PCR.calculate_volumes(vol_p_reac=0, no_of_reactions=1, standard_reagents=[], standard_volumes=[])[source]

Can make a reaction scheme for PCR master mixes. :param vol_p_reac: :type vol_p_reac: int :param no_of_reactions: :type no_of_reactions: int :param standard_reagents: :type standard_reagents: list :param standard_volumes: :type standard_volumes: list

Return type:

pd.DataFrame

Examples

calculate_volumes(vol_p_reac = 10,

no_of_reactions = 6, standard_reagents = [“DNA”,”Buffer, Cutsmart”,”H20”,”Enz, USER”], standard_volumes = [1,1,7,1])

vol_p_reac vol_p_x_reac

DNA 1.0 6.0 Buffer, Cutsmart 1.0 6.0 H20 7.0 42.0 Enz, USER 1.0 6.0 Total 10.0 60.0 ————————-

constrain.lab.PCR.grouper(iterable, max_diff)[source]

Groups objects into distinct groups based on differences

constrain.lab.PCR.nanophotometer_concentrations(path='')[source]

Reads a CSV file with nanophotometer concentraions and returns the concentrations in a list

Parameters:

path (str) – path to file

Returns:

concentrations – list of concentrations from the file as floats

Return type:

list

constrain.lab.PCR.pcr_locations(amplicons: list)[source]

Obtain information annotation information from amplicons.

Parameters:

amplicon (list) – List of amplicon objects `pydna.amplicon`() # check this

Returns:

Pandas dataframe with locations of your amplicons

Return type:

pd.DataFrame

constrain.lab.PCR.primer_ta_neb(primer1, primer2, conc=0.5, prodcode='q5-0')[source]

Calculates primer pair melting temp TA, from NEB.

Parameters:
  • primer1 (str) – first primer to be used for finding the optimal ta

  • primer2 (str) – second primer to be used for finding the optimal ta

  • conc (float) –

  • prodcode (str) – find product codes on nebswebsite: https://tmapi.neb.com/docs/productcodes

Returns:

ta – primer pair annealing temp

Return type:

int

constrain.lab.PCR.primer_tm_neb(primer, conc=0.5, prodcode='q5-0')[source]

Calculates a single primers melting temp from NEB.

Parameters:
Returns:

tm – primer melting temperature

Return type:

int

constrain.lab.PCR.set_plate_locations(amplicons: list)[source]

Makes a dataframe from amplicons

Parameters:

amplicons (list) – list of pydna.amplicon objects

Returns:

with overview of plate locations

Return type:

pd.DataFrame

constrain.lab.PCR.update_amplicon_annotations(amplicon_names: list, amplicons: list, locations: list, concentrations: list, volumes: list) None[source]

Updates the annotations of amplicons in the amplicon list.

Parameters:
  • amplicon_names (list) – List of amplicon names.

  • locations (list) – List of locations for each amplicon.

  • concentrations (list) – List of concentrations for each amplicon.

  • volumes (list) – List of volumes for each amplicon.

Return type:

None

Containers module

exception constrain.lab.containers_wells_picklists.NoUniqueWell[source]

Bases: Exception

NoUniqueWell exception class.

class constrain.lab.containers_wells_picklists.PickList(transfers_list=(), data=None)[source]

Bases: object

Representation of a list of well-to-well transfers.

Parameters:
  • transfers_list – A list of Transfer objects that will be part of the same dispensing operation, in the order in which they are meant to be simulated.

  • data – A dict with information on the picklist.

add_transfer(source_well=None, destination_well=None, volume=None, data=None, transfer=None)[source]

Add a transfer to the picklist’s tranfers list.

You can either provide a Transfer object with the transfer parameter, or the parameters.

enforce_maximum_dispense_volume(max_dispense_volume)[source]

Return a new picklist were every too-large dispense is broken down into smaller dispenses.

static merge_picklists(picklists_list)[source]

Merge the list of picklists into a single picklist.

The transfers in the final picklist are the concatenation of the transfers in the different picklists, in the order in which they appear in the list.

restricted_to(transfer_filter=None, source_well=None, destination_well=None)[source]

Return a version of the picklist restricted to transfers with the right source/destination well.

You can provide source_well and destination_well or alternatively just a function transfer_filter with signature (transfer)=>True/False that will be used to filter out transfers (for which it returns false).

simulate(content_field='content', inplace=True)[source]

Simulate the execution of the picklist.

sorted_by(sorting_method='source_well')[source]

Return a new version of the picklist sorted by some parameter.

The sorting_method is either the name of an attribute of the transfers, such as “source_well”, or a function f(transfer) -> value.

to_flowbot_instructions_string()[source]

Return the list of transfers in Flowbot format.

to_plain_string()[source]

Return the list of transfers in human-readable format.

to_plain_textfile(filename)[source]

Write the picklist in a file in a human reable format.

total_transferred_volume()[source]

Return the sum of all volumes from all transfers.

class constrain.lab.containers_wells_picklists.Plate(name=None, wells_data=None, plate_data=None)[source]

Bases: object

Base class for all plates.

See the builtin_containers for usage classes, such as generic microplate classes (Plate96, Plate384, etc).

Parameters:
  • name – Name or ID of the Plate as it will appear in strings and reports

  • wells_data – A dict {“A1”: {data}, “A2”: …}. The format of the data is left free

  • plate_data – plate data

find_unique_well_by_condition(condition)[source]

Return the unique well of the plate satisfying the condition.

The condition method should have a signature of Well=>True/False.

Raises a NoUniqueWell error if 0 or several wells satisfy the condition.

find_unique_well_containing(query)[source]

Return the unique well whose content contains the query.

get_well_at_index(index, direction='row')[source]

Return the well at the corresponding index.

Examples:

>>> plate.get_well_at_index(1)  # well A1
>>> plate.get_well_at_index(2)  # well A2
>>> plate.get_well_at_index(2, direction="column")  # well B1
index_to_wellname(index, direction='row')[source]

Return the name of the well at the corresponding index.

Examples:

>>> plate.index_to_wellname(1)  # "A1"
>>> plate.get_well_at_index(2)  # "A2"
>>> plate.get_well_at_index(2, direction="column")  # "B1"
iter_wells(direction='row')[source]

Iter through the wells either by row or by column.

Examples:

>>> for well in plate.iter_wells():
>>>     print (well.name)
list_filtered_wells(well_filter)[source]

List filtered wells.

Examples:

>>> def condition(well):
>>>     return well.volume > 50
>>> for well in myplate.list_filtered_wells(condition):
>>>     print(well.name)
list_well_data_fields()[source]

Return all fields used in well data in the plate.

list_wells_in_column(column_number)[source]

Return the list of all wells of the plate in the given column.

Examples:

>>> for well in plate.list_wells_in_column(5):
>>>      print(well.name)
list_wells_in_row(row)[source]

Return the list of all wells of the plate in the given row.

The row can be either a row number (1,2,3) or row letter(s) (A,B,C).

Examples:

>>> for well in plate.list_wells_in_row("H"):
>>>      print(well.name)
return_column(column_number)[source]

Return the list of all wells of the plate in the given column.

return_row(row)[source]

Return the list of all wells of the plate in the given row.

The row can be either a row number (1,2,3) or row letter(s) (A,B,C).

to_dict(replace_nans_by='null')[source]

Convert plate to dict.

to_pandas_dataframe(fields=None, direction='row')[source]

Return a dataframe with the info on each well.

well_class

alias of Well

wellname_to_index(wellname, direction='row')[source]

Return the index of the well in the plate.

Examples: >>> plate.wellname_to_index(“A1”) # 1 >>> plate.wellname_to_index(“A2”) # 2 >>> plate.wellname_to_index(“A1”, direction=”column”) # 9 (8x12 plate)

wells_grouped_by(data_field=None, key=None, sort_keys=False, ignore_none=False, direction_of_occurence='row')[source]

Return wells grouped by key.

wells_sorted_by(sortkey)[source]

Return wells sorted by sortkey

class constrain.lab.containers_wells_picklists.Plate2x4(name=None, wells_data=None, plate_data=None)[source]

Bases: Plate

Class for 8-well (2 x 4) plates such as colony plating plates

num_columns = 4
num_rows = 2
class constrain.lab.containers_wells_picklists.Plate96(name=None, wells_data=None, plate_data=None)[source]

Bases: Plate

Base class for standard 96-well plates

num_columns = 12
num_rows = 8
class constrain.lab.containers_wells_picklists.Transfer(source_well, destination_well, volume, data=None)[source]

Bases: object

Class representing a transfer from a source well to a destination well.

Parameters:
  • source_well – A Well object from which to transfer.

  • destination_well – A Well object to which to transfer.

  • volume – Volume to be transferred, expressed in liters.

  • data – A dict containing any useful information about the transfer. This information can be used later e.g. as parameters for the transfer when exporting a picklist.

apply()[source]
to_flowbot_instructions()[source]
Return Flowbot instructions: i.e

source, destination, volume # 4:A3, 4:A6, 20 # 3:A1, 7, 50.7 # 2:A, 2:B-F, 100

.

to_plain_string()[source]

Return “Transfer {volume}L from {source_well} into {dest_well}”.

to_short_string()[source]

Return “Transfer {volume}L {source_well} -> {dest_well}”.

with_new_volume(new_volume)[source]

Return a version of the transfer with a new volume.

exception constrain.lab.containers_wells_picklists.TransferError[source]

Bases: ValueError

class constrain.lab.containers_wells_picklists.Well(plate, row, column, name, data=None)[source]

Bases: object

Generic class for a well.

Parameters:
  • plate – The plate on which the well is located

  • row – The well’s row (a number, starting from 0)

  • column – The well’s column (a number, starting from 0)

  • name – The well’s name, for instance “A1”

  • data – A dictionary storing data on the well, used in algorithms and reports.

add_content(components_quantities, volume=None, unit_volume='L')[source]

Add content to well.

Parameters:
  • components_quantities – Dictionary of components and quantities (default: gram). Example {“Compound_1”: 5}.

  • volume – Volume (default: liter).

  • unit_volume – Unit of volume (default: liter). Options: liter (L), milliliter (mL), microliter (uL), nanoliter (nL).

capacity = None
property coordinates

Return (well.row, well.column).

dead_volume_per_transfer_class = None
empty_completely()[source]

Empty the well.

index_in_plate(direction='row')[source]

Return the index of the well in the plate.

is_after(other, direction='row')[source]

Return whether this well is located strictly after the other well.

Example: iterate over all free wells after the last non-free well:

>>> direction = 'row'
>>> last_occupied_well = plate.last_nonempty_well(direction=direction)
>>> free_wells = (w for w in plate.iter_wells(direction=direction)
>>>               if w.is_after(last_occupied_well))
>>> for well in free_wells: ...
property is_empty

Return true if the well’s volume is 0.

iterate_sources_tree()[source]

Iterate through the tree of sources.

pretty_summary()[source]

Return a summary string of the well.

subtract_content(components_quantities, volume=0)[source]

Subtract content from well.

to_dict()[source]

Convert well to dict

property volume

Return volume.

class constrain.lab.containers_wells_picklists.WellContent(quantities=None, volume=0)[source]

Bases: object

Class to represent the volume and quantities of a well.

Having the well content represented as a separate object makes it possible to have several wells share the same content, e.g. in throughs.

components_as_string(separator=' ')[source]

Return a string representation of what’s in the well mix.

concentration(component=None, default=0)[source]

Return concentration of component.

make_empty()[source]

Empty the well.

to_dict()[source]

Return a dict {volume: 0.0001, quantities: {…:…}}.

constrain.lab.containers_wells_picklists.compute_rows_columns(num_wells)[source]

Convert 96->(8,12), 384->(16,24), etc.

constrain.lab.containers_wells_picklists.coordinates_to_wellname(coords)[source]

Convert (1,1)->A1, (4,3)->D3, (12, 12)->H12, etc.

constrain.lab.containers_wells_picklists.index_to_row_column(index, num_wells, direction='row')[source]
constrain.lab.containers_wells_picklists.index_to_wellname(index, num_wells, direction='row')[source]

Convert e.g. 1..96 into A1..H12

Parameters:
  • index (int) – the index of the well

  • num_wells (int) – number of wells on the plate

  • direction (str) – the direction of counting. Either “row” or “column”.

constrain.lab.containers_wells_picklists.number_to_rowname(number)[source]

Convert 1->A 26->Z 27->AA etc.

constrain.lab.containers_wells_picklists.replace_nans_in_dict(dictionary, replace_by='null')[source]

Replace NaNs in a dictionary with a string.

Parameters:
  • dictionary (dict) – the dictionary

  • replace_by (str) – replacement

constrain.lab.containers_wells_picklists.rowname_to_number(name)[source]

Convert A->1 Z->26 AA->27 etc.

constrain.lab.containers_wells_picklists.wellname_to_coordinates(wellname)[source]

Convert A1->(1,1), H11->(8, 11), etc.

constrain.lab.containers_wells_picklists.wellname_to_index(wellname, num_wells, direction='row')[source]

Convert e.g. A1..H12 into 1..96 direction is either row for A1 A2 A3… or column for A1 B1 C1 D1 etc.

Parameters:
  • wellname – the name of the well

  • num_wells (int) – number of wells on the plate

  • direction (str) – the direction of counting. Either “row” or “column”.

Robot assembly module

A module to for automating biological assemblies with robots

class constrain.lab.robot_assembly.LiquidHandler[source]

Bases: Transfer

This class is a subclass of the synbiopython Transfer class and be used to make flowbot instructions.

to_flowbot_instructions()[source]
Return Flowbot instructions: i.e

source, destination, volume # 4:A3, 4:A6, 20 # 3:A1, 7, 50.7 # 2:A, 2:B-F, 100

.

class constrain.lab.robot_assembly.RobotAssembly(Pandas_dataframe_PCR, F_primers: list, R_primers: list, Templates: list)[source]

Bases: object

Class to generate instructions for robots on demand.

Parameters

F_primerslist

list of forward primers

R_primers :list

list of reverse primers

Templateslist

list of templates

Returns:

Methods include printing robot- excecutable intructions.

Return type:

RobotAssembly object.

FlowbotInstructionsToCSV()[source]

Prints flowbot instructions to csv format

PlatesToExcelFile()[source]

Returns an excel file of the plate setup that needs to be made before the flowbot can operate

print_well_df_to_string()[source]

Prints Pandas dataframe in string format

constrain.lab.robot_assembly.make_virtual_plates_fromDF(f_primers: list, r_primers: list, templates: list, Dataframe_with_PCR_contents)[source]

This function can make virtual plates from lists of primers and templates.The Pandas DataFrame is used to calculate how much pcr and h2o is needed for the reactions.

Parameters:
  • f_primers (list) – list of forward primers

  • r_primers (list) – list of reverse primers

  • templates (list) – list of templates

  • Dataframe_with_PCR_contents (pandas.DataFrame) – dataframe with a PCR scheme.

Return type:

Virtual 96 plates as containers.

constrain.lab.robot_assembly.picklist_from_plates(F_primer_plate, R_primer_plate, Templates_plate, MM_H20_plate, PCR_dataframe)[source]

This function can generate picklist from virtual plates and pandas dataframe with PCR components

constrain.lab.robot_assembly.well_keys_96(row=True)[source]

If true it generates keys for a 96 well plate by row. else it does it by column

Parameters:

row (bool) – if true it will generate keys horisontally for a 96 well plate. Else vertically.

Returns:

keys – list of keys i.e [‘A1’, ‘A2’, ‘A3’,..]

Return type:

list

Transformation module

This part of the lab module is used for making transformations

constrain.lab.transformation.ODtime(initialOD: float, time: float, td: float = 0.5)[source]

Calculates the OD based on doupling time. :param initialOD: in OD :type initialOD: float :param time: in hours :type time: float :param td: doupling time i.e. td in h^-1 :type td: float

Returns:

OD – the OD after a certain time()

Return type:

float

constrain.lab.transformation.calculate_volume_and_total_concentration(amplicons, amplicon_parts_amounts_total, n=1)[source]

Calculates the volume and total concentration of a list of DNA parts.Parameters

ampliconslist

A list of amplicon objects

amplicon_parts_amounts_totaldict

A dictionary of amplicon names and their respective total amounts

nint (optional)

Gives the option of multiplying the volume is needed. Optional set to 1.

returns:
  • volumes (list) – List of volumes of each amplicon

  • ngs (list) – List of ngs of each amplicon

  • total_conc (float) – Total concentration of all amplicons

constrain.lab.transformation.ng_to_nmol(ng: float, bp: float)[source]

Calculates nanogram to nanomol for transformation mixes.

To do a transformation it is important to have the right ratio of plasmid to insert. In other words this is done by calculating the nanomolar ratios and this tool can do that

Parameters:
  • ng (float) – eg. nanogram

  • param (float) – eg. number of basepairs. Can also be an int

Returns:

ng_to_nmol

Return type:

float

Note

It calculates the nmol in the following way: nmol = ng/(bp*650)

constrain.lab.transformation.pool_parts(amplicons: list, part_names: list, part_amounts: list, pool_names: list, pool_lengths) dict[source]

Pools amplicon parts and returns a dictionary of pooled volumes.

Parameters:
  • amplicons (list) – List of amplicon objects.

  • part_names (list) – List of part names.

  • part_amounts (list) – List of amounts of each part.

  • pool_names (list) – List of pool names.

  • pool_lengths (list) – List of pool lengths.

Returns:

pooled_volumes – Dictionary containing the pooled volumes for each amplicon part.

Return type:

dict

constrain.lab.transformation.print_pooled_parts(pooled_volumes)[source]

Prints the pooled parts and calculated concentrations.

Parameters:

pooled_volumes (dict) – Dictionary containing the pooled volumes for each amplicon part.

Return type:

None

constrain.lab.transformation.time_to_inculate(initialOD=0.0025, td=0.4, verbose=False, transformation_time: int = 12)[source]
Calculates when a starter culture is ready to be inoculated

with a transformation mixture.

Parameters:
  • initialOD (float) –

  • td (float) – is doubling time

  • transformation_time (int) – The time you want to transform

  • verbose (Bool) – Provides extra information

Return type:

A plot of cell growth at different td

Notes

This is used to calculate when the cells should be used for transformation. For example: OD_1 = 1 * 10^7 cells / ml For a succesfull S.cerevisiae transformation between 1 to 2 × 10^7 cells/ml should be used Normal doupling time is between 3-6 hours

constrain.lab.transformation.transformation_mix(reaction_names, reaction_participants, wanted_amounts, water_dna_p_reac, media='')[source]
This function makes a pandas dataframe of the parts(their location)

that needs to be put into the transformation mixes

Parameters:
  • reaction_names (list) – list of reaction names

  • reaction_participants (list) – list of pydna.Dseqrecord objects of Bio.seqrecord objects

  • wanted_concentrations (dict) – dict of the names of the reactants with their calculated nmol

  • water_dna_p_reac (int) – the amount of water wanted for the reaction

  • media (list) – list of names of the media used. e.g. [‘LB_AMP’]

Returns:

with a transformation scheme showing which parts should be mixed for each reaction including positive and negative controls.

Return type:

pandas.DataFrame

Examples

# 1. Mention which reacion names you have reaction_names = [“insert”, “n.ctr”, “n.ctr”, “n.ctr”, “p. ctr”]

# 2. Add reaction reaction_participants reaction_participants = [[vector, gRNA1_pcr_prod,gRNA2_pcr_prod], #the insert we want

[vector], #negative control [gRNA1_pcr_prod], #negative control [gRNA2_pcr_prod], #negative control [LEU_plasmid]] #positive control

# 2. Calculate nmol: nmol_vector = ng_to_nmol(ng = 15, bp = len(vector)) nmol_gRNA = ng_to_nmol(ng = 30, bp = len(gRNA1_pcr_prod)) nmol_pctr = ng_to_nmol(ng = 10, bp = len(LEU_plasmid))

# 3. Add the concentrations wanted_concentrations = {‘p0056(pESC-LEU-ccdB-USER)’ : nmol_vector,

‘ATF1’ : nmol_gRNA, ‘CroCPR’ : nmol_gRNA, ‘LEU_plasmid’ : nmol_pctr}

# 4. what media the transformants are plated on (5 transformations here) media = [‘LB_AMP’] * 5

# 5. initate the function transformation_mix(reaction_names, reaction_participants, wanted_amounts = (wanted_concentrations, water_dna_p_reac = 7, media = media)

Returns:

#these are freezer locations

name l4_I06 l4_I07 l4_I08 p1_F06 water plate on

0 insert 0.1 0.6 0.6 NaN 5.7 LB_AMP 1 n.ctr 0.1 NaN NaN NaN 6.9 LB_AMP 2 n.ctr NaN 0.6 NaN NaN 6.4 LB_AMP 3 n.ctr NaN NaN 0.6 NaN 6.4 LB_AMP 4 p. ctr NaN NaN NaN 0.1 6.9 LB_AMP

constrain.lab.transformation.transformation_partitipants(reaction_participants, amnt=0.0005, sgRNA_plasmid_name=None, sgRNA_plasmid_conc=None)[source]

Returns a dict with the µl amounts needed in a transformation reaction.

Parameters:
  • reaction_participants (list of list of Dseqrecord) – List of lists of Dseqrecord objects representing the reaction participants.

  • amnt (float, optional) – Amount in µl of the reagents other than sgRNA_plasmid_name. Default is 0.0005.

  • sgRNA_plasmid_name (str, optional) – Name of the sgRNA plasmid. If not provided, amnt is used for all reaction participants.

  • sgRNA_plasmid_conc (float, optional) – Concentration in µl of the sgRNA plasmid. If not provided, amnt is used for all reaction participants.

Returns:

Dict with the µl amounts needed for the transformation reaction, with keys being the names of the reaction participants and values being the corresponding µl amounts.

Return type:

dict

constrain.lab.transformation.wanted_mass(wanted_moles, size)[source]
Parameters:
  • wanted_moles (int) – wanted moles in nmol

  • size (int) – size in bp

Returns:

w_mass_rounded – in ng. Mass wanted for the reaction.

Return type:

int

constrain.lab.transformation.wanted_volume(wanted_mass, actual_concentration)[source]
Parameters:
  • wanted_mass (int) – wanted mass in ng

  • actual_concentration (int) – actual_concentration in ng/ul

Returns:

wanted_volume_rounded – return in ul

Return type:

int