pydna package

Contents

pydna package#

copyright:

Copyright 2013-2023 by Björn Johansson. All rights reserved.

license:

This code is part of the pydna package, governed by the license in LICENSE.txt that should be included as part of this package.

pydna#

Pydna is a python package providing code for simulation of the creation of recombinant DNA molecules using molecular biology techniques. Development of pydna happens in this Github repository.

Provided:
  1. PCR simulation

  2. Assembly simulation based on shared identical sequences

  3. Primer design for amplification of a given sequence

  4. Automatic design of primer tails for Gibson assembly or homologous recombination.

  5. Restriction digestion and cut&paste cloning

  6. Agarose gel simulation

  7. Download sequences from Genbank

  8. Parsing various sequence formats including the capacity to handle broken Genbank format

pydna package layout#

The most important modules and how to import functions or classes from them are listed below. Class names starts with a capital letter, functions with a lowercase letter:

from pydna.module import function
from pydna.module import Class

Example: from pydna.gel import Gel

pydna
   ├── amplify
   │         ├── Anneal
   │         └── pcr
   ├── assembly
   │          └── Assembly
   ├── design
   │        ├── assembly_fragments
   │        └── primer_design
   ├── download
   │          └── download_text
   ├── dseqrecord
   │            └── Dseqrecord
   ├── gel
   │     └── Gel
   ├── genbank
   │         ├── genbank
   │         └── Genbank
   ├── parsers
   │         ├── parse
   │         └── parse_primers
   └── readers
             ├── read
             └── read_primers

How to use the documentation#

Documentation is available as docstrings provided in the source code for each module. These docstrings can be inspected by reading the source code directly. See further below on how to obtain the code for pydna.

In the python shell, use the built-in help function to view a function’s docstring:

>>> from pydna import readers
>>> help(readers.read)
...

The doctrings are also used to provide an automaticly generated reference manual available online at read the docs.

Docstrings can be explored using IPython, an advanced Python shell with TAB-completion and introspection capabilities. To see which functions are available in pydna, type pydna.<TAB> (where <TAB> refers to the TAB key). Use pydna.open_config_folder?<ENTER>`to view the docstring or `pydna.open_config_folder??<ENTER> to view the source code.

In the Spyder IDE it is possible to place the cursor immediately before the name of a module,class or function and press ctrl+i to bring up docstrings in a separate window in Spyder

Code snippets are indicated by three greater-than signs:

>>> x=41
>>> x=x+1
>>> x
42

pydna source code#

The pydna source code is available on Github.

How to get more help#

Please join the Google group for pydna, this is the preferred location for help. If you find bugs in pydna itself, open an issue at the Github repository.

Examples of pydna in use#

See this repository for a collection of

examples.

pydna.get_env()[source]#

Print a an ascii table containing all environmental variables.

Pydna related variables have names that starts with pydna_

Ascii-art logotype of pydna.

Submodules#

pydna.all module#

This module provide most pydna functionality in the local namespace.

Example

>>> from pydna.all import *
>>> Dseq("aaa")
Dseq(-3)
aaa
ttt
>>> Dseqrecord("aaa")
Dseqrecord(-3)
>>> from pydna.all import __all__
>>> __all__
['Anneal', 'pcr', 'Assembly', 'genbank', 'Genbank', 'download_text', 'Dseqrecord',
'Dseq', 'read', 'read_primer', 'parse', 'parse_primers', 'primer_design', 'assembly_fragments', 'eq', 'gbtext_clean']
>>>
class pydna.all.Anneal(primers, template, limit=13, **kwargs)[source]#

Bases: object

The Anneal class has the following important attributes:

forward_primers#

Description of forward_primers.

Type:

list

reverse_primers#

Description of reverse_primers.

Type:

list

template#

A copy of the template argument. Primers annealing sites has been added as features that can be visualized in a seqence editor such as ApE.

Type:

Dseqrecord

limit#

The limit of PCR primer annealing, default is 13 bp.

Type:

int, optional

property products#
report()#

returns a short report describing if or where primer anneal on the template.

pydna.all.pcr(*args, **kwargs) Amplicon[source]#

pcr is a convenience function for the Anneal class to simplify its usage, especially from the command line. If more than one or no PCR product is formed, a ValueError is raised.

args is any iterable of Dseqrecords or an iterable of iterables of Dseqrecords. args will be greedily flattened.

Parameters:
  • args (iterable containing sequence objects) – Several arguments are also accepted.

  • limit (int = 13, optional) – limit length of the annealing part of the primers.

Notes

sequences in args could be of type:

  • string

  • Seq

  • SeqRecord (or subclass)

  • Dseqrecord (or sublcass)

The last sequence will be assumed to be the template while all preceeding sequences will be assumed to be primers.

This is a powerful function, use with care!

Returns:

product – An pydna.amplicon.Amplicon object representing the PCR product. The direction of the PCR product will be the same as for the template sequence.

Return type:

Amplicon

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.readers import read
>>> from pydna.amplify import pcr
>>> from pydna.primer import Primer
>>> template = Dseqrecord("tacactcaccgtctatcattatctactatcgactgtatcatctgatagcac")
>>> from Bio.SeqRecord import SeqRecord
>>> p1 = Primer("tacactcaccgtctatcattatc")
>>> p2 = Primer("cgactgtatcatctgatagcac").reverse_complement()
>>> pcr(p1, p2, template)
Amplicon(51)
>>> pcr([p1, p2], template)
Amplicon(51)
>>> pcr((p1,p2,), template)
Amplicon(51)
>>>
class pydna.all.Assembly(frags: List[Dseqrecord], limit: int = 25, algorithm: Callable[[str, str, int], List[Tuple[int, int, int]]] = common_sub_strings)[source]#

Bases: object

Assembly of a list of linear DNA fragments into linear or circular constructs. The Assembly is meant to replace the Assembly method as it is easier to use. Accepts a list of Dseqrecords (source fragments) to initiate an Assembly object. Several methods are available for analysis of overlapping sequences, graph construction and assembly.

Parameters:
  • fragments (list) – a list of Dseqrecord objects.

  • limit (int, optional) – The shortest shared homology to be considered

  • algorithm (function, optional) – The algorithm used to determine the shared sequences.

  • max_nodes (int) – The maximum number of nodes in the graph. This can be tweaked to manage sequences with a high number of shared sub sequences.

Examples

>>> from pydna.assembly import Assembly
>>> from pydna.dseqrecord import Dseqrecord
>>> a = Dseqrecord("acgatgctatactgCCCCCtgtgctgtgctcta")
>>> b = Dseqrecord("tgtgctgtgctctaTTTTTtattctggctgtatc")
>>> c = Dseqrecord("tattctggctgtatcGGGGGtacgatgctatactg")
>>> x = Assembly((a,b,c), limit=14)
>>> x
Assembly
fragments....: 33bp 34bp 35bp
limit(bp)....: 14
G.nodes......: 6
algorithm....: common_sub_strings
>>> x.assemble_circular()
[Contig(o59), Contig(o59)]
>>> x.assemble_circular()[0].seq.watson
'acgatgctatactgCCCCCtgtgctgtgctctaTTTTTtattctggctgtatcGGGGGt'
assemble_circular(**kwargs)#
assemble_linear(**kwargs)#
pydna.all.genbank(accession: str = 'CS570233.1', *args, **kwargs) GenbankRecord[source]#

Download a genbank nuclotide record.

This function takes the same paramenters as the :func:pydna.genbank.Genbank.nucleotide method. The email address stored in the pydna_email environment variable is used. The easiest way set this permanantly is to edit the pydna.ini file. See the documentation of pydna.open_config_folder()

if no accession is given, a very short Genbank entry is used as an example (see below). This can be useful for testing the connection to Genbank.

Please note that this result is also cached by default by settings in the pydna.ini file. See the documentation of pydna.open_config_folder()

LOCUS       CS570233                  14 bp    DNA     linear   PAT 18-MAY-2007
DEFINITION  Sequence 6 from Patent WO2007025016.
ACCESSION   CS570233
VERSION     CS570233.1
KEYWORDS    .
SOURCE      synthetic construct
  ORGANISM  synthetic construct
            other sequences; artificial sequences.
REFERENCE   1
  AUTHORS   Shaw,R.W. and Cottenoir,M.
  TITLE     Inhibition of metallo-beta-lactamase by double-stranded dna
  JOURNAL   Patent: WO 2007025016-A1 6 01-MAR-2007;
            Texas Tech University System (US)
FEATURES             Location/Qualifiers
     source          1..14
                     /organism="synthetic construct"
                     /mol_type="unassigned DNA"
                     /db_xref="taxon:32630"
                     /note="This is a 14bp aptamer inhibitor."
ORIGIN
        1 atgttcctac atga
//
class pydna.all.Genbank(users_email: str, *, tool: str = 'pydna')[source]#

Bases: object

Class to facilitate download from genbank. It is easier and quicker to use the pydna.genbank.genbank() function directly.

Parameters:

users_email (string) – Has to be a valid email address. You should always tell Genbanks who you are, so that they can contact you.

Examples

>>> from pydna.genbank import Genbank
>>> gb=Genbank("bjornjobb@gmail.com")
>>> rec = gb.nucleotide("LP002422.1")   # <- entry from genbank
>>> print(len(rec))
1
nucleotide(item: str, seq_start: int | None = None, seq_stop: int | None = None, strand: Literal[1, 2] = 1) GenbankRecord[source]#

This method downloads a genbank nuclotide record from genbank. This method is cached by default. This can be controlled by editing the pydna_cached_funcs environment variable. The best way to do this permanently is to edit the edit the pydna.ini file. See the documentation of pydna.open_config_folder()

Item is a string containing one genbank accession number for a nucleotide file. Genbank nucleotide accession numbers have this format:

A12345 = 1 letter + 5 numerals
AB123456 = 2 letters + 6 numerals

The accession number is sometimes followed by a point and version number

BK006936.2

Item can also contain optional interval information in the following formats:

BK006936.2 REGION: complement(613900..615202)
NM_005546 REGION: 1..100
NM_005546 REGION: complement(1..100)
21614549:1-100
21614549:c100-1
21614549 1-100
21614549 c100-1

It is useful to set an interval for large genbank records to limit the download time. The items above containing interval information and can be obtained directly by looking up an entry in Genbank and setting the Change region shown on the upper right side of the page. The ACCESSION line of the displayed Genbank file will have the formatting shown.

Alternatively, seq_start and seq_stop can be set explicitly to the sequence intervals to be downloaded.

If strand is 2. “c”, “C”, “crick”, “Crick”, “antisense”,”Antisense”, “2”, 2, “-” or “-1”, the antisense (Crick) strand is returned, otherwise the sense (Watson) strand is returned.

Result is returned as a pydna.genbankrecord.GenbankRecord object.

References

pydna.all.download_text(url)[source]#

docstring.

class pydna.all.Dseqrecord(record, *args, circular=None, n=5e-14, source=None, **kwargs)[source]#

Bases: SeqRecord

Dseqrecord is a double stranded version of the Biopython SeqRecord [1] class. The Dseqrecord object holds a Dseq object describing the sequence. Additionally, Dseqrecord hold meta information about the sequence in the from of a list of SeqFeatures, in the same way as the SeqRecord does.

The Dseqrecord can be initialized with a string, Seq, Dseq, SeqRecord or another Dseqrecord. The sequence information will be stored in a Dseq object in all cases.

Dseqrecord objects can be read or parsed from sequences in FASTA, EMBL or Genbank formats. See the pydna.readers and pydna.parsers modules for further information.

There is a short representation associated with the Dseqrecord. Dseqrecord(-3) represents a linear sequence of length 2 while Dseqrecord(o7) represents a circular sequence of length 7.

Dseqrecord and Dseq share the same concept of length. This length can be larger than each strand alone if they are staggered as in the example below.

<-- length -->
GATCCTTT
     AAAGCCTAG
Parameters:
  • record (string, Seq, SeqRecord, Dseq or other Dseqrecord object) – This data will be used to form the seq property

  • circular (bool, optional) – True or False reflecting the shape of the DNA molecule

  • linear (bool, optional) – True or False reflecting the shape of the DNA molecule

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("aaa")
>>> a
Dseqrecord(-3)
>>> a.seq
Dseq(-3)
aaa
ttt
>>> from pydna.seq import Seq
>>> b=Dseqrecord(Seq("aaa"))
>>> b
Dseqrecord(-3)
>>> b.seq
Dseq(-3)
aaa
ttt
>>> from Bio.SeqRecord import SeqRecord
>>> c=Dseqrecord(SeqRecord(Seq("aaa")))
>>> c
Dseqrecord(-3)
>>> c.seq
Dseq(-3)
aaa
ttt

References

add_feature(x=None, y=None, seq=None, type_='misc', strand=1, *args, **kwargs)[source]#

Add a feature of type misc to the feature list of the sequence.

Parameters:
  • x (int) – Indicates start of the feature

  • y (int) – Indicates end of the feature

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a=SeqRecord("atgtaa")
>>> a.features
[]
>>> a.add_feature(2,4)
>>> a.features
[SeqFeature(SimpleLocation(ExactPosition(2), ExactPosition(4), strand=1), type='misc', qualifiers=...)]
apply_cut(left_cut, right_cut)[source]#
cas9(RNA: str)[source]#

docstring.

property circular#

The circular property can not be set directly. Use looped()

copy_fasta_to_clipboard()[source]#

docstring.

copy_gb_to_clipboard()[source]#

docstring.

cut(*enzymes)[source]#

Digest a Dseqrecord object with one or more restriction enzymes.

returns a list of linear Dseqrecords. If there are no cuts, an empty list is returned.

See also Dseq.cut() :param enzymes: A Bio.Restriction.XXX restriction object or iterable of such. :type enzymes: enzyme object or iterable of such objects

Returns:

Dseqrecord_frags – list of Dseqrecord objects formed by the digestion

Return type:

list

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggatcc")
>>> from Bio.Restriction import BamHI
>>> a.cut(BamHI)
(Dseqrecord(-5), Dseqrecord(-5))
>>> frag1, frag2 = a.cut(BamHI)
>>> frag1.seq
Dseq(-5)
g
cctag
>>> frag2.seq
Dseq(-5)
gatcc
    g
cutters(batch: RestrictionBatch = None)[source]#

docstring.

extract_feature(n)[source]#

Extracts a feature and creates a new Dseqrecord object.

Parameters:

n (int) – Indicates the feature to extract

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("atgtaa")
>>> a.add_feature(2,4)
>>> b=a.extract_feature(0)
>>> b
Dseqrecord(-2)
>>> b.seq
Dseq(-2)
gt
ca
figure(feature=0, highlight='\x1b[48;5;11m', plain='\x1b[0m')[source]#

docstring.

find(other)[source]#
find_aa(other)#
>>> from pydna.dseqrecord import Dseqrecord
>>> s=Dseqrecord("atgtacgatcgtatgctggttatattttag")
>>> s.seq.translate()
Seq('MYDRMLVIF*')
>>> "RML" in s
True
>>> "MMM" in s
False
>>> s.seq.rc().translate()
Seq('LKYNQHTIVH')
>>> "QHT" in s.rc()
True
>>> "QHT" in s
False
>>> slc = s.find_aa("RML")
>>> slc
slice(9, 18, None)
>>> s[slc]
Dseqrecord(-9)
>>> code = s[slc].seq
>>> code
Dseq(-9)
cgtatgctg
gcatacgac
>>> code.translate()
Seq('RML')
find_aminoacids(other)[source]#
>>> from pydna.dseqrecord import Dseqrecord
>>> s=Dseqrecord("atgtacgatcgtatgctggttatattttag")
>>> s.seq.translate()
Seq('MYDRMLVIF*')
>>> "RML" in s
True
>>> "MMM" in s
False
>>> s.seq.rc().translate()
Seq('LKYNQHTIVH')
>>> "QHT" in s.rc()
True
>>> "QHT" in s
False
>>> slc = s.find_aa("RML")
>>> slc
slice(9, 18, None)
>>> s[slc]
Dseqrecord(-9)
>>> code = s[slc].seq
>>> code
Dseq(-9)
cgtatgctg
gcatacgac
>>> code.translate()
Seq('RML')
format(f='gb')[source]#

Returns the sequence as a string using a format supported by Biopython SeqIO [2]. Default is “gb” which is short for Genbank.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> x=Dseqrecord("aaa")
>>> x.annotations['date'] = '02-FEB-2013'
>>> x
Dseqrecord(-3)
>>> print(x.format("gb"))
LOCUS       name                       3 bp    DNA     linear   UNK 02-FEB-2013
DEFINITION  description.
ACCESSION   id
VERSION     id
KEYWORDS    .
SOURCE      .
  ORGANISM  .
            .
FEATURES             Location/Qualifiers
ORIGIN
        1 aaa
//

References

classmethod from_SeqRecord(record: SeqRecord, *args, circular=None, n=5e-14, **kwargs)[source]#
classmethod from_string(record: str = '', *args, circular=False, n=5e-14, **kwargs)[source]#

docstring.

history()[source]#

Returns a string representation of the cloning history of the sequence. Returns an empty string if the sequence has no source.

Check the documentation notebooks for extensive examples.

Returns:

str

Return type:

A string representation of the cloning history of the sequence.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.assembly2 import gibson_assembly
>>> fragments = [
...    Dseqrecord("TTTTacgatAAtgctccCCCC", circular=False, name="fragment1"),
...    Dseqrecord("CCCCtcatGGGG", circular=False, name="fragment2"),
...    Dseqrecord("GGGGatataTTTT", circular=False, name="fragment3"),
... ]
>>> product, *_ = gibson_assembly(fragments, limit=4)
>>> product.name = "product_name"
>>> print(product.history())
╙── product_name (Dseqrecord(o34))
    └─╼ GibsonAssemblySource
        ├─╼ fragment1 (Dseqrecord(-21))
        ├─╼ fragment2 (Dseqrecord(-12))
        └─╼ fragment3 (Dseqrecord(-13))
linearize(*enzymes)[source]#

Similar to :func:cut.

Throws an exception if there is not excactly one cut i.e. none or more than one digestion products.

looped()[source]#

Circular version of the Dseqrecord object.

The underlying linear Dseq object has to have compatible ends.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("aaa")
>>> a
Dseqrecord(-3)
>>> b=a.looped()
>>> b
Dseqrecord(o3)
>>>
lower()[source]#
>>> from pydna.dseqrecord import Dseqrecord
>>> my_seq = Dseqrecord("aAa")
>>> my_seq.seq
Dseq(-3)
aAa
tTt
>>> upper = my_seq.upper()
>>> upper.seq
Dseq(-3)
AAA
TTT
>>> lower = my_seq.lower()
>>> lower
Dseqrecord(-3)
>>>
Returns:

Dseqrecord object in lowercase

Return type:

Dseqrecord

m()[source]#

This method returns the mass of the DNA molecule in grams. This is calculated as the product between the molecular weight of the Dseq object and the

map_trace_files(pth, limit=25)[source]#
n_cutters(n=3, batch: RestrictionBatch = None)[source]#

docstring.

no_cutters(batch: RestrictionBatch = None)[source]#

docstring.

number_of_cuts(*enzymes)[source]#

The number of cuts by digestion with the Restriction enzymes contained in the iterable.

once_cutters(batch: RestrictionBatch = None)[source]#

docstring.

orfs(minsize=300)[source]#

docstring.

orfs_to_features(minsize=300)[source]#

docstring.

rc()#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
reverse_complement()[source]#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
seguid()[source]#

Url safe SEGUID for the sequence.

This checksum is the same as seguid but with base64.urlsafe encoding instead of the normal base64. This means that the characters + and / are replaced with - and _ so that the checksum can be part of a URL.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a = Dseqrecord("aa")
>>> a.seguid()
'ldseguid=TEwydy0ugvGXh3VJnVwgtxoyDQA'
shifted(shift)[source]#

Circular Dseqrecord with a new origin <shift>.

This only works on circular Dseqrecords. If we consider the following circular sequence:

GAAAT   <-- watson strand
CTTTA   <-- crick strand

The T and the G on the watson strand are linked together as well as the A and the C of the of the crick strand.

if shift is 1, this indicates a new origin at position 1:

new origin at the | symbol:

G|AAAT
C|TTTA

new sequence:

AAATG
TTTAC

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("aaat",circular=True)
>>> a
Dseqrecord(o4)
>>> a.seq
Dseq(o4)
aaat
ttta
>>> b=a.shifted(1)
>>> b
Dseqrecord(o4)
>>> b.seq
Dseq(o4)
aata
ttat
source: Source | None = None#
synced(ref, limit=25)[source]#

This method returns a new circular sequence (Dseqrecord object), which has been rotated in such a way that there is maximum overlap between the sequence and ref, which may be a string, Biopython Seq, SeqRecord object or another Dseqrecord object.

The reason for using this could be to rotate a new recombinant plasmid so that it starts at the same position after cloning. See the example below:

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("gaat", circular=True)
>>> a.seq
Dseq(o4)
gaat
ctta
>>> d = a[2:] + a[:2]
>>> d.seq
Dseq(-4)
atga
tact
>>> insert=Dseqrecord("CCC")
>>> recombinant = (d+insert).looped()
>>> recombinant.seq
Dseq(o7)
atgaCCC
tactGGG
>>> recombinant.synced(a).seq
Dseq(o7)
gaCCCat
ctGGGta
terminal_transferase(nucleotides='a')[source]#

docstring.

tolinear()[source]#

Returns a linear, blunt copy of a circular Dseqrecord object. The underlying Dseq object has to be circular.

This method is deprecated, use slicing instead. See example below.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("aaa", circular = True)
>>> a
Dseqrecord(o3)
>>> b=a[:]
>>> b
Dseqrecord(-3)
>>>
twice_cutters(batch: RestrictionBatch = None)[source]#

docstring.

unique_cutters(batch: RestrictionBatch = None)[source]#

docstring.

upper()[source]#

Returns an uppercase copy. >>> from pydna.dseqrecord import Dseqrecord >>> my_seq = Dseqrecord(“aAa”) >>> my_seq.seq Dseq(-3) aAa tTt >>> upper = my_seq.upper() >>> upper.seq Dseq(-3) AAA TTT >>>

Returns:

Dseqrecord object in uppercase

Return type:

Dseqrecord

write(filename=None, f='gb')[source]#

Writes the Dseqrecord to a file using the format f, which must be a format supported by Biopython SeqIO for writing [3]. Default is “gb” which is short for Genbank. Note that Biopython SeqIO reads more formats than it writes.

Filename is the path to the file where the sequece is to be written. The filename is optional, if it is not given, the description property (string) is used together with the format.

If obj is the Dseqrecord object, the default file name will be:

<obj.locus>.<f>

Where <f> is “gb” by default. If the filename already exists and AND the sequence it contains is different, a new file name will be used so that the old file is not lost:

<obj.locus>_NEW.<f>

References

class pydna.all.Dseq(watson: str | bytes, crick: str | bytes | None = None, ovhg=None, circular=False, pos=0)[source]#

Bases: Seq

Dseq holds information for a double stranded DNA fragment.

Dseq also holds information describing the topology of the DNA fragment (linear or circular).

Parameters:
  • watson (str) – a string representing the watson (sense) DNA strand.

  • crick (str, optional) – a string representing the crick (antisense) DNA strand.

  • ovhg (int, optional) – A positive or negative number to describe the stagger between the watson and crick strands. see below for a detailed explanation.

  • linear (bool, optional) – True indicates that sequence is linear, False that it is circular.

  • circular (bool, optional) – True indicates that sequence is circular, False that it is linear.

Examples

Dseq is a subclass of the Biopython Seq object. It stores two strings representing the watson (sense) and crick(antisense) strands. two properties called linear and circular, and a numeric value ovhg (overhang) describing the stagger for the watson and crick strand in the 5’ end of the fragment.

The most common usage is probably to create a Dseq object as a part of a Dseqrecord object (see pydna.dseqrecord.Dseqrecord).

There are three ways of creating a Dseq object directly listed below, but you can also use the function Dseq.from_full_sequence_and_overhangs() to create a Dseq:

Only one argument (string):

>>> from pydna.dseq import Dseq
>>> Dseq("aaa")
Dseq(-3)
aaa
ttt

The given string will be interpreted as the watson strand of a blunt, linear double stranded sequence object. The crick strand is created automatically from the watson strand.

Two arguments (string, string):

>>> from pydna.dseq import Dseq
>>> Dseq("gggaaat","ttt")
Dseq(-7)
gggaaat
   ttt

If both watson and crick are given, but not ovhg an attempt will be made to find the best annealing between the strands. There are limitations to this. For long fragments it is quite slow. The length of the annealing sequences have to be at least half the length of the shortest of the strands.

Three arguments (string, string, ovhg=int):

The ovhg parameter is an integer describing the length of the crick strand overhang in the 5’ end of the molecule.

The ovhg parameter controls the stagger at the five prime end:

dsDNA       overhang

  nnn...    2
nnnnn...

 nnnn...    1
nnnnn...

nnnnn...    0
nnnnn...

nnnnn...   -1
 nnnn...

nnnnn...   -2
  nnn...

Example of creating Dseq objects with different amounts of stagger:

>>> Dseq(watson="agt", crick="actta", ovhg=-2)
Dseq(-7)
agt
  attca
>>> Dseq(watson="agt",crick="actta",ovhg=-1)
Dseq(-6)
agt
 attca
>>> Dseq(watson="agt",crick="actta",ovhg=0)
Dseq(-5)
agt
attca
>>> Dseq(watson="agt",crick="actta",ovhg=1)
Dseq(-5)
 agt
attca
>>> Dseq(watson="agt",crick="actta",ovhg=2)
Dseq(-5)
  agt
attca

If the ovhg parameter is specified a crick strand also needs to be supplied, otherwise an exception is raised.

