{ "cells": [ { "cell_type": "markdown", "source": [ "# Example usage\n", "\n", "The main goal of `codino` is to convert amino acid (AA) frequencies to codon design (CD), and vice versa." ], "metadata": {} }, { "cell_type": "code", "execution_count": 36, "source": [ "import codino\n", "\n", "print(codino.__version__)" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.1.1\n" ] } ], "metadata": { "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "Users should initialise a `Converter`." ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 37, "outputs": [], "source": [ "from codino.process import Converter\n", "\n", "c = Converter()" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "The two useful methods within a `Converter` are `cd_to_aa()` and `aa_to_cd()`, which converts a CD to AA frequencies and vice versa." ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 38, "outputs": [ { "data": { "text/plain": "True" }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# input the expected nucleotide frequencies at each position\n", "c.cd_to_aa(first={\"A\": 1}, second={\"T\": 1}, third={\"G\": 1})\n", "\n", "# input the desired AA frequencies\n", "first, second, third = c.aa_to_cd(aa={'D': 0.4, 'N': 0.6})\n", "\n", "# you can check the output by converting the codon design back to AA frequencies\n", "c.cd_to_aa(first, second, third) == {'D': 0.4, 'N': 0.6}" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "For more complex examples, the conversion of the AA frequencies to a CD will be an estimate." ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 39, "outputs": [ { "data": { "text/plain": "False" }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "exp_aa = {'A': 0.1771,\n", " 'D': 0.208131,\n", " 'E': 0.18456899999999998,\n", " 'I': 0.031694,\n", " 'K': 0.055131,\n", " 'M': 0.028106000000000003,\n", " 'N': 0.062169,\n", " 'T': 0.0529,\n", " 'V': 0.2002}\n", "\n", "first, second, third = c.aa_to_cd(aa=exp_aa)\n", "pred_aa = c.cd_to_aa(first, second, third)\n", "\n", "pred_aa == exp_aa" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "In this case, it can be helpful to obtain the error between the expected and predicted AA frequencies." ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 40, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Average error per AA ==> 0.0055103958222222325\n", "Total error across AAs ==> 0.049593562400000096\n" ] } ], "source": [ "errors = [abs(pred_aa[a] - exp_aa[a]) for a in exp_aa]\n", "\n", "print(f'Average error per AA ==> {sum(errors)/len(errors)}')\n", "\n", "print(f'Total error across AAs ==> {sum(errors)}')" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }