Demonstration of the Dseq object


In [1]:
from pydna.dseq import Dseq

A small Dseq object can be created directly. The Dseq class which is a double stranded version of the Biopython Seq class.


In [2]:
seq = Dseq("GGATCCAAA","TTTGGATCC", ovhg=0)
seq


Out[2]:
Dseq(-9)
GGATCCAAA
CCTAGGTTT

The Dseq class is the main pydna data type together with the Dseqrecord class which is a double stranded version of the BioPython SeqRecord class.

The Dseq object was initialized using two strings and a value for the stagger (ovhg) between the DNA strands in the 5' (left) extremity. This is of course not a practical way of creating a Dseq object in most cases, but there are other methods as we will see further on.

The Dseq object comes with a cut method that takes one or more restriction enzymes as arguments. A list is returned with the fragments produced in the digestion:


In [3]:
from Bio.Restriction import BamHI
a, b = seq.cut(BamHI)

The two fragments formed (a and b) have the structure we would expect.


In [4]:
a


Out[4]:
Dseq(-5)
G
CCTAG

In [5]:
b


Out[5]:
Dseq(-8)
GATCCAAA
    GTTT

The fragments a and b formed in the example above can be religated together by simply adding them together.

a+b gives us the old fragment back.


In [6]:
a+b


Out[6]:
Dseq(-9)
GGATCCAAA
CCTAGGTTT

b+a gives us a fragment with the sticky ends facing outwards.


In [7]:
b+a


Out[7]:
Dseq(-13)
GATCCAAAG
    GTTTCCTAG

We can add as many fragment together as we want, as long as the sticky ends are compatible.


In [8]:
b+a+b


Out[8]:
Dseq(-17)
GATCCAAAGGATCCAAA
    GTTTCCTAGGTTT

Adding sequences together (ligation) will not work if the sticky ends are not compatible. The Dseq objects keep track of the structure of the DNA ends and only allow ligation of compatible fragments. The last line of the error message below gives an idea of what is wrong.


In [9]:
# NBVAL_RAISES_EXCEPTION
b+a+a


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-602319c60e34> in <module>()
      1 # NBVAL_RAISES_EXCEPTION
----> 2 b+a+a

~/python_packages/pydna/pydna/dseq.py in __add__(self, other)
    844             answer = _copy.copy(self)
    845         else:
--> 846             raise TypeError("sticky ends not compatible!")
    847         return answer
    848 

TypeError: sticky ends not compatible!

The Dseq class is not often used directly. The Dseqrecord class provides a Dseq object to hold the sequence information as well as other class