>>> Dseq(watson="agt", ovhg=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pydna_/dsdna.py", line 169, in __init__
    else:
ValueError: ovhg defined without crick strand!

The shape of the fragment is set by circular = True, False

Note that both ends of the DNA fragment has to be compatible to set circular = True.

>>> Dseq("aaa","ttt")
Dseq(-3)
aaa
ttt
>>> Dseq("aaa","ttt",ovhg=0)
Dseq(-3)
aaa
ttt
>>> Dseq("aaa","ttt",ovhg=1)
Dseq(-4)
 aaa
ttt
>>> Dseq("aaa","ttt",ovhg=-1)
Dseq(-4)
aaa
 ttt
>>> Dseq("aaa", "ttt", circular = True , ovhg=0)
Dseq(o3)
aaa
ttt
>>> a=Dseq("tttcccc","aaacccc")
>>> a
Dseq(-11)
    tttcccc
ccccaaa
>>> a.ovhg
4
>>> b=Dseq("ccccttt","ccccaaa")
>>> b
Dseq(-11)
ccccttt
    aaacccc
>>> b.ovhg
-4
>>>

Coercing to string

>>> str(a)
'ggggtttcccc'

A Dseq object can be longer that either the watson or crick strands.

<-- length -->
GATCCTTT
     AAAGCCTAG

<-- length -->
      GATCCTTT
AAAGCCCTA

The slicing of a linear Dseq object works mostly as it does for a string.

>>> s="ggatcc"
>>> s[2:3]
'a'
>>> s[2:4]
'at'
>>> s[2:4:-1]
''
>>> s[::2]
'gac'
>>> from pydna.dseq import Dseq
>>> d=Dseq(s, circular=False)
>>> d[2:3]
Dseq(-1)
a
t
>>> d[2:4]
Dseq(-2)
at
ta
>>> d[2:4:-1]
Dseq(-0)


>>> d[::2]
Dseq(-3)
gac
ctg

The slicing of a circular Dseq object has a slightly different meaning.

>>> s="ggAtCc"
>>> d=Dseq(s, circular=True)
>>> d
Dseq(o6)
ggAtCc
ccTaGg
>>> d[4:3]
Dseq(-5)
CcggA
GgccT

The slice [X:X] produces an empty slice for a string, while this will return the linearized sequence starting at X:

>>> s="ggatcc"
>>> d=Dseq(s, circular=True)
>>> d
Dseq(o6)
ggatcc
cctagg
>>> d[3:3]
Dseq(-6)
tccgga
aggcct
>>>
T4(nucleotides=None) Dseq[source]#

Fill in five prime protruding ends and chewing back three prime protruding ends by a DNA polymerase providing both 5’-3’ DNA polymerase activity and 3’-5’ nuclease acitivty (such as T4 DNA polymerase). This can be done in presence of any combination of the four A, G, C or T. Removing one or more nucleotides can facilitate engineering of sticky ends. Default are all four nucleotides together.

Parameters:

nucleotides (str)

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("gatcgatc")
>>> a
Dseq(-8)
gatcgatc
ctagctag
>>> a.T4()
Dseq(-8)
gatcgatc
ctagctag
>>> a.T4("t")
Dseq(-8)
gatcgat
 tagctag
>>> a.T4("a")
Dseq(-8)
gatcga
  agctag
>>> a.T4("g")
Dseq(-8)
gatcg
   gctag
>>>
apply_cut(left_cut: Tuple[Tuple[int, int], AbstractCut | None | _cas], right_cut: Tuple[Tuple[int, int], AbstractCut | None | _cas]) Dseq[source]#

Extracts a subfragment of the sequence between two cuts.

For more detail see the documentation of get_cutsite_pairs.

Parameters:
Return type:

Dseq

Examples

>>> from Bio.Restriction import EcoRI
>>> from pydna.dseq import Dseq
>>> dseq = Dseq('aaGAATTCaaGAATTCaa')
>>> cutsites = dseq.get_cutsites([EcoRI])
>>> cutsites
[((3, -4), EcoRI), ((11, -4), EcoRI)]
>>> p1, p2, p3 = dseq.get_cutsite_pairs(cutsites)
>>> p1
(None, ((3, -4), EcoRI))
>>> dseq.apply_cut(*p1)
Dseq(-7)
aaG
ttCTTAA
>>> p2
(((3, -4), EcoRI), ((11, -4), EcoRI))
>>> dseq.apply_cut(*p2)
Dseq(-12)
AATTCaaG
    GttCTTAA
>>> p3
(((11, -4), EcoRI), None)
>>> dseq.apply_cut(*p3)
Dseq(-7)
AATTCaa
    Gtt
>>> dseq = Dseq('TTCaaGAA', circular=True)
>>> cutsites = dseq.get_cutsites([EcoRI])
>>> cutsites
[((6, -4), EcoRI)]
>>> pair = dseq.get_cutsite_pairs(cutsites)[0]
>>> pair
(((6, -4), EcoRI), ((6, -4), EcoRI))
>>> dseq.apply_cut(*pair)
Dseq(-12)
AATTCaaG
    GttCTTAA
cas9(RNA: str) Tuple[slice, ...][source]#

docstring.

cut(*enzymes: EnzymesType) Tuple[DseqType, ...][source]#

Returns a list of linear Dseq fragments produced in the digestion. If there are no cuts, an empty list is returned.

Parameters:

enzymes (enzyme object or iterable of such objects) – A Bio.Restriction.XXX restriction objects or iterable.

Returns:

frags – list of Dseq objects formed by the digestion

Return type:

list

Examples

>>> from pydna.dseq import Dseq
>>> seq=Dseq("ggatccnnngaattc")
>>> seq
Dseq(-15)
ggatccnnngaattc
cctaggnnncttaag
>>> from Bio.Restriction import BamHI,EcoRI
>>> type(seq.cut(BamHI))
<class 'tuple'>
>>> for frag in seq.cut(BamHI): print(repr(frag))
Dseq(-5)
g
cctag
Dseq(-14)
gatccnnngaattc
    gnnncttaag
>>> seq.cut(EcoRI, BamHI) ==  seq.cut(BamHI, EcoRI)
True
>>> a,b,c = seq.cut(EcoRI, BamHI)
>>> a+b+c
Dseq(-15)
ggatccnnngaattc
cctaggnnncttaag
>>>
cutsite_is_valid(cutsite: Tuple[Tuple[int, int], AbstractCut | None | _cas]) bool[source]#

Returns False if: - Cut positions fall outside the sequence (could be moved to Biopython) - Overhang is not double stranded - Recognition site is not double stranded or is outside the sequence - For enzymes that cut twice, it checks that at least one possibility is valid

cutters(batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch cutting sequence at least once.

exo1_end(n=1) DseqType[source]#

5’-3’ resection at the end (right side) of the molecule.

exo1_front(n=1) DseqType[source]#

5’-3’ resection at the start (left side) of the molecule.

fill_in(nucleotides: None | str = None) Dseq[source]#

Fill in of five prime protruding end with a DNA polymerase that has only DNA polymerase activity (such as exo-klenow [4]) and any combination of A, G, C or T. Default are all four nucleotides together.

Parameters:

nucleotides (str)

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("aaa", "ttt")
>>> a
Dseq(-3)
aaa
ttt
>>> a.fill_in()
Dseq(-3)
aaa
ttt
>>> b=Dseq("caaa", "cttt")
>>> b
Dseq(-5)
caaa
 tttc
>>> b.fill_in()
Dseq(-5)
caaag
gtttc
>>> b.fill_in("g")
Dseq(-5)
caaag
gtttc
>>> b.fill_in("tac")
Dseq(-5)
caaa
 tttc
>>> c=Dseq("aaac", "tttg")
>>> c
Dseq(-5)
 aaac
gttt
>>> c.fill_in()
Dseq(-5)
 aaac
gttt
>>>

References

find(sub: _SeqAbstractBaseClass | str | bytes, start=0, end=_sys.maxsize) int[source]#

This method behaves like the python string method of the same name.

Returns an integer, the index of the first occurrence of substring argument sub in the (sub)sequence given by [start:end].

Returns -1 if the subsequence is NOT found.

Parameters:
  • sub (string or Seq object) – a string or another Seq object to look for.

  • start (int, optional) – slice start.

  • end (int, optional) – slice end.

Examples

>>> from pydna.dseq import Dseq
>>> seq = Dseq("atcgactgacgtgtt")
>>> seq
Dseq(-15)
atcgactgacgtgtt
tagctgactgcacaa
>>> seq.find("gac")
3
>>> seq = Dseq(watson="agt",crick="actta",ovhg=-2)
>>> seq
Dseq(-7)
agt
  attca
>>> seq.find("taa")
2
five_prime_end() Tuple[str, str][source]#

Returns a tuple describing the structure of the 5’ end of the DNA fragment

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("aaa", "ttt")
>>> a
Dseq(-3)
aaa
ttt
>>> a.five_prime_end()
('blunt', '')
>>> a=Dseq("aaa", "ttt", ovhg=1)
>>> a
Dseq(-4)
 aaa
ttt
>>> a.five_prime_end()
("3'", 't')
>>> a=Dseq("aaa", "ttt", ovhg=-1)
>>> a
Dseq(-4)
aaa
 ttt
>>> a.five_prime_end()
("5'", 'a')
>>>
classmethod from_full_sequence_and_overhangs(full_sequence: str, crick_ovhg: int, watson_ovhg: int)[source]#

Create a linear Dseq object from a full sequence and the 3’ overhangs of each strand.

The order of the parameters is like this because the 3’ overhang of the crick strand is the one on the left side of the sequence.

Parameters:
  • full_sequence (str) – The full sequence of the Dseq object.

  • crick_ovhg (int) – The overhang of the crick strand in the 3’ end. Equivalent to Dseq.ovhg.

  • watson_ovhg (int) – The overhang of the watson strand in the 5’ end.

Returns:

A Dseq object.

Return type:

Dseq

Examples

>>> Dseq.from_full_sequence_and_overhangs('AAAAAA', crick_ovhg=2, watson_ovhg=2)
Dseq(-6)
  AAAA
TTTT
>>> Dseq.from_full_sequence_and_overhangs('AAAAAA', crick_ovhg=-2, watson_ovhg=2)
Dseq(-6)
AAAAAA
  TT
>>> Dseq.from_full_sequence_and_overhangs('AAAAAA', crick_ovhg=2, watson_ovhg=-2)
Dseq(-6)
  AA
TTTTTT
>>> Dseq.from_full_sequence_and_overhangs('AAAAAA', crick_ovhg=-2, watson_ovhg=-2)
Dseq(-6)
AAAA
  TTTT
classmethod from_representation(dsdna: str, *args, **kwargs)[source]#
classmethod from_string(dna: str, *args, circular=False, **kwargs)[source]#
get_cut_parameters(cut: Tuple[Tuple[int, int], AbstractCut | None | _cas] | None, is_left: bool) Tuple[int, int, int][source]#

For a given cut expressed as ((cut_watson, ovhg), enz), returns a tuple (cut_watson, cut_crick, ovhg).

  • cut_watson: see get_cutsites docs

  • cut_crick: equivalent of cut_watson in the crick strand

  • ovhg: see get_cutsites docs

The cut can be None if it represents the left or right end of the sequence. Then it will return the position of the watson and crick ends with respect to the “full sequence”. The is_left parameter is only used in this case.

get_cutsite_pairs(cutsites: List[Tuple[Tuple[int, int], AbstractCut | None | _cas]]) List[Tuple[None | Tuple[Tuple[int, int], AbstractCut | None | _cas], None | Tuple[Tuple[int, int], AbstractCut | None | _cas]]][source]#

Returns pairs of cutsites that render the edges of the resulting fragments.

A fragment produced by restriction is represented by a tuple of length 2 that may contain cutsites or None:

  • Two cutsites: represents the extraction of a fragment between those two cutsites, in that orientation. To represent the opening of a circular molecule with a single cutsite, we put the same cutsite twice.

  • None, cutsite: represents the extraction of a fragment between the left edge of linear sequence and the cutsite.

  • cutsite, None: represents the extraction of a fragment between the cutsite and the right edge of a linear sequence.

Parameters:

cutsites (list[tuple[tuple[int,int], _AbstractCut]])

Return type:

list[tuple[tuple[tuple[int,int], _AbstractCut]|None],tuple[tuple[int,int], _AbstractCut]|None]

Examples

>>> from Bio.Restriction import EcoRI
>>> from pydna.dseq import Dseq
>>> dseq = Dseq('aaGAATTCaaGAATTCaa')
>>> cutsites = dseq.get_cutsites([EcoRI])
>>> cutsites
[((3, -4), EcoRI), ((11, -4), EcoRI)]
>>> dseq.get_cutsite_pairs(cutsites)
[(None, ((3, -4), EcoRI)), (((3, -4), EcoRI), ((11, -4), EcoRI)), (((11, -4), EcoRI), None)]
>>> dseq = Dseq('TTCaaGAA', circular=True)
>>> cutsites = dseq.get_cutsites([EcoRI])
>>> cutsites
[((6, -4), EcoRI)]
>>> dseq.get_cutsite_pairs(cutsites)
[(((6, -4), EcoRI), ((6, -4), EcoRI))]
get_cutsites(*enzymes: EnzymesType) List[Tuple[Tuple[int, int], AbstractCut | None | _cas]][source]#

Returns a list of cutsites, represented represented as ((cut_watson, ovhg), enz):

  • cut_watson is a positive integer contained in [0,len(seq)), where seq is the sequence that will be cut. It represents the position of the cut on the watson strand, using the full sequence as a reference. By “full sequence” I mean the one you would get from str(Dseq).

  • ovhg is the overhang left after the cut. It has the same meaning as ovhg in the Bio.Restriction enzyme objects, or pydna’s Dseq property.

  • enz is the enzyme object. It’s not necessary to perform the cut, but can be

    used to keep track of which enzyme was used.

Cuts are only returned if the recognition site and overhang are on the double-strand part of the sequence.

Parameters:

enzymes (Union[_RestrictionBatch,list[_AbstractCut]])

Return type:

list[tuple[tuple[int,int], _AbstractCut]]

Examples

>>> from Bio.Restriction import EcoRI
>>> from pydna.dseq import Dseq
>>> seq = Dseq('AAGAATTCAAGAATTC')
>>> seq.get_cutsites(EcoRI)
[((3, -4), EcoRI), ((11, -4), EcoRI)]

cut_watson is defined with respect to the “full sequence”, not the watson strand:

>>> dseq = Dseq.from_full_sequence_and_overhangs('aaGAATTCaa', 1, 0)
>>> dseq
Dseq(-10)
 aGAATTCaa
ttCTTAAGtt
>>> dseq.get_cutsites([EcoRI])
[((3, -4), EcoRI)]

Cuts are only returned if the recognition site and overhang are on the double-strand part of the sequence.

>>> Dseq('GAATTC').get_cutsites([EcoRI])
[((1, -4), EcoRI)]
>>> Dseq.from_full_sequence_and_overhangs('GAATTC', -1, 0).get_cutsites([EcoRI])
[]
isblunt() bool[source]#

isblunt.

Return True if Dseq is linear and blunt and false if staggered or circular.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("gat")
>>> a
Dseq(-3)
gat
cta
>>> a.isblunt()
True
>>> a=Dseq("gat", "atcg")
>>> a
Dseq(-4)
 gat
gcta
>>> a.isblunt()
False
>>> a=Dseq("gat", "gatc")
>>> a
Dseq(-4)
gat
ctag
>>> a.isblunt()
False
>>> a=Dseq("gat", circular=True)
>>> a
Dseq(o3)
gat
cta
>>> a.isblunt()
False
left_end_position() Tuple[int, int][source]#

The index in the full sequence of the watson and crick start positions.

full sequence (str(self)) for all three cases is AAA

AAA              AA               AAT
 TT             TTT               TTT
Returns (0, 1)  Returns (1, 0)    Returns (0, 0)
looped() DseqType[source]#

Circularized Dseq object.

This can only be done if the two ends are compatible, otherwise a TypeError is raised.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("catcgatc")
>>> a
Dseq(-8)
catcgatc
gtagctag
>>> a.looped()
Dseq(o8)
catcgatc
gtagctag
>>> a.T4("t")
Dseq(-8)
catcgat
 tagctag
>>> a.T4("t").looped()
Dseq(o7)
catcgat
gtagcta
>>> a.T4("a")
Dseq(-8)
catcga
  agctag
>>> a.T4("a").looped()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pydna/dsdna.py", line 357, in looped
    if type5 == type3 and str(sticky5) == str(rc(sticky3)):
TypeError: DNA cannot be circularized.
5' and 3' sticky ends not compatible!
>>>
lower() DseqType[source]#

Return a lower case copy of the sequence.

>>> from pydna.dseq import Dseq
>>> my_seq = Dseq("aAa")
>>> my_seq
Dseq(-3)
aAa
tTt
>>> my_seq.lower()
Dseq(-3)
aaa
ttt
Returns:

Dseq object in lowercase

Return type:

Dseq

mung() Dseq[source]#

Simulates treatment a nuclease with 5’-3’ and 3’-5’ single strand specific exonuclease activity (such as mung bean nuclease [5])

    ggatcc    ->     gatcc
     ctaggg          ctagg

     ggatcc   ->      ggatc
    tcctag            cctag

>>> from pydna.dseq import Dseq
>>> b=Dseq("caaa", "cttt")
>>> b
Dseq(-5)
caaa
 tttc
>>> b.mung()
Dseq(-3)
aaa
ttt
>>> c=Dseq("aaac", "tttg")
>>> c
Dseq(-5)
 aaac
gttt
>>> c.mung()
Dseq(-3)
aaa
ttt

References

mw() float[source]#

This method returns the molecular weight of the DNA molecule in g/mol. The following formula is used:

MW = (A x 313.2) + (T x 304.2) +
     (C x 289.2) + (G x 329.2) +
     (N x 308.9) + 79.0
n_cutters(n=3, batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch cutting n times.

no_cutters(batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch not cutting sequence.

once_cutters(batch: RestrictionBatch | None = None) RestrictionBatch#

Enzymes in a RestrictionBatch cutting sequence once.

classmethod quick(watson: str, crick: str, ovhg=0, circular=False, pos=0)[source]#
rc() Dseq#

Dseq object where watson and crick have switched places.

This represents the same double stranded sequence.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("catcgatc")
>>> a
Dseq(-8)
catcgatc
gtagctag
>>> b=a.reverse_complement()
>>> b
Dseq(-8)
gatcgatg
ctagctac
>>>
reverse_complement() Dseq[source]#

Dseq object where watson and crick have switched places.

This represents the same double stranded sequence.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("catcgatc")
>>> a
Dseq(-8)
catcgatc
gtagctag
>>> b=a.reverse_complement()
>>> b
Dseq(-8)
gatcgatg
ctagctac
>>>
right_end_position() Tuple[int, int][source]#

The index in the full sequence of the watson and crick end positions.

full sequence (str(self)) for all three cases is AAA

` AAA               AA                   AAA TT                TTT                  TTT Returns (3, 2)    Returns (2, 3)       Returns (3, 3) `

seguid() str[source]#

SEGUID checksum for the sequence.

shifted(shift: int) DseqType[source]#

Shifted version of a circular Dseq object.

t4(nucleotides=None) Dseq#

Fill in five prime protruding ends and chewing back three prime protruding ends by a DNA polymerase providing both 5’-3’ DNA polymerase activity and 3’-5’ nuclease acitivty (such as T4 DNA polymerase). This can be done in presence of any combination of the four A, G, C or T. Removing one or more nucleotides can facilitate engineering of sticky ends. Default are all four nucleotides together.

Parameters:

nucleotides (str)

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("gatcgatc")
>>> a
Dseq(-8)
gatcgatc
ctagctag
>>> a.T4()
Dseq(-8)
gatcgatc
ctagctag
>>> a.T4("t")
Dseq(-8)
gatcgat
 tagctag
>>> a.T4("a")
Dseq(-8)
gatcga
  agctag
>>> a.T4("g")
Dseq(-8)
gatcg
   gctag
>>>
terminal_transferase(nucleotides='a') Dseq[source]#

docstring.

three_prime_end() Tuple[str, str][source]#

Returns a tuple describing the structure of the 5’ end of the DNA fragment

>>> from pydna.dseq import Dseq
>>> a=Dseq("aaa", "ttt")
>>> a
Dseq(-3)
aaa
ttt
>>> a.three_prime_end()
('blunt', '')
>>> a=Dseq("aaa", "ttt", ovhg=1)
>>> a
Dseq(-4)
 aaa
ttt
>>> a.three_prime_end()
("3'", 'a')
>>> a=Dseq("aaa", "ttt", ovhg=-1)
>>> a
Dseq(-4)
aaa
 ttt
>>> a.three_prime_end()
("5'", 't')
>>>
tolinear() DseqType[source]#

Returns a blunt, linear copy of a circular Dseq object. This can only be done if the Dseq object is circular, otherwise a TypeError is raised.

This method is deprecated, use slicing instead. See example below.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("catcgatc", circular=True)
>>> a
Dseq(o8)
catcgatc
gtagctag
>>> a[:]
Dseq(-8)
catcgatc
gtagctag
>>>
transcribe() Seq[source]#

Transcribe a DNA sequence into RNA and return the RNA sequence as a new Seq object.

Following the usual convention, the sequence is interpreted as the coding strand of the DNA double helix, not the template strand. This means we can get the RNA sequence just by switching T to U.

>>> from Bio.Seq import Seq
>>> coding_dna = Seq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
>>> coding_dna
Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> coding_dna.transcribe()
Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')

The sequence is modified in-place and returned if inplace is True:

>>> sequence = MutableSeq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
>>> sequence
MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> sequence.transcribe()
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
>>> sequence
MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> sequence.transcribe(inplace=True)
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
>>> sequence
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')

As Seq objects are immutable, a TypeError is raised if transcribe is called on a Seq object with inplace=True.

Trying to transcribe an RNA sequence has no effect. If you have a nucleotide sequence which might be DNA or RNA (or even a mixture), calling the transcribe method will ensure any T becomes U.

Trying to transcribe a protein sequence will replace any T for Threonine with U for Selenocysteine, which has no biologically plausible rational.

>>> from Bio.Seq import Seq
>>> my_protein = Seq("MAIVMGRT")
>>> my_protein.transcribe()
Seq('MAIVMGRU')
translate(table='Standard', stop_symbol='*', to_stop=False, cds=False, gap='-') Seq[source]#

Translate..

trunc = 30#
twice_cutters(batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch cutting sequence twice.

unique_cutters(batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch cutting sequence once.

upper() DseqType[source]#

Return an upper case copy of the sequence.

>>> from pydna.dseq import Dseq
>>> my_seq = Dseq("aAa")
>>> my_seq
Dseq(-3)
aAa
tTt
>>> my_seq.upper()
Dseq(-3)
AAA
TTT
Returns:

Dseq object in uppercase

Return type:

Dseq

watson_ovhg() int[source]#

Returns the overhang of the watson strand at the three prime.

pydna.all.read(data, ds=True)[source]#

This function is similar the parse() function but expects one and only one sequence or and exception is thrown.

Parameters:
  • data (string) – see below

  • ds (bool) – Double stranded or single stranded DNA, if True return Dseqrecord objects, else Bio.SeqRecord objects.

Returns:

contains the first Dseqrecord or SeqRecord object parsed.

Return type:

Dseqrecord

Notes

The data parameter is similar to the data parameter for parse().

See also

parse

pydna.all.read_primer(data)[source]#

Use this function to read a primer sequence from a string or a local file. The usage is similar to the parse_primer() function.

pydna.all.parse(data, ds=True)[source]#

Return all DNA sequences found in data.

If no sequences are found, an empty list is returned. This is a greedy function, use carefully.

Parameters:
  • data (string or iterable) –

    The data parameter is a string containing:

    1. an absolute path to a local file. The file will be read in text mode and parsed for EMBL, FASTA and Genbank sequences. Can be a string or a Path object.

    2. a string containing one or more sequences in EMBL, GENBANK, or FASTA format. Mixed formats are allowed.

    3. data can be a list or other iterable where the elements are 1 or 2

  • ds (bool) – If True double stranded Dseqrecord objects are returned. If False single stranded Bio.SeqRecord [6] objects are returned.

Returns:

contains Dseqrecord or SeqRecord objects

Return type:

list

References

See also

read

pydna.all.parse_primers(data)[source]#

docstring.

pydna.all.primer_design(template, fp=None, rp=None, limit=13, target_tm=55.0, tm_func=_tm_default, estimate_function=None, **kwargs)[source]#

This function designs a forward primer and a reverse primer for PCR amplification of a given template sequence.

The template argument is a Dseqrecord object or equivalent containing the template sequence.

The optional fp and rp arguments can contain an existing primer for the sequence (either the forward or reverse primer). One or the other primers can be specified, not both (since then there is nothing to design!, use the pydna.amplify.pcr function instead).

The limit argument is the minimum length of the primer. The default value is 13.

If one of the primers is given, the other primer is designed to match in terms of Tm. If both primers are designed, they will be designed to target_tm

tm_func is a function that takes an ascii string representing an oligonuceotide as argument and returns a float. Some useful functions can be found in the pydna.tm module, but can be substituted for a custom made function.

estimate_function is a tm_func-like function that is used to get a first guess for the primer design, that is then used as starting point for the final result. This is useful when the tm_func function is slow to calculate (e.g. it relies on an external API, such as the NEB primer design API). The estimate_function should be faster than the tm_func function. The default value is None. To use the default tm_func as estimate function to get the NEB Tm faster, you can do: primer_design(dseqr, target_tm=55, tm_func=tm_neb, estimate_function=tm_default).

The function returns a pydna.amplicon.Amplicon class instance. This object has the object.forward_primer and object.reverse_primer properties which contain the designed primers.

Parameters:
  • template (pydna.dseqrecord.Dseqrecord) – a Dseqrecord object. The only required argument.

  • fp (pydna.primer.Primer, optional) – optional pydna.primer.Primer objects containing one primer each.

  • rp (pydna.primer.Primer, optional) – optional pydna.primer.Primer objects containing one primer each.

  • target_tm (float, optional) – target tm for the primers, set to 55°C by default.

  • tm_func (function) – Function used for tm calculation. This function takes an ascii string representing an oligonuceotide as argument and returns a float. Some useful functions can be found in the pydna.tm module, but can be substituted for a custom made function.

Returns:

result

Return type:

Amplicon

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> t=Dseqrecord("atgactgctaacccttccttggtgttgaacaagatcgacgacatttcgttcgaaacttacgatg")
>>> t
Dseqrecord(-64)
>>> from pydna.design import primer_design
>>> ampl = primer_design(t)
>>> ampl
Amplicon(64)
>>> ampl.forward_primer
f64 17-mer:5'-atgactgctaacccttc-3'
>>> ampl.reverse_primer
r64 18-mer:5'-catcgtaagtttcgaacg-3'
>>> print(ampl.figure())
5atgactgctaacccttc...cgttcgaaacttacgatg3
                     ||||||||||||||||||
                    3gcaagctttgaatgctac5
5atgactgctaacccttc3
 |||||||||||||||||
3tactgacgattgggaag...gcaagctttgaatgctac5
>>> pf = "GGATCC" + ampl.forward_primer
>>> pr = "GGATCC" + ampl.reverse_primer
>>> pf
f64 23-mer:5'-GGATCCatgactgct..ttc-3'
>>> pr
r64 24-mer:5'-GGATCCcatcgtaag..acg-3'
>>> from pydna.amplify import pcr
>>> pcr_prod = pcr(pf, pr, t)
>>> print(pcr_prod.figure())
      5atgactgctaacccttc...cgttcgaaacttacgatg3
                           ||||||||||||||||||
                          3gcaagctttgaatgctacCCTAGG5
5GGATCCatgactgctaacccttc3
       |||||||||||||||||
      3tactgacgattgggaag...gcaagctttgaatgctac5
>>> print(pcr_prod.seq)
GGATCCatgactgctaacccttccttggtgttgaacaagatcgacgacatttcgttcgaaacttacgatgGGATCC
>>> from pydna.primer import Primer
>>> pf = Primer("atgactgctaacccttccttggtgttg", id="myprimer")
>>> ampl = primer_design(t, fp = pf)
>>> ampl.forward_primer
myprimer 27-mer:5'-atgactgctaaccct..ttg-3'
>>> ampl.reverse_primer
r64 32-mer:5'-catcgtaagtttcga..atc-3'
pydna.all.assembly_fragments(f, overlap=35, maxlink=40, circular=False)[source]#

This function return a list of pydna.amplicon.Amplicon objects where primers have been modified with tails so that the fragments can be fused in the order they appear in the list by for example Gibson assembly or homologous recombination.

Given that we have two linear pydna.amplicon.Amplicon objects a and b

we can modify the reverse primer of a and forward primer of b with tails to allow fusion by fusion PCR, Gibson assembly or in-vivo homologous recombination. The basic requirements for the primers for the three techniques are the same.

 _________ a _________
/                     \
agcctatcatcttggtctctgca
                  |||||
                 <gacgt
agcct>
|||||
tcggatagtagaaccagagacgt

                        __________ b ________
                       /                     \
                       TTTATATCGCATGACTCTTCTTT
                                         |||||
                                        <AGAAA
                       TTTAT>
                       |||||
                       AAATATAGCGTACTGAGAAGAAA

agcctatcatcttggtctctgcaTTTATATCGCATGACTCTTCTTT
||||||||||||||||||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATAGCGTACTGAGAAGAAA
\___________________ c ______________________/

Design tailed primers incorporating a part of the next or previous fragment to be assembled.

agcctatcatcttggtctctgca
|||||||||||||||||||||||
                gagacgtAAATATA

|||||||||||||||||||||||
tcggatagtagaaccagagacgt

                       TTTATATCGCATGACTCTTCTTT
                       |||||||||||||||||||||||

                ctctgcaTTTATAT
                       |||||||||||||||||||||||
                       AAATATAGCGTACTGAGAAGAAA

PCR products with flanking sequences are formed in the PCR process.

agcctatcatcttggtctctgcaTTTATAT
||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATA
                \____________/

                   identical
                   sequences
                 ____________
                /            \
                ctctgcaTTTATATCGCATGACTCTTCTTT
                ||||||||||||||||||||||||||||||
                gagacgtAAATATAGCGTACTGAGAAGAAA

The fragments can be fused by any of the techniques mentioned earlier to form c:

agcctatcatcttggtctctgcaTTTATATCGCATGACTCTTCTTT
||||||||||||||||||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATAGCGTACTGAGAAGAAA

The first argument of this function is a list of sequence objects containing Amplicons and other similar objects.

At least every second sequence object needs to be an Amplicon

This rule exists because if a sequence object is that is not a PCR product is to be fused with another fragment, that other fragment needs to be an Amplicon so that the primer of the other object can be modified to include the whole stretch of sequence homology needed for the fusion. See the example below where a is a non-amplicon (a linear plasmid vector for instance)

 _________ a _________           __________ b ________
/                     \         /                     \
agcctatcatcttggtctctgca   <-->  TTTATATCGCATGACTCTTCTTT
|||||||||||||||||||||||         |||||||||||||||||||||||
tcggatagtagaaccagagacgt                          <AGAAA
                                TTTAT>
                                |||||||||||||||||||||||
                          <-->  AAATATAGCGTACTGAGAAGAAA

     agcctatcatcttggtctctgcaTTTATATCGCATGACTCTTCTTT
     ||||||||||||||||||||||||||||||||||||||||||||||
     tcggatagtagaaccagagacgtAAATATAGCGTACTGAGAAGAAA
     \___________________ c ______________________/

In this case only the forward primer of b is fitted with a tail with a part a:

agcctatcatcttggtctctgca
|||||||||||||||||||||||
tcggatagtagaaccagagacgt

                       TTTATATCGCATGACTCTTCTTT
                       |||||||||||||||||||||||
                                        <AGAAA
         tcttggtctctgcaTTTATAT
                       |||||||||||||||||||||||
                       AAATATAGCGTACTGAGAAGAAA

PCR products with flanking sequences are formed in the PCR process.

agcctatcatcttggtctctgcaTTTATAT
||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATA
                \____________/

                   identical
                   sequences
                 ____________
                /            \
                ctctgcaTTTATATCGCATGACTCTTCTTT
                ||||||||||||||||||||||||||||||
                gagacgtAAATATAGCGTACTGAGAAGAAA

The fragments can be fused by for example Gibson assembly:

agcctatcatcttggtctctgcaTTTATAT
||||||||||||||||||||||||||||||
tcggatagtagaacca

                             TCGCATGACTCTTCTTT
                ||||||||||||||||||||||||||||||
                gagacgtAAATATAGCGTACTGAGAAGAAA

to form c:

agcctatcatcttggtctctgcaTTTATATCGCATGACTCTTCTTT
||||||||||||||||||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATAGCGTACTGAGAAGAAA

The first argument of this function is a list of sequence objects containing Amplicons and other similar objects.

The overlap argument controls how many base pairs of overlap required between adjacent sequence fragments. In the junction between Amplicons, tails with the length of about half of this value is added to the two primers closest to the junction.

>       <
Amplicon1
         Amplicon2
         >       <

         ⇣

>       <-
Amplicon1
         Amplicon2
        ->       <

In the case of an Amplicon adjacent to a Dseqrecord object, the tail will be twice as long (1*overlap) since the recombining sequence is present entirely on this primer:

Dseqrecd1
         Amplicon1
         >       <

         ⇣

Dseqrecd1
         Amplicon1
       -->       <

Note that if the sequence of DNA fragments starts or stops with an Amplicon, the very first and very last prinmer will not be modified i.e. assembles are always assumed to be linear. There are simple tricks around that for circular assemblies depicted in the last two examples below.

The maxlink arguments controls the cut off length for sequences that will be synhtesized by adding them to primers for the adjacent fragment(s). The argument list may contain short spacers (such as spacers between fusion proteins).

Example 1: Linear assembly of PCR products (pydna.amplicon.Amplicon class objects) ------

>       <         >       <
Amplicon1         Amplicon3
         Amplicon2         Amplicon4
         >       <         >       <

                     ⇣
                     pydna.design.assembly_fragments
                     ⇣

>       <-       ->       <-                      pydna.assembly.Assembly
Amplicon1         Amplicon3
         Amplicon2         Amplicon4     ➤  Amplicon1Amplicon2Amplicon3Amplicon4
        ->       <-       ->       <

Example 2: Linear assembly of alternating Amplicons and other fragments

>       <         >       <
Amplicon1         Amplicon2
         Dseqrecd1         Dseqrecd2

                     ⇣
                     pydna.design.assembly_fragments
                     ⇣

>       <--     -->       <--                     pydna.assembly.Assembly
Amplicon1         Amplicon2
         Dseqrecd1         Dseqrecd2     ➤  Amplicon1Dseqrecd1Amplicon2Dseqrecd2

Example 3: Linear assembly of alternating Amplicons and other fragments

Dseqrecd1         Dseqrecd2
         Amplicon1         Amplicon2
         >       <       -->       <

                     ⇣
             pydna.design.assembly_fragments
                     ⇣
                                                  pydna.assembly.Assembly
Dseqrecd1         Dseqrecd2
         Amplicon1         Amplicon2     ➤  Dseqrecd1Amplicon1Dseqrecd2Amplicon2
       -->       <--     -->       <

Example 4: Circular assembly of alternating Amplicons and other fragments

                 ->       <==
Dseqrecd1         Amplicon2
         Amplicon1         Dseqrecd1
       -->       <-
                     ⇣
                     pydna.design.assembly_fragments
                     ⇣
                                                   pydna.assembly.Assembly
                 ->       <==
Dseqrecd1         Amplicon2                    -Dseqrecd1Amplicon1Amplicon2-
         Amplicon1                       ➤    |                             |
       -->       <-                            -----------------------------

------ Example 5: Circular assembly of Amplicons

>       <         >       <
Amplicon1         Amplicon3
         Amplicon2         Amplicon1
         >       <         >       <

                     ⇣
                     pydna.design.assembly_fragments
                     ⇣

>       <=       ->       <-
Amplicon1         Amplicon3
         Amplicon2         Amplicon1
        ->       <-       +>       <

                     ⇣
             make new Amplicon using the Amplicon1.template and
             the last fwd primer and the first rev primer.
                     ⇣
                                                   pydna.assembly.Assembly
+>       <=       ->       <-
 Amplicon1         Amplicon3                  -Amplicon1Amplicon2Amplicon3-
          Amplicon2                      ➤   |                             |
         ->       <-                          -----------------------------
Parameters:
  • f (list of pydna.amplicon.Amplicon and other Dseqrecord like objects) – list Amplicon and Dseqrecord object for which fusion primers should be constructed.

  • overlap (int, optional) – Length of required overlap between fragments.

  • maxlink (int, optional) – Maximum length of spacer sequences that may be present in f. These will be included in tails for designed primers.

  • circular (bool, optional) – If True, the assembly is circular. If False, the assembly is linear.

Returns:

seqs

[Amplicon1,
 Amplicon2, ...]

Return type:

list of pydna.amplicon.Amplicon and other Dseqrecord like objects pydna.amplicon.Amplicon objects

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.design import primer_design
>>> a=primer_design(Dseqrecord("atgactgctaacccttccttggtgttgaacaagatcgacgacatttcgttcgaaacttacgatg"))
>>> b=primer_design(Dseqrecord("ccaaacccaccaggtaccttatgtaagtacttcaagtcgccagaagacttcttggtcaagttgcc"))
>>> c=primer_design(Dseqrecord("tgtactggtgctgaaccttgtatcaagttgggtgttgacgccattgccccaggtggtcgtttcgtt"))
>>> from pydna.design import assembly_fragments
>>> # We would like a circular recombination, so the first sequence has to be repeated
>>> fa1,fb,fc,fa2 = assembly_fragments([a,b,c,a])
>>> # Since all fragments are Amplicons, we need to extract the rp of the 1st and fp of the last fragments.
>>> from pydna.amplify import pcr
>>> fa = pcr(fa2.forward_primer, fa1.reverse_primer, a)
>>> [fa,fb,fc]
[Amplicon(100), Amplicon(101), Amplicon(102)]
>>> fa.name, fb.name, fc.name = "fa fb fc".split()
>>> from pydna.assembly import Assembly
>>> assemblyobj = Assembly([fa,fb,fc])
>>> assemblyobj
Assembly
fragments....: 100bp 101bp 102bp
limit(bp)....: 25
G.nodes......: 6
algorithm....: common_sub_strings
>>> assemblyobj.assemble_linear()
[Contig(-231), Contig(-166), Contig(-36)]
>>> assemblyobj.assemble_circular()[0].seguid()
'cdseguid=85t6tfcvWav0wnXEIb-lkUtrl4s'
>>> (a+b+c).looped().seguid()
'cdseguid=85t6tfcvWav0wnXEIb-lkUtrl4s'
>>> print(assemblyobj.assemble_circular()[0].figure())
 -|fa|36
|     \/
|     /\
|     36|fb|36
|           \/
|           /\
|           36|fc|36
|                 \/
|                 /\
|                 36-
|                    |
 --------------------
>>>
pydna.all.eq(*args, **kwargs)[source]#

Compare two or more DNA sequences for equality.

Compares two or more DNA sequences for equality i.e. if they represent the same double stranded DNA molecule.

Parameters:
  • args (iterable) – iterable containing sequences args can be strings, Biopython Seq or SeqRecord, Dseqrecord or dsDNA objects.

  • circular (bool, optional) – Consider all molecules circular or linear

  • linear (bool, optional) – Consider all molecules circular or linear

Returns:

eq – Returns True or False

Return type:

bool

Notes

Compares two or more DNA sequences for equality i.e. if they represent the same DNA molecule.

Two linear sequences are considiered equal if either:

  1. They have the same sequence (case insensitive)

  2. One sequence is the reverse complement of the other

Two circular sequences are considered equal if they are circular permutations meaning that they have the same length and:

  1. One sequence can be found in the concatenation of the other sequence with itself.

  2. The reverse complement of one sequence can be found in the concatenation of the other sequence with itself.

The topology for the comparison can be set using one of the keywords linear or circular to True or False.

If circular or linear is not set, it will be deduced from the topology of each sequence for sequences that have a linear or circular attribute (like Dseq and Dseqrecord).

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.utils import eq
>>> eq("aaa","AAA")
True
>>> eq("aaa","AAA","TTT")
True
>>> eq("aaa","AAA","TTT","tTt")
True
>>> eq("aaa","AAA","TTT","tTt", linear=True)
True
>>> eq("Taaa","aTaa", linear = True)
False
>>> eq("Taaa","aTaa", circular = True)
True
>>> a=Dseqrecord("Taaa")
>>> b=Dseqrecord("aTaa")
>>> eq(a,b)
False
>>> eq(a,b,circular=True)
True
>>> a=a.looped()
>>> b=b.looped()
>>> eq(a,b)
True
>>> eq(a,b,circular=False)
False
>>> eq(a,b,linear=True)
False
>>> eq(a,b,linear=False)
True
>>> eq("ggatcc","GGATCC")
True
>>> eq("ggatcca","GGATCCa")
True
>>> eq("ggatcca","tGGATCC")
True
pydna.all.gbtext_clean(gbtext)[source]#

This function takes a string containing one genbank sequence in Genbank format and returns a named tuple containing two fields, the gbtext containing a string with the corrected genbank sequence and jseq which contains the JSON intermediate.

Examples

>>> s = '''LOCUS       New_DNA      3 bp    DNA   CIRCULAR SYN        19-JUN-2013
... DEFINITION  .
... ACCESSION
... VERSION
... SOURCE      .
...   ORGANISM  .
... COMMENT
... COMMENT     ApEinfo:methylated:1
... ORIGIN
...         1 aaa
... //'''
>>> from pydna.readers import read
>>> read(s)
... /site-packages/Bio/GenBank/Scanner.py:1388: BiopythonParserWarning: Malformed LOCUS line found - is this correct?
:'LOCUS       New_DNA      3 bp    DNA   CIRCULAR SYN        19-JUN-2013\n'
  "correct?\n:%r" % line, BiopythonParserWarning)
Traceback (most recent call last):
  File "... /pydna/readers.py", line 48, in read
    results = results.pop()
IndexError: pop from empty list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "... /pydna/readers.py", line 50, in read
    raise ValueError("No sequences found in data:\n({})".format(data[:79]))
ValueError: No sequences found in data:
(LOCUS       New_DNA      3 bp    DNA   CIRCULAR SYN        19-JUN-2013
DEFINITI)
>>> from pydna.genbankfixer import gbtext_clean
>>> s2, j2 = gbtext_clean(s)
>>> print(s2)
LOCUS       New_DNA                    3 bp ds-DNA     circular SYN 19-JUN-2013
DEFINITION  .
ACCESSION
VERSION
SOURCE      .
ORGANISM  .
COMMENT
COMMENT     ApEinfo:methylated:1
FEATURES             Location/Qualifiers
ORIGIN
        1 aaa
//
>>> s3 = read(s2)
>>> s3
Dseqrecord(o3)
>>> print(s3.format())
LOCUS       New_DNA                    3 bp    DNA     circular SYN 19-JUN-2013
DEFINITION  .
ACCESSION   New_DNA
VERSION     New_DNA
KEYWORDS    .
SOURCE
  ORGANISM  .
            .
COMMENT
            ApEinfo:methylated:1
FEATURES             Location/Qualifiers
ORIGIN
        1 aaa
//

pydna.amplicon module#

This module provides the Amplicon class for PCR simulation. This class is not meant to be use directly but is used by the amplify module

class pydna.amplicon.Amplicon(record, *args, template=None, forward_primer=None, reverse_primer=None, **kwargs)[source]#

Bases: Dseqrecord

The Amplicon class holds information about a PCR reaction involving two primers and one template. This class is used by the Anneal class and is not meant to be instantiated directly.

Parameters:
  • forward_primer (SeqRecord(Biopython)) – SeqRecord object holding the forward (sense) primer

  • reverse_primer (SeqRecord(Biopython)) – SeqRecord object holding the reverse (antisense) primer

  • template (Dseqrecord) – Dseqrecord object holding the template (circular or linear)

classmethod from_SeqRecord(record, *args, path=None, **kwargs)[source]#
reverse_complement()[source]#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
rc()#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
figure()[source]#

This method returns a simple figure of the two primers binding to a part of the template.

5tacactcaccgtctatcattatc...cgactgtatcatctgatagcac3
                           ||||||||||||||||||||||
                          3gctgacatagtagactatcgtg5
5tacactcaccgtctatcattatc3
 |||||||||||||||||||||||
3atgtgagtggcagatagtaatag...gctgacatagtagactatcgtg5
Returns:

figure – A string containing a text representation of the primers annealing on the template (see example above).

Return type:

string

set_forward_primer_footprint(length)[source]#
set_reverse_primer_footprint(length)[source]#
program()[source]#
dbd_program()[source]#
primers()[source]#

pydna.amplify module#

This module provide the Anneal class and the pcr() function for PCR simulation. The pcr function is simpler to use, but expects only one PCR product. The Anneal class should be used if more flexibility is required.

Primers with 5’ tails as well as inverse PCR on circular templates are handled correctly.

class pydna.amplify.Anneal(primers, template, limit=13, **kwargs)[source]#

Bases: object

The Anneal class has the following important attributes:

forward_primers#

Description of forward_primers.

Type:

list

reverse_primers#

Description of reverse_primers.

Type:

list

template#

A copy of the template argument. Primers annealing sites has been added as features that can be visualized in a seqence editor such as ApE.

Type:

Dseqrecord

limit#

The limit of PCR primer annealing, default is 13 bp.

Type:

int, optional

property products#
report()#

returns a short report describing if or where primer anneal on the template.

pydna.amplify.pcr(*args, **kwargs) Amplicon[source]#

pcr is a convenience function for the Anneal class to simplify its usage, especially from the command line. If more than one or no PCR product is formed, a ValueError is raised.

args is any iterable of Dseqrecords or an iterable of iterables of Dseqrecords. args will be greedily flattened.

Parameters:
  • args (iterable containing sequence objects) – Several arguments are also accepted.

  • limit (int = 13, optional) – limit length of the annealing part of the primers.

Notes

sequences in args could be of type:

  • string

  • Seq

  • SeqRecord (or subclass)

  • Dseqrecord (or sublcass)

The last sequence will be assumed to be the template while all preceeding sequences will be assumed to be primers.

This is a powerful function, use with care!

Returns:

product – An pydna.amplicon.Amplicon object representing the PCR product. The direction of the PCR product will be the same as for the template sequence.

Return type:

Amplicon

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.readers import read
>>> from pydna.amplify import pcr
>>> from pydna.primer import Primer
>>> template = Dseqrecord("tacactcaccgtctatcattatctactatcgactgtatcatctgatagcac")
>>> from Bio.SeqRecord import SeqRecord
>>> p1 = Primer("tacactcaccgtctatcattatc")
>>> p2 = Primer("cgactgtatcatctgatagcac").reverse_complement()
>>> pcr(p1, p2, template)
Amplicon(51)
>>> pcr([p1, p2], template)
Amplicon(51)
>>> pcr((p1,p2,), template)
Amplicon(51)
>>>

pydna.assembly module#

Assembly of sequences by homologous recombination.

Should also be useful for related techniques such as Gibson assembly and fusion PCR. Given a list of sequences (Dseqrecords), all sequences are analyzed for shared homology longer than the set limit.

A graph is constructed where each overlapping region form a node and sequences separating the overlapping regions form edges.

            -- A --
catgatctacgtatcgtgt     -- B --
            atcgtgtactgtcatattc
                        catattcaaagttct



--x--> A --y--> B --z-->   (Graph)

Nodes:

A : atcgtgt
B : catattc

Edges:

x : catgatctacgt
y : actgt
z : aaagttct

The NetworkX package is used to trace linear and circular paths through the graph.

class pydna.assembly.Assembly(frags: List[Dseqrecord], limit: int = 25, algorithm: Callable[[str, str, int], List[Tuple[int, int, int]]] = common_sub_strings)[source]#

Bases: object

Assembly of a list of linear DNA fragments into linear or circular constructs. The Assembly is meant to replace the Assembly method as it is easier to use. Accepts a list of Dseqrecords (source fragments) to initiate an Assembly object. Several methods are available for analysis of overlapping sequences, graph construction and assembly.

Parameters:
  • fragments (list) – a list of Dseqrecord objects.

  • limit (int, optional) – The shortest shared homology to be considered

  • algorithm (function, optional) – The algorithm used to determine the shared sequences.

  • max_nodes (int) – The maximum number of nodes in the graph. This can be tweaked to manage sequences with a high number of shared sub sequences.

Examples

>>> from pydna.assembly import Assembly
>>> from pydna.dseqrecord import Dseqrecord
>>> a = Dseqrecord("acgatgctatactgCCCCCtgtgctgtgctcta")
>>> b = Dseqrecord("tgtgctgtgctctaTTTTTtattctggctgtatc")
>>> c = Dseqrecord("tattctggctgtatcGGGGGtacgatgctatactg")
>>> x = Assembly((a,b,c), limit=14)
>>> x
Assembly
fragments....: 33bp 34bp 35bp
limit(bp)....: 14
G.nodes......: 6
algorithm....: common_sub_strings
>>> x.assemble_circular()
[Contig(o59), Contig(o59)]
>>> x.assemble_circular()[0].seq.watson
'acgatgctatactgCCCCCtgtgctgtgctctaTTTTTtattctggctgtatcGGGGGt'
assemble_linear(**kwargs)#
assemble_circular(**kwargs)#

pydna.assembly2 module#

Improved implementation of the assembly module. To see a list of issues with the previous implementation, see [issues tagged with fixed-with-new-assembly-model](pydna-group/pydna#issues)

pydna.assembly2.gather_overlapping_locations(locs: list[Location], fragment_length: int) list[tuple[Location, ...]][source]#

Turn a list of locations into a list of tuples of those locations, where each tuple contains locations that overlap. For example, if locs = [loc1, loc2, loc3], and loc1 and loc2 overlap, the output will be [(loc1, loc2), (loc3,)].

pydna.assembly2.ends_from_cutsite(cutsite: Tuple[Tuple[int, int], AbstractCut | None | _cas], seq: Dseq) tuple[tuple[str, str], tuple[str, str]][source]#

Get the sticky or blunt ends created by a restriction enzyme cut.

Parameters:
  • cutsite (CutSiteType) – A tuple ((cut_watson, ovhg), enzyme) describing where the cut occurs

  • seq (_Dseq) – The DNA sequence being cut

Raises:

ValueError – If cutsite is None

Returns:

  • tuple[tuple[str, str], tuple[str, str]] – A tuple of two tuples, each containing the type of end (‘5’’, ‘3’’, or ‘blunt’) and the sequence of the overhang. The first tuple is for the left end, second for the right end.

  • >>> from Bio.Restriction import NotI

  • >>> x = _Dseq(“ctcgGCGGCCGCcagcggccg”)

  • >>> x.get_cutsites(NotI)

  • [((6, -4), NotI)]

  • >>> ends_from_cutsite(x.get_cutsites(NotI)[0], x)

  • ((“5’”, ‘ggcc’), (“5’”, ‘ggcc’))

pydna.assembly2.restriction_ligation_overlap(seqx: Dseqrecord, seqy: Dseqrecord, enzymes=RestrictionBatch, partial=False, allow_blunt=False) list[Tuple[int, int, int]][source]#

Assembly algorithm to find overlaps that would result from restriction and ligation.

Like in sticky and gibson, the order matters (see example below of partial overlap)

Parameters:
  • seqx (_Dseqrecord) – The first sequence

  • seqy (_Dseqrecord) – The second sequence

  • enzymes (RestrictionBatch) – The enzymes to use

  • partial (bool) – Whether to allow partial overlaps

  • allow_blunt (bool) – Whether to allow blunt ends

Returns:

  • list[SequenceOverlap] – A list of overlaps between the two sequences

  • >>> from pydna.dseqrecord import Dseqrecord

  • >>> from pydna.assembly2 import restriction_ligation_overlap

  • >>> from Bio.Restriction import EcoRI, RgaI, DrdI, EcoRV

  • >>> x = Dseqrecord(“ccGAATTCaa”)

  • >>> y = Dseqrecord(“aaaaGAATTCgg”)

  • >>> restriction_ligation_overlap(x, y, [EcoRI])

  • [(3, 5, 4)]

  • >>> restriction_ligation_overlap(y, x, [EcoRI])

  • [(5, 3, 4)]

  • Partial overlap, note how it is not symmetric

  • >>> x = Dseqrecord(“GACTAAAGGGTC”)

  • >>> y = Dseqrecord(“AAGCGATCGCAAGCGATCGCAA”)

  • >>> restriction_ligation_overlap(x, y, [RgaI, DrdI], partial=True)

  • [(6, 5, 1), (6, 15, 1)]

  • >>> restriction_ligation_overlap(y, x, [RgaI, DrdI], partial=True)

  • []

  • Blunt overlap, returns length of the overlap 0

  • >>> x = Dseqrecord(“aaGATATCcc”)

  • >>> y = Dseqrecord(“ttttGATATCaa”)

  • >>> restriction_ligation_overlap(x, y, [EcoRV], allow_blunt=True)

  • [(5, 7, 0)]

  • >>> restriction_ligation_overlap(y, x, [EcoRV], allow_blunt=True)

  • [(7, 5, 0)]

pydna.assembly2.combine_algorithms(*algorithms: Callable[[Dseqrecord, Dseqrecord, int], list[Tuple[int, int, int]]]) Callable[[Dseqrecord, Dseqrecord, int], list[Tuple[int, int, int]]][source]#

Combine assembly algorithms, if any of them returns a match, the match is returned.

This can be used for example in a ligation where you want to allow both sticky and blunt end ligation.

pydna.assembly2.blunt_overlap(seqx: Dseqrecord, seqy: Dseqrecord, limit=None) list[Tuple[int, int, int]][source]#

Assembly algorithm to find blunt overlaps. Used for blunt ligation.

It basically returns [(len(seqx), 0, 0)] if the right end of seqx is blunt and the left end of seqy is blunt (compatible with blunt ligation). Otherwise, it returns an empty list.

Parameters:
  • seqx (_Dseqrecord) – The first sequence

  • seqy (_Dseqrecord) – The second sequence

  • limit (int) – There for compatibility, but it is ignored

Returns:

  • list[SequenceOverlap] – A list of overlaps between the two sequences

  • >>> from pydna.assembly2 import blunt_overlap

  • >>> from pydna.dseqrecord import Dseqrecord

  • >>> x = Dseqrecord(“AAAAAA”)

  • >>> y = Dseqrecord(“TTTTTT”)

  • >>> blunt_overlap(x, y)

  • [(6, 0, 0)]

pydna.assembly2.common_sub_strings(seqx: Dseqrecord, seqy: Dseqrecord, limit=25) list[Tuple[int, int, int]][source]#

Assembly algorithm to find common substrings of length == limit. see the docs of the function common_sub_strings_str for more details. It is case insensitive.

>>> from pydna.dseqrecord import Dseqrecord
>>> x = Dseqrecord("TAAAAAAT")
>>> y = Dseqrecord("CCaAaAaACC")
>>> common_sub_strings(x, y, limit=5)
[(1, 2, 6), (1, 3, 5), (2, 2, 5)]
pydna.assembly2.gibson_overlap(seqx: Dseqrecord, seqy: Dseqrecord, limit=25)[source]#

Assembly algorithm to find terminal overlaps (e.g. for Gibson assembly). The order matters, we want alignments like:

seqx:    oooo------xxxx
seqy:              xxxx------oooo
Product: oooo------xxxx------oooo

Not like:

seqx:               oooo------xxxx
seqy:     xxxx------oooo
Product (unwanted): oooo
Parameters:
  • seqx (_Dseqrecord) – The first sequence

  • seqy (_Dseqrecord) – The second sequence

  • limit (int) – Minimum length of the overlap

Returns:

  • list[SequenceOverlap] – A list of overlaps between the two sequences

  • >>> from pydna.dseqrecord import Dseqrecord

  • >>> from pydna.assembly2 import gibson_overlap

  • >>> x = Dseqrecord(“ttactaAAAAAA”)

  • >>> y = Dseqrecord(“AAAAAAcgcacg”)

  • >>> gibson_overlap(x, y, limit=5)

  • [(6, 0, 6), (7, 0, 5)]

  • >>> gibson_overlap(y, x, limit=5)

  • []

pydna.assembly2.sticky_end_sub_strings(seqx: Dseqrecord, seqy: Dseqrecord, limit: bool = False)[source]#

Assembly algorithm for ligation of sticky ends.

For now, if limit 0 / False (default) only full overlaps are considered. Otherwise, partial overlaps are also returned.

Parameters:
  • seqx (_Dseqrecord) – The first sequence

  • seqy (_Dseqrecord) – The second sequence

  • limit (bool) – Whether to allow partial overlaps

Returns:

A list of overlaps between the two sequences

Return type:

list[SequenceOverlap]

Ligation of fully overlapping sticky ends, note how the order matters

>>> from pydna.dseq import Dseq
>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.assembly2 import sticky_end_sub_strings
>>> x = Dseqrecord(Dseq.from_full_sequence_and_overhangs("AAAAAA", 0, 3))
>>> y = Dseqrecord(Dseq.from_full_sequence_and_overhangs("AAAAAA", 3, 0))
>>> sticky_end_sub_strings(x, y, limit=False)
[(3, 0, 3)]
>>> sticky_end_sub_strings(y, x, limit=False)
[]

Ligation of partially overlapping sticky ends, specified with limit=True

>>> x = Dseqrecord(Dseq.from_full_sequence_and_overhangs("AAAAAA", 0, 2))
>>> y = Dseqrecord(Dseq.from_full_sequence_and_overhangs("AAAAAA", 3, 0))
>>> sticky_end_sub_strings(x, y, limit=False)
[]
>>> sticky_end_sub_strings(x, y, limit=True)
[(4, 0, 2)]
pydna.assembly2.zip_match_leftwards(seqx: SeqRecord, seqy: SeqRecord, match: Tuple[int, int, int]) Tuple[int, int, int][source]#

Starting from the rightmost edge of the match, return a new match encompassing the max number of bases. This can be used to return a longer match if a primer aligns for longer than the limit or a shorter match if there are mismatches. This is convenient to maintain as many features as possible. It is used in PCR assembly.

>>> seq = _Dseqrecord('AAAAACGTCCCGT')
>>> primer = _Dseqrecord('ACGTCCCGT')
>>> match = (13, 9, 0) # an empty match at the end of each
>>> zip_match_leftwards(seq, primer, match)
(4, 0, 9)

Works in circular molecules if the match spans the origin: >>> seq = _Dseqrecord(‘TCCCGTAAAAACG’, circular=True) >>> primer = _Dseqrecord(‘ACGTCCCGT’) >>> match = (6, 9, 0) >>> zip_match_leftwards(seq, primer, match) (10, 0, 9)

pydna.assembly2.zip_match_rightwards(seqx: Dseqrecord, seqy: Dseqrecord, match: Tuple[int, int, int]) Tuple[int, int, int][source]#

Same as zip_match_leftwards, but towards the right.

pydna.assembly2.seqrecord2_uppercase_DNA_string(seqr: SeqRecord) str[source]#

Transform a Dseqrecord to a sequence string where U is replaced by T, everything is upper case and circular sequences are repeated twice. This is used for PCR, to support primers with U’s (e.g. for USER cloning).

pydna.assembly2.primer_template_overlap(seqx: Dseqrecord | Primer, seqy: Dseqrecord | Primer, limit=25, mismatches=0) list[Tuple[int, int, int]][source]#

Assembly algorithm to find overlaps between a primer and a template. It accepts mismatches. When there are mismatches, it only returns the common part between the primer and the template.

If seqx is a primer and seqy is a template, it represents the binding of a forward primer. If seqx is a template and seqy is a primer, it represents the binding of a reverse primer, where the primer has been passed as its reverse complement (see examples).

Parameters:
  • seqx (_Dseqrecord | _Primer) – The primer

  • seqy (_Dseqrecord | _Primer) – The template

  • limit (int) – Minimum length of the overlap

  • mismatches (int) – Maximum number of mismatches (only substitutions, no deletion or insertion)

Returns:

  • list[SequenceOverlap] – A list of overlaps between the primer and the template

  • >>> from pydna.dseqrecord import Dseqrecord

  • >>> from pydna.primer import Primer

  • >>> from pydna.assembly2 import primer_template_overlap

  • >>> template = Dseqrecord(“AATTAGCAGCGATCGAGT”, circular=True)

  • >>> primer = Primer(“TTAGCAGC”)

  • >>> primer_template_overlap(primer, template, limit=8, mismatches=0)

  • [(0, 2, 8)]

  • This actually represents the binding of the primer GCTGCTAA (reverse complement)

  • >>> primer_template_overlap(template, primer, limit=8, mismatches=0)

  • [(2, 0, 8)]

  • >>> primer_template_overlap(primer, template.reverse_complement(), limit=8, mismatches=0)

  • []

  • >>> primer_template_overlap(primer.reverse_complement(), template, limit=8, mismatches=0)

  • []

pydna.assembly2.fill_left(seq: Dseq) Dseq[source]#

Fill the left overhang of a sequence with the complementary sequence.

pydna.assembly2.fill_right(seq: Dseq) Dseq[source]#

Fill the right overhang of a sequence with the complementary sequence.

pydna.assembly2.fill_dseq(seq: Dseq) Dseq[source]#

Fill the overhangs of a sequence with the complementary sequence.

pydna.assembly2.reverse_complement_assembly(assembly: list[Tuple[int, int, _Location | None, _Location | None]], fragments: list[Dseqrecord]) list[Tuple[int, int, _Location | None, _Location | None]][source]#

Complement an assembly, i.e. reverse the order of the fragments and the orientation of the overlaps.

pydna.assembly2.filter_linear_subassemblies(linear_assemblies: list[list[Tuple[int, int, _Location | None, _Location | None]]], circular_assemblies: list[list[Tuple[int, int, _Location | None, _Location | None]]], fragments: list[Dseqrecord]) list[list[Tuple[int, int, _Location | None, _Location | None]]][source]#

Remove linear assemblies which are sub-assemblies of circular assemblies

pydna.assembly2.remove_subassemblies(assemblies: list[list[Tuple[int, int, _Location | None, _Location | None]]]) list[list[Tuple[int, int, _Location | None, _Location | None]]][source]#

Filter out subassemblies, i.e. assemblies that are contained within another assembly.

For example:

[(1, 2, ‘1[8:14]:2[1:7]’), (2, 3, ‘2[10:17]:3[1:8]’)] [(1, 2, ‘1[8:14]:2[1:7]’)]

The second one is a subassembly of the first one.

pydna.assembly2.assembly2str(assembly: list[Tuple[int, int, _Location | None, _Location | None]]) str[source]#

Convert an assembly to a string representation, for example: ((1, 2, [8:14], [1:7]),(2, 3, [10:17], [1:8])) becomes: (‘1[8:14]:2[1:7]’, ‘2[10:17]:3[1:8]’)

The reason for this is that by default, a feature ‘[8:14]’ when present in a tuple is printed to the console as SimpleLocation(ExactPosition(8), ExactPosition(14), strand=1) (very long).

pydna.assembly2.assembly2str_tuple(assembly: list[Tuple[int, int, _Location | None, _Location | None]]) str[source]#

Convert an assembly to a string representation, like ((1, 2, [8:14], [1:7]),(2, 3, [10:17], [1:8]))

pydna.assembly2.assembly_has_mismatches(fragments: list[Dseqrecord], assembly: list[Tuple[int, int, _Location | None, _Location | None]]) bool[source]#

Check if an assembly has mismatches. This should never happen and if so it returns an error.

pydna.assembly2.assembly_is_circular(assembly: list[Tuple[int, int, _Location | None, _Location | None]], fragments: list[Dseqrecord]) bool[source]#

Based on the topology of the locations of an assembly, determine if it is circular. This does not work for insertion assemblies, that’s why assemble takes the optional argument is_insertion.

pydna.assembly2.assemble(fragments: list[Dseqrecord], assembly: list[Tuple[int, int, _Location | None, _Location | None]], is_insertion: bool = False) Dseqrecord[source]#

Generate a Dseqrecord from an assembly and a list of fragments.

pydna.assembly2.annotate_primer_binding_sites(input_dseqr: Dseqrecord, fragments: list[Dseqrecord]) Dseqrecord[source]#

Annotate the primer binding sites in a Dseqrecord.

pydna.assembly2.edge_representation2subfragment_representation(assembly: list[Tuple[int, int, _Location | None, _Location | None]], is_circular: bool) list[Tuple[int, _Location | None, _Location | None]][source]#

Turn this kind of edge representation fragment 1, fragment 2, right edge on 1, left edge on 2 a = [(1, 2, ‘loc1a’, ‘loc2a’), (2, 3, ‘loc2b’, ‘loc3b’), (3, 1, ‘loc3c’, ‘loc1c’)] Into this: fragment 1, left edge on 1, right edge on 1 b = [(1, ‘loc1c’, ‘loc1a’), (2, ‘loc2a’, ‘loc2b’), (3, ‘loc3b’, ‘loc3c’)]

pydna.assembly2.subfragment_representation2edge_representation(assembly: list[Tuple[int, _Location | None, _Location | None]], is_circular: bool) list[Tuple[int, int, _Location | None, _Location | None]][source]#

Turn this kind of subfragment representation fragment 1, left edge on 1, right edge on 1 a = [(1, ‘loc1c’, ‘loc1a’), (2, ‘loc2a’, ‘loc2b’), (3, ‘loc3b’, ‘loc3c’)] Into this: fragment 1, fragment 2, right edge on 1, left edge on 2 b = [(1, 2, ‘loc1a’, ‘loc2a’), (2, 3, ‘loc2b’ ‘loc3b’), (3, 1, ‘loc3c’, ‘loc1c’)]

pydna.assembly2.get_assembly_subfragments(fragments: list[Dseqrecord], subfragment_representation: list[Tuple[int, _Location | None, _Location | None]]) list[Dseqrecord][source]#

From the fragment representation returned by edge_representation2subfragment_representation, get the subfragments that are joined together.

Subfragments are the slices of the fragments that are joined together

For example:

  --A--
TACGTAAT
  --B--
 TCGTAACGA

Gives: TACGTAA / CGTAACGA

To reproduce:

a = Dseqrecord('TACGTAAT')
b = Dseqrecord('TCGTAACGA')
f = Assembly([a, b], limit=5)
a0 = f.get_linear_assemblies()[0]
print(assembly2str(a0))
a0_subfragment_rep =edge_representation2subfragment_representation(a0, False)
for f in get_assembly_subfragments([a, b], a0_subfragment_rep):
    print(f.seq)

# prints TACGTAA and CGTAACGA

Subfragments: cccccgtatcgtgt, atcgtgtactgtcatattc

pydna.assembly2.extract_subfragment(seq: Dseqrecord, start_location: Location, end_location: Location) Dseqrecord[source]#

Extract a subfragment from a sequence for an assembly, given the start and end locations of the subfragment.

pydna.assembly2.is_sublist(sublist: list, my_list: list, my_list_is_cyclic: bool = False) bool[source]#

Returns True if argument sublist is a sublist of argument my_list (can be treated as cyclic), False otherwise.

Examples

>>> is_sublist([1, 2], [1, 2, 3], False)
True
>>> is_sublist([1, 2], [1, 3, 2], False)
False

# See the case here for cyclic lists >>> is_sublist([3, 1], [1, 2, 3], False) False >>> is_sublist([3, 1], [1, 2, 3], True) True

pydna.assembly2.circular_permutation_min_abs(lst: list) list[source]#

Returns the circular permutation of lst with the smallest absolute value first.

Examples

>>> circular_permutation_min_abs([1, 2, 3])
[1, 2, 3]
>>> circular_permutation_min_abs([3, 1, 2])
[1, 2, 3]
class pydna.assembly2.Assembly(frags: list[Dseqrecord], limit: int = 25, algorithm: Callable[[Dseqrecord, Dseqrecord, int], list[Tuple[int, int, int]]] = common_sub_strings, use_fragment_order: bool = True, use_all_fragments: bool = False)[source]#

Bases: object

Assembly of a list of DNA fragments into linear or circular constructs. Accepts a list of Dseqrecords (source fragments) to initiate an Assembly object. Several methods are available for analysis of overlapping sequences, graph construction and assembly.

The assembly contains a directed graph, where nodes represent fragments and edges represent overlaps between fragments. :

  • The node keys are integers, representing the index of the fragment in the input list of fragments. The sign of the node key represents the orientation of the fragment, positive for forward orientation, negative for reverse orientation.

  • The edges contain the locations of the overlaps in the fragments. For an edge (u, v, key):
    • u and v are the nodes connected by the edge.

    • key is a string that represents the location of the overlap. In the format: ‘u[start:end](strand):v[start:end](strand)’.

    • Edges have a ‘locations’ attribute, which is a list of two FeatureLocation objects, representing the location of the overlap in the u and v fragment, respectively.

    • You can think of an edge as a representation of the join of two fragments.

If fragment 1 and 2 share a subsequence of 6bp, [8:14] in fragment 1 and [1:7] in fragment 2, there will be 4 edges representing that overlap in the graph, for all possible orientations of the fragments (see add_edges_from_match for details):

  • (1, 2, '1[8:14]:2[1:7]')

  • (2, 1, '2[1:7]:1[8:14]')

  • (-1, -2, '-1[0:6]:-2[10:16]')

  • (-2, -1, '-2[10:16]:-1[0:6]')

An assembly can be thought of as a tuple of graph edges, but instead of representing them with node indexes and keys, we represent them as u, v, locu, locv, where u and v are the nodes connected by the edge, and locu and locv are the locations of the overlap in the first and second fragment. Assemblies are then represented as:

  • Linear: ((1, 2, [8:14], [1:7]), (2, 3, [10:17], [1:8]))

  • Circular: ((1, 2, [8:14], [1:7]), (2, 3, [10:17], [1:8]), (3, 1, [12:17], [1:6]))

Note that the first and last fragment are the same in a circular assembly.

The following constrains are applied to remove duplicate assemblies:

  • Circular assemblies: the first subfragment is not reversed, and has the smallest index in the input fragment list. use_fragment_order is ignored.

  • Linear assemblies:
    • Using uid (see add_edges_from_match) to identify unique edges.

Parameters:
  • frags (list) – A list of Dseqrecord objects.

  • limit (int, optional) – The shortest shared homology to be considered, this is passed as the third argument to the algorithm function. For certain algorithms, this might be ignored.

  • algorithm (function, optional) – The algorithm used to determine the shared sequences. It’s a function that takes two Dseqrecord objects as inputs, and will get passed the third argument (limit), that may or may not be used. It must return a list of overlaps (see common_sub_strings for an example).

  • use_fragment_order (bool, optional) – It’s set to True by default to reproduce legacy pydna behaviour: only assemblies that start with the first fragment and end with the last are considered. You should set it to False.

  • use_all_fragments (bool, optional) – Constrain the assembly to use all fragments.

Examples

from assembly2 import Assembly, assembly2str from pydna.dseqrecord import Dseqrecord

example_fragments = (

Dseqrecord(‘AacgatCAtgctcc’, name=’a’), Dseqrecord(‘TtgctccTAAattctgc’, name=’b’), Dseqrecord(‘CattctgcGAGGacgatG’, name=’c’),

)

asm = Assembly(example_fragments, limit=5, use_fragment_order=False) print(‘Linear ===============’) for assembly in asm.get_linear_assemblies():

print(’ ‘, assembly2str(assembly))

print(‘Circular =============’) for assembly in asm.get_circular_assemblies():

print(’ ‘, assembly2str(assembly))

# Prints Linear ===============

(‘1[8:14]:2[1:7]’, ‘2[10:17]:3[1:8]’) (‘2[10:17]:3[1:8]’, ‘3[12:17]:1[1:6]’) (‘3[12:17]:1[1:6]’, ‘1[8:14]:2[1:7]’) (‘1[1:6]:3[12:17]’,) (‘2[1:7]:1[8:14]’,) (‘3[1:8]:2[10:17]’,)

Circular =============

(‘1[8:14]:2[1:7]’, ‘2[10:17]:3[1:8]’, ‘3[12:17]:1[1:6]’)

classmethod assembly_is_valid(fragments: list[Dseqrecord | Primer], assembly: list[Tuple[int, int, _Location | None, _Location | None]], is_circular: bool, use_all_fragments: bool, is_insertion: bool = False) bool[source]#

Returns True if the assembly is valid, False otherwise. See function comments for conditions tested.

add_edges_from_match(match: Tuple[int, int, int], u: int, v: int, first: Dseqrecord, secnd: Dseqrecord)[source]#

Add edges to the graph from a match returned by the algorithm function (see pydna.common_substrings). For format of edges (see documentation of the Assembly class).

Matches are directional, because not all algorithm functions return the same match for (u,v) and (v,u). For example, homologous recombination does but sticky end ligation does not. The function returns two edges:

  • Fragments in the orientation they were passed, with locations of the match (u, v, loc_u, loc_v)

  • Reverse complement of the fragments with inverted order, with flipped locations (-v, -u, flip(loc_v), flip(loc_u))/

format_assembly_edge(graph_edge: tuple[int, int, str]) Tuple[int, int, _Location | None, _Location | None][source]#

Go from the (u, v, key) to the (u, v, locu, locv) format.

get_linear_assemblies(only_adjacent_edges: bool = False, max_assemblies: int = 50) list[list[Tuple[int, int, _Location | None, _Location | None]]][source]#

Get linear assemblies, applying the constrains described in __init__, ensuring that paths represent real assemblies (see assembly_is_valid). Subassemblies are removed (see remove_subassemblies).

node_path2assembly_list(cycle: list[int], circular: bool) list[list[Tuple[int, int, _Location | None, _Location | None]]][source]#
Convert a node path in the format [1, 2, 3] (as returned by _nx.cycles.simple_cycles) to a list of all

possible assemblies.

There may be multiple assemblies for a given node path, if there are several edges connecting two nodes, for example two overlaps between 1 and 2, and single overlap between 2 and 3 should return 3 assemblies.

get_unique_linear_paths(G_with_begin_end: MultiDiGraph, max_paths=10000) list[list[int]][source]#

Get unique linear paths from the graph, removing those that contain the same node twice.

get_possible_assembly_number(paths: list[list[int]]) int[source]#

Get the number of possible assemblies from a list of node paths. Basically, for each path passed as a list of integers / nodes, we calculate the number of paths possible connecting the nodes in that order, given the graph (all the edges connecting them).

get_circular_assemblies(only_adjacent_edges: bool = False, max_assemblies: int = 50) list[list[Tuple[int, int, _Location | None, _Location | None]]][source]#

Get circular assemblies, applying the constrains described in __init__, ensuring that paths represent real assemblies (see assembly_is_valid).

format_insertion_assembly(assembly: list[Tuple[int, int, _Location | None, _Location | None]]) list[Tuple[int, int, _Location | None, _Location | None]] | None[source]#

Sorts the fragment representing a cycle so that they represent an insertion assembly if possible, else returns None.

Here we check if one of the joins between fragments represents the edges of an insertion assembly The fragment must be linear, and the join must be as indicated below

--------         -------           Fragment 1
    ||            ||
    xxxxxxxx      ||               Fragment 2
          ||      ||
          oooooooooo               Fragment 3

The above example will be [(1, 2, [4:6], [0:2]), (2, 3, [6:8], [0:2]), (3, 1, [8:10], [9:11)])]

These could be returned in any order by simple_cycles, so we sort the edges so that the first and last u and v match the fragment that gets the insertion (1 in the example above).

format_insertion_assembly_edge_case(assembly: list[Tuple[int, int, _Location | None, _Location | None]]) list[Tuple[int, int, _Location | None, _Location | None]][source]#

Edge case from manulera/OpenCloning_backend#329

get_insertion_assemblies(only_adjacent_edges: bool = False, max_assemblies: int = 50) list[list[Tuple[int, int, _Location | None, _Location | None]]][source]#

Assemblies that represent the insertion of a fragment or series of fragment inside a linear construct. For instance, digesting CCCCGAATTCCCCGAATTC with EcoRI and inserting the fragment with two overhangs into the EcoRI site of AAAGAATTCAAA. This is not so much meant for the use-case of linear fragments that represent actual linear fragments, but for linear fragments that represent a genome region. This can then be used to simulate homologous recombination.

assemble_linear(only_adjacent_edges: bool = False, max_assemblies: int = 50) list[Dseqrecord][source]#

Assemble linear constructs, from assemblies returned by self.get_linear_assemblies.

assemble_circular(only_adjacent_edges: bool = False, max_assemblies: int = 50) list[Dseqrecord][source]#

Assemble circular constructs, from assemblies returned by self.get_circular_assemblies.

assemble_insertion(only_adjacent_edges: bool = False) list[Dseqrecord][source]#

Assemble insertion constructs, from assemblies returned by self.get_insertion_assemblies.

get_locations_on_fragments() dict[int, dict[str, list[Location]]][source]#

Get a dictionary where the keys are the nodes in the graph, and the values are dictionaries with keys left, right, containing (for each fragment) the locations where the fragment is joined to another fragment on its left and right side. The values in left and right are often the same, except in restriction-ligation with partial overlap enabled, where we can end up with a situation like this:

GGTCTCCCCAATT and aGGTCTCCAACCAA as fragments

# Partial overlap in assembly 1[9:11]:2[8:10] GGTCTCCxxAACCAA CCAGAGGGGTTxxTT

# Partial overlap in 2[10:12]:1[7:9] aGGTCTCCxxCCAATT tCCAGAGGTTGGxxAA

Would return:

{
    1: {'left': [7:9], 'right': [9:11]},
    2: {'left': [8:10], 'right': [10:12]},
    -1: {'left': [2:4], 'right': [4:6]},
    -2: {'left': [2:4], 'right': [4:6]}
}
assembly_uses_only_adjacent_edges(assembly, is_circular: bool) bool[source]#

Check whether only adjacent edges within each fragment are used in the assembly. This is useful to check if a cut and ligate assembly is valid, and prevent including partially digested fragments. For example, imagine the following fragment being an input for a digestion and ligation assembly, where the enzyme cuts at the sites indicated by the vertical lines:

       x       y       z
-------|-------|-------|---------

We would only want assemblies that contain subfragments start-x, x-y, y-z, z-end, and not start-x, y-end, for instance. The latter would indicate that the fragment was partially digested.

class pydna.assembly2.PCRAssembly(frags: list[Dseqrecord | Primer], limit=25, mismatches=0)[source]#

Bases: Assembly

An assembly that represents a PCR, where fragments is a list of primer, template, primer (in that order). It always uses the primer_template_overlap algorithm and accepts the mismatches argument to indicate the number of mismatches allowed in the overlap. Only supports substitution mismatches, not indels.

get_linear_assemblies(only_adjacent_edges: bool = False, max_assemblies: int = 50) list[list[Tuple[int, int, _Location | None, _Location | None]]][source]#

Get linear assemblies, applying the constrains described in __init__, ensuring that paths represent real assemblies (see assembly_is_valid). Subassemblies are removed (see remove_subassemblies).

get_circular_assemblies(only_adjacent_edges: bool = False)[source]#

Get circular assemblies, applying the constrains described in __init__, ensuring that paths represent real assemblies (see assembly_is_valid).

get_insertion_assemblies(only_adjacent_edges: bool = False)[source]#

Assemblies that represent the insertion of a fragment or series of fragment inside a linear construct. For instance, digesting CCCCGAATTCCCCGAATTC with EcoRI and inserting the fragment with two overhangs into the EcoRI site of AAAGAATTCAAA. This is not so much meant for the use-case of linear fragments that represent actual linear fragments, but for linear fragments that represent a genome region. This can then be used to simulate homologous recombination.

class pydna.assembly2.SingleFragmentAssembly(frags: [<class 'pydna.dseqrecord.Dseqrecord'>], limit=25, algorithm=common_sub_strings)[source]#

Bases: Assembly

An assembly that represents the circularisation or splicing of a single fragment.

get_circular_assemblies(only_adjacent_edges: bool = False, max_assemblies: int = 50) list[list[Tuple[int, int, _Location | None, _Location | None]]][source]#

Get circular assemblies, applying the constrains described in __init__, ensuring that paths represent real assemblies (see assembly_is_valid).

get_insertion_assemblies(only_adjacent_edges: bool = False, max_assemblies: int = 50) list[list[Tuple[int, int, _Location | None, _Location | None]]][source]#

This could be renamed splicing assembly, but the essence is similar

get_linear_assemblies()[source]#

Get linear assemblies, applying the constrains described in __init__, ensuring that paths represent real assemblies (see assembly_is_valid). Subassemblies are removed (see remove_subassemblies).

pydna.assembly2.common_function_assembly_products(frags: list[Dseqrecord], limit: int | None, algorithm: Callable, circular_only: bool, filter_results_function: Callable | None = None) list[Dseqrecord][source]#

Common function to avoid code duplication. Could be simplified further once SingleFragmentAssembly and Assembly are merged.

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to assemble

  • limit (int or None) – Minimum overlap length required, or None if not applicable

  • algorithm (Callable) – Function that determines valid overlaps between fragments

  • circular_only (bool) – If True, only return circular assemblies

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

pydna.assembly2.gibson_assembly(frags: list[Dseqrecord], limit: int = 25, circular_only: bool = False) list[Dseqrecord][source]#

Returns the products for Gibson assembly.

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to assemble

  • limit (int, optional) – Minimum overlap length required, by default 25

  • circular_only (bool, optional) – If True, only return circular assemblies, by default False

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

pydna.assembly2.in_fusion_assembly(frags: list[Dseqrecord], limit: int = 25, circular_only: bool = False) list[Dseqrecord][source]#

Returns the products for in-fusion assembly. This is the same as Gibson assembly, but with a different name.

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to assemble

  • limit (int, optional) – Minimum overlap length required, by default 25

  • circular_only (bool, optional) – If True, only return circular assemblies, by default False

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

pydna.assembly2.fusion_pcr_assembly(frags: list[Dseqrecord], limit: int = 25, circular_only: bool = False) list[Dseqrecord][source]#

Returns the products for fusion PCR assembly. This is the same as Gibson assembly, but with a different name.

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to assemble

  • limit (int, optional) – Minimum overlap length required, by default 25

  • circular_only (bool, optional) – If True, only return circular assemblies, by default False

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

pydna.assembly2.in_vivo_assembly(frags: list[Dseqrecord], limit: int = 25, circular_only: bool = False) list[Dseqrecord][source]#

Returns the products for in vivo assembly (IVA), which relies on homologous recombination between the fragments.

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to assemble

  • limit (int, optional) – Minimum overlap length required, by default 25

  • circular_only (bool, optional) – If True, only return circular assemblies, by default False

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

pydna.assembly2.restriction_ligation_assembly(frags: list[Dseqrecord], enzymes: list[_AbstractCut], allow_blunt: bool = True, circular_only: bool = False) list[Dseqrecord][source]#

Returns the products for restriction ligation assembly:

  • Finds cutsites in the fragments

  • Finds all products that could be assembled by ligating the fragments based on those cutsites

  • Will NOT return products that combine an existing end with an end generated by the same enzyme (see example below)

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to assemble

  • enzymes (list[_AbstractCut]) – List of restriction enzymes to use

  • allow_blunt (bool, optional) – If True, allow blunt end ligations, by default True

  • circular_only (bool, optional) – If True, only return circular assemblies, by default False

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

Examples

In the example below, we plan to assemble a plasmid from a backbone and an insert, using the EcoRI and SalI enzymes. Note how 2 circular products are returned, one contains the insert (acgt) and the desired part of the backbone (cccccc), the other contains the reversed insert (tgga) and the cut-out part of the backbone (aaa).

>>> from pydna.assembly2 import restriction_ligation_assembly
>>> from pydna.dseqrecord import Dseqrecord
>>> from Bio.Restriction import EcoRI, SalI
>>> backbone = Dseqrecord("cccGAATTCaaaGTCGACccc", circular=True)
>>> insert = Dseqrecord("ggGAATTCaggtGTCGACgg")
>>> products = restriction_ligation_assembly([backbone, insert], [EcoRI, SalI], circular_only=True)
>>> products[0].seq
Dseq(o22)
TCGACccccccGAATTCaggtG
AGCTGggggggCTTAAGtccaC
>>> products[1].seq
Dseq(o19)
AATTCaaaGTCGACacctG
TTAAGtttCAGCTGtggaC

Note that passing a pre-cut fragment will not work.

>>> restriction_products = insert.cut([EcoRI, SalI])
>>> cut_insert = restriction_products[1]
>>> restriction_ligation_assembly([backbone, cut_insert], [EcoRI, SalI], circular_only=True)
[]

It also works with a single fragment, for circularization:

>>> seq = Dseqrecord("GAATTCaaaGAATTC")
>>> products =restriction_ligation_assembly([seq], [EcoRI])
>>> products[0].seq
Dseq(o9)
AATTCaaaG
TTAAGtttC
pydna.assembly2.golden_gate_assembly(frags: list[Dseqrecord], enzymes: list[_AbstractCut], allow_blunt: bool = True, circular_only: bool = False) list[Dseqrecord][source]#

Returns the products for Golden Gate assembly. This is the same as restriction ligation assembly, but with a different name. Check the documentation for restriction_ligation_assembly for more details.

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to assemble

  • enzymes (list[_AbstractCut]) – List of restriction enzymes to use

  • allow_blunt (bool, optional) – If True, allow blunt end ligations, by default True

  • circular_only (bool, optional) – If True, only return circular assemblies, by default False

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

Examples

See the example for restriction_ligation_assembly.

pydna.assembly2.ligation_assembly(frags: list[Dseqrecord], allow_blunt: bool = False, allow_partial_overlap: bool = False, circular_only: bool = False) list[Dseqrecord][source]#

Returns the products for ligation assembly, as inputs pass the fragments (digested if needed) that will be ligated.

For most cases, you probably should use restriction_ligation_assembly instead.

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to assemble

  • allow_blunt (bool, optional) – If True, allow blunt end ligations, by default False

  • allow_partial_overlap (bool, optional) – If True, allow partial overlaps between sticky ends, by default False

  • circular_only (bool, optional) – If True, only return circular assemblies, by default False

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

Examples

In the example below, we plan to assemble a plasmid from a backbone and an insert, using the EcoRI enzyme. The insert and insertion site in the backbone are flanked by EcoRI sites, so there are two possible products depending on the orientation of the insert.

>>> from pydna.assembly2 import ligation_assembly
>>> from pydna.dseqrecord import Dseqrecord
>>> from Bio.Restriction import EcoRI
>>> backbone = Dseqrecord("cccGAATTCaaaGAATTCccc", circular=True)
>>> backbone_cut = backbone.cut(EcoRI)[1]
>>> insert = Dseqrecord("ggGAATTCaggtGAATTCgg")
>>> insert_cut = insert.cut(EcoRI)[1]
>>> products = ligation_assembly([backbone_cut, insert_cut])
>>> products[0].seq
Dseq(o22)
AATTCccccccGAATTCaggtG
TTAAGggggggCTTAAGtccaC
>>> products[1].seq
Dseq(o22)
AATTCccccccGAATTCacctG
TTAAGggggggCTTAAGtggaC
pydna.assembly2.assembly_is_multi_site(asm: list[list[Tuple[int, int, _Location | None, _Location | None]]]) bool[source]#

Returns True if the assembly is a multi-site assembly, False otherwise.

pydna.assembly2.gateway_assembly(frags: list[Dseqrecord], reaction_type: Literal['BP', 'LR'], greedy: bool = False, circular_only: bool = False, multi_site_only: bool = False) list[Dseqrecord][source]#

Returns the products for Gateway assembly / Gateway cloning.

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to assemble

  • reaction_type (Literal['BP', 'LR']) – Type of Gateway reaction

  • greedy (bool, optional) – If True, use greedy gateway consensus sites, by default False

  • circular_only (bool, optional) – If True, only return circular assemblies, by default False

  • multi_site_only (bool, optional) – If True, only return products that where 2 sites recombined. Even if input sequences contain multiple att sites (typically 2), a product could be generated where only one site recombines. That’s typically not what you want, so you can set this to True to only return products where both att sites recombined.

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

Examples

Below an example with dummy Gateway sequences, composed with minimal sequences and the consensus att sites.

>>> from pydna.assembly2 import gateway_assembly
>>> from pydna.dseqrecord import Dseqrecord
>>> attB1 = "ACAACTTTGTACAAAAAAGCAGAAG"
>>> attP1 = "AAAATAATGATTTTATTTGACTGATAGTGACCTGTTCGTTGCAACAAATTGATGAGCAATGCTTTTTTATAATGCCAACTTTGTACAAAAAAGCTGAACGAGAAGCGTAAAATGATATAAATATCAATATATTAAATTAGATTTTGCATAAAAAACAGACTACATAATACTGTAAAACACAACATATCCAGTCACTATGAATCAACTACTTAGATGGTATTAGTGACCTGTA"
>>> attR1 = "ACAACTTTGTACAAAAAAGCTGAACGAGAAACGTAAAATGATATAAATATCAATATATTAAATTAGATTTTGCATAAAAAACAGACTACATAATACTGTAAAACACAACATATGCAGTCACTATG"
>>> attL1 = "CAAATAATGATTTTATTTTGACTGATAGTGACCTGTTCGTTGCAACAAATTGATAAGCAATGCTTTCTTATAATGCCAACTTTGTACAAAAAAGCAGGCT"
>>> seq1 = Dseqrecord("aaa" + attB1 + "ccc")
>>> seq2 = Dseqrecord("aaa" + attP1 + "ccc")
>>> seq3 = Dseqrecord("aaa" + attR1 + "ccc")
>>> seq4 = Dseqrecord("aaa" + attL1 + "ccc")
>>> products_BP = gateway_assembly([seq1, seq2], "BP")
>>> products_LR = gateway_assembly([seq3, seq4], "LR")
>>> len(products_BP)
2
>>> len(products_LR)
2

Now let’s understand the multi_site_only parameter. Let’s consider a case where we are swapping fragments between two plasmids using an LR reaction. Experimentally, we expect to obtain two plasmids, resulting from the swapping between the two att sites. That’s what we get if we set multi_site_only to True.

>>> attL2 = 'aaataatgattttattttgactgatagtgacctgttcgttgcaacaaattgataagcaatgctttcttataatgccaactttgtacaagaaagctg'
>>> attR2 = 'accactttgtacaagaaagctgaacgagaaacgtaaaatgatataaatatcaatatattaaattagattttgcataaaaaacagactacataatactgtaaaacacaacatatccagtcactatg'
>>> insert = Dseqrecord("cccccc" + attL1 + "ccc" + attL2 + "cccccc", circular=True)
>>> backbone = Dseqrecord("ttttt" + attR1 + "aaa" + attR2, circular=True)
>>> products = gateway_assembly([insert, backbone], "LR", multi_site_only=True)
>>> len(products)
2

However, if we set multi_site_only to False, we get 4 products, which also include the intermediate products where the two plasmids are combined into a single one through recombination of a single att site. This is an intermediate of the reaction, and typically we don’t want it:

>>> products = gateway_assembly([insert, backbone], "LR", multi_site_only=False)
>>> print([len(p) for p in products])
[469, 237, 232, 469]
pydna.assembly2.common_function_integration_products(frags: list[Dseqrecord], limit: int | None, algorithm: Callable) list[Dseqrecord][source]#

Common function to avoid code duplication for integration products.

Parameters:
  • frags (list[_Dseqrecord]) – List of DNA fragments to integrate

  • limit (int or None) – Minimum overlap length required, or None if not applicable

  • algorithm (Callable) – Function that determines valid overlaps between fragments

Returns:

List of integrated DNA molecules

Return type:

list[_Dseqrecord]

pydna.assembly2.common_handle_insertion_fragments(genome: Dseqrecord, inserts: list[Dseqrecord]) list[Dseqrecord][source]#

Common function to handle / validate insertion fragments.

Parameters:
  • genome (_Dseqrecord) – Target genome sequence

  • inserts (list[_Dseqrecord] or _Dseqrecord) – DNA fragment(s) to insert

Returns:

List containing genome and insert fragments

Return type:

list[_Dseqrecord]

pydna.assembly2.common_function_excision_products(genome: Dseqrecord, limit: int | None, algorithm: Callable) list[Dseqrecord][source]#

Common function to avoid code duplication for excision products.

Parameters:
  • genome (_Dseqrecord) – Target genome sequence

  • limit (int or None) – Minimum overlap length required, or None if not applicable

  • algorithm (Callable) – Function that determines valid overlaps between fragments

Returns:

List of excised DNA molecules

Return type:

list[_Dseqrecord]

pydna.assembly2.homologous_recombination_integration(genome: Dseqrecord, inserts: list[Dseqrecord], limit: int = 40) list[Dseqrecord][source]#

Returns the products resulting from the integration of an insert (or inserts joined through in vivo recombination) into the genome through homologous recombination.

Parameters:
  • genome (_Dseqrecord) – Target genome sequence

  • inserts (list[_Dseqrecord]) – DNA fragment(s) to insert

  • limit (int, optional) – Minimum homology length required, by default 40

Returns:

List of integrated DNA molecules

Return type:

list[_Dseqrecord]

Examples

Below an example with a single insert.

>>> from pydna.assembly2 import homologous_recombination_integration
>>> from pydna.dseqrecord import Dseqrecord
>>> homology = "AAGTCCGTTCGTTTTACCTG"
>>> genome = Dseqrecord(f"aaaaaa{homology}ccccc{homology}aaaaaa")
>>> insert = Dseqrecord(f"{homology}gggg{homology}")
>>> products = homologous_recombination_integration(genome, [insert], 20)
>>> str(products[0].seq)
'aaaaaaAAGTCCGTTCGTTTTACCTGggggAAGTCCGTTCGTTTTACCTGaaaaaa'

Below an example with two inserts joined through homology.

>>> homology2 = "ATTACAGCATGGGAAGAAAGA"
>>> insert_1 = Dseqrecord(f"{homology}gggg{homology2}")
>>> insert_2 = Dseqrecord(f"{homology2}cccc{homology}")
>>> products = homologous_recombination_integration(genome, [insert_1, insert_2], 20)
>>> str(products[0].seq)
'aaaaaaAAGTCCGTTCGTTTTACCTGggggATTACAGCATGGGAAGAAAGAccccAAGTCCGTTCGTTTTACCTGaaaaaa'
pydna.assembly2.homologous_recombination_excision(genome: Dseqrecord, limit: int = 40) list[Dseqrecord][source]#

Returns the products resulting from the excision of a fragment from the genome through homologous recombination.

Parameters:
  • genome (_Dseqrecord) – Target genome sequence

  • limit (int, optional) – Minimum homology length required, by default 40

Returns:

List containing excised plasmid and remaining genome sequence

Return type:

list[_Dseqrecord]

Examples

Example of a homologous recombination event, where a plasmid is excised from the genome (circular sequence of 25 bp), and that part is removed from the genome, leaving a shorter linear sequence (32 bp).

>>> from pydna.assembly2 import homologous_recombination_excision
>>> from pydna.dseqrecord import Dseqrecord
>>> homology = "AAGTCCGTTCGTTTTACCTG"
>>> genome = Dseqrecord(f"aaaaaa{homology}ccccc{homology}aaaaaa")
>>> products = homologous_recombination_excision(genome, 20)
>>> products
[Dseqrecord(o25), Dseqrecord(-32)]
pydna.assembly2.cre_lox_integration(genome: Dseqrecord, inserts: list[Dseqrecord]) list[Dseqrecord][source]#

Returns the products resulting from the integration of an insert (or inserts joined through cre-lox recombination among them) into the genome through cre-lox integration.

Also works with lox66 and lox71 (see pydna.cre_lox for more details).

Parameters:
  • genome (_Dseqrecord) – Target genome sequence

  • inserts (list[_Dseqrecord] or _Dseqrecord) – DNA fragment(s) to insert

Returns:

List of integrated DNA molecules

Return type:

list[_Dseqrecord]

Examples

Below an example of reversible integration and excision.

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.assembly2 import cre_lox_integration, cre_lox_excision
>>> from pydna.cre_lox import LOXP_SEQUENCE
>>> a = Dseqrecord(f"cccccc{LOXP_SEQUENCE}aaaaa")
>>> b = Dseqrecord(f"{LOXP_SEQUENCE}bbbbb", circular=True)
>>> [a, b]
[Dseqrecord(-45), Dseqrecord(o39)]
>>> res = cre_lox_integration(a, [b])
>>> res
[Dseqrecord(-84)]
>>> res2 = cre_lox_excision(res[0])
>>> res2
[Dseqrecord(o39), Dseqrecord(-45)]

Below an example with lox66 and lox71 (irreversible integration). Here, the result of excision is still returned because there is a low probability of it happening, but it’s considered a rare event.

>>> lox66 = 'ATAACTTCGTATAGCATACATTATACGAACGGTA'
>>> lox71 = 'TACCGTTCGTATAGCATACATTATACGAAGTTAT'
>>> a = Dseqrecord(f"cccccc{lox66}aaaaa")
>>> b = Dseqrecord(f"{lox71}bbbbb", circular=True)
>>> res = cre_lox_integration(a, [b])
>>> res
[Dseqrecord(-84)]
>>> res2 = cre_lox_excision(res[0])
>>> res2
[Dseqrecord(o39), Dseqrecord(-45)]
pydna.assembly2.cre_lox_excision(genome: Dseqrecord) list[Dseqrecord][source]#

Returns the products for CRE-lox excision.

Parameters:

genome (_Dseqrecord) – Target genome sequence

Returns:

List containing excised plasmid and remaining genome sequence

Return type:

list[_Dseqrecord]

Examples

Below an example of reversible integration and excision.

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.assembly2 import cre_lox_integration, cre_lox_excision
>>> from pydna.cre_lox import LOXP_SEQUENCE
>>> a = Dseqrecord(f"cccccc{LOXP_SEQUENCE}aaaaa")
>>> b = Dseqrecord(f"{LOXP_SEQUENCE}bbbbb", circular=True)
>>> [a, b]
[Dseqrecord(-45), Dseqrecord(o39)]
>>> res = cre_lox_integration(a, [b])
>>> res
[Dseqrecord(-84)]
>>> res2 = cre_lox_excision(res[0])
>>> res2
[Dseqrecord(o39), Dseqrecord(-45)]

Below an example with lox66 and lox71 (irreversible integration). Here, the result of excision is still returned because there is a low probability of it happening, but it’s considered a rare event.

>>> lox66 = 'ATAACTTCGTATAGCATACATTATACGAACGGTA'
>>> lox71 = 'TACCGTTCGTATAGCATACATTATACGAAGTTAT'
>>> a = Dseqrecord(f"cccccc{lox66}aaaaa")
>>> b = Dseqrecord(f"{lox71}bbbbb", circular=True)
>>> res = cre_lox_integration(a, [b])
>>> res
[Dseqrecord(-84)]
>>> res2 = cre_lox_excision(res[0])
>>> res2
[Dseqrecord(o39), Dseqrecord(-45)]
pydna.assembly2.crispr_integration(genome: Dseqrecord, inserts: list[Dseqrecord], guides: list[Primer], limit: int = 40) list[Dseqrecord][source]#

Returns the products for CRISPR integration.

Parameters:
  • genome (_Dseqrecord) – Target genome sequence

  • inserts (list[_Dseqrecord]) – DNA fragment(s) to insert

  • guides (list[_Primer]) – List of guide RNAs as Primer objects. This may change in the future.

  • limit (int, optional) – Minimum overlap length required, by default 40

Returns:

List of integrated DNA molecules

Return type:

list[_Dseqrecord]

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.assembly2 import crispr_integration
>>> from pydna.primer import Primer
>>> genome = Dseqrecord("aaccggttcaatgcaaacagtaatgatggatgacattcaaagcac", name="genome")
>>> insert = Dseqrecord("aaccggttAAAAAAAAAttcaaagcac", name="insert")
>>> guide = Primer("ttcaatgcaaacagtaatga", name="guide")
>>> product, *_ = crispr_integration(genome, [insert], [guide], 8)
>>> product
Dseqrecord(-27)
pydna.assembly2.pcr_assembly(template: Dseqrecord, fwd_primer: Primer, rvs_primer: Primer, add_primer_features: bool = False, limit: int = 14, mismatches: int = 0) list[Dseqrecord][source]#

Returns the products for PCR assembly.

Parameters:
  • template (_Dseqrecord) – Template sequence

  • fwd_primer (_Primer) – Forward primer

  • rvs_primer (_Primer) – Reverse primer

  • add_primer_features (bool, optional) – If True, add primer features to the product, by default False

  • limit (int, optional) – Minimum overlap length required, by default 14

  • mismatches (int, optional) – Maximum number of mismatches, by default 0

Returns:

List of assembled DNA molecules

Return type:

list[_Dseqrecord]

pydna.codon module#

docstring.

pydna.common_sub_strings module#

This module is based on the Py-rstr-max package that was written by Romain Brixtel (rbrixtel_at_gmail_dot_com) (https://brixtel.users.greyc.fr) and is available from https://code.google.com/p/py-rstr-max gip0/py-rstr-max the original code was covered by an MIT licence.

pydna.common_sub_strings.common_sub_strings(stringx: str, stringy: str, limit: int = 25) List[Tuple[int, int, int]][source]#

Finds all common substrings between stringx and stringy, and returns them sorted by length.

This function is case sensitive.

Parameters:
  • stringx (str)

  • stringy (str)

  • limit (int, optional)

Returns:

[(startx1, starty1, length1),(startx2, starty2, length2), …]

startx1 = startposition in x, where substring 1 starts starty1 = position in y where substring 1 starts length1 = lenght of substring

Return type:

list of tuple

pydna.common_sub_strings.terminal_overlap(stringx: str, stringy: str, limit: int = 15) List[Tuple[int, int, int]][source]#

Finds the the flanking common substrings between stringx and stringy longer than limit. This means that the results only contains substrings that starts or ends at the the ends of stringx and stringy.

This function is case sensitive.

returns a list of tuples describing the substrings The list is sorted longest -> shortest.

Parameters:
  • stringx (str)

  • stringy (str)

  • limit (int, optional)

Returns:

[(startx1,starty1,length1),(startx2,starty2,length2), …]

startx1 = startposition in x, where substring 1 starts starty1 = position in y where substring 1 starts length1 = lenght of substring

Return type:

list of tuple

Examples

>>> from pydna.common_sub_strings import terminal_overlap
>>> terminal_overlap("agctatgtatcttgcatcgta", "gcatcgtagtctatttgcttac", limit=8)
[(13, 0, 8)]
             <-- 8 ->
<---- 13 --->
agctatgtatcttgcatcgta                    stringx
             gcatcgtagtctatttgcttac      stringy
             0

pydna.conftest module#

conftest.py

pydna.contig module#

class pydna.contig.Contig(record, *args, graph=None, nodemap=None, **kwargs)[source]#

Bases: Dseqrecord

This class holds information about a DNA assembly. This class is instantiated by the Assembly class and is not meant to be used directly.

classmethod from_string(record: str = '', *args, graph=None, nodemap=None, **kwargs)[source]#

docstring.

classmethod from_SeqRecord(record, *args, graph=None, nodemap=None, **kwargs)[source]#
reverse_complement()[source]#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
rc()#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
detailed_figure()[source]#

Returns a text representation of the assembled fragments.

Linear:

acgatgctatactgCCCCCtgtgctgtgctcta
                   TGTGCTGTGCTCTA
                   tgtgctgtgctctaTTTTTtattctggctgtatc

Circular:

||||||||||||||
acgatgctatactgCCCCCtgtgctgtgctcta
                   TGTGCTGTGCTCTA
                   tgtgctgtgctctaTTTTTtattctggctgtatc
                                      TATTCTGGCTGTATC
                                      tattctggctgtatcGGGGGtacgatgctatactg
                                                           ACGATGCTATACTG
figure()[source]#

Compact ascii representation of the assembled fragments.

Each fragment is represented by:

Size of common 5' substring|Name and size of DNA fragment|
Size of common 5' substring

Linear:

frag20| 6
       \\/
       /\\
        6|frag23| 6
                 \\/
                 /\\
                  6|frag14

Circular:

 -|2577|61
|       \\/
|       /\\
|       61|5681|98
|               \\/
|               /\\
|               98|2389|557
|                       \\/
|                       /\\
|                       557-
|                          |
 --------------------------

pydna.cre_lox module#

pydna.cre_lox.cre_loxP_overlap(x: Dseqrecord, y: Dseqrecord, _l: None = None) list[tuple[int, int, int]][source]#

Find matching loxP sites between two sequences.

pydna.cre_lox.get_regex_dict(original_dict: dict[str, str]) dict[str, str][source]#

Get the regex dictionary for the original dictionary.

pydna.cre_lox.find_loxP_sites(seq: Dseqrecord) dict[str, list[Location]][source]#

Find all loxP sites in a sequence and return a dictionary with the name and positions of the sites.

pydna.cre_lox.annotate_loxP_sites(seq: Dseqrecord) Dseqrecord[source]#

pydna.crispr module#

Provides the Dseq class for handling double stranded DNA sequences.

Dseq is a subclass of Bio.Seq.Seq. The Dseq class is mostly useful as a part of the pydna.dseqrecord.Dseqrecord class which can hold more meta data.

The Dseq class support the notion of circular and linear DNA topology.

class pydna.crispr.cas9(protospacer)[source]#

Bases: _cas

docstring.

    |----size----------|

    ---protospacer------
                    -fst3
    fst5             |-|
    |--------------|
                        PAM
5-NNGGAAGAGTAATACACTA-AAANGGNN-3
||||||||||||||||||| ||||||||
3-NNCCTTCTCATTATGTGAT-TTTNCCNN-5
    ||||||||||||||||| |||
5-GGAAGAGTAATACACTA-AAAg-u-a-a-g-g  Scaffold
    ---gRNA spacer---    u-a
                        u-a
                        u-a
                        u-a
                        a-u
                        g-u-g
                        a    a
                        g-c-a
                        c-g
                        u-a
                        a-u
                        g   a  tetraloop
                        a-a
scaffold = 'GTTTTAGAGCTAGAAATAGCAAGTTAAAATAAGG'#
pam = '.GG'#
size = 20#
fst5 = 17#
fst3 = -3#
ovhg = 0#
search(dna, linear=True)[source]#

docstring.

pydna.crispr.protospacer(guide_construct, cas=cas9)[source]#

docstring.

pydna.design module#

This module contain functions for primer design for various purposes.

  • :func:primer_design for designing primers for a sequence or a matching primer for an existing primer. Returns an Amplicon object (same as the amplify module returns).

  • :func:assembly_fragments Adds tails to primers for a linear assembly through homologous recombination or Gibson assembly.

  • :func:circular_assembly_fragments Adds tails to primers for a circular assembly through homologous recombination or Gibson assembly.

pydna.design.primer_design(template, fp=None, rp=None, limit=13, target_tm=55.0, tm_func=_tm_default, estimate_function=None, **kwargs)[source]#

This function designs a forward primer and a reverse primer for PCR amplification of a given template sequence.

The template argument is a Dseqrecord object or equivalent containing the template sequence.

The optional fp and rp arguments can contain an existing primer for the sequence (either the forward or reverse primer). One or the other primers can be specified, not both (since then there is nothing to design!, use the pydna.amplify.pcr function instead).

The limit argument is the minimum length of the primer. The default value is 13.

If one of the primers is given, the other primer is designed to match in terms of Tm. If both primers are designed, they will be designed to target_tm

tm_func is a function that takes an ascii string representing an oligonuceotide as argument and returns a float. Some useful functions can be found in the pydna.tm module, but can be substituted for a custom made function.

estimate_function is a tm_func-like function that is used to get a first guess for the primer design, that is then used as starting point for the final result. This is useful when the tm_func function is slow to calculate (e.g. it relies on an external API, such as the NEB primer design API). The estimate_function should be faster than the tm_func function. The default value is None. To use the default tm_func as estimate function to get the NEB Tm faster, you can do: primer_design(dseqr, target_tm=55, tm_func=tm_neb, estimate_function=tm_default).

The function returns a pydna.amplicon.Amplicon class instance. This object has the object.forward_primer and object.reverse_primer properties which contain the designed primers.

Parameters:
  • template (pydna.dseqrecord.Dseqrecord) – a Dseqrecord object. The only required argument.

  • fp (pydna.primer.Primer, optional) – optional pydna.primer.Primer objects containing one primer each.

  • rp (pydna.primer.Primer, optional) – optional pydna.primer.Primer objects containing one primer each.

  • target_tm (float, optional) – target tm for the primers, set to 55°C by default.

  • tm_func (function) – Function used for tm calculation. This function takes an ascii string representing an oligonuceotide as argument and returns a float. Some useful functions can be found in the pydna.tm module, but can be substituted for a custom made function.

Returns:

result

Return type:

Amplicon

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> t=Dseqrecord("atgactgctaacccttccttggtgttgaacaagatcgacgacatttcgttcgaaacttacgatg")
>>> t
Dseqrecord(-64)
>>> from pydna.design import primer_design
>>> ampl = primer_design(t)
>>> ampl
Amplicon(64)
>>> ampl.forward_primer
f64 17-mer:5'-atgactgctaacccttc-3'
>>> ampl.reverse_primer
r64 18-mer:5'-catcgtaagtttcgaacg-3'
>>> print(ampl.figure())
5atgactgctaacccttc...cgttcgaaacttacgatg3
                     ||||||||||||||||||
                    3gcaagctttgaatgctac5
5atgactgctaacccttc3
 |||||||||||||||||
3tactgacgattgggaag...gcaagctttgaatgctac5
>>> pf = "GGATCC" + ampl.forward_primer
>>> pr = "GGATCC" + ampl.reverse_primer
>>> pf
f64 23-mer:5'-GGATCCatgactgct..ttc-3'
>>> pr
r64 24-mer:5'-GGATCCcatcgtaag..acg-3'
>>> from pydna.amplify import pcr
>>> pcr_prod = pcr(pf, pr, t)
>>> print(pcr_prod.figure())
      5atgactgctaacccttc...cgttcgaaacttacgatg3
                           ||||||||||||||||||
                          3gcaagctttgaatgctacCCTAGG5
5GGATCCatgactgctaacccttc3
       |||||||||||||||||
      3tactgacgattgggaag...gcaagctttgaatgctac5
>>> print(pcr_prod.seq)
GGATCCatgactgctaacccttccttggtgttgaacaagatcgacgacatttcgttcgaaacttacgatgGGATCC
>>> from pydna.primer import Primer
>>> pf = Primer("atgactgctaacccttccttggtgttg", id="myprimer")
>>> ampl = primer_design(t, fp = pf)
>>> ampl.forward_primer
myprimer 27-mer:5'-atgactgctaaccct..ttg-3'
>>> ampl.reverse_primer
r64 32-mer:5'-catcgtaagtttcga..atc-3'
pydna.design.assembly_fragments(f, overlap=35, maxlink=40, circular=False)[source]#

This function return a list of pydna.amplicon.Amplicon objects where primers have been modified with tails so that the fragments can be fused in the order they appear in the list by for example Gibson assembly or homologous recombination.

Given that we have two linear pydna.amplicon.Amplicon objects a and b

we can modify the reverse primer of a and forward primer of b with tails to allow fusion by fusion PCR, Gibson assembly or in-vivo homologous recombination. The basic requirements for the primers for the three techniques are the same.

 _________ a _________
/                     \
agcctatcatcttggtctctgca
                  |||||
                 <gacgt
agcct>
|||||
tcggatagtagaaccagagacgt

                        __________ b ________
                       /                     \
                       TTTATATCGCATGACTCTTCTTT
                                         |||||
                                        <AGAAA
                       TTTAT>
                       |||||
                       AAATATAGCGTACTGAGAAGAAA

agcctatcatcttggtctctgcaTTTATATCGCATGACTCTTCTTT
||||||||||||||||||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATAGCGTACTGAGAAGAAA
\___________________ c ______________________/

Design tailed primers incorporating a part of the next or previous fragment to be assembled.

agcctatcatcttggtctctgca
|||||||||||||||||||||||
                gagacgtAAATATA

|||||||||||||||||||||||
tcggatagtagaaccagagacgt

                       TTTATATCGCATGACTCTTCTTT
                       |||||||||||||||||||||||

                ctctgcaTTTATAT
                       |||||||||||||||||||||||
                       AAATATAGCGTACTGAGAAGAAA

PCR products with flanking sequences are formed in the PCR process.

agcctatcatcttggtctctgcaTTTATAT
||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATA
                \____________/

                   identical
                   sequences
                 ____________
                /            \
                ctctgcaTTTATATCGCATGACTCTTCTTT
                ||||||||||||||||||||||||||||||
                gagacgtAAATATAGCGTACTGAGAAGAAA

The fragments can be fused by any of the techniques mentioned earlier to form c:

agcctatcatcttggtctctgcaTTTATATCGCATGACTCTTCTTT
||||||||||||||||||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATAGCGTACTGAGAAGAAA

The first argument of this function is a list of sequence objects containing Amplicons and other similar objects.

At least every second sequence object needs to be an Amplicon

This rule exists because if a sequence object is that is not a PCR product is to be fused with another fragment, that other fragment needs to be an Amplicon so that the primer of the other object can be modified to include the whole stretch of sequence homology needed for the fusion. See the example below where a is a non-amplicon (a linear plasmid vector for instance)

 _________ a _________           __________ b ________
/                     \         /                     \
agcctatcatcttggtctctgca   <-->  TTTATATCGCATGACTCTTCTTT
|||||||||||||||||||||||         |||||||||||||||||||||||
tcggatagtagaaccagagacgt                          <AGAAA
                                TTTAT>
                                |||||||||||||||||||||||
                          <-->  AAATATAGCGTACTGAGAAGAAA

     agcctatcatcttggtctctgcaTTTATATCGCATGACTCTTCTTT
     ||||||||||||||||||||||||||||||||||||||||||||||
     tcggatagtagaaccagagacgtAAATATAGCGTACTGAGAAGAAA
     \___________________ c ______________________/

In this case only the forward primer of b is fitted with a tail with a part a:

agcctatcatcttggtctctgca
|||||||||||||||||||||||
tcggatagtagaaccagagacgt

                       TTTATATCGCATGACTCTTCTTT
                       |||||||||||||||||||||||
                                        <AGAAA
         tcttggtctctgcaTTTATAT
                       |||||||||||||||||||||||
                       AAATATAGCGTACTGAGAAGAAA

PCR products with flanking sequences are formed in the PCR process.

agcctatcatcttggtctctgcaTTTATAT
||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATA
                \____________/

                   identical
                   sequences
                 ____________
                /            \
                ctctgcaTTTATATCGCATGACTCTTCTTT
                ||||||||||||||||||||||||||||||
                gagacgtAAATATAGCGTACTGAGAAGAAA

The fragments can be fused by for example Gibson assembly:

agcctatcatcttggtctctgcaTTTATAT
||||||||||||||||||||||||||||||
tcggatagtagaacca

                             TCGCATGACTCTTCTTT
                ||||||||||||||||||||||||||||||
                gagacgtAAATATAGCGTACTGAGAAGAAA

to form c:

agcctatcatcttggtctctgcaTTTATATCGCATGACTCTTCTTT
||||||||||||||||||||||||||||||||||||||||||||||
tcggatagtagaaccagagacgtAAATATAGCGTACTGAGAAGAAA

The first argument of this function is a list of sequence objects containing Amplicons and other similar objects.

The overlap argument controls how many base pairs of overlap required between adjacent sequence fragments. In the junction between Amplicons, tails with the length of about half of this value is added to the two primers closest to the junction.

>       <
Amplicon1
         Amplicon2
         >       <

         ⇣

>       <-
Amplicon1
         Amplicon2
        ->       <

In the case of an Amplicon adjacent to a Dseqrecord object, the tail will be twice as long (1*overlap) since the recombining sequence is present entirely on this primer:

Dseqrecd1
         Amplicon1
         >       <

         ⇣

Dseqrecd1
         Amplicon1
       -->       <

Note that if the sequence of DNA fragments starts or stops with an Amplicon, the very first and very last prinmer will not be modified i.e. assembles are always assumed to be linear. There are simple tricks around that for circular assemblies depicted in the last two examples below.

The maxlink arguments controls the cut off length for sequences that will be synhtesized by adding them to primers for the adjacent fragment(s). The argument list may contain short spacers (such as spacers between fusion proteins).

Example 1: Linear assembly of PCR products (pydna.amplicon.Amplicon class objects) ------

>       <         >       <
Amplicon1         Amplicon3
         Amplicon2         Amplicon4
         >       <         >       <

                     ⇣
                     pydna.design.assembly_fragments
                     ⇣

>       <-       ->       <-                      pydna.assembly.Assembly
Amplicon1         Amplicon3
         Amplicon2         Amplicon4     ➤  Amplicon1Amplicon2Amplicon3Amplicon4
        ->       <-       ->       <

Example 2: Linear assembly of alternating Amplicons and other fragments

>       <         >       <
Amplicon1         Amplicon2
         Dseqrecd1         Dseqrecd2

                     ⇣
                     pydna.design.assembly_fragments
                     ⇣

>       <--     -->       <--                     pydna.assembly.Assembly
Amplicon1         Amplicon2
         Dseqrecd1         Dseqrecd2     ➤  Amplicon1Dseqrecd1Amplicon2Dseqrecd2

Example 3: Linear assembly of alternating Amplicons and other fragments

Dseqrecd1         Dseqrecd2
         Amplicon1         Amplicon2
         >       <       -->       <

                     ⇣
             pydna.design.assembly_fragments
                     ⇣
                                                  pydna.assembly.Assembly
Dseqrecd1         Dseqrecd2
         Amplicon1         Amplicon2     ➤  Dseqrecd1Amplicon1Dseqrecd2Amplicon2
       -->       <--     -->       <

Example 4: Circular assembly of alternating Amplicons and other fragments

                 ->       <==
Dseqrecd1         Amplicon2
         Amplicon1         Dseqrecd1
       -->       <-
                     ⇣
                     pydna.design.assembly_fragments
                     ⇣
                                                   pydna.assembly.Assembly
                 ->       <==
Dseqrecd1         Amplicon2                    -Dseqrecd1Amplicon1Amplicon2-
         Amplicon1                       ➤    |                             |
       -->       <-                            -----------------------------

------ Example 5: Circular assembly of Amplicons

>       <         >       <
Amplicon1         Amplicon3
         Amplicon2         Amplicon1
         >       <         >       <

                     ⇣
                     pydna.design.assembly_fragments
                     ⇣

>       <=       ->       <-
Amplicon1         Amplicon3
         Amplicon2         Amplicon1
        ->       <-       +>       <

                     ⇣
             make new Amplicon using the Amplicon1.template and
             the last fwd primer and the first rev primer.
                     ⇣
                                                   pydna.assembly.Assembly
+>       <=       ->       <-
 Amplicon1         Amplicon3                  -Amplicon1Amplicon2Amplicon3-
          Amplicon2                      ➤   |                             |
         ->       <-                          -----------------------------
Parameters:
  • f (list of pydna.amplicon.Amplicon and other Dseqrecord like objects) – list Amplicon and Dseqrecord object for which fusion primers should be constructed.

  • overlap (int, optional) – Length of required overlap between fragments.

  • maxlink (int, optional) – Maximum length of spacer sequences that may be present in f. These will be included in tails for designed primers.

  • circular (bool, optional) – If True, the assembly is circular. If False, the assembly is linear.

Returns:

seqs

[Amplicon1,
 Amplicon2, ...]

Return type:

list of pydna.amplicon.Amplicon and other Dseqrecord like objects pydna.amplicon.Amplicon objects

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.design import primer_design
>>> a=primer_design(Dseqrecord("atgactgctaacccttccttggtgttgaacaagatcgacgacatttcgttcgaaacttacgatg"))
>>> b=primer_design(Dseqrecord("ccaaacccaccaggtaccttatgtaagtacttcaagtcgccagaagacttcttggtcaagttgcc"))
>>> c=primer_design(Dseqrecord("tgtactggtgctgaaccttgtatcaagttgggtgttgacgccattgccccaggtggtcgtttcgtt"))
>>> from pydna.design import assembly_fragments
>>> # We would like a circular recombination, so the first sequence has to be repeated
>>> fa1,fb,fc,fa2 = assembly_fragments([a,b,c,a])
>>> # Since all fragments are Amplicons, we need to extract the rp of the 1st and fp of the last fragments.
>>> from pydna.amplify import pcr
>>> fa = pcr(fa2.forward_primer, fa1.reverse_primer, a)
>>> [fa,fb,fc]
[Amplicon(100), Amplicon(101), Amplicon(102)]
>>> fa.name, fb.name, fc.name = "fa fb fc".split()
>>> from pydna.assembly import Assembly
>>> assemblyobj = Assembly([fa,fb,fc])
>>> assemblyobj
Assembly
fragments....: 100bp 101bp 102bp
limit(bp)....: 25
G.nodes......: 6
algorithm....: common_sub_strings
>>> assemblyobj.assemble_linear()
[Contig(-231), Contig(-166), Contig(-36)]
>>> assemblyobj.assemble_circular()[0].seguid()
'cdseguid=85t6tfcvWav0wnXEIb-lkUtrl4s'
>>> (a+b+c).looped().seguid()
'cdseguid=85t6tfcvWav0wnXEIb-lkUtrl4s'
>>> print(assemblyobj.assemble_circular()[0].figure())
 -|fa|36
|     \/
|     /\
|     36|fb|36
|           \/
|           /\
|           36|fc|36
|                 \/
|                 /\
|                 36-
|                    |
 --------------------
>>>
pydna.design.circular_assembly_fragments(f, overlap=35, maxlink=40)[source]#

Equivalent to assembly_fragments with circular=True.

Deprecated, kept for backward compatibility. Use assembly_fragments with circular=True instead.

pydna.download module#

Provides a function for downloading online text files.

pydna.download.download_text(url)[source]#

docstring.

pydna.dseq module#

Provides the Dseq class for handling double stranded DNA sequences.

Dseq is a subclass of Bio.Seq.Seq. The Dseq class is mostly useful as a part of the pydna.dseqrecord.Dseqrecord class which can hold more meta data.

The Dseq class support the notion of circular and linear DNA topology.

class pydna.dseq.Dseq(watson: str | bytes, crick: str | bytes | None = None, ovhg=None, circular=False, pos=0)[source]#

Bases: Seq

Dseq holds information for a double stranded DNA fragment.

Dseq also holds information describing the topology of the DNA fragment (linear or circular).

Parameters:
  • watson (str) – a string representing the watson (sense) DNA strand.

  • crick (str, optional) – a string representing the crick (antisense) DNA strand.

  • ovhg (int, optional) – A positive or negative number to describe the stagger between the watson and crick strands. see below for a detailed explanation.

  • linear (bool, optional) – True indicates that sequence is linear, False that it is circular.

  • circular (bool, optional) – True indicates that sequence is circular, False that it is linear.

Examples

Dseq is a subclass of the Biopython Seq object. It stores two strings representing the watson (sense) and crick(antisense) strands. two properties called linear and circular, and a numeric value ovhg (overhang) describing the stagger for the watson and crick strand in the 5’ end of the fragment.

The most common usage is probably to create a Dseq object as a part of a Dseqrecord object (see pydna.dseqrecord.Dseqrecord).

There are three ways of creating a Dseq object directly listed below, but you can also use the function Dseq.from_full_sequence_and_overhangs() to create a Dseq:

Only one argument (string):

>>> from pydna.dseq import Dseq
>>> Dseq("aaa")
Dseq(-3)
aaa
ttt

The given string will be interpreted as the watson strand of a blunt, linear double stranded sequence object. The crick strand is created automatically from the watson strand.

Two arguments (string, string):

>>> from pydna.dseq import Dseq
>>> Dseq("gggaaat","ttt")
Dseq(-7)
gggaaat
   ttt

If both watson and crick are given, but not ovhg an attempt will be made to find the best annealing between the strands. There are limitations to this. For long fragments it is quite slow. The length of the annealing sequences have to be at least half the length of the shortest of the strands.

Three arguments (string, string, ovhg=int):

The ovhg parameter is an integer describing the length of the crick strand overhang in the 5’ end of the molecule.

The ovhg parameter controls the stagger at the five prime end:

dsDNA       overhang

  nnn...    2
nnnnn...

 nnnn...    1
nnnnn...

nnnnn...    0
nnnnn...

nnnnn...   -1
 nnnn...

nnnnn...   -2
  nnn...

Example of creating Dseq objects with different amounts of stagger:

>>> Dseq(watson="agt", crick="actta", ovhg=-2)
Dseq(-7)
agt
  attca
>>> Dseq(watson="agt",crick="actta",ovhg=-1)
Dseq(-6)
agt
 attca
>>> Dseq(watson="agt",crick="actta",ovhg=0)
Dseq(-5)
agt
attca
>>> Dseq(watson="agt",crick="actta",ovhg=1)
Dseq(-5)
 agt
attca
>>> Dseq(watson="agt",crick="actta",ovhg=2)
Dseq(-5)
  agt
attca

If the ovhg parameter is specified a crick strand also needs to be supplied, otherwise an exception is raised.

>>> Dseq(watson="agt", ovhg=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pydna_/dsdna.py", line 169, in __init__
    else:
ValueError: ovhg defined without crick strand!

The shape of the fragment is set by circular = True, False

Note that both ends of the DNA fragment has to be compatible to set circular = True.

>>> Dseq("aaa","ttt")
Dseq(-3)
aaa
ttt
>>> Dseq("aaa","ttt",ovhg=0)
Dseq(-3)
aaa
ttt
>>> Dseq("aaa","ttt",ovhg=1)
Dseq(-4)
 aaa
ttt
>>> Dseq("aaa","ttt",ovhg=-1)
Dseq(-4)
aaa
 ttt
>>> Dseq("aaa", "ttt", circular = True , ovhg=0)
Dseq(o3)
aaa
ttt
>>> a=Dseq("tttcccc","aaacccc")
>>> a
Dseq(-11)
    tttcccc
ccccaaa
>>> a.ovhg
4
>>> b=Dseq("ccccttt","ccccaaa")
>>> b
Dseq(-11)
ccccttt
    aaacccc
>>> b.ovhg
-4
>>>

Coercing to string

>>> str(a)
'ggggtttcccc'

A Dseq object can be longer that either the watson or crick strands.

<-- length -->
GATCCTTT
     AAAGCCTAG

<-- length -->
      GATCCTTT
AAAGCCCTA

The slicing of a linear Dseq object works mostly as it does for a string.

>>> s="ggatcc"
>>> s[2:3]
'a'
>>> s[2:4]
'at'
>>> s[2:4:-1]
''
>>> s[::2]
'gac'
>>> from pydna.dseq import Dseq
>>> d=Dseq(s, circular=False)
>>> d[2:3]
Dseq(-1)
a
t
>>> d[2:4]
Dseq(-2)
at
ta
>>> d[2:4:-1]
Dseq(-0)


>>> d[::2]
Dseq(-3)
gac
ctg

The slicing of a circular Dseq object has a slightly different meaning.

>>> s="ggAtCc"
>>> d=Dseq(s, circular=True)
>>> d
Dseq(o6)
ggAtCc
ccTaGg
>>> d[4:3]
Dseq(-5)
CcggA
GgccT

The slice [X:X] produces an empty slice for a string, while this will return the linearized sequence starting at X:

>>> s="ggatcc"
>>> d=Dseq(s, circular=True)
>>> d
Dseq(o6)
ggatcc
cctagg
>>> d[3:3]
Dseq(-6)
tccgga
aggcct
>>>
trunc = 30#
classmethod quick(watson: str, crick: str, ovhg=0, circular=False, pos=0)[source]#
classmethod from_string(dna: str, *args, circular=False, **kwargs)[source]#
classmethod from_representation(dsdna: str, *args, **kwargs)[source]#
classmethod from_full_sequence_and_overhangs(full_sequence: str, crick_ovhg: int, watson_ovhg: int)[source]#

Create a linear Dseq object from a full sequence and the 3’ overhangs of each strand.

The order of the parameters is like this because the 3’ overhang of the crick strand is the one on the left side of the sequence.

Parameters:
  • full_sequence (str) – The full sequence of the Dseq object.

  • crick_ovhg (int) – The overhang of the crick strand in the 3’ end. Equivalent to Dseq.ovhg.

  • watson_ovhg (int) – The overhang of the watson strand in the 5’ end.

Returns:

A Dseq object.

Return type:

Dseq

Examples

>>> Dseq.from_full_sequence_and_overhangs('AAAAAA', crick_ovhg=2, watson_ovhg=2)
Dseq(-6)
  AAAA
TTTT
>>> Dseq.from_full_sequence_and_overhangs('AAAAAA', crick_ovhg=-2, watson_ovhg=2)
Dseq(-6)
AAAAAA
  TT
>>> Dseq.from_full_sequence_and_overhangs('AAAAAA', crick_ovhg=2, watson_ovhg=-2)
Dseq(-6)
  AA
TTTTTT
>>> Dseq.from_full_sequence_and_overhangs('AAAAAA', crick_ovhg=-2, watson_ovhg=-2)
Dseq(-6)
AAAA
  TTTT
mw() float[source]#

This method returns the molecular weight of the DNA molecule in g/mol. The following formula is used:

MW = (A x 313.2) + (T x 304.2) +
     (C x 289.2) + (G x 329.2) +
     (N x 308.9) + 79.0
upper() DseqType[source]#

Return an upper case copy of the sequence.

>>> from pydna.dseq import Dseq
>>> my_seq = Dseq("aAa")
>>> my_seq
Dseq(-3)
aAa
tTt
>>> my_seq.upper()
Dseq(-3)
AAA
TTT
Returns:

Dseq object in uppercase

Return type:

Dseq

lower() DseqType[source]#

Return a lower case copy of the sequence.

>>> from pydna.dseq import Dseq
>>> my_seq = Dseq("aAa")
>>> my_seq
Dseq(-3)
aAa
tTt
>>> my_seq.lower()
Dseq(-3)
aaa
ttt
Returns:

Dseq object in lowercase

Return type:

Dseq

find(sub: _SeqAbstractBaseClass | str | bytes, start=0, end=_sys.maxsize) int[source]#

This method behaves like the python string method of the same name.

Returns an integer, the index of the first occurrence of substring argument sub in the (sub)sequence given by [start:end].

Returns -1 if the subsequence is NOT found.

Parameters:
  • sub (string or Seq object) – a string or another Seq object to look for.

  • start (int, optional) – slice start.

  • end (int, optional) – slice end.

Examples

>>> from pydna.dseq import Dseq
>>> seq = Dseq("atcgactgacgtgtt")
>>> seq
Dseq(-15)
atcgactgacgtgtt
tagctgactgcacaa
>>> seq.find("gac")
3
>>> seq = Dseq(watson="agt",crick="actta",ovhg=-2)
>>> seq
Dseq(-7)
agt
  attca
>>> seq.find("taa")
2
reverse_complement() Dseq[source]#

Dseq object where watson and crick have switched places.

This represents the same double stranded sequence.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("catcgatc")
>>> a
Dseq(-8)
catcgatc
gtagctag
>>> b=a.reverse_complement()
>>> b
Dseq(-8)
gatcgatg
ctagctac
>>>
rc() Dseq#

Dseq object where watson and crick have switched places.

This represents the same double stranded sequence.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("catcgatc")
>>> a
Dseq(-8)
catcgatc
gtagctag
>>> b=a.reverse_complement()
>>> b
Dseq(-8)
gatcgatg
ctagctac
>>>
shifted(shift: int) DseqType[source]#

Shifted version of a circular Dseq object.

looped() DseqType[source]#

Circularized Dseq object.

This can only be done if the two ends are compatible, otherwise a TypeError is raised.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("catcgatc")
>>> a
Dseq(-8)
catcgatc
gtagctag
>>> a.looped()
Dseq(o8)
catcgatc
gtagctag
>>> a.T4("t")
Dseq(-8)
catcgat
 tagctag
>>> a.T4("t").looped()
Dseq(o7)
catcgat
gtagcta
>>> a.T4("a")
Dseq(-8)
catcga
  agctag
>>> a.T4("a").looped()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pydna/dsdna.py", line 357, in looped
    if type5 == type3 and str(sticky5) == str(rc(sticky3)):
TypeError: DNA cannot be circularized.
5' and 3' sticky ends not compatible!
>>>
tolinear() DseqType[source]#

Returns a blunt, linear copy of a circular Dseq object. This can only be done if the Dseq object is circular, otherwise a TypeError is raised.

This method is deprecated, use slicing instead. See example below.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("catcgatc", circular=True)
>>> a
Dseq(o8)
catcgatc
gtagctag
>>> a[:]
Dseq(-8)
catcgatc
gtagctag
>>>
five_prime_end() Tuple[str, str][source]#

Returns a tuple describing the structure of the 5’ end of the DNA fragment

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("aaa", "ttt")
>>> a
Dseq(-3)
aaa
ttt
>>> a.five_prime_end()
('blunt', '')
>>> a=Dseq("aaa", "ttt", ovhg=1)
>>> a
Dseq(-4)
 aaa
ttt
>>> a.five_prime_end()
("3'", 't')
>>> a=Dseq("aaa", "ttt", ovhg=-1)
>>> a
Dseq(-4)
aaa
 ttt
>>> a.five_prime_end()
("5'", 'a')
>>>
three_prime_end() Tuple[str, str][source]#

Returns a tuple describing the structure of the 5’ end of the DNA fragment

>>> from pydna.dseq import Dseq
>>> a=Dseq("aaa", "ttt")
>>> a
Dseq(-3)
aaa
ttt
>>> a.three_prime_end()
('blunt', '')
>>> a=Dseq("aaa", "ttt", ovhg=1)
>>> a
Dseq(-4)
 aaa
ttt
>>> a.three_prime_end()
("3'", 'a')
>>> a=Dseq("aaa", "ttt", ovhg=-1)
>>> a
Dseq(-4)
aaa
 ttt
>>> a.three_prime_end()
("5'", 't')
>>>
watson_ovhg() int[source]#

Returns the overhang of the watson strand at the three prime.

fill_in(nucleotides: None | str = None) Dseq[source]#

Fill in of five prime protruding end with a DNA polymerase that has only DNA polymerase activity (such as exo-klenow [7]) and any combination of A, G, C or T. Default are all four nucleotides together.

Parameters:

nucleotides (str)

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("aaa", "ttt")
>>> a
Dseq(-3)
aaa
ttt
>>> a.fill_in()
Dseq(-3)
aaa
ttt
>>> b=Dseq("caaa", "cttt")
>>> b
Dseq(-5)
caaa
 tttc
>>> b.fill_in()
Dseq(-5)
caaag
gtttc
>>> b.fill_in("g")
Dseq(-5)
caaag
gtttc
>>> b.fill_in("tac")
Dseq(-5)
caaa
 tttc
>>> c=Dseq("aaac", "tttg")
>>> c
Dseq(-5)
 aaac
gttt
>>> c.fill_in()
Dseq(-5)
 aaac
gttt
>>>

References

transcribe() Seq[source]#

Transcribe a DNA sequence into RNA and return the RNA sequence as a new Seq object.

Following the usual convention, the sequence is interpreted as the coding strand of the DNA double helix, not the template strand. This means we can get the RNA sequence just by switching T to U.

>>> from Bio.Seq import Seq
>>> coding_dna = Seq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
>>> coding_dna
Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> coding_dna.transcribe()
Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')

The sequence is modified in-place and returned if inplace is True:

>>> sequence = MutableSeq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
>>> sequence
MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> sequence.transcribe()
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
>>> sequence
MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> sequence.transcribe(inplace=True)
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
>>> sequence
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')

As Seq objects are immutable, a TypeError is raised if transcribe is called on a Seq object with inplace=True.

Trying to transcribe an RNA sequence has no effect. If you have a nucleotide sequence which might be DNA or RNA (or even a mixture), calling the transcribe method will ensure any T becomes U.

Trying to transcribe a protein sequence will replace any T for Threonine with U for Selenocysteine, which has no biologically plausible rational.

>>> from Bio.Seq import Seq
>>> my_protein = Seq("MAIVMGRT")
>>> my_protein.transcribe()
Seq('MAIVMGRU')
translate(table='Standard', stop_symbol='*', to_stop=False, cds=False, gap='-') Seq[source]#

Translate..

mung() Dseq[source]#

Simulates treatment a nuclease with 5’-3’ and 3’-5’ single strand specific exonuclease activity (such as mung bean nuclease [8])

    ggatcc    ->     gatcc
     ctaggg          ctagg

     ggatcc   ->      ggatc
    tcctag            cctag

>>> from pydna.dseq import Dseq
>>> b=Dseq("caaa", "cttt")
>>> b
Dseq(-5)
caaa
 tttc
>>> b.mung()
Dseq(-3)
aaa
ttt
>>> c=Dseq("aaac", "tttg")
>>> c
Dseq(-5)
 aaac
gttt
>>> c.mung()
Dseq(-3)
aaa
ttt

References

T4(nucleotides=None) Dseq[source]#

Fill in five prime protruding ends and chewing back three prime protruding ends by a DNA polymerase providing both 5’-3’ DNA polymerase activity and 3’-5’ nuclease acitivty (such as T4 DNA polymerase). This can be done in presence of any combination of the four A, G, C or T. Removing one or more nucleotides can facilitate engineering of sticky ends. Default are all four nucleotides together.

Parameters:

nucleotides (str)

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("gatcgatc")
>>> a
Dseq(-8)
gatcgatc
ctagctag
>>> a.T4()
Dseq(-8)
gatcgatc
ctagctag
>>> a.T4("t")
Dseq(-8)
gatcgat
 tagctag
>>> a.T4("a")
Dseq(-8)
gatcga
  agctag
>>> a.T4("g")
Dseq(-8)
gatcg
   gctag
>>>
t4(nucleotides=None) Dseq#

Fill in five prime protruding ends and chewing back three prime protruding ends by a DNA polymerase providing both 5’-3’ DNA polymerase activity and 3’-5’ nuclease acitivty (such as T4 DNA polymerase). This can be done in presence of any combination of the four A, G, C or T. Removing one or more nucleotides can facilitate engineering of sticky ends. Default are all four nucleotides together.

Parameters:

nucleotides (str)

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("gatcgatc")
>>> a
Dseq(-8)
gatcgatc
ctagctag
>>> a.T4()
Dseq(-8)
gatcgatc
ctagctag
>>> a.T4("t")
Dseq(-8)
gatcgat
 tagctag
>>> a.T4("a")
Dseq(-8)
gatcga
  agctag
>>> a.T4("g")
Dseq(-8)
gatcg
   gctag
>>>
exo1_front(n=1) DseqType[source]#

5’-3’ resection at the start (left side) of the molecule.

exo1_end(n=1) DseqType[source]#

5’-3’ resection at the end (right side) of the molecule.

no_cutters(batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch not cutting sequence.

unique_cutters(batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch cutting sequence once.

once_cutters(batch: RestrictionBatch | None = None) RestrictionBatch#

Enzymes in a RestrictionBatch cutting sequence once.

twice_cutters(batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch cutting sequence twice.

n_cutters(n=3, batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch cutting n times.

cutters(batch: RestrictionBatch | None = None) RestrictionBatch[source]#

Enzymes in a RestrictionBatch cutting sequence at least once.

seguid() str[source]#

SEGUID checksum for the sequence.

isblunt() bool[source]#

isblunt.

Return True if Dseq is linear and blunt and false if staggered or circular.

Examples

>>> from pydna.dseq import Dseq
>>> a=Dseq("gat")
>>> a
Dseq(-3)
gat
cta
>>> a.isblunt()
True
>>> a=Dseq("gat", "atcg")
>>> a
Dseq(-4)
 gat
gcta
>>> a.isblunt()
False
>>> a=Dseq("gat", "gatc")
>>> a
Dseq(-4)
gat
ctag
>>> a.isblunt()
False
>>> a=Dseq("gat", circular=True)
>>> a
Dseq(o3)
gat
cta
>>> a.isblunt()
False
cas9(RNA: str) Tuple[slice, ...][source]#

docstring.

terminal_transferase(nucleotides='a') Dseq[source]#

docstring.

cut(*enzymes: EnzymesType) Tuple[DseqType, ...][source]#

Returns a list of linear Dseq fragments produced in the digestion. If there are no cuts, an empty list is returned.

Parameters:

enzymes (enzyme object or iterable of such objects) – A Bio.Restriction.XXX restriction objects or iterable.

Returns:

frags – list of Dseq objects formed by the digestion

Return type:

list

Examples

>>> from pydna.dseq import Dseq
>>> seq=Dseq("ggatccnnngaattc")
>>> seq
Dseq(-15)
ggatccnnngaattc
cctaggnnncttaag
>>> from Bio.Restriction import BamHI,EcoRI
>>> type(seq.cut(BamHI))
<class 'tuple'>
>>> for frag in seq.cut(BamHI): print(repr(frag))
Dseq(-5)
g
cctag
Dseq(-14)
gatccnnngaattc
    gnnncttaag
>>> seq.cut(EcoRI, BamHI) ==  seq.cut(BamHI, EcoRI)
True
>>> a,b,c = seq.cut(EcoRI, BamHI)
>>> a+b+c
Dseq(-15)
ggatccnnngaattc
cctaggnnncttaag
>>>
cutsite_is_valid(cutsite: Tuple[Tuple[int, int], AbstractCut | None | _cas]) bool[source]#

Returns False if: - Cut positions fall outside the sequence (could be moved to Biopython) - Overhang is not double stranded - Recognition site is not double stranded or is outside the sequence - For enzymes that cut twice, it checks that at least one possibility is valid

get_cutsites(*enzymes: EnzymesType) List[Tuple[Tuple[int, int], AbstractCut | None | _cas]][source]#

Returns a list of cutsites, represented represented as ((cut_watson, ovhg), enz):

  • cut_watson is a positive integer contained in [0,len(seq)), where seq is the sequence that will be cut. It represents the position of the cut on the watson strand, using the full sequence as a reference. By “full sequence” I mean the one you would get from str(Dseq).

  • ovhg is the overhang left after the cut. It has the same meaning as ovhg in the Bio.Restriction enzyme objects, or pydna’s Dseq property.

  • enz is the enzyme object. It’s not necessary to perform the cut, but can be

    used to keep track of which enzyme was used.

Cuts are only returned if the recognition site and overhang are on the double-strand part of the sequence.

Parameters:

enzymes (Union[_RestrictionBatch,list[_AbstractCut]])

Return type:

list[tuple[tuple[int,int], _AbstractCut]]

Examples

>>> from Bio.Restriction import EcoRI
>>> from pydna.dseq import Dseq
>>> seq = Dseq('AAGAATTCAAGAATTC')
>>> seq.get_cutsites(EcoRI)
[((3, -4), EcoRI), ((11, -4), EcoRI)]

cut_watson is defined with respect to the “full sequence”, not the watson strand:

>>> dseq = Dseq.from_full_sequence_and_overhangs('aaGAATTCaa', 1, 0)
>>> dseq
Dseq(-10)
 aGAATTCaa
ttCTTAAGtt
>>> dseq.get_cutsites([EcoRI])
[((3, -4), EcoRI)]

Cuts are only returned if the recognition site and overhang are on the double-strand part of the sequence.

>>> Dseq('GAATTC').get_cutsites([EcoRI])
[((1, -4), EcoRI)]
>>> Dseq.from_full_sequence_and_overhangs('GAATTC', -1, 0).get_cutsites([EcoRI])
[]
left_end_position() Tuple[int, int][source]#

The index in the full sequence of the watson and crick start positions.

full sequence (str(self)) for all three cases is AAA

AAA              AA               AAT
 TT             TTT               TTT
Returns (0, 1)  Returns (1, 0)    Returns (0, 0)
right_end_position() Tuple[int, int][source]#

The index in the full sequence of the watson and crick end positions.

full sequence (str(self)) for all three cases is AAA

` AAA               AA                   AAA TT                TTT                  TTT Returns (3, 2)    Returns (2, 3)       Returns (3, 3) `

get_cut_parameters(cut: Tuple[Tuple[int, int], AbstractCut | None | _cas] | None, is_left: bool) Tuple[int, int, int][source]#

For a given cut expressed as ((cut_watson, ovhg), enz), returns a tuple (cut_watson, cut_crick, ovhg).

  • cut_watson: see get_cutsites docs

  • cut_crick: equivalent of cut_watson in the crick strand

  • ovhg: see get_cutsites docs

The cut can be None if it represents the left or right end of the sequence. Then it will return the position of the watson and crick ends with respect to the “full sequence”. The is_left parameter is only used in this case.

apply_cut(left_cut: Tuple[Tuple[int, int], AbstractCut | None | _cas], right_cut: Tuple[Tuple[int, int], AbstractCut | None | _cas]) Dseq[source]#

Extracts a subfragment of the sequence between two cuts.

For more detail see the documentation of get_cutsite_pairs.

Parameters:
Return type:

Dseq

Examples

>>> from Bio.Restriction import EcoRI
>>> from pydna.dseq import Dseq
>>> dseq = Dseq('aaGAATTCaaGAATTCaa')
>>> cutsites = dseq.get_cutsites([EcoRI])
>>> cutsites
[((3, -4), EcoRI), ((11, -4), EcoRI)]
>>> p1, p2, p3 = dseq.get_cutsite_pairs(cutsites)
>>> p1
(None, ((3, -4), EcoRI))
>>> dseq.apply_cut(*p1)
Dseq(-7)
aaG
ttCTTAA
>>> p2
(((3, -4), EcoRI), ((11, -4), EcoRI))
>>> dseq.apply_cut(*p2)
Dseq(-12)
AATTCaaG
    GttCTTAA
>>> p3
(((11, -4), EcoRI), None)
>>> dseq.apply_cut(*p3)
Dseq(-7)
AATTCaa
    Gtt
>>> dseq = Dseq('TTCaaGAA', circular=True)
>>> cutsites = dseq.get_cutsites([EcoRI])
>>> cutsites
[((6, -4), EcoRI)]
>>> pair = dseq.get_cutsite_pairs(cutsites)[0]
>>> pair
(((6, -4), EcoRI), ((6, -4), EcoRI))
>>> dseq.apply_cut(*pair)
Dseq(-12)
AATTCaaG
    GttCTTAA
get_cutsite_pairs(cutsites: List[Tuple[Tuple[int, int], AbstractCut | None | _cas]]) List[Tuple[None | Tuple[Tuple[int, int], AbstractCut | None | _cas], None | Tuple[Tuple[int, int], AbstractCut | None | _cas]]][source]#

Returns pairs of cutsites that render the edges of the resulting fragments.

A fragment produced by restriction is represented by a tuple of length 2 that may contain cutsites or None:

  • Two cutsites: represents the extraction of a fragment between those two cutsites, in that orientation. To represent the opening of a circular molecule with a single cutsite, we put the same cutsite twice.

  • None, cutsite: represents the extraction of a fragment between the left edge of linear sequence and the cutsite.

  • cutsite, None: represents the extraction of a fragment between the cutsite and the right edge of a linear sequence.

Parameters:

cutsites (list[tuple[tuple[int,int], _AbstractCut]])

Return type:

list[tuple[tuple[tuple[int,int], _AbstractCut]|None],tuple[tuple[int,int], _AbstractCut]|None]

Examples

>>> from Bio.Restriction import EcoRI
>>> from pydna.dseq import Dseq
>>> dseq = Dseq('aaGAATTCaaGAATTCaa')
>>> cutsites = dseq.get_cutsites([EcoRI])
>>> cutsites
[((3, -4), EcoRI), ((11, -4), EcoRI)]
>>> dseq.get_cutsite_pairs(cutsites)
[(None, ((3, -4), EcoRI)), (((3, -4), EcoRI), ((11, -4), EcoRI)), (((11, -4), EcoRI), None)]
>>> dseq = Dseq('TTCaaGAA', circular=True)
>>> cutsites = dseq.get_cutsites([EcoRI])
>>> cutsites
[((6, -4), EcoRI)]
>>> dseq.get_cutsite_pairs(cutsites)
[(((6, -4), EcoRI), ((6, -4), EcoRI))]

pydna.dseqrecord module#

This module provides the Dseqrecord class, for handling double stranded DNA sequences. The Dseqrecord holds sequence information in the form of a pydna.dseq.Dseq object. The Dseq and Dseqrecord classes are subclasses of Biopythons Seq and SeqRecord classes, respectively.

The Dseq and Dseqrecord classes support the notion of circular and linear DNA topology.

class pydna.dseqrecord.Dseqrecord(record, *args, circular=None, n=5e-14, source=None, **kwargs)[source]#

Bases: SeqRecord

Dseqrecord is a double stranded version of the Biopython SeqRecord [9] class. The Dseqrecord object holds a Dseq object describing the sequence. Additionally, Dseqrecord hold meta information about the sequence in the from of a list of SeqFeatures, in the same way as the SeqRecord does.

The Dseqrecord can be initialized with a string, Seq, Dseq, SeqRecord or another Dseqrecord. The sequence information will be stored in a Dseq object in all cases.

Dseqrecord objects can be read or parsed from sequences in FASTA, EMBL or Genbank formats. See the pydna.readers and pydna.parsers modules for further information.

There is a short representation associated with the Dseqrecord. Dseqrecord(-3) represents a linear sequence of length 2 while Dseqrecord(o7) represents a circular sequence of length 7.

Dseqrecord and Dseq share the same concept of length. This length can be larger than each strand alone if they are staggered as in the example below.

<-- length -->
GATCCTTT
     AAAGCCTAG
Parameters:
  • record (string, Seq, SeqRecord, Dseq or other Dseqrecord object) – This data will be used to form the seq property

  • circular (bool, optional) – True or False reflecting the shape of the DNA molecule

  • linear (bool, optional) – True or False reflecting the shape of the DNA molecule

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("aaa")
>>> a
Dseqrecord(-3)
>>> a.seq
Dseq(-3)
aaa
ttt
>>> from pydna.seq import Seq
>>> b=Dseqrecord(Seq("aaa"))
>>> b
Dseqrecord(-3)
>>> b.seq
Dseq(-3)
aaa
ttt
>>> from Bio.SeqRecord import SeqRecord
>>> c=Dseqrecord(SeqRecord(Seq("aaa")))
>>> c
Dseqrecord(-3)
>>> c.seq
Dseq(-3)
aaa
ttt

References

source: Source | None = None#
classmethod from_string(record: str = '', *args, circular=False, n=5e-14, **kwargs)[source]#

docstring.

classmethod from_SeqRecord(record: SeqRecord, *args, circular=None, n=5e-14, **kwargs)[source]#
property circular#

The circular property can not be set directly. Use looped()

m()[source]#

This method returns the mass of the DNA molecule in grams. This is calculated as the product between the molecular weight of the Dseq object and the

extract_feature(n)[source]#

Extracts a feature and creates a new Dseqrecord object.

Parameters:

n (int) – Indicates the feature to extract

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("atgtaa")
>>> a.add_feature(2,4)
>>> b=a.extract_feature(0)
>>> b
Dseqrecord(-2)
>>> b.seq
Dseq(-2)
gt
ca
add_feature(x=None, y=None, seq=None, type_='misc', strand=1, *args, **kwargs)[source]#

Add a feature of type misc to the feature list of the sequence.

Parameters:
  • x (int) – Indicates start of the feature

  • y (int) – Indicates end of the feature

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a=SeqRecord("atgtaa")
>>> a.features
[]
>>> a.add_feature(2,4)
>>> a.features
[SeqFeature(SimpleLocation(ExactPosition(2), ExactPosition(4), strand=1), type='misc', qualifiers=...)]
seguid()[source]#

Url safe SEGUID for the sequence.

This checksum is the same as seguid but with base64.urlsafe encoding instead of the normal base64. This means that the characters + and / are replaced with - and _ so that the checksum can be part of a URL.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a = Dseqrecord("aa")
>>> a.seguid()
'ldseguid=TEwydy0ugvGXh3VJnVwgtxoyDQA'
looped()[source]#

Circular version of the Dseqrecord object.

The underlying linear Dseq object has to have compatible ends.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("aaa")
>>> a
Dseqrecord(-3)
>>> b=a.looped()
>>> b
Dseqrecord(o3)
>>>
tolinear()[source]#

Returns a linear, blunt copy of a circular Dseqrecord object. The underlying Dseq object has to be circular.

This method is deprecated, use slicing instead. See example below.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("aaa", circular = True)
>>> a
Dseqrecord(o3)
>>> b=a[:]
>>> b
Dseqrecord(-3)
>>>
terminal_transferase(nucleotides='a')[source]#

docstring.

format(f='gb')[source]#

Returns the sequence as a string using a format supported by Biopython SeqIO [10]. Default is “gb” which is short for Genbank.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> x=Dseqrecord("aaa")
>>> x.annotations['date'] = '02-FEB-2013'
>>> x
Dseqrecord(-3)
>>> print(x.format("gb"))
LOCUS       name                       3 bp    DNA     linear   UNK 02-FEB-2013
DEFINITION  description.
ACCESSION   id
VERSION     id
KEYWORDS    .
SOURCE      .
  ORGANISM  .
            .
FEATURES             Location/Qualifiers
ORIGIN
        1 aaa
//

References

write(filename=None, f='gb')[source]#

Writes the Dseqrecord to a file using the format f, which must be a format supported by Biopython SeqIO for writing [11]. Default is “gb” which is short for Genbank. Note that Biopython SeqIO reads more formats than it writes.

Filename is the path to the file where the sequece is to be written. The filename is optional, if it is not given, the description property (string) is used together with the format.

If obj is the Dseqrecord object, the default file name will be:

<obj.locus>.<f>

Where <f> is “gb” by default. If the filename already exists and AND the sequence it contains is different, a new file name will be used so that the old file is not lost:

<obj.locus>_NEW.<f>

References

find(other)[source]#
find_aminoacids(other)[source]#
>>> from pydna.dseqrecord import Dseqrecord
>>> s=Dseqrecord("atgtacgatcgtatgctggttatattttag")
>>> s.seq.translate()
Seq('MYDRMLVIF*')
>>> "RML" in s
True
>>> "MMM" in s
False
>>> s.seq.rc().translate()
Seq('LKYNQHTIVH')
>>> "QHT" in s.rc()
True
>>> "QHT" in s
False
>>> slc = s.find_aa("RML")
>>> slc
slice(9, 18, None)
>>> s[slc]
Dseqrecord(-9)
>>> code = s[slc].seq
>>> code
Dseq(-9)
cgtatgctg
gcatacgac
>>> code.translate()
Seq('RML')
find_aa(other)#
>>> from pydna.dseqrecord import Dseqrecord
>>> s=Dseqrecord("atgtacgatcgtatgctggttatattttag")
>>> s.seq.translate()
Seq('MYDRMLVIF*')
>>> "RML" in s
True
>>> "MMM" in s
False
>>> s.seq.rc().translate()
Seq('LKYNQHTIVH')
>>> "QHT" in s.rc()
True
>>> "QHT" in s
False
>>> slc = s.find_aa("RML")
>>> slc
slice(9, 18, None)
>>> s[slc]
Dseqrecord(-9)
>>> code = s[slc].seq
>>> code
Dseq(-9)
cgtatgctg
gcatacgac
>>> code.translate()
Seq('RML')
map_trace_files(pth, limit=25)[source]#
linearize(*enzymes)[source]#

Similar to :func:cut.

Throws an exception if there is not excactly one cut i.e. none or more than one digestion products.

no_cutters(batch: RestrictionBatch = None)[source]#

docstring.

unique_cutters(batch: RestrictionBatch = None)[source]#

docstring.

once_cutters(batch: RestrictionBatch = None)[source]#

docstring.

twice_cutters(batch: RestrictionBatch = None)[source]#

docstring.

n_cutters(n=3, batch: RestrictionBatch = None)[source]#

docstring.

cutters(batch: RestrictionBatch = None)[source]#

docstring.

number_of_cuts(*enzymes)[source]#

The number of cuts by digestion with the Restriction enzymes contained in the iterable.

cas9(RNA: str)[source]#

docstring.

reverse_complement()[source]#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
rc()#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
synced(ref, limit=25)[source]#

This method returns a new circular sequence (Dseqrecord object), which has been rotated in such a way that there is maximum overlap between the sequence and ref, which may be a string, Biopython Seq, SeqRecord object or another Dseqrecord object.

The reason for using this could be to rotate a new recombinant plasmid so that it starts at the same position after cloning. See the example below:

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("gaat", circular=True)
>>> a.seq
Dseq(o4)
gaat
ctta
>>> d = a[2:] + a[:2]
>>> d.seq
Dseq(-4)
atga
tact
>>> insert=Dseqrecord("CCC")
>>> recombinant = (d+insert).looped()
>>> recombinant.seq
Dseq(o7)
atgaCCC
tactGGG
>>> recombinant.synced(a).seq
Dseq(o7)
gaCCCat
ctGGGta
upper()[source]#

Returns an uppercase copy. >>> from pydna.dseqrecord import Dseqrecord >>> my_seq = Dseqrecord(“aAa”) >>> my_seq.seq Dseq(-3) aAa tTt >>> upper = my_seq.upper() >>> upper.seq Dseq(-3) AAA TTT >>>

Returns:

Dseqrecord object in uppercase

Return type:

Dseqrecord

lower()[source]#
>>> from pydna.dseqrecord import Dseqrecord
>>> my_seq = Dseqrecord("aAa")
>>> my_seq.seq
Dseq(-3)
aAa
tTt
>>> upper = my_seq.upper()
>>> upper.seq
Dseq(-3)
AAA
TTT
>>> lower = my_seq.lower()
>>> lower
Dseqrecord(-3)
>>>
Returns:

Dseqrecord object in lowercase

Return type:

Dseqrecord

orfs(minsize=300)[source]#

docstring.

orfs_to_features(minsize=300)[source]#

docstring.

copy_gb_to_clipboard()[source]#

docstring.

copy_fasta_to_clipboard()[source]#

docstring.

figure(feature=0, highlight='\x1b[48;5;11m', plain='\x1b[0m')[source]#

docstring.

shifted(shift)[source]#

Circular Dseqrecord with a new origin <shift>.

This only works on circular Dseqrecords. If we consider the following circular sequence:

GAAAT   <-- watson strand
CTTTA   <-- crick strand

The T and the G on the watson strand are linked together as well as the A and the C of the of the crick strand.

if shift is 1, this indicates a new origin at position 1:

new origin at the | symbol:

G|AAAT
C|TTTA

new sequence:

AAATG
TTTAC

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("aaat",circular=True)
>>> a
Dseqrecord(o4)
>>> a.seq
Dseq(o4)
aaat
ttta
>>> b=a.shifted(1)
>>> b
Dseqrecord(o4)
>>> b.seq
Dseq(o4)
aata
ttat
cut(*enzymes)[source]#

Digest a Dseqrecord object with one or more restriction enzymes.

returns a list of linear Dseqrecords. If there are no cuts, an empty list is returned.

See also Dseq.cut() :param enzymes: A Bio.Restriction.XXX restriction object or iterable of such. :type enzymes: enzyme object or iterable of such objects

Returns:

Dseqrecord_frags – list of Dseqrecord objects formed by the digestion

Return type:

list

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggatcc")
>>> from Bio.Restriction import BamHI
>>> a.cut(BamHI)
(Dseqrecord(-5), Dseqrecord(-5))
>>> frag1, frag2 = a.cut(BamHI)
>>> frag1.seq
Dseq(-5)
g
cctag
>>> frag2.seq
Dseq(-5)
gatcc
    g
annotations: _AnnotationsDict#
dbxrefs: list[str]#
apply_cut(left_cut, right_cut)[source]#
history()[source]#

Returns a string representation of the cloning history of the sequence. Returns an empty string if the sequence has no source.

Check the documentation notebooks for extensive examples.

Returns:

str

Return type:

A string representation of the cloning history of the sequence.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.assembly2 import gibson_assembly
>>> fragments = [
...    Dseqrecord("TTTTacgatAAtgctccCCCC", circular=False, name="fragment1"),
...    Dseqrecord("CCCCtcatGGGG", circular=False, name="fragment2"),
...    Dseqrecord("GGGGatataTTTT", circular=False, name="fragment3"),
... ]
>>> product, *_ = gibson_assembly(fragments, limit=4)
>>> product.name = "product_name"
>>> print(product.history())
╙── product_name (Dseqrecord(o34))
    └─╼ GibsonAssemblySource
        ├─╼ fragment1 (Dseqrecord(-21))
        ├─╼ fragment2 (Dseqrecord(-12))
        └─╼ fragment3 (Dseqrecord(-13))

pydna.fakeseq module#

docstring.

class pydna.fakeseq.FakeSeq(length: int, n: float = 50e-15, rf: float = 0.0)[source]#

Bases: object

docstring.

m() float[source]#

Mass of the DNA molecule in grams.

M() float[source]#

M grams/mol.

pydna.fusionpcr module#

pydna.fusionpcr.fuse_by_pcr(fragments, limit=15)[source]#

docstring.

pydna.fusionpcr.list_parts(fusion_pcr_fragment)[source]#

pydna.gateway module#

pydna.gateway.gateway_overlap(seqx: Dseqrecord, seqy: Dseqrecord, reaction: str, greedy: bool) list[tuple[int, int, int]][source]#

Find gateway overlaps. If greedy is True, it uses a more greedy consensus site to find attP sites, which might give false positives

pydna.gateway.find_gateway_sites(seq: Dseqrecord, greedy: bool) dict[str, list[SimpleLocation]][source]#

Find all gateway sites in a sequence and return a dictionary with the name and positions of the sites.

pydna.gateway.annotate_gateway_sites(seq: Dseqrecord, greedy: bool) Dseqrecord[source]#

pydna.gel module#

docstring.

pydna.gel.interpolator(mwstd)[source]#

docstring.

pydna.gel.gel(samples=None, gel_length=600, margin=50, interpolator=interpolator(mwstd=_mwstd))[source]#

pydna.genbank module#

This module provides a class for downloading sequences from genbank called Genbank and an function that does the same thing called genbank.

The function can be used if the environmental variable pydna_email has been set to a valid email address. The easiest way to do this permanantly is to edit the pydna.ini file. See the documentation of pydna.open_config_folder()

class pydna.genbank.Genbank(users_email: str, *, tool: str = 'pydna')[source]#

Bases: object

Class to facilitate download from genbank. It is easier and quicker to use the pydna.genbank.genbank() function directly.

Parameters:

users_email (string) – Has to be a valid email address. You should always tell Genbanks who you are, so that they can contact you.

Examples

>>> from pydna.genbank import Genbank
>>> gb=Genbank("bjornjobb@gmail.com")
>>> rec = gb.nucleotide("LP002422.1")   # <- entry from genbank
>>> print(len(rec))
1
nucleotide(item: str, seq_start: int | None = None, seq_stop: int | None = None, strand: Literal[1, 2] = 1) GenbankRecord[source]#

This method downloads a genbank nuclotide record from genbank. This method is cached by default. This can be controlled by editing the pydna_cached_funcs environment variable. The best way to do this permanently is to edit the edit the pydna.ini file. See the documentation of pydna.open_config_folder()

Item is a string containing one genbank accession number for a nucleotide file. Genbank nucleotide accession numbers have this format:

A12345 = 1 letter + 5 numerals
AB123456 = 2 letters + 6 numerals

The accession number is sometimes followed by a point and version number

BK006936.2

Item can also contain optional interval information in the following formats:

BK006936.2 REGION: complement(613900..615202)
NM_005546 REGION: 1..100
NM_005546 REGION: complement(1..100)
21614549:1-100
21614549:c100-1
21614549 1-100
21614549 c100-1

It is useful to set an interval for large genbank records to limit the download time. The items above containing interval information and can be obtained directly by looking up an entry in Genbank and setting the Change region shown on the upper right side of the page. The ACCESSION line of the displayed Genbank file will have the formatting shown.

Alternatively, seq_start and seq_stop can be set explicitly to the sequence intervals to be downloaded.

If strand is 2. “c”, “C”, “crick”, “Crick”, “antisense”,”Antisense”, “2”, 2, “-” or “-1”, the antisense (Crick) strand is returned, otherwise the sense (Watson) strand is returned.

Result is returned as a pydna.genbankrecord.GenbankRecord object.

References

pydna.genbank.genbank(accession: str = 'CS570233.1', *args, **kwargs) GenbankRecord[source]#

Download a genbank nuclotide record.

This function takes the same paramenters as the :func:pydna.genbank.Genbank.nucleotide method. The email address stored in the pydna_email environment variable is used. The easiest way set this permanantly is to edit the pydna.ini file. See the documentation of pydna.open_config_folder()

if no accession is given, a very short Genbank entry is used as an example (see below). This can be useful for testing the connection to Genbank.

Please note that this result is also cached by default by settings in the pydna.ini file. See the documentation of pydna.open_config_folder()

LOCUS       CS570233                  14 bp    DNA     linear   PAT 18-MAY-2007
DEFINITION  Sequence 6 from Patent WO2007025016.
ACCESSION   CS570233
VERSION     CS570233.1
KEYWORDS    .
SOURCE      synthetic construct
  ORGANISM  synthetic construct
            other sequences; artificial sequences.
REFERENCE   1
  AUTHORS   Shaw,R.W. and Cottenoir,M.
  TITLE     Inhibition of metallo-beta-lactamase by double-stranded dna
  JOURNAL   Patent: WO 2007025016-A1 6 01-MAR-2007;
            Texas Tech University System (US)
FEATURES             Location/Qualifiers
     source          1..14
                     /organism="synthetic construct"
                     /mol_type="unassigned DNA"
                     /db_xref="taxon:32630"
                     /note="This is a 14bp aptamer inhibitor."
ORIGIN
        1 atgttcctac atga
//

pydna.genbankfile module#

class pydna.genbankfile.GenbankFile(record, *args, path=None, **kwargs)[source]#

Bases: Dseqrecord

classmethod from_SeqRecord(record, *args, path=None, **kwargs)[source]#
reverse_complement()[source]#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
rc()#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>

pydna.genbankfixer module#

This module provides the gbtext_clean() function which can clean up broken Genbank files enough to pass the BioPython Genbank parser

Almost all of this code was lifted from BioJSON (levskaya/BioJSON) by Anselm Levskaya. The original code was not accompanied by any software licence. This parser is based on pyparsing.

There are some modifications to deal with fringe cases.

The parser first produces JSON as an intermediate format which is then formatted back into a string in Genbank format.

The parser is not complete, so some fields do not survive the roundtrip (see below). This should not be a difficult fix. The returned result has two properties, .jseq which is the intermediate JSON produced by the parser and .gbtext which is the formatted genbank string.

pydna.genbankfixer.parseGBLoc(s, l_, t)[source]#

retwingles parsed genbank location strings, assumes no joins of RC and FWD sequences

pydna.genbankfixer.strip_multiline(s, l_, t)[source]#
pydna.genbankfixer.toInt(s, l_, t)[source]#
pydna.genbankfixer.strip_indent(str)[source]#
pydna.genbankfixer.concat_dict(dlist)[source]#

more or less dict(list of string pairs) but merges vals with the same keys so no duplicates occur

pydna.genbankfixer.toJSON(gbkstring)[source]#
pydna.genbankfixer.wrapstring(str_, rowstart, rowend, padfirst=True)[source]#

wraps the provided string in lines of length rowend-rowstart and padded on the left by rowstart. -> if padfirst is false the first line is not padded

pydna.genbankfixer.locstr(locs, strand)[source]#

genbank formatted location string, assumes no join’d combo of rev and fwd seqs

pydna.genbankfixer.originstr(sequence)[source]#

formats dna sequence as broken, numbered lines ala genbank

pydna.genbankfixer.toGB(jseq)[source]#

parses json jseq data and prints out ApE compatible genbank

pydna.genbankfixer.gbtext_clean(gbtext)[source]#

This function takes a string containing one genbank sequence in Genbank format and returns a named tuple containing two fields, the gbtext containing a string with the corrected genbank sequence and jseq which contains the JSON intermediate.

Examples

>>> s = '''LOCUS       New_DNA      3 bp    DNA   CIRCULAR SYN        19-JUN-2013
... DEFINITION  .
... ACCESSION
... VERSION
... SOURCE      .
...   ORGANISM  .
... COMMENT
... COMMENT     ApEinfo:methylated:1
... ORIGIN
...         1 aaa
... //'''
>>> from pydna.readers import read
>>> read(s)
... /site-packages/Bio/GenBank/Scanner.py:1388: BiopythonParserWarning: Malformed LOCUS line found - is this correct?
:'LOCUS       New_DNA      3 bp    DNA   CIRCULAR SYN        19-JUN-2013\n'
  "correct?\n:%r" % line, BiopythonParserWarning)
Traceback (most recent call last):
  File "... /pydna/readers.py", line 48, in read
    results = results.pop()
IndexError: pop from empty list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "... /pydna/readers.py", line 50, in read
    raise ValueError("No sequences found in data:\n({})".format(data[:79]))
ValueError: No sequences found in data:
(LOCUS       New_DNA      3 bp    DNA   CIRCULAR SYN        19-JUN-2013
DEFINITI)
>>> from pydna.genbankfixer import gbtext_clean
>>> s2, j2 = gbtext_clean(s)
>>> print(s2)
LOCUS       New_DNA                    3 bp ds-DNA     circular SYN 19-JUN-2013
DEFINITION  .
ACCESSION
VERSION
SOURCE      .
ORGANISM  .
COMMENT
COMMENT     ApEinfo:methylated:1
FEATURES             Location/Qualifiers
ORIGIN
        1 aaa
//
>>> s3 = read(s2)
>>> s3
Dseqrecord(o3)
>>> print(s3.format())
LOCUS       New_DNA                    3 bp    DNA     circular SYN 19-JUN-2013
DEFINITION  .
ACCESSION   New_DNA
VERSION     New_DNA
KEYWORDS    .
SOURCE
  ORGANISM  .
            .
COMMENT
            ApEinfo:methylated:1
FEATURES             Location/Qualifiers
ORIGIN
        1 aaa
//

pydna.genbankrecord module#

class pydna.genbankrecord.GenbankRecord(record, *args, item='accession', start=None, stop=None, strand=1, **kwargs)[source]#

Bases: Dseqrecord

classmethod from_string(record: str = '', *args, item='accession', start=None, stop=None, strand=1, **kwargs)[source]#

docstring.

classmethod from_SeqRecord(record, *args, item='accession', start=None, stop=None, strand=1, **kwargs)[source]#
reverse_complement()[source]#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
rc()#

Reverse complement.

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> a=Dseqrecord("ggaatt")
>>> a
Dseqrecord(-6)
>>> a.seq
Dseq(-6)
ggaatt
ccttaa
>>> a.reverse_complement().seq
Dseq(-6)
aattcc
ttaagg
>>>
pydna_code()[source]#

docstring.

biopython_code()[source]#

docstring.

pydna.goldengate module#

Assembly of sequences by GoldenGate ligation assembly.

pydna.ladders module#

Agarose gel DNA ladders.

A DNA ladder is a list of FakeSeq objects that has to be initiated with Size (bp), amount of substance (mol) and Relative mobility (Rf).

Rf is a float value between 0.000 and 1.000. These are used together with the cubic spline interpolator in the gel module to calculate migartion distance from fragment length. The Rf values are calculated manually from a gel image. Exampel can be found in scripts/molecular_weight_standards.ods.

pydna.ligate module#

docstring.

pydna.ligate.ligate(fragments: list)[source]#

docstring.

pydna.opencloning_models module#

This module provides classes that roughly map to the OpenCloning data model, which is defined using LinkML <https://linkml.io>, and available as a python package opencloning-linkml. These classes are documented there, and the ones in this module essentially replace the fields pointing to sequences and primers (which use ids in the data model) to Dseqrecord and Primer objects, respectively. Similarly, it uses Location from Biopython instead of a string, which is what the data model uses.

When using pydna to plan cloning, it stores the provenance of Dseqrecord objects in their source attribute. Not all methods generate sources so far, so refer to the documentation notebooks for examples on how to use this feature. The history method of Dseqrecord objects can be used to get a string representation of the provenance of the sequence. You can also use the CloningStrategy class to create a JSON representation of the cloning strategy. That CloningStrategy can be loaded in the OpenCloning web interface to see a representation of the cloning strategy.

pydna.opencloning_models.id_mode(use_python_internal_id: bool = True)[source]#

Context manager that is used to determine how ids are assigned to objects when mapping them to the OpenCloning data model. If use_python_internal_id is True, the built-in python id() function is used to assign ids to objects. That function produces a unique integer for each object in python, so it’s guaranteed to be unique. If use_python_internal_id is False, the object’s .id attribute (must be a string integer) is used to assign ids to objects. This is useful when the objects already have meaningful ids, and you want to keep references to them in SourceInput objects (which sequences and primers are used in a particular source).

Parameters:

use_python_internal_id (bool) – If True, use Python’s built-in id() function. If False, use the object’s .id attribute (must be a string integer).

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.opencloning_models import get_id, id_mode
>>> dseqr = Dseqrecord("ATGC")
>>> dseqr.name = "my_sequence"
>>> dseqr.id = "123"
>>> get_id(dseqr) == id(dseqr)
True
>>> with id_mode(use_python_internal_id=False):
...     get_id(dseqr)
123
pydna.opencloning_models.get_id(obj: Primer' | 'Dseqrecord) int[source]#

Get ID using the current strategy from thread-local storage (see id_mode) :param obj: The object to get the id of :type obj: Primer | Dseqrecord

Returns:

int

Return type:

The id of the object

class pydna.opencloning_models.SequenceLocationStr[source]#

Bases: str

A string representation of a sequence location, genbank-like.

classmethod from_biopython_location(location: Location)[source]#
to_biopython_location() Location[source]#
classmethod field_validator(v)[source]#
classmethod from_start_and_end(start: int, end: int, seq_len: int | None = None, strand: int | None = 1)[source]#
class pydna.opencloning_models.ConfiguredBaseModel[source]#

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.TextFileSequence(*, id: int, type: Literal['TextFileSequence'] = 'TextFileSequence', sequence_file_format: SequenceFileFormat, overhang_crick_3prime: int | None = 0, overhang_watson_3prime: int | None = 0, file_content: str | None = None)[source]#

Bases: TextFileSequence

classmethod from_dseqrecord(dseqr: Dseqrecord)[source]#
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.PrimerModel(*, id: int, type: Literal['Primer'] = 'Primer', name: str | None = None, database_id: int | None = None, sequence: str | None = None)[source]#

Bases: Primer

classmethod from_primer(primer: Primer)[source]#
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.SourceInput(*, sequence: object)[source]#

Bases: ConfiguredBaseModel

sequence: object#
to_pydantic_model() SourceInput[source]#
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.AssemblyFragment(*, sequence: object, left_location: Location | None = None, right_location: Location | None = None, reverse_complemented: bool)[source]#

Bases: SourceInput

left_location: Location | None#
right_location: Location | None#
reverse_complemented: bool#
static from_biopython_location(location: Location | None)[source]#
to_pydantic_model() AssemblyFragment[source]#
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.Source(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>)[source]#

Bases: ConfiguredBaseModel

input: list[SourceInput | AssemblyFragment]#
TARGET_MODEL#

alias of Source

input_models()[source]#
to_pydantic_model(seq_id: int)[source]#
add_to_history_graph(history_graph: nx.DiGraph, seq: Dseqrecord)[source]#

Add the source to the history graph.

It does not use the get_id function, because it just uses it to have unique identifiers for graph nodes, not to store them anywhere.

history_string(seq: Dseqrecord)[source]#

Returns a string representation of the cloning history of the sequence. See dseqrecord.history() for examples.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.AssemblySource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool)[source]#

Bases: Source

circular: bool#
TARGET_MODEL#

alias of AssemblySource

to_pydantic_model(seq_id: int)[source]#
classmethod from_subfragment_representation(assembly: SubFragmentRepresentationAssembly, fragments: list['Dseqrecord'], is_circular: bool)[source]#
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.RestrictionAndLigationSource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool, restriction_enzymes: list[~Bio.Restriction.Restriction.AbstractCut])[source]#

Bases: AssemblySource

restriction_enzymes: list[AbstractCut]#
TARGET_MODEL#

alias of RestrictionAndLigationSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.GibsonAssemblySource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool)[source]#

Bases: AssemblySource

TARGET_MODEL#

alias of GibsonAssemblySource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.InFusionSource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool)[source]#

Bases: AssemblySource

TARGET_MODEL#

alias of InFusionSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.OverlapExtensionPCRLigationSource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool)[source]#

Bases: AssemblySource

TARGET_MODEL#

alias of OverlapExtensionPCRLigationSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.InVivoAssemblySource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool)[source]#

Bases: AssemblySource

TARGET_MODEL#

alias of InVivoAssemblySource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.LigationSource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool)[source]#

Bases: AssemblySource

TARGET_MODEL#

alias of LigationSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.GatewaySource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool, reaction_type: ~opencloning_linkml.datamodel._models.GatewayReactionType, greedy: bool = False)[source]#

Bases: AssemblySource

TARGET_MODEL#

alias of GatewaySource

reaction_type: GatewayReactionType#
greedy: bool#
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.HomologousRecombinationSource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool)[source]#

Bases: AssemblySource

TARGET_MODEL#

alias of HomologousRecombinationSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.CRISPRSource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool)[source]#

Bases: HomologousRecombinationSource

TARGET_MODEL#

alias of CRISPRSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.CreLoxRecombinationSource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool)[source]#

Bases: AssemblySource

TARGET_MODEL#

alias of CreLoxRecombinationSource

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.PCRSource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, circular: bool, add_primer_features: bool = False)[source]#

Bases: AssemblySource

TARGET_MODEL#

alias of PCRSource

add_primer_features: bool#
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.SequenceCutSource(*, input: list[~pydna.opencloning_models.SourceInput | ~pydna.opencloning_models.AssemblyFragment] = <factory>, left_edge: ~typing.Tuple[~typing.Tuple[int, int], ~Bio.Restriction.Restriction.AbstractCut | None | ~pydna.crispr._cas] | None, right_edge: ~typing.Tuple[~typing.Tuple[int, int], ~Bio.Restriction.Restriction.AbstractCut | None | ~pydna.crispr._cas] | None)[source]#

Bases: Source

left_edge: CutSiteType | None#
right_edge: CutSiteType | None#
BASE_MODEL#

alias of SequenceCutSource

ENZYME_MODEL#

alias of RestrictionEnzymeDigestionSource

classmethod from_parent(parent: Dseqrecord, left_edge: CutSiteType, right_edge: CutSiteType)[source]#
to_pydantic_model(seq_id: int)[source]#
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class pydna.opencloning_models.CloningStrategy(*, sequences: list[~opencloning_linkml.datamodel._models.Sequence | ~opencloning_linkml.datamodel._models.TemplateSequence | ~opencloning_linkml.datamodel._models.TextFileSequence | ~opencloning_linkml.datamodel._models.Primer], sources: list[~opencloning_linkml.datamodel._models.Source | ~opencloning_linkml.datamodel._models.DatabaseSource | ~opencloning_linkml.datamodel._models.CollectionSource | ~opencloning_linkml.datamodel._models.ManuallyTypedSource | ~opencloning_linkml.datamodel._models.UploadedFileSource | ~opencloning_linkml.datamodel._models.RepositoryIdSource | ~opencloning_linkml.datamodel._models.GenomeCoordinatesSource | ~opencloning_linkml.datamodel._models.SequenceCutSource | ~opencloning_linkml.datamodel._models.AssemblySource | ~opencloning_linkml.datamodel._models.OligoHybridizationSource | ~opencloning_linkml.datamodel._models.PolymeraseExtensionSource | ~opencloning_linkml.datamodel._models.AnnotationSource | ~opencloning_linkml.datamodel._models.ReverseComplementSource | ~opencloning_linkml.datamodel._models.PCRSource | ~opencloning_linkml.datamodel._models.LigationSource | ~opencloning_linkml.datamodel._models.HomologousRecombinationSource | ~opencloning_linkml.datamodel._models.GibsonAssemblySource | ~opencloning_linkml.datamodel._models.InFusionSource | ~opencloning_linkml.datamodel._models.OverlapExtensionPCRLigationSource | ~opencloning_linkml.datamodel._models.InVivoAssemblySource | ~opencloning_linkml.datamodel._models.RestrictionAndLigationSource | ~opencloning_linkml.datamodel._models.GatewaySource | ~opencloning_linkml.datamodel._models.CreLoxRecombinationSource | ~opencloning_linkml.datamodel._models.CRISPRSource | ~opencloning_linkml.datamodel._models.RestrictionEnzymeDigestionSource | ~opencloning_linkml.datamodel._models.AddgeneIdSource | ~opencloning_linkml.datamodel._models.WekWikGeneIdSource | ~opencloning_linkml.datamodel._models.SEVASource | ~opencloning_linkml.datamodel._models.BenchlingUrlSource | ~opencloning_linkml.datamodel._models.SnapGenePlasmidSource | ~opencloning_linkml.datamodel._models.EuroscarfSource | ~opencloning_linkml.datamodel._models.IGEMSource | ~opencloning_linkml.datamodel._models.OpenDNACollectionsSource], primers: ~typing.List[~pydna.opencloning_models.PrimerModel] | None = <factory>, description: str | None = None, files: list[~opencloning_linkml.datamodel._models.AssociatedFile | ~opencloning_linkml.datamodel._models.SequencingFile] | None = None, schema_version: str | None = '0.4.5', backend_version: str | None = None, frontend_version: str | None = None)[source]#

Bases: CloningStrategy

primers: List[PrimerModel] | None#
add_primer(primer: Primer)[source]#
add_dseqrecord(dseqr: Dseqrecord)[source]#
reassign_ids()[source]#
classmethod from_dseqrecords(dseqrs: list['Dseqrecord'], description: str = '')[source]#
model_dump_json(*args, **kwargs)[source]#
!!! abstract “Usage Documentation”

[model_dump_json](../concepts/serialization.md#json-mode)

Generates a JSON representation of the model using Pydantic’s to_json method.

Parameters:
  • indent – Indentation to use in the JSON output. If None is passed, the output will be compact.

  • ensure_ascii – If True, the output is guaranteed to have all incoming non-ASCII characters escaped. If False (the default), these characters will be output as-is.

  • include – Field(s) to include in the JSON output.

  • exclude – Field(s) to exclude from the JSON output.

  • context – Additional context to pass to the serializer.

  • by_alias – Whether to serialize using field aliases.

  • exclude_unset – Whether to exclude fields that have not been explicitly set.

  • exclude_defaults – Whether to exclude fields that are set to their default value.

  • exclude_none – Whether to exclude fields that have a value of None.

  • exclude_computed_fields – Whether to exclude computed fields. While this can be useful for round-tripping, it is usually recommended to use the dedicated round_trip parameter instead.

  • round_trip – If True, dumped values should be valid as input for non-idempotent types such as Json[T].

  • warnings – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].

  • fallback – A function to call when an unknown value is encountered. If not provided, a [PydanticSerializationError][pydantic_core.PydanticSerializationError] error is raised.

  • serialize_as_any – Whether to serialize fields with duck-typing serialization behavior.

