Metadata-Version: 2.4
Name: pydna-utils
Version: 0.0.5
Summary: Utility functions to ease interactive work with pydna.
License: BSD-3
License-File: LICENSE
Keywords: pydna,molecular-biology,dna,cloning,genbank,bioinformatics,sequence-analysis
Author: Bjorn F. Johansson
Author-email: bjornjobb@gmail.com
Maintainer: Bjorn F. Johansson
Maintainer-email: bjornjobb@gmail.com
Requires-Python: >=3.12,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Dist: confz (>=2.1.0,<3.0.0)
Requires-Dist: platformdirs (>=4.5.0,<5.0.0)
Requires-Dist: prettytable (>=3.16.0,<4.0.0)
Requires-Dist: pydantic (>=2.12.0,<3.0.0)
Requires-Dist: pydna (>=5.5.1,<6.0.0)
Requires-Dist: requests_cache (>=1.2.1,<2.0.0)
Requires-Dist: tomli-w (>=1.2.0,<2.0.0)
Project-URL: Changelog, https://github.com/pydna-group/pydna-utils/blob/main/CHANGELOG.md
Project-URL: Documentation, https://pydna-utils.readthedocs.io/
Project-URL: Homepage, https://github.com/pydna-group/pydna-utils
Project-URL: Issues, https://github.com/pydna-group/pydna-utils/issues
Project-URL: Repository, https://github.com/pydna-group/pydna-utils
Description-Content-Type: text/markdown

# ![icon](https://github.com/pydna-group/pydna-utils/blob/main/docs/_static/icon.png?raw=true)

pydna-utils is a package containing utilities for
[pydna](https://github.com/pydna-group/pydna?tab=readme-ov-file)
facilitating interactive use.

- open a Dsecrecord in the ApE plasmid editor or snapgene
- a global PCR primer list
- a global restriction enzyme list
- cached access to genbank

Install:

```bash
pip install pydna-utils
```

pydna_utils creates a user settings file (`pydna_config.toml`) where user
information and links to useful data can be placed.

On my linux mint laptop, this is located at `/home/bjorn/.config/pydna/pydna_config.toml`.

The platformdirs package is used to decide where this file should be located.

The settings file is a [TOML](https://toml.io/en/) file and has this content
by default:
```
pydna_ape_cmd = "/usr/bin/tclsh /home/bjorn/.ApE/ApE.tcl"
pydna_snapgene_cmd = "/opt/gslbiotech/snapgene/snapgene.sh"
pydna_enzymes = "/home/bjorn/.ApE/Enzymes/LGM_group.txt"
pydna_primers = "/home/bjorn/myvault/PRIMERS.md"
pydna_email = "someone@example.com"
pydna_ncbi_cache_dir = "/home/bjorn/.cache/pydna_utils"
pydna_ncbi_expiration = "604800"
```


## pydna_utils.editor.ape starts the ApE plasmid editor.

```python
>>> from pydna_utils.editor import ape
>>> from pydna.dseqrecord import Dseqrecord
>>> sequence = Dseqrecord("GGATCC")
>>> sequence.seq
Dseq(-6)
GGATCC
CCTAGG
>>> ape(sequence)
```

![ape](https://github.com/pydna-group/pydna-utils/blob/main/docs/_static/ape.png?raw=true)


## pydna_utils.myprimers.PrimerList enables a global primer list for pydna

The primer list is typically a text file containing primer sequences in
a format that pydna understands, such as FASTA.

This feature is most useful if the laboratory keeps a plain text file with
primer sequences for all lab members. As visible below, our list had 1821
primers when this example was created.

You may not want to ship this list with your pydna code. The list may be long
nd contain mostly irrelevant primers. It may also have information that best be
kept inside the lab. For this reason, PrimerList remembers which primers
have been accessed in a particular session and can also create pydna code
ready to be pasted into a pydna script or notebook that contain the relevant
part of the list. See example below:

```python
>>> from pydna_utils.myprimers import PrimerList
>>> pl = PrimerList()
>>> len(pl)
1821
>>> pl[1]
1_5CYC1clone 35-mer:5'-GATCGGCCGGATCCA..CCG-3'
>>> pl[2]
2_3CYC1clon 35-mer:5'-CGATGTCGACTTAGA..AAG-3'
>>> print(pl[1].format("fasta"))
>>> print(pl[2].format("fasta"))
>>> pl.accessed
[1_5CYC1clone 35-mer:5'-GATCGGCCGGATCCA..CCG-3',
 2_3CYC1clon 35-mer:5'-CGATGTCGACTTAGA..AAG-3']
>>> pl.code(pl.accessed)
from pydna.parsers import parse_primers

p = {}

p[1], p[2] = parse_primers('''

>1_5CYC1clone 35-mer
GATCGGCCGGATCCAAATGACTGAATTCAAGGCCG

>2_3CYC1clon 35-mer
CGATGTCGACTTAGATCTCACAGGCTTTTTTCAAG

''')
```

## pydna_utils.myenzymes.myenzymes enables a global restriction enzyme batch

pydna_enzymes should contain a path to a text file containing restriction
enzyme names. No particular formatting is required, but the names have to
be separated by white space and exactly as they appear on
[REBASE](https://rebase.neb.com/rebase/rebase.html).

```python
>>> from pydna_utils.myenzymes import myenzymes
>>> myenzymes
RestrictionBatch(['AatII', 'Acc65I', 'AflII', 'AjiI', 'BamHI', 'BglI'])
```


## pydna_utils.genbank.genbank is a cached version of pydna.genbank.genbank

```python
>>> from pydna_utils.genbank import genbank
>>> gb_sequence = genbank("A23695.1")
>>> gb_sequence
Gbnk(-4 A23695.1)
>>> gb_sequence.seq
Dseq(-4)
AAAA
TTTT
```

The settings `pydna_email, pydna_ncbi_cache_dir and pydna_ncbi_expiration`
are important for how the cache works. 
The user only needs to set the email as this is a NCBI requirement. 



```python
>>> import pydna_utils
>>> pydna_utils.get_settings()
+-----------------------+-----------------------------------------+
| Setting               | Value                                   |
+-----------------------+-----------------------------------------+
| pydna_ape_cmd         | /usr/bin/tclsh /home/bjorn/.ApE/ApE.tcl |
| pydna_snapgene_cmd    | /opt/gslbiotech/snapgene/snapgene.sh    |
| pydna_enzymes         | /home/bjorn/.ApE/Enzymes/LGM_group.txt  |
| pydna_primers         | /home/bjorn/myvault/PRIMERS.md          |
| pydna_email           | b*******b@gmail.com                     |
| pydna_ncbi_cache_dir  | /home/bjorn/.cache/pydna_utils          |
| pydna_ncbi_expiration | 604800                                  |
+-----------------------+-----------------------------------------+
>>> from pydna_utils import open_config_file
>>> open_config_file()  # opens the config file for editing in system text editor.
>>> from pydna_utils import open_cache_folder
>>> open_cache_folder() # opens the cache folder in system file explorer.
```

