Giter Site home page Giter Site logo

benjamin-lee / codonadaptationindex Goto Github PK

View Code? Open in Web Editor NEW
27.0 4.0 7.0 35.63 MB

Python Implementation of Codon Adaption Index

Home Page: https://cai.readthedocs.io

License: MIT License

Python 21.79% Jupyter Notebook 76.07% TeX 2.14%
bioinformatics codons genetics

codonadaptationindex's Introduction

Python Codon Adaptation Index

DOI Docs Travis CodeFactor PyPI

An implementation of Sharp and Li's 1987 formulation of the codon adaption index.

Installation

This module is available from PyPI and can be downloaded with the following command:

$ pip install CAI

To install the latest development version:

$ pip install git+https://github.com/Benjamin-Lee/CodonAdaptationIndex.git

Quickstart

Finding the CAI of a sequence is easy:

>>> from CAI import CAI
>>> CAI("ATG...", reference=["ATGTTT...", "ATGCGC...",...])
0.24948128951724224

Similarly, from the command line:

$ CAI -s sequence.fasta -r reference_sequences.fasta
0.24948128951724224

Determining which sequences to use as the reference set is left to the user, though the HEG-DB is a great resource of highly expressed genes.

Contributing and Getting Support

If you encounter any issues using CAI, feel free to create an issue.

To contribute to the project, please create a pull request. For more information on how to do so, please look at GitHub's documentation on pull requests.

Citation

Lee, B. D. (2018). Python Implementation of Codon Adaptation Index. Journal of Open Source Software, 3 (30), 905. https://doi.org/10.21105/joss.00905 :