Returns:

A JSON string representation of the model.

model_dump(*args, **kwargs)[source]#
!!! abstract “Usage Documentation”

[model_dump](../concepts/serialization.md#python-mode)

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Parameters:
  • mode – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.

  • include – A set of fields to include in the output.

  • exclude – A set of fields to exclude from the output.

  • context – Additional context to pass to the serializer.

  • by_alias – Whether to use the field’s alias in the dictionary key if defined.

  • exclude_unset – Whether to exclude fields that have not been explicitly set.

  • exclude_defaults – Whether to exclude fields that are set to their default value.

  • exclude_none – Whether to exclude fields that have a value of None.

  • exclude_computed_fields – Whether to exclude computed fields. While this can be useful for round-tripping, it is usually recommended to use the dedicated round_trip parameter instead.

  • round_trip – If True, dumped values should be valid as input for non-idempotent types such as Json[T].

  • warnings – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].

  • fallback – A function to call when an unknown value is encountered. If not provided, a [PydanticSerializationError][pydantic_core.PydanticSerializationError] error is raised.

  • serialize_as_any – Whether to serialize fields with duck-typing serialization behavior.

Returns:

A dictionary representation of the model.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False, 'use_enum_values': True, 'validate_assignment': True, 'validate_default': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

pydna.parsers module#

