Package: pygenetic-code
Genetic CodesA Python and C library with no external dependencies for translating DNA sequences into protein sequences using different translation tables (aka genetic codes).TheNCBI Genetic Codesare central to working with alternate genetic codes. This Python tool kit includes a library that exposes the genetic codes so you can query a codon and get its variants or query a code and get its table. We also provide fast mechanisms to translate DNA sequences into protein sequences using the translation table of your choice.InstallationYou can installpygenetic_codewith pip.pipinstallpygenetic_codepygenetic_code--versionA conda installation is in the works!UsageThere is a command line application, Python example code, and a library that you can use. The command line application and examples show you how to use the library.Example codeThese examples show you how to incorporatepygenetic_codeinto your own Python code.We have a very simple translate function that you can use if you want to translate one (or more) ORFs. The signature istranslate(dna_sequence,translation_table)and we have a simple example that translates a sequence:pythonexamples/translate_a_sequence.pyWe can also translate DNA sequences in all six reading frames, and here is an example that reads a fasta file and translates all six frames using the bacterial genetic code (translation table 11):pythonexamples/translate_sequence_in_all_frames.py-ftests/JQ995537.fna-t11or an alternate genetic code (translation table 15):pythonexamples/translate_sequence_in_all_frames.py-ftests/JQ995537.fna-t15Or you can translate theE. coliK-12 sequence, and so you can identify all the ORFs in that genome:pythonexamples/translate_sequence_in_all_frames.py-ftests/U00096.3.fna.gz-t11(yes, you can use gzip files without decompressing them).This will take about 0.1 seconds to do the actual translation, but starting python and all the other overheads make it almost 3/4 second to run.You can also look at the effect of translation tables on the same sequences by runningpythonexamples/average_translation_length.py-ftests/JQ995537.fna# for crassphagepythonexamples/average_translation_length.py-ftests/U00096.3.fna.gz# for E. coli K-12We recommend using our easy Python wrappers to access the translate functionsfrompygenetic_codeimporttranslate,six_frame_translationBut you can also access our C library directly, using thePyGeneticCodemodule (see below)Command line applicationspygenetic_codetranslates DNA sequences either in one reading frame or in all six reading frames using the translation table of your choice.To translate a sequence in the current reading frame, you can usepygenetic_code--translateFirst, make sure you have a DNA sequence. We provide a few intests/includinga very short sequence,crAssphage, and [E. coli])(tests/U00096.3.fna.gz).LibraryUsing the C library directly in PythonYou can import the C library by importing PyGeneticCode.There are two main methods that you can call:The first function just returns the translation of your DNA sequence in 5' -> 3' format, so for example, this is the method you might use to translate an ORF.PyGeneticCode.translate(DNA_sequence,translation_table)(Seeexamples/translate_a_sequence.pyfor an example.The second method returns all the 6 frame translations.PyGeneticCode.translate_six_frames(DNA_sequence,translation_table,verbose)(Seeexamples/translate_sequence_in_all_frames.pyfor an example invocation.)The DNA sequence is the DNA sequence you want to translate. The translation table must be one of the valid translation tables (seepygenetic_code/genetic_code.translation_tablesfor the valid tables).Translate a codonAnother way to access the code in your python application is to access thetranslate_codon()function, that has this signature:amino_acid=translate_codon(codon,translation_table=1,one_letter=False)Thecodonis the codon that you want to translate as either an RNA (e.g.AUG) or DNA (e.g.ATG) sequence. Thetranslation_tableis your required translation table (see theNCBI websitefor valid tables), andone_letteris whether to return a three letter amino acid code (e.g.MetorTer) or a one letter amino acid code (e.g.Mor*).The library provides other ways to access the genetic codes, and those are exemplified in thepytestfiles intests/Viewing translation tablesYou can print the translation tables using thepygenetic_codecommand. There are currently a couple of options:jsonprints the table in machine readable json format.differenceprints a.tsvfile with the the difference from the standard (translation table 1) codemaxdifferenceprints a.tsvfile with the difference from the most common amino acid. The main difference is thatTGAis more frequently tryptophan than a stop.CitingPlease cite this repository as:Edwards, Robert A. 2023. pygenetic_code.https://github.com/linsalrob/genetic_codes. DOI: 10.5281/zenodo.10453453