pax_global_header00006660000000000000000000000064150074423330014513gustar00rootroot0000000000000052 comment=00e59756556842456f0705880dda5552c8ba7c0e python_codon_tables-0.1.18/000077500000000000000000000000001500744233300156375ustar00rootroot00000000000000python_codon_tables-0.1.18/.github/000077500000000000000000000000001500744233300171775ustar00rootroot00000000000000python_codon_tables-0.1.18/.github/workflows/000077500000000000000000000000001500744233300212345ustar00rootroot00000000000000python_codon_tables-0.1.18/.github/workflows/build.yml000066400000000000000000000007721500744233300230640ustar00rootroot00000000000000name: build on: [push, workflow_dispatch] jobs: build: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.12" - name: Install dependencies run: | python -m pip install --upgrade pip pip install pytest - name: Install run: | pip install -e . - name: Test with pytest run: | python -m pytest python_codon_tables-0.1.18/.github/workflows/document.yml000066400000000000000000000007251500744233300236010ustar00rootroot00000000000000name: documentation on: workflow_dispatch: release: types: [created] jobs: document: runs-on: ubuntu-24.04 environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} permissions: pages: write id-token: write steps: - id: deployment uses: sphinx-notes/pages@v3 with: python_version: 3.12 documentation_path: ./docs requirements_path: ./docs/requirements.txt python_codon_tables-0.1.18/.github/workflows/publish.yml000066400000000000000000000016531500744233300234320ustar00rootroot00000000000000name: Publish to PyPI on: release: types: [created] jobs: test: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.12" - name: Install run: | pip install pytest pip install -e . - name: Test run: | python -m pytest deploy: runs-on: ubuntu-24.04 needs: [test] permissions: id-token: write steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12' cache: pip cache-dependency-path: '**/pyproject.toml' - name: Install dependencies run: | pip install setuptools wheel build - name: Build run: | python -m build - name: Publish uses: pypa/gh-action-pypi-publish@release/v1 python_codon_tables-0.1.18/.gitignore000066400000000000000000000034071500744233300176330ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock # PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ python_codon_tables-0.1.18/LICENSE000066400000000000000000000156101500744233300166470ustar00rootroot00000000000000Creative Commons Legal Code CC0 1.0 Universal CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER. Statement of Purpose The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; ii. moral rights retained by the original author(s) and/or performer(s); iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; v. rights protecting the extraction, dissemination, use and reuse of data in a Work; vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and vii. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. 4. Limitations and Disclaimers. a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. python_codon_tables-0.1.18/README.rst000066400000000000000000000063411500744233300173320ustar00rootroot00000000000000Python Codon Tables =================== .. image:: https://github.com/Edinburgh-Genome-Foundry/python_codon_tables/actions/workflows/build.yml/badge.svg :target: https://github.com/Edinburgh-Genome-Foundry/python_codon_tables/actions/workflows/build.yml :alt: GitHub CI build status Provides codon usage tables as dictionaries, for Python. Tables for the following organisms are provided with the package (other tables can be downloaded using a TaxID): - *B. subtilis* - *C. elegans* - *D. melanogaster* - *E. coli* - *G. gallus* - *H. sapiens* - *M. musculus* - *M. musculus domesticus* - *S. cerevisiae* All tables are from `kazusa.or.jp `_ (codon usages were computed using NCBI sequence data). The original publication: .. code:: Codon usage tabulated from the international DNA sequence databases: status for the year 2000. Nakamura, Y., Gojobori, T. and Ikemura, T. (2000) Nucl. Acids Res. 28, 292. Usage ----- .. code:: python import python_codon_tables as pct # PRINT THE LIST OF NAMES OF ALL AVAILABLE TABLES print ('Available tables:', pct.available_codon_tables_names) # LOAD ONE TABLE BY NAME table = pct.get_codons_table("b_subtilis_1423") print (table['T']['ACA']) # returns 0.4 print (table['*']['TAA']) # returns 0.61 # LOAD ONE TABLE BY TAXID (it will get it from the internet if it is not # in the builtin tables) table = pct.get_codons_table(1423) print (table['T']['ACA']) # returns 0.4 print (table['*']['TAA']) # returns 0.61 # LOAD ALL BUIL-IN TABLES AT ONCE codons_tables = pct.get_all_available_codons_tables() print (codons_tables['c_elegans_6239']['L']['CTA']) # returns 0.09 - Notice that by default the tables use nucleotide T instead of U. Using ``get_codons_table('e_coli', replace_U_by_T=False)`` will leave Us as Us. - In ``get_codons_table`` you can also provide a "shorthand" notation ``b_subtilis``, which will be automatically extended to ``b_subtilis_1423`` as it appears so in the built-in table (use this feature at your own risks!) The package can also use codon usage data from a CSV file in the form: ``` amino_acid,codon,relative_frequency *,UAA,0.64 *,UAG,0.07 *,UGA,0.29 A,GCA,0.21 A,GCC,0.27 K,AAA,0.76 K,AAG,0.24 etc. ``` Contribute ---------- This project was started at the Edinburgh Genome Foundry by Zulko and is released on `Github `_ under the CC0 (Public Domain) license (and no warranty whatsoever, please cross-check the codon usage with other sources if you are not sure). Feel free to add other tables if you think of more commonly used species. Installation ------------ via pip: .. code:: bash pip install python_codon_tables Manual: .. code:: bash python setup.py install More biology software --------------------- .. image:: https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/Edinburgh-Genome-Foundry.github.io/master/static/imgs/logos/egf-codon-horizontal.png :target: https://edinburgh-genome-foundry.github.io/ This library is part of the `EGF Codons `_ synthetic biology software suite for DNA design, manufacturing and validation. python_codon_tables-0.1.18/docs/000077500000000000000000000000001500744233300165675ustar00rootroot00000000000000python_codon_tables-0.1.18/docs/Makefile000066400000000000000000000011721500744233300202300ustar00rootroot00000000000000# Minimal makefile for Sphinx documentation # # You can set these variables from the command line, and also # from the environment for the first two. SPHINXOPTS ?= SPHINXBUILD ?= sphinx-build SOURCEDIR = . BUILDDIR = _build # Put it first so that "make" without argument is like "make help". help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) python_codon_tables-0.1.18/docs/conf.py000066400000000000000000000021161500744233300200660ustar00rootroot00000000000000# Configuration file for the Sphinx documentation builder. # # For the full list of built-in configuration values, see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information import os, sys sys.path.insert(0, os.path.abspath("../python_codon_tables/")) project = "python_codon_tables" author = "Zulko" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration extensions = [] templates_path = ["_templates"] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] extensions = [ "sphinx.ext.autodoc", "sphinx.ext.napoleon", ] napoleon_numpy_docstring = True # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output html_theme = "sphinx_rtd_theme" html_static_path = ["_static"] python_codon_tables-0.1.18/docs/index.rst000066400000000000000000000005541500744233300204340ustar00rootroot00000000000000.. Python Codon Tables documentation master file, created by sphinx-quickstart on Fri Mar 28 14:35:51 2025. Python Codon Tables =================== `General documentation `_ :doc:`API reference ` ---- .. toctree:: :hidden: :maxdepth: 1 :caption: Python Codon Tables ref python_codon_tables-0.1.18/docs/make.bat000066400000000000000000000014401500744233300201730ustar00rootroot00000000000000@ECHO OFF pushd %~dp0 REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set SOURCEDIR=. set BUILDDIR=_build %SPHINXBUILD% >NUL 2>NUL if errorlevel 9009 ( echo. echo.The 'sphinx-build' command was not found. Make sure you have Sphinx echo.installed, then set the SPHINXBUILD environment variable to point echo.to the full path of the 'sphinx-build' executable. Alternatively you echo.may add the Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from echo.https://www.sphinx-doc.org/ exit /b 1 ) if "%1" == "" goto help %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% goto end :help %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% :end popd python_codon_tables-0.1.18/docs/ref.rst000066400000000000000000000001671500744233300201010ustar00rootroot00000000000000API reference ============= .. automodule:: python_codon_tables :members: :undoc-members: :show-inheritance: python_codon_tables-0.1.18/docs/requirements.txt000066400000000000000000000000211500744233300220440ustar00rootroot00000000000000sphinx_rtd_theme python_codon_tables-0.1.18/examples/000077500000000000000000000000001500744233300174555ustar00rootroot00000000000000python_codon_tables-0.1.18/examples/basic_example.py000066400000000000000000000007001500744233300226200ustar00rootroot00000000000000import python_codon_tables as pct # PRINT THE LIST OF NAMES OF ALL AVAILABLE TABLES print("Available tables:", pct.available_codon_tables_names) # LOAD ONE TABLE BY NAME table = pct.get_codons_table("b_subtilis_1423") print(table["T"]["ACA"]) # returns 0.4 print(table["*"]["TAA"]) # returns 0.61 # LOAD ALL TABLES AT ONCE codon_tables = pct.get_all_available_codons_tables() print(codon_tables["c_elegans_6239"]["L"]["CTA"]) # returns 0.09 python_codon_tables-0.1.18/pypi-readme.rst000066400000000000000000000014601500744233300206060ustar00rootroot00000000000000Python Codon Tables =================== Provides codon usage tables as dictionaries, for Python. Infos ----- **PIP installation:** .. code:: bash pip install python_codon_tables **Web documentation:** ``_ **Github Page:** ``_ **License:** CC0 More biology software --------------------- .. image:: https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/Edinburgh-Genome-Foundry.github.io/master/static/imgs/logos/egf-codon-horizontal.png :target: https://edinburgh-genome-foundry.github.io/ Python Codon Tables is part of the `EGF Codons `_ synthetic biology software suite for DNA design, manufacturing and validation. python_codon_tables-0.1.18/pyproject.toml000066400000000000000000000011171500744233300205530ustar00rootroot00000000000000[project] name = "python_codon_tables" version = "0.1.18" license = "CC0-1.0" authors = [{ name = "Zulko" }] description = "Codon Usage Tables for Python, from kazusa.or.jp" readme = "pypi-readme.rst" keywords = ["DNA", "codon", "usage"] [project.urls] Homepage = "https://github.com/Edinburgh-Genome-Foundry/python_codon_tables" [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" [tool.setuptools.packages.find] exclude = ["docs*", "examples*", "tests*"] [tool.setuptools.package-data] python_codon_tables = ["codon_usage_data/*", "codon_usage_data/**/*"] python_codon_tables-0.1.18/python_codon_tables/000077500000000000000000000000001500744233300216745ustar00rootroot00000000000000python_codon_tables-0.1.18/python_codon_tables/__init__.py000066400000000000000000000003361500744233300240070ustar00rootroot00000000000000from .python_codon_tables import ( available_codon_tables_names, csv_string_to_codons_dict, get_codons_table, get_all_available_codons_tables, download_codons_table, ) from .version import __version__ python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/000077500000000000000000000000001500744233300251535ustar00rootroot00000000000000python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/codon_usage_retriever.py000066400000000000000000000021001500744233300320730ustar00rootroot00000000000000#!/usr/bin/env python """Retrieve a Codon usage table from kazusa.or.jp, and store in a CSV file. Usage: ------ To retrieve a codon table for one organism, given its TaxID, use: > python codon_usage_retriever.py [TaxidNumber] [TargetFile.csv] For instance: > python codon_usage_retriever.py 316407 e_coli_codon_usage.csv To retrieve codon tables from all organisms in ``organisms.csv`` at once, use: > python codon_usage_retriever.py all """ import sys import os from python_codon_tables import download_codons_table def download_all_tables(): with open("organisms.csv", "r") as f: for line in f.readlines()[1:]: organism, taxid = line.strip("\n").split(",") print("Retrieving %s (taxid %s)" % (organism, taxid)) target = os.path.join("tables", "%s_%s.csv" % (organism, taxid)) download_codons_table(taxid=taxid, target_file=target) if __name__ == "__main__": print(" ".join(sys.argv)) if sys.argv[1] == "all": download_all_tables() else: download_codons_table(sys.argv[1], sys.argv[2]) python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/organisms.csv000066400000000000000000000002541500744233300276730ustar00rootroot00000000000000organism,taxid b_subtilis,1423 c_elegans,6239 d_melanogaster,7227 e_coli,316407 g_gallus,9031 h_sapiens,9606 m_musculus,10090 m_musculus_domesticus,10092 s_cerevisiae,4932 python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tables/000077500000000000000000000000001500744233300264255ustar00rootroot00000000000000python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tables/b_subtilis_1423.csv000066400000000000000000000013431500744233300317530ustar00rootroot00000000000000amino_acid,codon,relative_frequency *,UAA,0.61 *,UAG,0.15 *,UGA,0.24 A,GCA,0.28 A,GCC,0.22 A,GCG,0.26 A,GCU,0.24 C,UGC,0.54 C,UGU,0.46 D,GAC,0.36 D,GAU,0.64 E,GAA,0.68 E,GAG,0.32 F,UUC,0.32 F,UUU,0.68 G,GGA,0.31 G,GGC,0.34 G,GGG,0.16 G,GGU,0.19 H,CAC,0.32 H,CAU,0.68 I,AUA,0.13 I,AUC,0.37 I,AUU,0.49 K,AAA,0.70 K,AAG,0.30 L,CUA,0.05 L,CUC,0.11 L,CUG,0.24 L,CUU,0.23 L,UUA,0.21 L,UUG,0.16 M,AUG,1.00 N,AAC,0.44 N,AAU,0.56 P,CCA,0.19 P,CCC,0.09 P,CCG,0.44 P,CCU,0.28 Q,CAA,0.52 Q,CAG,0.48 R,AGA,0.25 R,AGG,0.10 R,CGA,0.10 R,CGC,0.20 R,CGG,0.17 R,CGU,0.18 S,AGC,0.23 S,AGU,0.11 S,UCA,0.23 S,UCC,0.13 S,UCG,0.10 S,UCU,0.20 T,ACA,0.40 T,ACC,0.17 T,ACG,0.27 T,ACU,0.16 V,GUA,0.20 V,GUC,0.26 V,GUG,0.26 V,GUU,0.28 W,UGG,1.00 Y,UAC,0.35 Y,UAU,0.65python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tables/c_elegans_6239.csv000066400000000000000000000013431500744233300315460ustar00rootroot00000000000000amino_acid,codon,relative_frequency *,UAA,0.43 *,UAG,0.18 *,UGA,0.39 A,GCA,0.31 A,GCC,0.20 A,GCG,0.13 A,GCU,0.36 C,UGC,0.45 C,UGU,0.55 D,GAC,0.32 D,GAU,0.68 E,GAA,0.62 E,GAG,0.38 F,UUC,0.51 F,UUU,0.49 G,GGA,0.59 G,GGC,0.12 G,GGG,0.08 G,GGU,0.20 H,CAC,0.39 H,CAU,0.61 I,AUA,0.16 I,AUC,0.31 I,AUU,0.53 K,AAA,0.59 K,AAG,0.41 L,CUA,0.09 L,CUC,0.17 L,CUG,0.14 L,CUU,0.25 L,UUA,0.11 L,UUG,0.23 M,AUG,1.00 N,AAC,0.38 N,AAU,0.62 P,CCA,0.53 P,CCC,0.09 P,CCG,0.20 P,CCU,0.18 Q,CAA,0.66 Q,CAG,0.34 R,AGA,0.29 R,AGG,0.08 R,CGA,0.23 R,CGC,0.10 R,CGG,0.09 R,CGU,0.21 S,AGC,0.10 S,AGU,0.15 S,UCA,0.26 S,UCC,0.13 S,UCG,0.15 S,UCU,0.21 T,ACA,0.34 T,ACC,0.18 T,ACG,0.15 T,ACU,0.32 V,GUA,0.16 V,GUC,0.22 V,GUG,0.23 V,GUU,0.39 W,UGG,1.00 Y,UAC,0.44 Y,UAU,0.56python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tables/d_melanogaster_7227.csv000066400000000000000000000013431500744233300326100ustar00rootroot00000000000000amino_acid,codon,relative_frequency *,UAA,0.41 *,UAG,0.33 *,UGA,0.25 A,GCA,0.17 A,GCC,0.45 A,GCG,0.19 A,GCU,0.19 C,UGC,0.71 C,UGU,0.29 D,GAC,0.47 D,GAU,0.53 E,GAA,0.33 E,GAG,0.67 F,UUC,0.62 F,UUU,0.38 G,GGA,0.29 G,GGC,0.43 G,GGG,0.07 G,GGU,0.21 H,CAC,0.60 H,CAU,0.40 I,AUA,0.19 I,AUC,0.47 I,AUU,0.34 K,AAA,0.30 K,AAG,0.70 L,CUA,0.09 L,CUC,0.15 L,CUG,0.43 L,CUU,0.10 L,UUA,0.05 L,UUG,0.18 M,AUG,1.00 N,AAC,0.56 N,AAU,0.44 P,CCA,0.25 P,CCC,0.33 P,CCG,0.29 P,CCU,0.13 Q,CAA,0.30 Q,CAG,0.70 R,AGA,0.09 R,AGG,0.11 R,CGA,0.15 R,CGC,0.33 R,CGG,0.15 R,CGU,0.16 S,AGC,0.25 S,AGU,0.14 S,UCA,0.09 S,UCC,0.24 S,UCG,0.20 S,UCU,0.08 T,ACA,0.20 T,ACC,0.38 T,ACG,0.26 T,ACU,0.17 V,GUA,0.11 V,GUC,0.24 V,GUG,0.47 V,GUU,0.19 W,UGG,1.00 Y,UAC,0.63 Y,UAU,0.37python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tables/e_coli_316407.csv000066400000000000000000000013431500744233300312210ustar00rootroot00000000000000amino_acid,codon,relative_frequency *,UAA,0.64 *,UAG,0.07 *,UGA,0.29 A,GCA,0.21 A,GCC,0.27 A,GCG,0.36 A,GCU,0.16 C,UGC,0.56 C,UGU,0.44 D,GAC,0.37 D,GAU,0.63 E,GAA,0.69 E,GAG,0.31 F,UUC,0.43 F,UUU,0.57 G,GGA,0.11 G,GGC,0.41 G,GGG,0.15 G,GGU,0.34 H,CAC,0.43 H,CAU,0.57 I,AUA,0.07 I,AUC,0.42 I,AUU,0.51 K,AAA,0.76 K,AAG,0.24 L,CUA,0.04 L,CUC,0.10 L,CUG,0.50 L,CUU,0.10 L,UUA,0.13 L,UUG,0.13 M,AUG,1.00 N,AAC,0.55 N,AAU,0.45 P,CCA,0.19 P,CCC,0.12 P,CCG,0.53 P,CCU,0.16 Q,CAA,0.35 Q,CAG,0.65 R,AGA,0.04 R,AGG,0.02 R,CGA,0.06 R,CGC,0.40 R,CGG,0.10 R,CGU,0.38 S,AGC,0.28 S,AGU,0.15 S,UCA,0.12 S,UCC,0.15 S,UCG,0.15 S,UCU,0.15 T,ACA,0.13 T,ACC,0.44 T,ACG,0.27 T,ACU,0.16 V,GUA,0.15 V,GUC,0.22 V,GUG,0.37 V,GUU,0.26 W,UGG,1.00 Y,UAC,0.43 Y,UAU,0.57python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tables/g_gallus_9031.csv000066400000000000000000000013431500744233300314140ustar00rootroot00000000000000amino_acid,codon,relative_frequency *,UAA,0.32 *,UAG,0.20 *,UGA,0.47 A,GCA,0.26 A,GCC,0.32 A,GCG,0.13 A,GCU,0.29 C,UGC,0.60 C,UGU,0.40 D,GAC,0.50 D,GAU,0.50 E,GAA,0.43 E,GAG,0.57 F,UUC,0.55 F,UUU,0.45 G,GGA,0.27 G,GGC,0.31 G,GGG,0.25 G,GGU,0.18 H,CAC,0.60 H,CAU,0.40 I,AUA,0.18 I,AUC,0.46 I,AUU,0.35 K,AAA,0.44 K,AAG,0.56 L,CUA,0.06 L,CUC,0.18 L,CUG,0.41 L,CUU,0.13 L,UUA,0.08 L,UUG,0.13 M,AUG,1.00 N,AAC,0.57 N,AAU,0.43 P,CCA,0.28 P,CCC,0.30 P,CCG,0.14 P,CCU,0.27 Q,CAA,0.27 Q,CAG,0.73 R,AGA,0.22 R,AGG,0.21 R,CGA,0.10 R,CGC,0.19 R,CGG,0.18 R,CGU,0.10 S,AGC,0.26 S,AGU,0.14 S,UCA,0.15 S,UCC,0.20 S,UCG,0.07 S,UCU,0.18 T,ACA,0.30 T,ACC,0.31 T,ACG,0.14 T,ACU,0.25 V,GUA,0.12 V,GUC,0.22 V,GUG,0.45 V,GUU,0.21 W,UGG,1.00 Y,UAC,0.60 Y,UAU,0.40python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tables/h_sapiens_9606.csv000066400000000000000000000013431500744233300316000ustar00rootroot00000000000000amino_acid,codon,relative_frequency *,UAA,0.30 *,UAG,0.24 *,UGA,0.47 A,GCA,0.23 A,GCC,0.40 A,GCG,0.11 A,GCU,0.27 C,UGC,0.54 C,UGU,0.46 D,GAC,0.54 D,GAU,0.46 E,GAA,0.42 E,GAG,0.58 F,UUC,0.54 F,UUU,0.46 G,GGA,0.25 G,GGC,0.34 G,GGG,0.25 G,GGU,0.16 H,CAC,0.58 H,CAU,0.42 I,AUA,0.17 I,AUC,0.47 I,AUU,0.36 K,AAA,0.43 K,AAG,0.57 L,CUA,0.07 L,CUC,0.20 L,CUG,0.40 L,CUU,0.13 L,UUA,0.08 L,UUG,0.13 M,AUG,1.00 N,AAC,0.53 N,AAU,0.47 P,CCA,0.28 P,CCC,0.32 P,CCG,0.11 P,CCU,0.29 Q,CAA,0.27 Q,CAG,0.73 R,AGA,0.21 R,AGG,0.21 R,CGA,0.11 R,CGC,0.18 R,CGG,0.20 R,CGU,0.08 S,AGC,0.24 S,AGU,0.15 S,UCA,0.15 S,UCC,0.22 S,UCG,0.05 S,UCU,0.19 T,ACA,0.28 T,ACC,0.36 T,ACG,0.11 T,ACU,0.25 V,GUA,0.12 V,GUC,0.24 V,GUG,0.46 V,GUU,0.18 W,UGG,1.00 Y,UAC,0.56 Y,UAU,0.44python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tables/m_musculus_10090.csv000066400000000000000000000013431500744233300320700ustar00rootroot00000000000000amino_acid,codon,relative_frequency *,UAA,0.28 *,UAG,0.23 *,UGA,0.49 A,GCA,0.23 A,GCC,0.38 A,GCG,0.09 A,GCU,0.29 C,UGC,0.52 C,UGU,0.48 D,GAC,0.55 D,GAU,0.45 E,GAA,0.41 E,GAG,0.59 F,UUC,0.56 F,UUU,0.44 G,GGA,0.26 G,GGC,0.33 G,GGG,0.23 G,GGU,0.18 H,CAC,0.59 H,CAU,0.41 I,AUA,0.16 I,AUC,0.50 I,AUU,0.34 K,AAA,0.39 K,AAG,0.61 L,CUA,0.08 L,CUC,0.20 L,CUG,0.39 L,CUU,0.13 L,UUA,0.07 L,UUG,0.13 M,AUG,1.00 N,AAC,0.57 N,AAU,0.43 P,CCA,0.29 P,CCC,0.30 P,CCG,0.10 P,CCU,0.31 Q,CAA,0.26 Q,CAG,0.74 R,AGA,0.22 R,AGG,0.22 R,CGA,0.12 R,CGC,0.17 R,CGG,0.19 R,CGU,0.08 S,AGC,0.24 S,AGU,0.15 S,UCA,0.14 S,UCC,0.22 S,UCG,0.05 S,UCU,0.20 T,ACA,0.29 T,ACC,0.35 T,ACG,0.10 T,ACU,0.25 V,GUA,0.12 V,GUC,0.25 V,GUG,0.46 V,GUU,0.17 W,UGG,1.00 Y,UAC,0.57 Y,UAU,0.43m_musculus_domesticus_10092.csv000066400000000000000000000013431500744233300342520ustar00rootroot00000000000000python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tablesamino_acid,codon,relative_frequency *,UAA,0.27 *,UAG,0.45 *,UGA,0.27 A,GCA,0.30 A,GCC,0.36 A,GCG,0.11 A,GCU,0.23 C,UGC,0.55 C,UGU,0.45 D,GAC,0.61 D,GAU,0.39 E,GAA,0.49 E,GAG,0.51 F,UUC,0.61 F,UUU,0.39 G,GGA,0.29 G,GGC,0.32 G,GGG,0.22 G,GGU,0.17 H,CAC,0.65 H,CAU,0.35 I,AUA,0.29 I,AUC,0.43 I,AUU,0.27 K,AAA,0.58 K,AAG,0.42 L,CUA,0.14 L,CUC,0.21 L,CUG,0.35 L,CUU,0.13 L,UUA,0.07 L,UUG,0.10 M,AUG,1.00 N,AAC,0.59 N,AAU,0.41 P,CCA,0.34 P,CCC,0.30 P,CCG,0.10 P,CCU,0.26 Q,CAA,0.24 Q,CAG,0.76 R,AGA,0.34 R,AGG,0.25 R,CGA,0.10 R,CGC,0.13 R,CGG,0.13 R,CGU,0.06 S,AGC,0.23 S,AGU,0.13 S,UCA,0.21 S,UCC,0.21 S,UCG,0.06 S,UCU,0.16 T,ACA,0.40 T,ACC,0.28 T,ACG,0.08 T,ACU,0.24 V,GUA,0.19 V,GUC,0.24 V,GUG,0.43 V,GUU,0.14 W,UGG,1.00 Y,UAC,0.59 Y,UAU,0.41python_codon_tables-0.1.18/python_codon_tables/codon_usage_data/tables/s_cerevisiae_4932.csv000066400000000000000000000013431500744233300322650ustar00rootroot00000000000000amino_acid,codon,relative_frequency *,UAA,0.47 *,UAG,0.23 *,UGA,0.30 A,GCA,0.29 A,GCC,0.22 A,GCG,0.11 A,GCU,0.38 C,UGC,0.37 C,UGU,0.63 D,GAC,0.35 D,GAU,0.65 E,GAA,0.70 E,GAG,0.30 F,UUC,0.41 F,UUU,0.59 G,GGA,0.22 G,GGC,0.19 G,GGG,0.12 G,GGU,0.47 H,CAC,0.36 H,CAU,0.64 I,AUA,0.27 I,AUC,0.26 I,AUU,0.46 K,AAA,0.58 K,AAG,0.42 L,CUA,0.14 L,CUC,0.06 L,CUG,0.11 L,CUU,0.13 L,UUA,0.28 L,UUG,0.29 M,AUG,1.00 N,AAC,0.41 N,AAU,0.59 P,CCA,0.42 P,CCC,0.15 P,CCG,0.12 P,CCU,0.31 Q,CAA,0.69 Q,CAG,0.31 R,AGA,0.48 R,AGG,0.21 R,CGA,0.07 R,CGC,0.06 R,CGG,0.04 R,CGU,0.14 S,AGC,0.11 S,AGU,0.16 S,UCA,0.21 S,UCC,0.16 S,UCG,0.10 S,UCU,0.26 T,ACA,0.30 T,ACC,0.22 T,ACG,0.14 T,ACU,0.35 V,GUA,0.21 V,GUC,0.21 V,GUG,0.19 V,GUU,0.39 W,UGG,1.00 Y,UAC,0.44 Y,UAU,0.56python_codon_tables-0.1.18/python_codon_tables/python_codon_tables.py000066400000000000000000000106721500744233300263110ustar00rootroot00000000000000import sys import re import os from functools import lru_cache if sys.version_info[0] == 3: import urllib.request urlopen = urllib.request.urlopen else: import urllib2 urlopen = urllib2.urlopen _this_dir = os.path.dirname(os.path.realpath(__file__)) _tables_dir = os.path.join(_this_dir, "codon_usage_data", "tables") available_codon_tables_names = [filename[:-4] for filename in os.listdir(_tables_dir)] available_codon_tables_shortnames = { "_".join(table_name.split("_")[:-1]): table_name for table_name in available_codon_tables_names } def csv_string_to_codons_dict(csv_string): """Transform a CSV string of a codon table to a dict.""" result = {} csv_stripped = csv_string.rstrip() for line in csv_stripped.split("\n")[1:]: aa, codon, freq = line.split(",") if aa not in result: result[aa] = {} result[aa][codon] = float(freq) return result def table_with_U_replaced_by_T(table): return { aa: {codon.replace("U", "T"): freq for codon, freq in aa_data.items()} for aa, aa_data in table.items() } @lru_cache(maxsize=128) def get_codons_table(table_name, replace_U_by_T=True, web_timeout=5): """Get data from one of this package's builtin codon usage tables. The ``table_name`` argument very flexible on purpose, it can be either an integer representing a taxonomic ID (which will be downloaded from the kazusa database), or a string "12245" representing a TaxID, or a string "e_coli_316407" referring to a builtin table of python_codon_optimization, or a short form "e_coli" which will be automatically extended to "e_coli_316407" (at your own risks). If a taxonomic ID is provided and no table with this taxID is present in the ``codon_usage_data/tables/`` folder, the table will be downloaded from the http://www.kazusa.or.jp/codon website. As this website sometimes go down, the parameter ``web_timeout`` controls how long to wait before a Python exception is raised, informing the user that Kazusa may be down. The ``replace_U_by_T`` argument will replace all codons names from UAA to TAA etc. Returns a dict {"*": {'TAA': 0.64...}, 'K': {'AAA': 0.76...}, ...} """ if replace_U_by_T: table = get_codons_table(table_name, replace_U_by_T=False, web_timeout=5) return table_with_U_replaced_by_T(table) if isinstance(table_name, int) or str.isdigit(table_name): return download_codons_table(taxid=table_name, timeout=web_timeout) if table_name in available_codon_tables_shortnames: table_name = available_codon_tables_shortnames[table_name] with open(os.path.join(_tables_dir, table_name + ".csv"), "r") as f: return csv_string_to_codons_dict(f.read()) def get_all_available_codons_tables(replace_U_by_T=True): """Get all data from all of this package's builtin codon usage tables.""" return { table_name: get_codons_table(table_name, replace_U_by_T=replace_U_by_T) for table_name in available_codon_tables_names } @lru_cache(maxsize=128) def download_codons_table(taxid=316407, target_file=None, timeout=5): """Get all data from all of this package's builtin codon usage tables.""" _kazusa_url = ( "http://www.kazusa.or.jp/codon/cgi-bin/showcodon.cgi" "?aa=1&style=N&species=%s" ) _codon_regexpr = r"([ATGCU]{3}) ([A-Z]|\*) (\d.\d+)" url = _kazusa_url % taxid try: web_handle = urlopen(url, timeout=timeout) except Exception as err: if "timed out" in str(err): raise RuntimeError( ( "connexion to %s timed out after %d seconds. Maybe " "their website is down?" ) % (url, timeout) ) else: raise err html_content = web_handle.read().decode().replace("\n", " ") if "not found" in html_content.lower(): raise RuntimeError( "Codon usage table for taxonomy ID '%s' not found:" " %s" % (taxid, url) ) csv_data = "\n".join( ["amino_acid,codon,relative_frequency"] + sorted( [ "%s,%s,%s" % (aa, codon, usage) for codon, aa, usage in re.findall(_codon_regexpr, html_content) ] ) ) if target_file is not None: with open(target_file, "w+") as f: f.write(csv_data) else: return csv_string_to_codons_dict(csv_data) python_codon_tables-0.1.18/python_codon_tables/version.py000066400000000000000000000000271500744233300237320ustar00rootroot00000000000000__version__ = "0.1.18" python_codon_tables-0.1.18/tests/000077500000000000000000000000001500744233300170015ustar00rootroot00000000000000python_codon_tables-0.1.18/tests/data/000077500000000000000000000000001500744233300177125ustar00rootroot00000000000000python_codon_tables-0.1.18/tests/data/table_newline.csv000066400000000000000000000000571500744233300232410ustar00rootroot00000000000000amino_acid,codon,relative_frequency A,GCA,0.21 python_codon_tables-0.1.18/tests/test_basics.py000066400000000000000000000044121500744233300216570ustar00rootroot00000000000000"""Basic tests to check that the main examples work.""" import os import pytest import python_codon_tables as pct mock_table_path = os.path.join("tests", "data", "table_newline.csv") def test_basics(): # LOAD ONE TABLE BY NAME table = pct.get_codons_table("b_subtilis_1423") assert table["T"]["ACA"] == 0.4 assert table["*"]["TAA"] == 0.61 # LOAD ALL TABLES AT ONCE codon_tables = pct.get_all_available_codons_tables() assert codon_tables["c_elegans_6239"]["L"]["CTA"] == 0.09 def test_download_codon_table(tmpdir): table = pct.download_codons_table(taxid=316407) assert table["*"]["UAG"] == 0.07 target = os.path.join(str(tmpdir), "test.csv") table = pct.download_codons_table(taxid=316407, target_file=target) def test_readme_example(): table = pct.get_codons_table("b_subtilis_1423") assert table["T"]["ACA"] == 0.4 assert table["*"]["TAA"] == 0.61 # LOAD ALL TABLES AT ONCE codons_tables = pct.get_all_available_codons_tables() assert codons_tables["c_elegans_6239"]["L"]["CTA"] == 0.09 # GET A TABLE DIRECTLY FROM THE INTERNET table = pct.download_codons_table(taxid=316407) assert table["*"]["TGA"] == 0.29 with pytest.raises(RuntimeError): table = pct.download_codons_table(taxid=000000000) # does not exist def test_readme_example(): table = pct.get_codons_table("b_subtilis_1423") assert table["T"]["ACA"] == 0.4 assert table["*"]["TAA"] == 0.61 # LOAD ALL TABLES AT ONCE codons_tables = pct.get_all_available_codons_tables() assert codons_tables["c_elegans_6239"]["L"]["CTA"] == 0.09 # GET A TABLE DIRECTLY FROM THE INTERNET table = pct.download_codons_table(taxid=316407) assert table["*"]["UGA"] == 0.29 def test_get_codons_table(): for table_name in (1423, "1423", "b_subtilis", "b_subtilis_1423"): table = pct.get_codons_table(table_name) assert table["T"]["ACA"] == 0.4 assert table["*"]["TAA"] == 0.61 def test_replace_U_by_T(): table = pct.get_codons_table("b_subtilis_1423", replace_U_by_T=False) assert table["*"]["UAA"] == 0.61 def test_csv_string_to_codons_dict(): with open(mock_table_path, "r") as f: codon_dict = pct.csv_string_to_codons_dict(f.read()) assert type(codon_dict) == dict