Provides two functions, parse and parse_primers

pydna.parsers.extract_from_text(text)[source]#

docstring.

pydna.parsers.embl_gb_fasta(text)[source]#

Parse embl, genbank or fasta format from text.

Returns list of Bio.SeqRecord.SeqRecord

annotations[“molecule_type”] annotations[“topology”]

pydna.parsers.parse(data, ds=True)[source]#

Return all DNA sequences found in data.

If no sequences are found, an empty list is returned. This is a greedy function, use carefully.

Parameters:
  • data (string or iterable) –

    The data parameter is a string containing:

    1. an absolute path to a local file. The file will be read in text mode and parsed for EMBL, FASTA and Genbank sequences. Can be a string or a Path object.

    2. a string containing one or more sequences in EMBL, GENBANK, or FASTA format. Mixed formats are allowed.

    3. data can be a list or other iterable where the elements are 1 or 2

  • ds (bool) – If True double stranded Dseqrecord objects are returned. If False single stranded Bio.SeqRecord [12] objects are returned.

Returns:

contains Dseqrecord or SeqRecord objects

Return type:

list

References

See also

read

pydna.parsers.parse_primers(data)[source]#

docstring.

pydna.parsers.parse_snapgene(file_path: str) list[Dseqrecord][source]#

Parse a SnapGene file and return a Dseqrecord object.

Parameters:

file_path (str) – The path to the SnapGene file to parse.

Returns:

The parsed SnapGene file as a Dseqrecord object.

Return type:

Dseqrecord

pydna.primer module#

This module provide the Primer class that is a subclass of the biopython SeqRecord.

class pydna.primer.Primer(record, *args, amplicon=None, position=None, footprint=0, **kwargs)[source]#

Bases: SeqRecord

Primer and its position on a template, footprint and tail.

property footprint#
property tail#
reverse_complement(*args, **kwargs)[source]#

Return the reverse complement of the sequence.

pydna.readers module#

Provides two functions, read and read_primer.

pydna.readers.read(data, ds=True)[source]#

This function is similar the parse() function but expects one and only one sequence or and exception is thrown.

Parameters:
  • data (string) – see below

  • ds (bool) – Double stranded or single stranded DNA, if True return Dseqrecord objects, else Bio.SeqRecord objects.

Returns:

contains the first Dseqrecord or SeqRecord object parsed.

Return type:

Dseqrecord

Notes

The data parameter is similar to the data parameter for parse().

See also

parse

pydna.readers.read_primer(data)[source]#

Use this function to read a primer sequence from a string or a local file. The usage is similar to the parse_primer() function.

pydna.seq module#

A subclass of the Biopython SeqRecord class.

Has a number of extra methods and uses the pydna._pretty_str.pretty_str class instread of str for a nicer output in the IPython shell.

class pydna.seq.Seq(data: str | bytes | bytearray | _SeqAbstractBaseClass | SequenceDataAbstractBaseClass | dict | None, length: int | None = None)[source]#

Bases: Seq

docstring.

translate(*args, stop_symbol: str = '*', to_stop: bool = False, cds: bool = False, gap: str = '-', **kwargs) ProteinSeq[source]#

Translate..

gc() float[source]#

Return GC content.

cai(organism: str = 'sce') float[source]#

docstring.

rarecodons(organism: str = 'sce') List[slice][source]#

docstring.

startcodon(organism: str = 'sce') float | None[source]#

docstring.

stopcodon(organism: str = 'sce') float | None[source]#

docstring.

express(organism: str = 'sce') PrettyTable[source]#

docstring.

orfs2(minsize: int = 30) List[str][source]#

docstring.

orfs(minsize: int = 100) List[Tuple[int, int]][source]#
seguid() str[source]#

Url safe SEGUID [13] for the sequence.

This checksum is the same as seguid but with base64.urlsafe encoding instead of the normal base64. This means that the characters + and / are replaced with - and _ so that the checksum can be part of a URL.

Examples

>>> from pydna.seq import Seq
>>> a = Seq("aa")
>>> a.seguid()
'lsseguid=gBw0Jp907Tg_yX3jNgS4qQWttjU'

References

reverse_complement()[source]#

Return the reverse complement as a DNA sequence.

>>> Seq("CGA").reverse_complement()
Seq('TCG')

Any U in the sequence is treated as a T:

>>> Seq("CGAUT").reverse_complement()
Seq('AATCG')

In contrast, reverse_complement_rna returns an RNA sequence:

>>> Seq("CGA").reverse_complement_rna()
Seq('UCG')

The sequence is modified in-place and returned if inplace is True:

>>> my_seq = MutableSeq("CGA")
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement()
MutableSeq('TCG')
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement(inplace=True)
MutableSeq('TCG')
>>> my_seq
MutableSeq('TCG')

As Seq objects are immutable, a TypeError is raised if reverse_complement is called on a Seq object with inplace=True.

rc()#

Return the reverse complement as a DNA sequence.

>>> Seq("CGA").reverse_complement()
Seq('TCG')

Any U in the sequence is treated as a T:

>>> Seq("CGAUT").reverse_complement()
Seq('AATCG')

In contrast, reverse_complement_rna returns an RNA sequence:

>>> Seq("CGA").reverse_complement_rna()
Seq('UCG')

The sequence is modified in-place and returned if inplace is True:

>>> my_seq = MutableSeq("CGA")
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement()
MutableSeq('TCG')
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement(inplace=True)
MutableSeq('TCG')
>>> my_seq
MutableSeq('TCG')

As Seq objects are immutable, a TypeError is raised if reverse_complement is called on a Seq object with inplace=True.

class pydna.seq.ProteinSeq(data: str | bytes | bytearray | _SeqAbstractBaseClass | SequenceDataAbstractBaseClass | dict | None, length: int | None = None)[source]#

Bases: Seq

docstring.

translate()[source]#

Turn a nucleotide sequence into a protein sequence by creating a new sequence object.

This method will translate DNA or RNA sequences. It should not be used on protein sequences as any result will be biologically meaningless.

Parameters:
  • name (- table - Which codon table to use? This can be either a) – (string), an NCBI identifier (integer), or a CodonTable object (useful for non-standard genetic codes). This defaults to the “Standard” table.

  • string (- stop_symbol - Single character) – terminators. This defaults to the asterisk, “*”.

  • for (what to use) – terminators. This defaults to the asterisk, “*”.

  • Boolean (- cds -) – translation continuing on past any stop codons (translated as the specified stop_symbol). If True, translation is terminated at the first in frame stop codon (and the stop_symbol is not appended to the returned protein sequence).

  • full (defaults to False meaning do a) – translation continuing on past any stop codons (translated as the specified stop_symbol). If True, translation is terminated at the first in frame stop codon (and the stop_symbol is not appended to the returned protein sequence).

  • Boolean – this checks the sequence starts with a valid alternative start codon (which will be translated as methionine, M), that the sequence length is a multiple of three, and that there is a single in frame stop codon at the end (this will be excluded from the protein sequence, regardless of the to_stop option). If these tests fail, an exception is raised.

  • True (indicates this is a complete CDS. If) – this checks the sequence starts with a valid alternative start codon (which will be translated as methionine, M), that the sequence length is a multiple of three, and that there is a single in frame stop codon at the end (this will be excluded from the protein sequence, regardless of the to_stop option). If these tests fail, an exception is raised.

