Planning genetic constructs with many parts and assembly steps, such as recombinant metabolic pathways π§«, are often difficult to properly document as is evident from the poor state of documentation in the scientific literature β’οΈ.
The pydna python package provide a human-readable formal descriptions of 𧬠cloning and genetic assembly strategies in Python π which allow for simulation and verification. Pydna can be used as executable documentation for cloning.
A cloning strategy expressed in pydna is complete, unambiguous and stable.
Pydna provides simulation of:
- Primer design
- PCR
- Restriction digestion
- Ligation
- Gel electrophoresis of DNA with generation of gel images
- Homologous recombination
- Gibson assembly
- Golden gate assembly (in progress)
Virtually any sub-cloning experiment can be described in pydna, and its execution yield the sequences of intermediate and final DNA molecules.
Pydna has been designed with the goal of being understandable for biologists with only some basic understanding of Python.
Pydna can formalize planning and sharing of cloning strategies and is especially useful for complex or combinatorial DNA molecule constructions.
Start by looking at the cookbook.
Some simple examples can be found here.
For more elaborate use, look at some assembly strategies of D-xylose metabolic pathways MetabolicEngineeringGroupCBMA/ypk-xylose-pathways.
See below for documentation.
Most pydna functionality is implemented as methods for the double stranded DNA sequence record classes Dseq and Dseqrecord, which are subclasses of the Biopython Seq and SeqRecord classes.
These classes make PCR primer design, PCR simulation and cut-and-paste cloning very simple:
As the example above shows, pydna keeps track of sticky ends and features.
Pydna can be very compact. The eleven lines of Python below simulates the construction of a recombinant plasmid. DNA sequences are downloaded from Genbank by accession numbers that are guaranteed to be stable over time.
from pydna.genbank import Genbank
gb = Genbank("[email protected]") # Tell Genbank who you are!
gene = gb.nucleotide("X06997") # Kluyveromyces lactis LAC12 gene for lactose permease.
from pydna.parsers import parse_primers
primer_f,primer_r = parse_primers(''' >760_KlLAC12_rv (20-mer)
ttaaacagattctgcctctg
>759_KlLAC12_fw (19-mer)
aaatggcagatcattcgag ''')
from pydna.amplify import pcr
pcr_prod = pcr(primer_f,primer_r, gene)
vector = gb.nucleotide("AJ001614") # pCAPs cloning vector
from Bio.Restriction import EcoRV
lin_vector = vector.linearize(EcoRV)
rec_vec = ( lin_vector + pcr_prod ).looped()
Another use case for pydna in the automatic generation of sub cloning examples for teaching purposes. These examples
Feedback & suggestions are very welcome! Please post a message in the google group for pydna if you need help or have problems, questions or comments π.
Taylor, L. J., & Strebel, K. (2017). Pyviko: an automated Python tool to design gene knockouts in complex viruses with overlapping genes. BMC Microbiology, 17(1), 12. PubMed
Wang, Y., Xue, H., Pourcel, C., Du, Y., & Gautheret, D. (2021). 2-kupl: mapping-free variant detection from DNA-seq data of matched samples. In Cold Spring Harbor Laboratory (p. 2021.01.17.427048). DOI PubMed
An Automated Protein Synthesis Pipeline with Transcriptic and Snakemake
and other projects on github
There is an open access paper in BMC Bioinformatics describing pydna:
Please reference the above paper:
Pereira, F., Azevedo, F., Carvalho, Γ., Ribeiro, G. F., Budde, M. W., & Johansson, B. (2015). Pydna: a simulation and documentation tool for DNA assembly strategies using python. BMC Bioinformatics, 16(142), 142.
When using pydna.
Documentation is built using Sphinx from docstrings in the code and displayed at readthedocs . The numpy docstring format is used.
Pip is included in recent Python versions and is the officially recommended tool.
Pip installs the minimal installation requirements automatically, but not the optional requirements (see below). The --pre switch to get the latest version of pydna.
pip install --pre --upgrade pydna
for optional functionality do:
pip install --pre --upgrade pydna[clipboard,download,express,gel]
Remove options inside the square brackets as required, but be sure not to leave spaces as pip will not recognize the options. See below under "Optional dependencies".
You should be able to pip install pydna from the Windows terminal as biopython now can be installed with pip as well.
C:\> pip install pydna
By default python and pip are not on the PATH. You can re-install Python and select this option during installation, or give the full path for pip. Try something like this, depending on where your copy of Python is installed:
C:\Python37\Scripts\pip install pydna
Pydna is developed on Github . I am happy to collaborate on new features or bugfixes.
We use pre-commit-hooks to help with source code formatting.
Prior to each commit, a series of checks and source code formatters are run (see .pre-commit-config.yaml
file below).
This can modify the commited code, which might have to be added again.
A good practice is to run pre-commit run --all-files
before committing.
The .pre-commit-config.yaml
file located in the root of the repository has the following content:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: no-commit-to-branch
args: [--branch, master]
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: debug-statements
- id: fix-encoding-pragma
- id: mixed-line-ending
- repo: https://github.com/ambv/black
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
exclude: scripts/|docs/|tests/
The list below is the minimal requirements for installing pydna. Biopython and pydivsufsort has c-extensions, but the other modules are pure python.
Pydna is importable even without pyfiglet.
These can be installed pip install pydna[clipboard,gel,download,express]
where [clipboard,gel,download,express]
is the list of options available. Any
combination of the words inside the square brackets are allowed, but no white space.
Enables the pydna.dseqrecord.Dseqrecord.copy_gb_to_clipboard()
and pydna.dseqrecord.Dseqrecord.copy_fasta_to_clipboard()
These methods will put a copy the sequence on the clipboard in either Genbank (gb) or fasta format.
Dependency | Function in pydna |
---|---|
pyperclip | copy sequence to clipboard |
Pyparsing enables the pydna.genbankfixer.gbtext_clean()
function that can automatically
correct malformed sequence files in Genbank format. These are often found online, so this option also installs requests to enable the pydna.genbankfixer.download.download_text()
function which can be used to get cleaned up text from a URL.
Dependency | Function in pydna |
---|---|
pyparsing | fix corrupt Genbank files with pydna.genbankfixer |
requests | download sequences with pydna.download |
This option enables the pydna.utils.cai()
function and the cai()
method
available from subclasses of pydna.seqrecord.SeqRecord
, such as
pydna.dseqrecord.Dseqrecord
.
| cai2 | codon adaptation index calculations in several modules |
Scipy, matplotlib and pillow (PIL) enable the generation of gel images. Numpy is also needed, but usually installed as a dependency of biopython.
Dependency | Function in pydna |
---|---|
scipy | gel simulation with pydna.gel |
matplotlib | β |
pillow | β |
for instance by pip install pytest pytest-cov pytest-doctestplus pytest-profiling coverage nbval requests-mock
Running the entire test suite also require:
- scipy
- matplotlib
- pillow
- pyparsing
- requests
- cai2
That can be installed by pip install pydna[clipboard,gel,download,express]
or by pip install pyparsing requests cai2 scipy matplotlib pillow
Please direct pull requests towards the develop
branch.
-
Use Poetry to install dependencies and activate virtual environment.
# If you want the virtual environment to be created in this folder poetry config virtualenvs.in-project true # Install dependencies (extras are required for tests to pass) poetry install --all-extras # Activate virtual environment poetry shell
-
Make your changes.
-
Add the necessary tests in
tests/
. -
Run the tests from the root directory with
python run_test.py
.
Below the commands to run a local sphinx server that auto-updated when files are changed.
# Install docs dependency group
poetry install --with docs
# Start the sphinx server to see docs live by default at http://127.0.0.1:8000/
sphinx-autobuild --watch src/ docs docs/_build/html
See the releases for changes and releases.
There are two github actions for this package:
.github/workflows/pydna_test_and_coverage_workflow.yml
.github/workflows/pydna_pypi_build_workflow.yml
The test_and_coverage workflow is triggered on all pushed commits for all branches except the master
branch. This workflow run tests, doctests and a series of Jupyter notebooks using pytest on Linux, Windows and macOS with all
supported python versions.
The build workflow builds a PyPI packages using poetry. This workflow is triggered by publishing a Github release manually from the Github web interface.
Building a PyPI package with Poetry
-
Commit changes to git
-
Tag the commit according to the Semantic Versioning format, for example "v2.0.1a3". Do not forget the "v" or poetry will not recognize the tag.
git tag v2.0.1a3
-
Pydna uses the poetry poetry-dynamic-versioning plugin.
poetry dynamic-versioning # This sets the version number in the source files
-
Verify the version
poetry version
-
Build package:
poetry build # run this command in the root directory where the pyproject.toml file is located
-
Verify the filename of the files in the dist/ folder, they should match
-
Publish to pypi
poetry publish
Pydna was made public in 2012 on Google code.
π¦
π΅πΉ