@article{Lee2018,
  doi = {10.21105/joss.00905},
  url = {https://doi.org/10.21105/joss.00905},
  year  = {2018},
  month = {oct},
  publisher = {The Open Journal},
  volume = {3},
  number = {30},
  pages = {905},
  author = {Benjamin D. Lee},
  title = {Python Implementation of Codon Adaptation Index},
  journal = {Journal of Open Source Software}

Contact

I'm available for contact at [email protected].

Reference

Sharp, P. M., & Li, W. H. (1987). The codon adaptation index--a measure of directional synonymous codon usage bias, and its potential applications. Nucleic Acids Research, 15(3), 1281–1295.

codonadaptationindex's People

Contributors

benjamin-lee avatar bjornfjohansson avatar ctb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

codonadaptationindex's Issues

Dependabot can't evaluate your Python dependency files

Dependabot can't evaluate your Python dependency files.

As a result, Dependabot couldn't check whether any of your dependencies are out-of-date.

The error Dependabot encountered was:

InstallationError("Invalid requirement: 'MIT License'\n",)

You can mention @dependabot in the comments below to contact the Dependabot team.

Conda package

I made a conda package of version v1.0.3, available here.
Install by:

conda install -c bjornfjohansson cai

Documentation Request for Using RSCU param with `python_codon_tables`

Just like it sounds. It'd be great to see how to use the RSCU param in the docs. In particular how to integrate it with the value from python_codon_tables.get_codons_table().

Most of the examples are using a reference genome and I get key errors when I try:

RSCU = python_codon_tables.get_codons_table("h_sapiens")
initial_grade = CAI.CAI(initial_seq, RSCUs=RSCU)

Bug report

from CAI import CAI
from Bio import SeqIO # to parse FASTA files
reference = [seq.seq for seq in SeqIO.parse("/Users/rthapa/Downloads/Sbicolor_454_v3.1.1.protein.fa", "fasta")]
sequence = SeqIO.read("/Users/rthapa/Downloads/Sbicolor_454_v3.0.1.fa", "fasta")
CAI(sequence, reference=reference)

Some test input files would be useful for newcomers.

It would be great to provide some full examples that let a new user immediately run CAI on some real data. For my JOSS review I'm going to have to hunt down the right files before I review the functionality!

Add a jupyter notebook to docs or tests

Hi, I made a notebook confirming that CAI gives the expected results from the old data in the original papers.

gist

Perhaps you would consider including it? Is so, I can do a pull request.

More guidance on contributing / filing issues.

In the README, it would be good to provide more guidance, e.g. "open a pull request to contribute" (With a pointer to github documentation) and "use the issue tracker (link) to file an issue."

Small performance improvement

I am checking RSCU() method and it seems to me that small performance improvement is possible in codon counting. It should be faster to once call upper() method for a sequence than for each of it's codons separately.
Lines ~80, adding line like sequences = [s.upper() for s in sequences] can improve perf.

Simple check shows ~30% improvements:

python3 -m timeit 'x = ("a"*300000); [x[i: i+3].upper() for i in range(0, len(x), 3)]'
10 loops, best of 3: 21.3 msec per loop
python3 -m timeit 'x = ("a"*300000).upper(); [x[i: i+3] for i in range(0, len(x), 3)]'
100 loops, best of 3: 14.5 msec per loop

pip install not working

I think it is the 2to3 option in setup.py.
Is 2to3 still needed?

Collecting CAI Using cached CAI-1.0.3.tar.gz (6.0 kB) ERROR: Command errored out with exit status 1: command: /home/bjorn/anaconda3/envs/new39/bin/python3.9 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-y9phjkp9/cai_8c869096cf864cb8934fa27a731d3393/setup.py'"'"'; __file__='"'"'/tmp/pip-install-y9phjkp9/cai_8c869096cf864cb8934fa27a731d3393/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-52f8wm2g cwd: /tmp/pip-install-y9phjkp9/cai_8c869096cf864cb8934fa27a731d3393/ Complete output (1 lines): error in CAI setup command: use_2to3 is invalid.

Locale issues installing from pip

Hi Ben,

I just thought I’d let you know about an issue with installing I found. I’ve hacked my way around it, but others may encounter it.

Any variation of pip3 install CAI greeted me with:

Processing /home/wms_joe/repos/CodonAdaptationIndex
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-req-build-441r21d4/setup.py", line 7, in <module>
        long_description = f.read()
      File "/home/wms_joe/bin/miniconda3/lib/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 2445: ordinal not in range(128)
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-441r21d4/

Searching online suggests its a locale encoding issue, however I tried to set several locale environmental variables, as corresponds to other issues I’ve seen for this ascii error:

export LC_ALL=C
export LC_CTYPE=en_US.UTF-8
export LANG=en_US.UTF-8

None of which worked.

The issue appears to be with the README.rst, so I was able to finally install it inside a cloned repo with pip3 install . after emptying the contents of the file. I’m still not sure exactly where the issue arises though, as at a glance, I couldn’t see an unusual character anywhere.

Edit:

Subsequently discovered that, contrary to the internet’s advice, the encoding should be en_US.utf8 not UTF-8. Though I suspect that may be due to this being installed on an older ubuntu box (14.04!).

Fortunately, click outputs a useful error message, and setting LC_ALL to en_US.utf8 allowed the program to run correctly (I haven’t checked if that is also the case for the installation as it’s already on the system now).

Traceback (most recent call last):
  File "/home/wms_joe/bin/miniconda3/bin/CAI", line 11, in <module>
    sys.exit(cli())
  File "/home/wms_joe/bin/miniconda3/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/wms_joe/bin/miniconda3/lib/python3.6/site-packages/click/core.py", line 696, in main
    _verify_python3_env()
  File "/home/wms_joe/bin/miniconda3/lib/python3.6/site-packages/click/_unicodefun.py", line 124, in _verify_python3_env
    ' mitigation steps.' + extra
RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/en/7.x/python3/ for mitigation steps.

This system lists a couple of UTF-8 supporting locales that
you can pick from.  The following suitable locales were
discovered: en_US.utf8
$ export LC_ALL=en_US.utf8
$ CAI -h
Usage: CAI [OPTIONS]
Try "CAI --help" for help.

Error: no such option: -h

I don’t know if you want to consider this resolved or if this is something worth patching/including in the install instructions?!

Bug with sequence length

I am testing CAI package following your instructions and I got a bug when processing small sequences. My sequence is:

>testseq
ATGAAATTAATATTGAAACTCGTGGAACGGAAAAAACTGATCAAGGAGTTAAAAGAAGATATTGAAGTAATTTAA

Then, when I execute the program:

>>> reference = [seq.seq for seq in SeqIO.parse("../database/annotation/1036673.PRJNA67335/1036673.PRJNA67335.ffn", "fasta")]
>>> CAI(sequence, reference=reference)

I receive this message:

  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/CAI/CAI.py", line 220, in CAI
    weights = relative_adaptiveness(sequences=reference, genetic_code=genetic_code)
  File "/usr/local/lib/python3.7/dist-packages/CAI/CAI.py", line 149, in relative_adaptiveness
    RSCUs = RSCU(sequences, genetic_code=genetic_code)
  File "/usr/local/lib/python3.7/dist-packages/CAI/CAI.py", line 75, in RSCU
    raise ValueError("Input sequence not divisible by three")
ValueError: Input sequence not divisible by three

The problem is, this is a coding sequence that we work for long time now and it is divisible in codons (presents even the start and stop codon there). So, I do not know what is misinterpreted by the package. I look forward to hearing from you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.