:paramthis checks the sequence starts with a valid alternative start

codon (which will be translated as methionine, M), that the sequence length is a multiple of three, and that there is a single in frame stop codon at the end (this will be excluded from the protein sequence, regardless of the to_stop option). If these tests fail, an exception is raised.

Parameters:

gaps. (- gap - Single character string to denote symbol used for) – Defaults to the minus sign.

A Seq object is returned if translate is called on a Seq object; a MutableSeq object is returned if translate is called pn a MutableSeq object.

e.g. Using the standard table:

>>> coding_dna = Seq("GTGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
>>> coding_dna.translate()
Seq('VAIVMGR*KGAR*')
>>> coding_dna.translate(stop_symbol="@")
Seq('VAIVMGR@KGAR@')
>>> coding_dna.translate(to_stop=True)
Seq('VAIVMGR')

Now using NCBI table 2, where TGA is not a stop codon:

>>> coding_dna.translate(table=2)
Seq('VAIVMGRWKGAR*')
>>> coding_dna.translate(table=2, to_stop=True)
Seq('VAIVMGRWKGAR')

In fact, GTG is an alternative start codon under NCBI table 2, meaning this sequence could be a complete CDS:

>>> coding_dna.translate(table=2, cds=True)
Seq('MAIVMGRWKGAR')

It isn’t a valid CDS under NCBI table 1, due to both the start codon and also the in frame stop codons:

>>> coding_dna.translate(table=1, cds=True)
Traceback (most recent call last):
    ...
Bio.Data.CodonTable.TranslationError: First codon 'GTG' is not a start codon

If the sequence has no in-frame stop codon, then the to_stop argument has no effect:

>>> coding_dna2 = Seq("TTGGCCATTGTAATGGGCCGC")
>>> coding_dna2.translate()
Seq('LAIVMGR')
>>> coding_dna2.translate(to_stop=True)
Seq('LAIVMGR')

NOTE - Ambiguous codons like “TAN” or “NNN” could be an amino acid or a stop codon. These are translated as “X”. Any invalid codon (e.g. “TA?” or “T-A”) will throw a TranslationError.

NOTE - This does NOT behave like the python string’s translate method. For that use str(my_seq).translate(…) instead

complement()[source]#

Return the complement as a DNA sequence.

>>> Seq("CGA").complement()
Seq('GCT')

Any U in the sequence is treated as a T:

>>> Seq("CGAUT").complement()
Seq('GCTAA')

In contrast, complement_rna returns an RNA sequence:

>>> Seq("CGAUT").complement_rna()
Seq('GCUAA')

The sequence is modified in-place and returned if inplace is True:

>>> my_seq = MutableSeq("CGA")
>>> my_seq
MutableSeq('CGA')
>>> my_seq.complement()
MutableSeq('GCT')
>>> my_seq
MutableSeq('CGA')
>>> my_seq.complement(inplace=True)
MutableSeq('GCT')
>>> my_seq
MutableSeq('GCT')

As Seq objects are immutable, a TypeError is raised if complement_rna is called on a Seq object with inplace=True.

complement_rna()[source]#

Return the complement as an RNA sequence.

>>> Seq("CGA").complement_rna()
Seq('GCU')

Any T in the sequence is treated as a U:

>>> Seq("CGAUT").complement_rna()
Seq('GCUAA')

In contrast, complement returns a DNA sequence by default:

>>> Seq("CGA").complement()
Seq('GCT')

The sequence is modified in-place and returned if inplace is True:

>>> my_seq = MutableSeq("CGA")
>>> my_seq
MutableSeq('CGA')
>>> my_seq.complement_rna()
MutableSeq('GCU')
>>> my_seq
MutableSeq('CGA')
>>> my_seq.complement_rna(inplace=True)
MutableSeq('GCU')
>>> my_seq
MutableSeq('GCU')

As Seq objects are immutable, a TypeError is raised if complement_rna is called on a Seq object with inplace=True.

reverse_complement()[source]#

Return the reverse complement as a DNA sequence.

>>> Seq("CGA").reverse_complement()
Seq('TCG')

Any U in the sequence is treated as a T:

>>> Seq("CGAUT").reverse_complement()
Seq('AATCG')

In contrast, reverse_complement_rna returns an RNA sequence:

>>> Seq("CGA").reverse_complement_rna()
Seq('UCG')

The sequence is modified in-place and returned if inplace is True:

>>> my_seq = MutableSeq("CGA")
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement()
MutableSeq('TCG')
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement(inplace=True)
MutableSeq('TCG')
>>> my_seq
MutableSeq('TCG')

As Seq objects are immutable, a TypeError is raised if reverse_complement is called on a Seq object with inplace=True.

rc()#

Return the reverse complement as a DNA sequence.

>>> Seq("CGA").reverse_complement()
Seq('TCG')

Any U in the sequence is treated as a T:

>>> Seq("CGAUT").reverse_complement()
Seq('AATCG')

In contrast, reverse_complement_rna returns an RNA sequence:

>>> Seq("CGA").reverse_complement_rna()
Seq('UCG')

The sequence is modified in-place and returned if inplace is True:

>>> my_seq = MutableSeq("CGA")
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement()
MutableSeq('TCG')
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement(inplace=True)
MutableSeq('TCG')
>>> my_seq
MutableSeq('TCG')

As Seq objects are immutable, a TypeError is raised if reverse_complement is called on a Seq object with inplace=True.

reverse_complement_rna()[source]#

Return the reverse complement as an RNA sequence.

>>> Seq("CGA").reverse_complement_rna()
Seq('UCG')

Any T in the sequence is treated as a U:

>>> Seq("CGAUT").reverse_complement_rna()
Seq('AAUCG')

In contrast, reverse_complement returns a DNA sequence:

>>> Seq("CGA").reverse_complement()
Seq('TCG')

The sequence is modified in-place and returned if inplace is True:

>>> my_seq = MutableSeq("CGA")
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement_rna()
MutableSeq('UCG')
>>> my_seq
MutableSeq('CGA')
>>> my_seq.reverse_complement_rna(inplace=True)
MutableSeq('UCG')
>>> my_seq
MutableSeq('UCG')

As Seq objects are immutable, a TypeError is raised if reverse_complement_rna is called on a Seq object with inplace=True.

transcribe()[source]#

Transcribe a DNA sequence into RNA and return the RNA sequence as a new Seq object.

Following the usual convention, the sequence is interpreted as the coding strand of the DNA double helix, not the template strand. This means we can get the RNA sequence just by switching T to U.

>>> from Bio.Seq import Seq
>>> coding_dna = Seq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
>>> coding_dna
Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> coding_dna.transcribe()
Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')

The sequence is modified in-place and returned if inplace is True:

>>> sequence = MutableSeq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
>>> sequence
MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> sequence.transcribe()
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
>>> sequence
MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> sequence.transcribe(inplace=True)
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
>>> sequence
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')

As Seq objects are immutable, a TypeError is raised if transcribe is called on a Seq object with inplace=True.

Trying to transcribe an RNA sequence has no effect. If you have a nucleotide sequence which might be DNA or RNA (or even a mixture), calling the transcribe method will ensure any T becomes U.

Trying to transcribe a protein sequence will replace any T for Threonine with U for Selenocysteine, which has no biologically plausible rational.

>>> from Bio.Seq import Seq
>>> my_protein = Seq("MAIVMGRT")
>>> my_protein.transcribe()
Seq('MAIVMGRU')
back_transcribe()[source]#

Return the DNA sequence from an RNA sequence by creating a new Seq object.

>>> from Bio.Seq import Seq
>>> messenger_rna = Seq("AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG")
>>> messenger_rna
Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
>>> messenger_rna.back_transcribe()
Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')

The sequence is modified in-place and returned if inplace is True:

>>> sequence = MutableSeq("AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG")
>>> sequence
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
>>> sequence.back_transcribe()
MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> sequence
MutableSeq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG')
>>> sequence.back_transcribe(inplace=True)
MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')
>>> sequence
MutableSeq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG')

As Seq objects are immutable, a TypeError is raised if transcribe is called on a Seq object with inplace=True.

Trying to back-transcribe DNA has no effect, If you have a nucleotide sequence which might be DNA or RNA (or even a mixture), calling the back-transcribe method will ensure any U becomes T.

Trying to back-transcribe a protein sequence will replace any U for Selenocysteine with T for Threonine, which is biologically meaningless.

>>> from Bio.Seq import Seq
>>> my_protein = Seq("MAIVMGRU")
>>> my_protein.back_transcribe()
Seq('MAIVMGRT')
seguid() str[source]#

Url safe SEGUID [14] for the sequence.

This checksum is the same as seguid but with base64.urlsafe encoding instead of the normal base64. This means that the characters + and / are replaced with - and _ so that the checksum can be part of a URL.

Examples

>>> from pydna.seq import ProteinSeq
>>> a = ProteinSeq("aa")
>>> a.seguid()
'lsseguid=gBw0Jp907Tg_yX3jNgS4qQWttjU'

References

molecular_weight() float[source]#
pI() float[source]#
instability_index() float[source]#

Instability index according to Guruprasad et al.

Value above 40 means the protein is has a short half life.

Guruprasad K., Reddy B.V.B., Pandit M.W. Protein Engineering 4:155-161(1990).

pydna.seqrecord module#

A subclass of the Biopython SeqRecord class.

Has a number of extra methods and uses the pydna._pretty_str.pretty_str class instread of str for a nicer output in the IPython shell.

class pydna.seqrecord.SeqRecord(seq, id='id', name='name', description='description', dbxrefs=None, features=None, annotations=None, letter_annotations=None)[source]#

Bases: SeqRecord

A subclass of the Biopython SeqRecord class.

Has a number of extra methods and uses the pydna._pretty_str.pretty_str class instread of str for a nicer output in the IPython shell.

classmethod from_Bio_SeqRecord(sr: SeqRecord)[source]#

Creates a pydnaSeqRecord from a Biopython SeqRecord.

property locus#

Alias for name property.

property accession#

Alias for id property.

property definition#

Alias for description property.

reverse_complement(*args, **kwargs)[source]#

Return the reverse complement of the sequence.

rc(*args, **kwargs)#

Return the reverse complement of the sequence.

isorf(table=1)[source]#

Detect if sequence is an open reading frame (orf) in the 5’-3’.

direction.

Translation tables are numbers according to the NCBI numbering [15].

Parameters:

table (int) – Sets the translation table, default is 1 (standard code)

Returns:

True if sequence is an orf, False otherwise.

Return type:

bool

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a=SeqRecord("atgtaa")
>>> a.isorf()
True
>>> b=SeqRecord("atgaaa")
>>> b.isorf()
False
>>> c=SeqRecord("atttaa")
>>> c.isorf()
False

References

translate()[source]#

docstring.

add_colors_to_features_for_ape()[source]#

Assign colors to features.

compatible with the ApE editor.

add_feature(x=None, y=None, seq=None, type_='misc', strand=1, *args, **kwargs)[source]#

Add a feature of type misc to the feature list of the sequence.

Parameters:
  • x (int) – Indicates start of the feature

  • y (int) – Indicates end of the feature

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a=SeqRecord("atgtaa")
>>> a.features
[]
>>> a.add_feature(2,4)
>>> a.features
[SeqFeature(SimpleLocation(ExactPosition(2),
                           ExactPosition(4),
                           strand=1),
            type='misc',
            qualifiers=...)]
list_features()[source]#

Print ASCII table with all features.

Examples

>>> from pydna.seq import Seq
>>> from pydna.seqrecord import SeqRecord
>>> a=SeqRecord(Seq("atgtaa"))
>>> a.add_feature(2,4)
>>> print(a.list_features())
+-----+---------------+-----+-----+-----+-----+------+------+
| Ft# | Label or Note | Dir | Sta | End | Len | type | orf? |
+-----+---------------+-----+-----+-----+-----+------+------+
|   0 | L:ft2         | --> | 2   | 4   |   2 | misc |  no  |
+-----+---------------+-----+-----+-----+-----+------+------+
extract_feature(n)[source]#

Extract feature and return a new SeqRecord object.

Parameters:
  • n (int)

  • extract (Indicates the feature to)

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a=SeqRecord("atgtaa")
>>> a.add_feature(2,4)
>>> b=a.extract_feature(0)
>>> b
SeqRecord(seq=Seq('gt'), id='ft2', name='part_name',
          description='description', dbxrefs=[])
sorted_features()[source]#

Return a list of the features sorted by start position.

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a=SeqRecord("atgtaa")
>>> a.add_feature(3,4)
>>> a.add_feature(2,4)
>>> print(a.features)
[SeqFeature(SimpleLocation(ExactPosition(3), ExactPosition(4),
                           strand=1),
            type='misc', qualifiers=...),
 SeqFeature(SimpleLocation(ExactPosition(2), ExactPosition(4),
                           strand=1),
            type='misc', qualifiers=...)]
>>> print(a.sorted_features())
[SeqFeature(SimpleLocation(ExactPosition(2), ExactPosition(4),
                           strand=1),
            type='misc', qualifiers=...),
 SeqFeature(SimpleLocation(ExactPosition(3), ExactPosition(4),
                           strand=1),
            type='misc', qualifiers=...)]
seguid()[source]#

Return the url safe SEGUID [16] for the sequence.

This checksum is the same as seguid but with base64.urlsafe encoding instead of the normal base 64. This means that the characters + and / are replaced with - and _ so that the checksum can be a part of and URL or a filename.

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a=SeqRecord("gattaca")
>>> a.seguid() # original seguid is +bKGnebMkia5kNg/gF7IORXMnIU
'lsseguid=tp2jzeCM2e3W4yxtrrx09CMKa_8'

References

comment(newcomment='')[source]#

docstring.

datefunction()[source]#

docstring.

stamp(now=datefunction, tool='pydna', separator=' ', comment='')[source]#

Add seguid checksum to COMMENTS sections

The checksum is stored in object.annotations[“comment”]. This shows in the COMMENTS section of a formatted genbank file.

For blunt linear sequences:

SEGUID <seguid>

For circular sequences:

cSEGUID <seguid>

Fore linear sequences which are not blunt:

lSEGUID <seguid>

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a = SeqRecord("aa")
>>> a.stamp()
'lsseguid=gBw0Jp907Tg_yX3jNgS4qQWttjU'
>>> a.annotations["comment"][:41]
'pydna lsseguid=gBw0Jp907Tg_yX3jNgS4qQWttj'
lcs(other, *args, limit=25, **kwargs)[source]#

Return the longest common substring between the sequence.

and another sequence (other). The other sequence can be a string, Seq, SeqRecord, Dseq or DseqRecord. The method returns a SeqFeature with type “read” as this method is mostly used to map sequence reads to the sequence. This can be changed by passing a type as keyword with some other string value.

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a = SeqRecord("GGATCC")
>>> a.lcs("GGATCC", limit=6)
SeqFeature(SimpleLocation(ExactPosition(0),
                          ExactPosition(6), strand=1),
                          type='read',
                          qualifiers=...)
>>> a.lcs("GATC", limit=4)
SeqFeature(SimpleLocation(ExactPosition(1),
                          ExactPosition(5), strand=1),
                          type='read',
                          qualifiers=...)
>>> a = SeqRecord("CCCCC")
>>> a.lcs("GGATCC", limit=6)
SeqFeature(None)
gc()[source]#

Return GC content.

cai(organism='sce')[source]#

docstring.

rarecodons(organism='sce')[source]#

docstring.

startcodon(organism='sce')[source]#

docstring.

stopcodon(organism='sce')[source]#

docstring.

express(organism='sce')[source]#

docstring.

copy()[source]#

docstring.

dump(filename, protocol=None)[source]#

docstring.

class pydna.seqrecord.ProteinSeqRecord(seq, id='id', name='name', description='description', dbxrefs=None, features=None, annotations=None, letter_annotations=None)[source]#

Bases: SeqRecord

reverse_complement(*args, **kwargs)[source]#

Return the reverse complement of the sequence.

rc(*args, **kwargs)#

Return the reverse complement of the sequence.

isorf(*args, **kwargs)[source]#

Detect if sequence is an open reading frame (orf) in the 5’-3’.

direction.

Translation tables are numbers according to the NCBI numbering [17].

Parameters:

table (int) – Sets the translation table, default is 1 (standard code)

Returns:

True if sequence is an orf, False otherwise.

Return type:

bool

Examples

>>> from pydna.seqrecord import SeqRecord
>>> a=SeqRecord("atgtaa")
>>> a.isorf()
True
>>> b=SeqRecord("atgaaa")
>>> b.isorf()
False
>>> c=SeqRecord("atttaa")
>>> c.isorf()
False

References

gc()[source]#

Return GC content.

cai(*args, **kwargs)[source]#

docstring.

rarecodons(*args, **kwargs)[source]#

docstring.

startcodon(*args, **kwargs)[source]#

docstring.

stopcodon(*args, **kwargs)[source]#

docstring.

express(*args, **kwargs)[source]#

docstring.

pydna.sequence_picker module#

pydna.sequence_picker.genbank_accession(s: str) Dseqrecord[source]#

docstring.

pydna.sequence_regex module#

pydna.sequence_regex.compute_regex_site(site: str) str[source]#

Creates a regex pattern from a string that may contain degenerate bases.

Parameters:

site – The string to convert to a regex pattern.

Returns:

The regex pattern.

pydna.sequence_regex.dseqrecord_finditer(pattern: str, seq: Dseqrecord) list[Match][source]#

Finds all matches of a regex pattern in a Dseqrecord.

Parameters:
  • pattern – The regex pattern to search for.

  • seq – The Dseqrecord to search in.

Returns:

A list of matches.

pydna.threading_timer_decorator_exit module#

MIT License

Copyright (c) 2015 Aaron Hall

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pydna.threading_timer_decorator_exit.cdquit(fn_name)[source]#
pydna.threading_timer_decorator_exit.exit_after(s)[source]#

use as decorator to exit process if function takes longer than s seconds

pydna.threading_timer_decorator_exit.a(*args, **kwargs)[source]#
pydna.threading_timer_decorator_exit.b(*args, **kwargs)[source]#
pydna.threading_timer_decorator_exit.c(*args, **kwargs)[source]#
pydna.threading_timer_decorator_exit.d(*args, **kwargs)[source]#
pydna.threading_timer_decorator_exit.countdown(*args, **kwargs)[source]#
pydna.threading_timer_decorator_exit.main()[source]#

pydna.tm module#

This module provide functions for melting temperature calculations.

pydna.tm.tm_default(seq, check=True, strict=True, c_seq=None, shift=0, nn_table=_mt.DNA_NN4, tmm_table=None, imm_table=None, de_table=None, dnac1=500 / 2, dnac2=500 / 2, selfcomp=False, Na=40, K=0, Tris=75.0, Mg=1.5, dNTPs=0.8, saltcorr=7, func=_mt.Tm_NN)[source]#
pydna.tm.tm_dbd(seq, check=True, strict=True, c_seq=None, shift=0, nn_table=_mt.DNA_NN3, tmm_table=None, imm_table=None, de_table=None, dnac1=250, dnac2=250, selfcomp=False, Na=50, K=0, Tris=0, Mg=1.5, dNTPs=0.8, saltcorr=1, func=_mt.Tm_NN)[source]#
pydna.tm.tm_product(seq: str, K=0.050)[source]#

Tm calculation for the amplicon.

according to:

Rychlik, Spencer, and Rhoads, 1990, Optimization of the anneal ing temperature for DNA amplification in vitro http://www.ncbi.nlm.nih.gov/pubmed/2243783

pydna.tm.ta_default(fp: str, rp: str, seq: str, tm=tm_default, tm_product=tm_product)[source]#

Ta calculation.

according to:

Rychlik, Spencer, and Rhoads, 1990, Optimization of the anneal ing temperature for DNA amplification in vitro http://www.ncbi.nlm.nih.gov/pubmed/2243783

The formula described uses the length and GC content of the product and salt concentration (monovalent cations)

pydna.tm.ta_dbd(fp, rp, seq, tm=tm_dbd, tm_product=None)[source]#
pydna.tm.program(amplicon, tm=tm_default, ta=ta_default)[source]#

Returns a string containing a text representation of a suggested PCR program using Taq or similar polymerase.

|95°C|95°C               |    |tmf:59.5
|____|_____          72°C|72°C|tmr:59.7
|3min|30s  \ 59.1°C _____|____|60s/kb
|    |      \______/ 0:32|5min|GC 51%
|    |       30s         |    |1051bp
pydna.tm.taq_program(amplicon, tm=tm_default, ta=ta_default)#

Returns a string containing a text representation of a suggested PCR program using Taq or similar polymerase.

|95°C|95°C               |    |tmf:59.5
|____|_____          72°C|72°C|tmr:59.7
|3min|30s  \ 59.1°C _____|____|60s/kb
|    |      \______/ 0:32|5min|GC 51%
|    |       30s         |    |1051bp
pydna.tm.dbd_program(amplicon, tm=tm_dbd, ta=ta_dbd)[source]#

Text representation of a suggested PCR program.

Using a polymerase with a DNA binding domain such as Pfu-Sso7d.

|98°C|98°C               |    |tmf:53.8
|____|_____          72°C|72°C|tmr:54.8
|30s |10s  \ 57.0°C _____|____|15s/kb
|    |      \______/ 0:15|5min|GC 51%
|    |       10s         |    |1051bp

|98°C|98°C      |    |tmf:82.5
|____|____      |    |tmr:84.4
|30s |10s \ 72°C|72°C|15s/kb
|    |     \____|____|GC 52%
|    |      3:45|5min|15058bp
pydna.tm.pfu_sso7d_program(amplicon, tm=tm_dbd, ta=ta_dbd)#

Text representation of a suggested PCR program.

Using a polymerase with a DNA binding domain such as Pfu-Sso7d.

|98°C|98°C               |    |tmf:53.8
|____|_____          72°C|72°C|tmr:54.8
|30s |10s  \ 57.0°C _____|____|15s/kb
|    |      \______/ 0:15|5min|GC 51%
|    |       10s         |    |1051bp

|98°C|98°C      |    |tmf:82.5
|____|____      |    |tmr:84.4
|30s |10s \ 72°C|72°C|15s/kb
|    |     \____|____|GC 52%
|    |      3:45|5min|15058bp
pydna.tm.Q5(primer: str, *args, **kwargs)[source]#

For Q5 Ta they take the lower of the two Tms and add 1C (up to 72C). For Phusion they take the lower of the two and add 3C (up to 72C).

pydna.tm.tmbresluc(primer: str, *args, primerc=500.0, saltc=50, **kwargs)[source]#

Returns the tm for a primer using a formula adapted to polymerases with a DNA binding domain, such as the Phusion polymerase.

Parameters:
  • primer (string) – primer sequence 5’-3’

  • primerc (float) – primer concentration in nM), set to 500.0 nm by default.

  • saltc (float, optional) – Monovalent cation concentration in mM, set to 50.0 mM by default.

  • thermodynamics (bool, optional) – prints details of the thermodynamic data to stdout. For debugging only.

Returns:

tm – the tm of the primer

Return type:

float

pydna.tm.tm_neb(primer, conc=0.5, prodcode='q5-0')[source]#

pydna.types module#

Types used in the pydna package.

pydna.user_cloning module#

Nicking & USER cloning

CGAuGTCGACTTAGATCTCACAGGCTTTTTTCAAGaCGGCCTTGAATTCAGTCATTTGGATCCGGCCGATC GCTACAGCTGAATCTAGAGTGTCCGAAAAAAGTTCTGCCGGAACTTAAGTCAGTAAACCTAGGCCGGCuAG

  1. Digest both strands

  2. Collect all linear ssDNA

  3. Anneal all combinations

  4. Keep ones present in original molecule

5. Rank by stability 6.

pydna.utils module#

Miscellaneous functions.

pydna.utils.three_frame_orfs(dna: str, limit: int = 100, startcodons: tuple = ('ATG',), stopcodons: tuple = ('TAG', 'TAA', 'TGA'))[source]#

Overlapping orfs in three frames.

pydna.utils.shift_location(original_location, shift, lim)[source]#

docstring.

pydna.utils.shift_feature(feature, shift, lim)[source]#

Return a new feature with shifted location.

pydna.utils.smallest_rotation(s)[source]#

Smallest rotation of a string.

Algorithm described in Pierre Duval, Jean. 1983. Factorizing Words over an Ordered Alphabet. Journal of Algorithms & Computational Technology 4 (4) (December 1): 363–381. and Algorithms on strings and sequences based on Lyndon words, David Eppstein 2011. https://gist.github.com/dvberkel/1950267

Examples

>>> from pydna.utils import smallest_rotation
>>> smallest_rotation("taaa")
'aaat'
pydna.utils.cai(seq: str, organism: str = 'sce', weights: dict = _weights)[source]#

docstring.

pydna.utils.rarecodons(seq: str, organism='sce')[source]#

docstring.

pydna.utils.express(seq: str, organism='sce')[source]#

docstring.

NOT IMPLEMENTED YET

pydna.utils.open_folder(pth)[source]#

docstring.

pydna.utils.rc(sequence: StrOrBytes) StrOrBytes[source]#

Reverse complement.

accepts mixed DNA/RNA

pydna.utils.complement(sequence: str)[source]#

Complement.

accepts mixed DNA/RNA

pydna.utils.identifier_from_string(s: str) str[source]#

Return a valid python identifier.

based on the argument s or an empty string

pydna.utils.flatten(*args) List[source]#

Flattens an iterable of iterables.

Down to str, bytes, bytearray or any of the pydna or Biopython seq objects

pydna.utils.seq31(seq)[source]#

Turn a three letter code protein sequence into one with one letter code.

The single input argument ‘seq’ should be a protein sequence using single letter codes, as a python string.

This function returns the amino acid sequence as a string using the one letter amino acid codes. Output follows the IUPAC standard (including ambiguous characters B for “Asx”, J for “Xle” and X for “Xaa”, and also U for “Sel” and O for “Pyl”) plus “Ter” for a terminator given as an asterisk.

Any unknown character (including possible gap characters), is changed into ‘Xaa’.

Examples

>>> from Bio.SeqUtils import seq3
>>> seq3("MAIVMGRWKGAR*")
'MetAlaIleValMetGlyArgTrpLysGlyAlaArgTer'
>>> from pydna.utils import seq31
>>> seq31('MetAlaIleValMetGlyArgTrpLysGlyAlaArgTer')
'M  A  I  V  M  G  R  W  K  G  A  R  *'
pydna.utils.randomRNA(length, maxlength=None)[source]#

docstring.

pydna.utils.randomDNA(length, maxlength=None)[source]#

docstring.

pydna.utils.randomORF(length, maxlength=None)[source]#

docstring.

pydna.utils.randomprot(length, maxlength=None)[source]#

docstring.

pydna.utils.eq(*args, **kwargs)[source]#

Compare two or more DNA sequences for equality.

Compares two or more DNA sequences for equality i.e. if they represent the same double stranded DNA molecule.

Parameters:
  • args (iterable) – iterable containing sequences args can be strings, Biopython Seq or SeqRecord, Dseqrecord or dsDNA objects.

  • circular (bool, optional) – Consider all molecules circular or linear

  • linear (bool, optional) – Consider all molecules circular or linear

Returns:

eq – Returns True or False

Return type:

bool

Notes

Compares two or more DNA sequences for equality i.e. if they represent the same DNA molecule.

Two linear sequences are considiered equal if either:

  1. They have the same sequence (case insensitive)

  2. One sequence is the reverse complement of the other

Two circular sequences are considered equal if they are circular permutations meaning that they have the same length and:

  1. One sequence can be found in the concatenation of the other sequence with itself.

  2. The reverse complement of one sequence can be found in the concatenation of the other sequence with itself.

The topology for the comparison can be set using one of the keywords linear or circular to True or False.

If circular or linear is not set, it will be deduced from the topology of each sequence for sequences that have a linear or circular attribute (like Dseq and Dseqrecord).

Examples

>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.utils import eq
>>> eq("aaa","AAA")
True
>>> eq("aaa","AAA","TTT")
True
>>> eq("aaa","AAA","TTT","tTt")
True
>>> eq("aaa","AAA","TTT","tTt", linear=True)
True
>>> eq("Taaa","aTaa", linear = True)
False
>>> eq("Taaa","aTaa", circular = True)
True
>>> a=Dseqrecord("Taaa")
>>> b=Dseqrecord("aTaa")
>>> eq(a,b)
False
>>> eq(a,b,circular=True)
True
>>> a=a.looped()
>>> b=b.looped()
>>> eq(a,b)
True
>>> eq(a,b,circular=False)
False
>>> eq(a,b,linear=True)
False
>>> eq(a,b,linear=False)
True
>>> eq("ggatcc","GGATCC")
True
>>> eq("ggatcca","GGATCCa")
True
>>> eq("ggatcca","tGGATCC")
True
pydna.utils.cuts_overlap(left_cut, right_cut, seq_len)[source]#
pydna.utils.location_boundaries(loc: SimpleLocation | CompoundLocation)[source]#
pydna.utils.locations_overlap(loc1: SimpleLocation | CompoundLocation, loc2: SimpleLocation | CompoundLocation, seq_len)[source]#
pydna.utils.sum_is_sticky(three_prime_end: tuple[str, str], five_prime_end: tuple[str, str], partial: bool = False) int[source]#

Return the overlap length if the 3’ end of seq1 and 5’ end of seq2 ends are sticky and compatible for ligation. Return 0 if they are not compatible.

pydna.utils.limit_iterator(iterator, limit)[source]#

Call the function with an iterator to raise an error if the number of items is greater than the limit.

pydna.utils.create_location(start: int, end: int, lim: int, strand: int | None = None) Location[source]#

Create a location object from a start and end position. If the end position is less than the start position, the location is circular. It handles negative positions.

Parameters:
  • start (int) – The start position of the location.

  • end (int) – The end position of the location.

  • lim (int) – The length of the sequence.

  • strand (int, optional) – The strand of the location. None, 1 or -1.

Returns:

location – The location object. Can be a SimpleLocation or a CompoundLocation if the feature spans the origin of a circular sequence.

Return type:

Location

Examples

>>> from pydna.utils import create_location
>>> str(create_location(0, 5, 10,-1))
'[0:5](-)'
>>> str(create_location(0, 5, 10,+1))
'[0:5](+)'
>>> str(create_location(0, 5, 10))
'[0:5]'
>>> str(create_location(8, 2, 10))
'join{[8:10], [0:2]}'
>>> str(create_location(8, 2, 10,-1))
'join{[0:2](-), [8:10](-)}'
>>> str(create_location(-2, 2, 10))
'join{[8:10], [0:2]}'

Note this special case, 0 is the same as len(seq) >>> str(create_location(5, 0, 10)) ‘[5:10]’

Note the special case where if start and end are the same, the location spans the entire sequence (it’s not empty). >>> str(create_location(5, 5, 10)) ‘join{[5:10], [0:5]}’