# HG changeset patch # User Vimalkumar Velayudhan # Date 1439368065 -3600 # Node ID 8e1efafa627786a818d0a9c3a21c9fbeaf424eff # Parent b6fd86c539ea185ac2312afe6d0b9cf761ff5dcf Updated version * Bugfix: blue lines in some plots (bar colors were not set correctly) * Cookiecutter template * Additional unit tests * Add plot legend diff -r b6fd86c539ea -r 8e1efafa6277 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,6 @@ +syntax: glob +*.pyc +*.swp +.git* +tests/data/*.bam* +tests/data/*.fna* diff -r b6fd86c539ea -r 8e1efafa6277 .travis.yml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.travis.yml Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,16 @@ +# Config file for automatic testing at travis-ci.org + +language: python + +python: + - "3.4" + - "3.3" + - "2.7" + - "2.6" + - "pypy" + +# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors +install: pip install -r requirements.txt + +# command to run tests, e.g. python setup.py test +script: python setup.py test \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 AUTHORS.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AUTHORS.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,13 @@ +======= +Credits +======= + +Development Lead +---------------- + +* Vimalkumar Velayudhan + +Contributors +------------ + +None yet. Why not be the first? \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 CONTRIBUTING.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CONTRIBUTING.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,111 @@ +============ +Contributing +============ + +Contributions are welcome, and they are greatly appreciated! Every +little bit helps, and credit will always be given. + +You can contribute in many ways: + +Types of Contributions +---------------------- + +Report Bugs +~~~~~~~~~~~ + +Report bugs at https://github.com/vimalkumarvelayudhan/riboplot/issues. + +If you are reporting a bug, please include: + +* Your operating system name and version. +* Any details about your local setup that might be helpful in troubleshooting. +* Detailed steps to reproduce the bug. + +Fix Bugs +~~~~~~~~ + +Look through the GitHub issues for bugs. Anything tagged with "bug" +is open to whoever wants to implement it. + +Implement Features +~~~~~~~~~~~~~~~~~~ + +Look through the GitHub issues for features. Anything tagged with "feature" +is open to whoever wants to implement it. + +Write Documentation +~~~~~~~~~~~~~~~~~~~ + +RiboPlot could always use more documentation, whether as part of the +official RiboPlot docs, in docstrings, or even on the web in blog posts, +articles, and such. + +Submit Feedback +~~~~~~~~~~~~~~~ + +The best way to send feedback is to file an issue at https://github.com/vimalkumarvelayudhan/riboplot/issues. + +If you are proposing a feature: + +* Explain in detail how it would work. +* Keep the scope as narrow as possible, to make it easier to implement. +* Remember that this is a volunteer-driven project, and that contributions + are welcome :) + +Get Started! +------------ + +Ready to contribute? Here's how to set up `riboplot` for local development. + +1. Fork the `riboplot` repo on GitHub. +2. Clone your fork locally:: + + $ git clone git@github.com:your_name_here/riboplot.git + +3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: + + $ mkvirtualenv riboplot + $ cd riboplot/ + $ python setup.py develop + +4. Create a branch for local development:: + + $ git checkout -b name-of-your-bugfix-or-feature + + Now you can make your changes locally. + +5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: + + $ flake8 riboplot tests + $ python setup.py test + $ tox + + To get flake8 and tox, just pip install them into your virtualenv. + +6. Commit your changes and push your branch to GitHub:: + + $ git add . + $ git commit -m "Your detailed description of your changes." + $ git push origin name-of-your-bugfix-or-feature + +7. Submit a pull request through the GitHub website. + +Pull Request Guidelines +----------------------- + +Before you submit a pull request, check that it meets these guidelines: + +1. The pull request should include tests. +2. If the pull request adds functionality, the docs should be updated. Put + your new functionality into a function with a docstring, and add the + feature to the list in README.rst. +3. The pull request should work for Python 2.6, 2.7, 3.3, and 3.4, and for PyPy. Check + https://travis-ci.org/vimalkumarvelayudhan/riboplot/pull_requests + and make sure that the tests pass for all supported Python versions. + +Tips +---- + +To run a subset of tests:: + + $ python -m unittest tests.test_riboplot \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 HISTORY.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HISTORY.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,9 @@ +.. :changelog: + +History +------- + +0.1.0 (2015-08-05) +--------------------- + +* First release on PyPI. \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 LICENSE --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,12 @@ +Copyright (c) 2015, Vimalkumar Velayudhan +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +* Neither the name of RiboPlot nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 MANIFEST.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MANIFEST.in Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,11 @@ +include AUTHORS.rst +include CONTRIBUTING.rst +include HISTORY.rst +include LICENSE +include README.rst + +recursive-include tests * +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] + +recursive-include docs *.rst conf.py Makefile make.bat \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,70 @@ +.PHONY: clean-pyc clean-build docs clean + +help: + @echo "clean - remove all build, test, coverage and Python artifacts" + @echo "clean-build - remove build artifacts" + @echo "clean-pyc - remove Python file artifacts" + @echo "clean-test - remove test and coverage artifacts" + @echo "lint - check style with flake8" + @echo "test - run tests quickly with the default Python" + @echo "test-all - run tests on every Python version with tox" + @echo "coverage - check code coverage quickly with the default Python" + @echo "docs - generate Sphinx HTML documentation, including API docs" + @echo "release - package and upload a release" + @echo "dist - package" + @echo "install - install the package to the active Python's site-packages" + +clean: clean-build clean-pyc clean-test + +clean-build: + rm -fr build/ + rm -fr dist/ + rm -fr .eggs/ + find . -name '*.egg-info' -exec rm -fr {} + + find . -name '*.egg' -exec rm -f {} + + +clean-pyc: + find . -name '*.pyc' -exec rm -f {} + + find . -name '*.pyo' -exec rm -f {} + + find . -name '*~' -exec rm -f {} + + find . -name '__pycache__' -exec rm -fr {} + + +clean-test: + rm -fr .tox/ + rm -f .coverage + rm -fr htmlcov/ + +lint: + flake8 riboplot tests + +test: + python setup.py test + +test-all: + tox + +coverage: + coverage run --source riboplot setup.py test + coverage report -m + coverage html + open htmlcov/index.html + +docs: + rm -f docs/riboplot.rst + rm -f docs/modules.rst + sphinx-apidoc -o docs/ riboplot + $(MAKE) -C docs clean + $(MAKE) -C docs html + open docs/_build/html/index.html + +release: clean + python setup.py sdist upload + python setup.py bdist_wheel upload + +dist: clean + python setup.py sdist + python setup.py bdist_wheel + ls -l dist + +install: clean + python setup.py install \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 README.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,20 @@ +=============================== +RiboPlot +=============================== + +.. image:: https://img.shields.io/travis/vimalkumarvelayudhan/riboplot.svg + :target: https://travis-ci.org/vimalkumarvelayudhan/riboplot + +.. image:: https://img.shields.io/pypi/v/riboplot.svg + :target: https://pypi.python.org/pypi/riboplot + + +Plot read counts of RiboSeq data from BAM format alignment files + +* Free software: BSD license +* Documentation: https://riboplot.readthedocs.org. + +Features +-------- + +* TODO \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 data/riboplot.html --- a/data/riboplot.html Thu Jul 02 11:53:59 2015 +0100 +++ b/data/riboplot.html Wed Aug 12 09:27:45 2015 +0100 @@ -39,10 +39,10 @@

Ribo-Seq profile plot

-
+

Download plots
- PNG, SVG + PNG, SVG
Download counts
diff -r b6fd86c539ea -r 8e1efafa6277 docs/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/Makefile Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,177 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/riboplot.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/riboplot.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/riboplot" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/riboplot" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 docs/authors.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/authors.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +.. include:: ../AUTHORS.rst \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 docs/conf.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/conf.py Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,275 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# riboplot documentation build configuration file, created by +# sphinx-quickstart on Tue Jul 9 22:26:36 2013. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another +# directory, add these directories to sys.path here. If the directory is +# relative to the documentation root, use os.path.abspath to make it +# absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# Get the project root dir, which is the parent dir of this +cwd = os.getcwd() +project_root = os.path.dirname(cwd) + +# Insert the project root dir as the first element in the PYTHONPATH. +# This lets us ensure that the source package is imported, and that its +# version is used. +sys.path.insert(0, project_root) + +import riboplot + +# -- General configuration --------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'RiboPlot' +copyright = u'2015, Vimalkumar Velayudhan' + +# The version info for the project you're documenting, acts as replacement +# for |version| and |release|, also used in various other places throughout +# the built documents. +# +# The short X.Y version. +version = riboplot.__version__ +# The full version, including alpha/beta/rc tags. +release = riboplot.__version__ + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to +# some non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built +# documents. +#keep_warnings = False + + +# -- Options for HTML output ------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a +# theme further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as +# html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the +# top of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon +# of the docs. This file should be a Windows icon file (.ico) being +# 16x16 or 32x32 pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) +# here, relative to this directory. They are copied after the builtin +# static files, so a file named "default.css" will overwrite the builtin +# "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page +# bottom, using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names +# to template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. +# Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. +# Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages +# will contain a tag referring to it. The value of this option +# must be the base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'riboplotdoc' + + +# -- Options for LaTeX output ------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + #'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass +# [howto/manual]). +latex_documents = [ + ('index', 'riboplot.tex', + u'RiboPlot Documentation', + u'Vimalkumar Velayudhan', 'manual'), +] + +# The name of an image file (relative to this directory) to place at +# the top of the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings +# are parts, not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output ------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'riboplot', + u'RiboPlot Documentation', + [u'Vimalkumar Velayudhan'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ---------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'riboplot', + u'RiboPlot Documentation', + u'Vimalkumar Velayudhan', + 'riboplot', + 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 docs/contributing.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/contributing.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +.. include:: ../CONTRIBUTING.rst \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 docs/history.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/history.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +.. include:: ../HISTORY.rst \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 docs/index.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/index.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,26 @@ +.. riboplot documentation master file, created by + sphinx-quickstart on Tue Jul 9 22:26:36 2013. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to RiboPlot's documentation! +====================================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + readme + installation + usage + contributing + authors + history + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff -r b6fd86c539ea -r 8e1efafa6277 docs/installation.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/installation.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,12 @@ +============ +Installation +============ + +At the command line:: + + $ easy_install riboplot + +Or, if you have virtualenvwrapper installed:: + + $ mkvirtualenv riboplot + $ pip install riboplot \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 docs/make.bat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/make.bat Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,242 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +%SPHINXBUILD% 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.http://sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\riboplot.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\riboplot.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 docs/readme.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/readme.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +.. include:: ../README.rst \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 docs/todo.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/todo.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,38 @@ +Outline +------- +Log information by default +Errors to stderr + + +Arguments +--------- +-b ribo_file +-f transcriptome_fasta +-t transcript_name +-n rna_file +-l read_length +-s read_offset +-m html_file +-o output_path +-d debug + +Tests +----- + +Check arguments +............... +* BAM file valid (should be indexed for fetch to work) +* FASTA file should be valid +* Transcript name should exist in both BAM and FASTA (riboplot: yes, ribocount: no). +* If RNA file is provided, bedtools should exist in PATH +* Read length should be a valid integer (must exist in BAM) +* Read offset - positive integer (can't exceed ?) +* Should be possible to get codon positions. + + +Notes +----- +* No way to check if input BAM is RNA-Seq/Ribo-Seq (plot will still be generated in either case) +* No way to check if BAM is sorted + + diff -r b6fd86c539ea -r 8e1efafa6277 docs/usage.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/usage.rst Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,7 @@ +======== +Usage +======== + +To use RiboPlot in a project:: + + import riboplot \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 galaxy/ribocount.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/galaxy/ribocount.xml Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,30 @@ + + Get read counts for all transcripts in an alignment (BAM) + + + pysam + + + + + ../riboplot/ribocount.py + --ribo_file "${ribo_file}" + --transcriptome_fasta "${transcriptome_fasta}" + --read_length "${read_length}" + --read_offset "${read_offset}" + --html_file "${html_file}" + --output_path "${html_file.files_path}" + ## --debug + + + + + + + + + + + + + diff -r b6fd86c539ea -r 8e1efafa6277 galaxy/riboplot.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/galaxy/riboplot.xml Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,54 @@ + + Plot and output read counts for a single transcript in an alignment (BAM) + + + matplotlib + pysam + + + + + ../riboplot/riboplot.py + --ribo_file "${ribo_file}" + --transcriptome_fasta "${transcriptome_fasta}" + --transcript_name "${transcript_name}" + #if $rnacov.rnacov_select=="yes" + --rna_file "${rna_file}" + #end if + --read_length "${read_length}" + --read_offset "${read_offset}" + --html_file "${html_file}" + --output_path "${html_file.files_path}" + ## --debug + + + + + + len(value.split(',')) == 1 + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r b6fd86c539ea -r 8e1efafa6277 requirements.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/requirements.txt Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +wheel==0.23.0 \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 ribocount.xml --- a/ribocount.xml Thu Jul 02 11:53:59 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ - - Get read counts for all transcripts in an alignment (BAM) - - - pysam - - - - - riboplot/ribocount.py - --ribo_file "${ribo_file}" - --transcriptome_fasta "${transcriptome_fasta}" - --read_length "${read_length}" - --read_offset "${read_offset}" - --html_file "${html_file}" - --output_path "${html_file.files_path}" - ## --debug - - - - - - - - - - - - - diff -r b6fd86c539ea -r 8e1efafa6277 riboplot.egg-info/PKG-INFO --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/riboplot.egg-info/PKG-INFO Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,50 @@ +Metadata-Version: 1.1 +Name: riboplot +Version: 0.1.0 +Summary: Plot read counts of RiboSeq data from BAM format alignment files +Home-page: https://github.com/vimalkumarvelayudhan/riboplot +Author: Vimalkumar Velayudhan +Author-email: vimalkumarvelayudhan@gmail.com +License: BSD +Description: =============================== + RiboPlot + =============================== + + .. image:: https://img.shields.io/travis/vimalkumarvelayudhan/riboplot.svg + :target: https://travis-ci.org/vimalkumarvelayudhan/riboplot + + .. image:: https://img.shields.io/pypi/v/riboplot.svg + :target: https://pypi.python.org/pypi/riboplot + + + Plot read counts of RiboSeq data from BAM format alignment files + + * Free software: BSD license + * Documentation: https://riboplot.readthedocs.org. + + Features + -------- + + * TODO + + + + History + ------- + + 0.1.0 (2015-08-05) + --------------------- + + * First release on PyPI. +Keywords: riboplot +Platform: UNKNOWN +Classifier: Development Status :: 2 - Pre-Alpha +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: BSD License +Classifier: Natural Language :: English +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.6 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.3 +Classifier: Programming Language :: Python :: 3.4 diff -r b6fd86c539ea -r 8e1efafa6277 riboplot.egg-info/SOURCES.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/riboplot.egg-info/SOURCES.txt Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,43 @@ +AUTHORS.rst +CONTRIBUTING.rst +HISTORY.rst +LICENSE +MANIFEST.in +README.rst +setup.cfg +setup.py +docs/Makefile +docs/authors.rst +docs/conf.py +docs/contributing.rst +docs/history.rst +docs/index.rst +docs/installation.rst +docs/make.bat +docs/readme.rst +docs/todo.rst +docs/usage.rst +riboplot/__init__.py +riboplot/config.py +riboplot/ribocore.py +riboplot/ribocount.py +riboplot/riboplot.py +riboplot.egg-info/PKG-INFO +riboplot.egg-info/SOURCES.txt +riboplot.egg-info/dependency_links.txt +riboplot.egg-info/not-zip-safe +riboplot.egg-info/top_level.txt +tests/.test_riboplot.py.swp +tests/__init__.py +tests/test_riboplot.py +tests/data/5hRPF.bam +tests/data/5hRPF.bam.bai +tests/data/5hRPFsorted.bam +tests/data/5hRPFsorted.bam.bai +tests/data/5hmRNA.bam +tests/data/5hmRNAsorted.bam +tests/data/ribocount.html +tests/data/ribocount_index.html +tests/data/riboplot.html +tests/data/zebrafish.fna +tests/data/zebrafish.fna.fai \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 riboplot.egg-info/dependency_links.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/riboplot.egg-info/dependency_links.txt Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ + diff -r b6fd86c539ea -r 8e1efafa6277 riboplot.egg-info/not-zip-safe --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/riboplot.egg-info/not-zip-safe Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ + diff -r b6fd86c539ea -r 8e1efafa6277 riboplot.egg-info/top_level.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/riboplot.egg-info/top_level.txt Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +riboplot diff -r b6fd86c539ea -r 8e1efafa6277 riboplot.xml --- a/riboplot.xml Thu Jul 02 11:53:59 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ - - Plot and output read counts for a single transcript in an alignment (BAM) - - - matplotlib - pysam - - - - - riboplot/riboplot.py - --ribo_file "${ribo_file}" - --transcriptome_fasta "${transcriptome_fasta}" - --transcript_name "${transcript_name}" - #if $rnacov.rnacov_select=="yes" - --rna_file "${rna_file}" - #end if - --read_length "${read_length}" - --read_offset "${read_offset}" - --html_file "${html_file}" - --output_path "${html_file.files_path}" - ## --debug - - - - - - len(value.split(',')) == 1 - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r b6fd86c539ea -r 8e1efafa6277 riboplot/__init__.py --- a/riboplot/__init__.py Thu Jul 02 11:53:59 2015 +0100 +++ b/riboplot/__init__.py Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +__author__ = 'Vimalkumar Velayudhan' +__email__ = 'vimalkumarvelayudhan@gmail.com' +__version__ = '0.1.0' \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 riboplot/core.py --- a/riboplot/core.py Thu Jul 02 11:53:59 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -"""Common functions. """ -import logging -import pysam - - -class BAMProfilesError(Exception): - pass - - -class BAMFileError(Exception): - pass - - -class TranscriptError(Exception): - pass - - -class RNACountsError(Exception): - """For errors related to RNA Coverage generation using bedtools. """ - pass - - -def check_bam_file(bam_file): - """Check if bam file is indexed. If not, index. """ - with pysam.AlignmentFile(bam_file, 'rb') as bam_fileobj: - try: - bam_fileobj.fetch(bam_fileobj.references[0]) - except ValueError as err: - if err.message == 'fetch called on bamfile without index': - bam_fileobj.close() - logging.debug('Indexing bam file {}'.format(bam_file)) - pysam.index(bam_file) - - -def get_ribo_counts(ribo_fileobj, transcript_name, read_length=None, read_offset=0): - """Get total reads and read counts in all 3 frames for the give transcript - from input BAM file (indexed). - - """ - read_counts = {} - total_reads = 0 - - if transcript_name not in ribo_fileobj.references: - raise BAMFileError('Transcript "{}" does not exist in BAM ' - 'file. '.format(transcript_name)) - - for record in ribo_fileobj.fetch(transcript_name): - if read_length: - if record.query_length != read_length: - continue - total_reads += 1 - position = record.pos + 1 - - try: - read_counts[position] - except KeyError: - read_counts[position] = {1: 0, 2: 0, 3: 0} - - rem = position % 3 - if rem == 0: - read_counts[position][3] += 1 - else: - read_counts[position][rem] += 1 - - return read_counts, total_reads - diff -r b6fd86c539ea -r 8e1efafa6277 riboplot/ribocore.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/riboplot/ribocore.py Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,188 @@ +"""Common functions. """ +import pysam +import logging +import subprocess + + +class ArgumentError(Exception): + """Raised when invalid arguments are sent in the command line.""" + pass + + +class RiboPlotError(Exception): + """General errors relating to riboplot.""" + pass + + +class RiboCountError(Exception): + """General errors relating to ribocount.""" + pass + + +class RNACountsError(Exception): + """For errors related to RNA Coverage generation using bedtools. """ + pass + + +def is_bam_valid(bam_file): + """Check if bam file is valid. Raises a ValueError if pysam cannot read the file. + + #TODO: pysam does not differentiate between BAM and SAM + """ + try: + f = pysam.AlignmentFile(bam_file) + except ValueError: + raise + else: + f.close() + + return True + + +def bam_has_index(bam_file): + """Check if bam file has an index. Returns True/False.""" + has_index = None + with pysam.AlignmentFile(bam_file, 'rb') as bam_fileobj: + try: + bam_fileobj.fetch(bam_fileobj.references[0]) + except ValueError as err: + if err.message == 'fetch called on bamfile without index': + bam_fileobj.close() + has_index = False + else: + has_index = True + return has_index + + +def create_bam_index(bam_file): + """Create an index for the given BAM file.""" + pysam.index(bam_file) + + +def get_bam_read_lengths(bam_file): + """For a given BAM file, return an unique list of read lengths present.""" + read_lengths = [] + with pysam.AlignmentFile(bam_file, 'rb') as bam_fileobj: + for record in bam_fileobj: + read_lengths.append(record.query_length) + return set(read_lengths) + + +def is_fasta_valid(fasta_file): + """Check if fasta file is valid. Raises a ValueError if pysam cannot read the file. + + #TODO: pysam does not differentiate between BAM and SAM + """ + try: + f = pysam.FastaFile(fasta_file) + except IOError: + raise + else: + f.close() + return True + + +def get_fasta_records(fasta, transcripts): + """Return list of transcript records from the given fasta file. + Each record will be of the form {'sequence_id': {'sequence': 'AAA', 'length': 3}} + + trascripts should be provided as a list of sequence id's. + + """ + records = {} + f = pysam.FastaFile(fasta) + for transcript in transcripts: + try: + sequence, length = f.fetch(transcript), f.get_reference_length(transcript) + except KeyError: + raise ArgumentError('Transcript "{}" does not exist in FASTA file "{}"'.format(transcript, fasta)) + records[transcript] = {'sequence': sequence, 'length': length} + f.close() + return records + + +def get_ribo_counts(ribo_fileobj, transcript_name, read_length=0): + """Get total reads and read counts in all 3 frames for the give transcript + from input BAM file (indexed). + + """ + read_counts = {} + total_reads = 0 + + for record in ribo_fileobj.fetch(transcript_name): + if read_length: + if record.query_length != read_length: + continue + total_reads += 1 + position = record.pos + 1 + + try: + read_counts[position] + except KeyError: + read_counts[position] = {1: 0, 2: 0, 3: 0} + + rem = position % 3 + if rem == 0: + read_counts[position][3] += 1 + else: + read_counts[position][rem] += 1 + + return read_counts, total_reads + +def check_required_arguments(ribo_file, transcriptome_fasta, transcript_name=None): + """Check required arguments of both riboplot and ribocount.""" + # Is this a valid BAM file? i.e., can pysam read it? + try: + is_bam_valid(ribo_file) + except ValueError: + logging.error('The given RiboSeq BAM file is not valid') + raise + + # Does the BAM file have an index? If not, create it. + if not bam_has_index(ribo_file): + logging.info('Creating an index for the BAM file...') + create_bam_index(ribo_file) + + # Is FASTA file valid? + try: + fasta_valid = is_fasta_valid(transcriptome_fasta) + except IOError: + logging.error('This FASTA file is not valid -> {}'.format(transcriptome_fasta)) + + if fasta_valid and transcript_name: + try: + get_fasta_records(transcriptome_fasta, [transcript_name]) + except IOError: + logging.error('This FASTA file is not valid -> {}'.format(transcriptome_fasta)) + raise + except ArgumentError: # does transcript exist in fasta? + raise + + with pysam.AlignmentFile(ribo_file, 'rb') as bam_file: + if transcript_name not in bam_file.references: + raise ArgumentError('Transcript "{}" does not exist in BAM file'.format(transcript_name)) + +def check_optional_arguments(ribo_file, rna_file=None, read_length=None, read_offset=None): + """Check all optional arguments.""" + if rna_file: + try: + subprocess.check_output(['bedtools', '--version']) + except OSError: + logging.error('Could not find bedtools in PATH. bedtools is ' + 'required for generating RNA coverage plot.') + raise + # If read_length is given, it must be a positive integer or reads of that + # length must exist in the BAM file + if read_length: + if read_length < 0: + raise ArgumentError('Read length must be a positive value') + + bam_read_lengths = get_bam_read_lengths(ribo_file) + if read_length not in bam_read_lengths: + raise ArgumentError('Reads of the length "{}" does not exist in the BAM file'.format(read_length)) + + # If read_offset is given, it must be a positive integer + if read_offset: + if read_offset < 0: + raise ArgumentError('Read offset must be 0 or greater') + diff -r b6fd86c539ea -r 8e1efafa6277 riboplot/ribocount.py --- a/riboplot/ribocount.py Thu Jul 02 11:53:59 2015 +0100 +++ b/riboplot/ribocount.py Wed Aug 12 09:27:45 2015 +0100 @@ -1,16 +1,12 @@ -# check dependencies +# -*- coding: utf-8 -*- import sys -missing_deps = [] +# check dependencies try: import pysam -except ImportError: - missing_deps.append('pysam') - -if len(missing_deps): - sys.exit('''\nCould not import the following modules. Please check if they - (or their dependencies are installed correctly. - \n\n{}\n'''.format('\n'.join(missing_deps))) +except ImportError as e: + sys.exit('Could not import the "pysam" module\n\nImporting failed with' + '{}\n\n'.format(e)) import os # import timeit @@ -20,7 +16,7 @@ import argparse from datetime import datetime -import core +import ribocore import config # Default is production @@ -30,26 +26,26 @@ def create_parser(): """Argument parser. """ parser = argparse.ArgumentParser( - prog='ribograph.counts', description='Output read counts for all transcripts') + prog='ribocount.py', description='Output read counts for all transcripts') # required arguments required = parser.add_argument_group('required arguments') - required.add_argument('--ribo_file', help='Ribo-Seq alignment file in BAM format', required=True) - required.add_argument('--transcriptome_fasta', help='FASTA format file of the transcriptome', required=True) + required.add_argument('-b', '--ribo_file', help='Ribo-Seq alignment file in BAM format', required=True) + required.add_argument('-f', '--transcriptome_fasta', help='FASTA format file of the transcriptome', required=True) # optional arguments - parser.add_argument('--read_length', help='Read length to consider (default: %(default)s)', + parser.add_argument('-l', '--read_length', help='Read length to consider (default: %(default)s)', metavar='INTEGER', type=int) - parser.add_argument('--read_offset', help='Read offset (default: %(default)s)', + parser.add_argument('-s', '--read_offset', help='Read offset (default: %(default)s)', metavar='INTEGER', type=int, default=0) - parser.add_argument('--html_file', help='Output file for results (HTML)', default='ribocount.html') - parser.add_argument('--output_path', help='Files are saved in this directory', default='output') - parser.add_argument('--debug', help='Flag. Produce debug output', action='store_true') + parser.add_argument('-m', '--html_file', help='Output file for results (HTML)', default='output/index.html') + parser.add_argument('-o', '--output_path', help='Files are saved in this directory', default='output') + parser.add_argument('-d', '--debug', help='Flag. Produce debug output', action='store_true') return parser -def main(): +if __name__ == '__main__': parsed = create_parser() args = parsed.parse_args() @@ -58,42 +54,44 @@ else: level = logging.INFO - logging.basicConfig(format='%(asctime)s: %(levelname)s %(message)s', + logging.basicConfig(format='%(levelname)s: %(message)s', level=level, stream=sys.stdout, datefmt='%d/%m/%Y %I:%M:%S %p') start = datetime.now() - logging.debug('Start') - logging.debug('Supplied Arguments') - logging.debug('\n{}'.format('\n'.join(['{:<20}: {}'.format(k, v) for k, v in vars(args).items()]))) + logging.debug('Supplied arguments\n{}'.format('\n'.join(['{:<20}: {}'.format(k, v) for k, v in vars(args).items()]))) - (ribo_file, transcriptome_fasta, read_length, read_offset) = ( - args.ribo_file, args.transcriptome_fasta, args.read_length, args.read_offset) - - logging.debug('Checking if BAM file is indexed') - core.check_bam_file(ribo_file) + (ribo_file, transcriptome_fasta, read_length, read_offset, output_path) = ( + args.ribo_file, args.transcriptome_fasta, args.read_length, args.read_offset, args.output_path) - logging.debug('Get transcript information') - fasta_file = pysam.FastaFile(transcriptome_fasta) + logging.info('Checking if required arguments are valid...') + ribocore.check_required_arguments(ribo_file, transcriptome_fasta) + logging.info('Done') - count = 0 - table_content = '' + logging.info('Checking if optional arguments are valid...') + ribocore.check_optional_arguments(ribo_file, read_length, read_offset) + logging.info('Done') - if not os.path.exists(args.output_path): - os.mkdir(args.output_path) - - output_path = os.path.join(args.output_path, 'ribocount_output') if not os.path.exists(output_path): os.mkdir(output_path) - csv_dir = os.path.join(output_path, 'csv') + # zip_dir contents will be written here and a zip archive will be created + # from this directory + zip_dir = os.path.join(output_path, 'ribocount_output') + if not os.path.exists(zip_dir): + os.mkdir(zip_dir) + + csv_dir = os.path.join(zip_dir, 'csv') if not os.path.exists(csv_dir): os.mkdir(csv_dir) + logging.info('Get RiboSeq read counts for all transcripts in FASTA') + count = 0 + table_content = '' bam_fileobj = pysam.AlignmentFile(ribo_file, 'rb') + fasta_file = pysam.FastaFile(transcriptome_fasta) for transcript in fasta_file.references: - rp_counts, rp_reads = core.get_ribo_counts(bam_fileobj, transcript, read_length, read_offset) - - if not rp_reads: + rp_counts, rp_reads = ribocore.get_ribo_counts(bam_fileobj, transcript, read_length) + if not rp_reads: # no reads for this transcript. skip. continue logging.debug('Writing counts for {}'.format(transcript)) @@ -114,40 +112,48 @@ table_content += '' table_content += '{0}{1}{2}{3}'.format( count, transcript, rp_reads, csv_file) + fasta_file.close() bam_fileobj.close() + # only for display in HTML if not read_length: read_length = 'All' duration = str(datetime.now() - start).split('.')[0] - logging.debug('Time taken for generating counts {}'.format(duration)) - - with open(os.path.join(CONFIG.DATA_DIR, 'ribocount.html')) as g,\ - open(os.path.join(output_path, 'index.html'), 'w') as h: - h.write(g.read().format(count=count, length=read_length, table_content=table_content, duration=duration)) + logging.info('Done') - for asset in ('css', 'js'): - asset_dir = os.path.join(output_path, asset) - if not os.path.exists(asset_dir): - os.mkdir(asset_dir) - asset_data_dir = os.path.join(CONFIG.DATA_DIR, asset) - for fname in os.listdir(asset_data_dir): - shutil.copy(os.path.join(asset_data_dir, fname), - os.path.join(output_path, asset, fname)) + if not count: + if read_length: + logging.info('No transcripts found for read length {}'.format(read_length)) + else: + logging.info('No transcripts found') + else: + logging.info('Time taken for generating counts for {0} transcripts: {1}, footprint ' + 'length: {2}'.format(count, duration, read_length)) + + with open(os.path.join(CONFIG.DATA_DIR, 'ribocount.html')) as g,\ + open(os.path.join(zip_dir, 'index.html'), 'w') as h: + h.write(g.read().format(count=count, length=read_length, table_content=table_content, duration=duration)) - logging.debug('Creating zip file') - os.chdir(args.output_path) - with zipfile.ZipFile('ribocount_output.zip', 'w') as zip: - for root, d, f in os.walk('ribocount_output'): - for name in f: - zip.write(os.path.join(root, name)) + for asset in ('css', 'js'): + asset_dir = os.path.join(zip_dir, asset) + if not os.path.exists(asset_dir): + os.mkdir(asset_dir) + asset_data_dir = os.path.join(CONFIG.DATA_DIR, asset) + for fname in os.listdir(asset_data_dir): + shutil.copy(os.path.join(asset_data_dir, fname), + os.path.join(zip_dir, asset, fname)) - shutil.rmtree(output_path) - logging.debug('Writing HTML report') + logging.info('Creating zip file') + os.chdir(output_path) + with zipfile.ZipFile('ribocount_output.zip', 'w') as zipf: + for root, d, f in os.walk('ribocount_output'): + for name in f: + zipf.write(os.path.join(root, name)) + shutil.rmtree('ribocount_output') + os.chdir('../') + logging.debug('Writing HTML report') - with open(os.path.join(CONFIG.DATA_DIR, 'ribocount_index.html')) as j, open(args.html_file, 'w') as k: - k.write(j.read().format(count=count, read_length=read_length)) - -if __name__ == '__main__': - # print timeit.timeit('main()', number=1, setup='from __main__ import main') - main() + with open(os.path.join(CONFIG.DATA_DIR, 'ribocount_index.html')) as j, open(args.html_file, 'w') as k: + k.write(j.read().format(count=count, read_length=read_length)) + logging.info('Finished') diff -r b6fd86c539ea -r 8e1efafa6277 riboplot/riboplot.py --- a/riboplot/riboplot.py Thu Jul 02 11:53:59 2015 +0100 +++ b/riboplot/riboplot.py Wed Aug 12 09:27:45 2015 +0100 @@ -1,30 +1,30 @@ -# check dependencies +# -*- coding: utf-8 -*- import sys -missing_deps = [] +# check dependencies +module_errors = {} try: import pysam -except ImportError: - missing_deps.append('pysam') +except ImportError as e: + module_errors['pysam'] = str(e) try: from matplotlib import pyplot as plt -except ImportError: - missing_deps.append('matplotlib') +except ImportError as e: + module_errors['matplotlib'] = str(e) else: from matplotlib import gridspec from matplotlib.font_manager import FontProperties -if len(missing_deps): - sys.exit('''\nCould not import the following modules. Please check if they - (or their dependencies are installed correctly. - \n\n{}\n'''.format('\n'.join(missing_deps))) - +if len(module_errors): + msg = 'Could not import all required modules:\n\n' + for module, error in module_errors.items(): + msg += 'Importing "{0}" failed with \n{1}\n\n'.format(module, error) + sys.exit(msg) import os import re import config -import pysam # import timeit import shutil import logging @@ -32,7 +32,7 @@ import argparse import subprocess -import core +import ribocore # Default is production CONFIG = config.ProductionConfig() @@ -73,13 +73,6 @@ def get_rna_counts(rna_file, transcript_name): """Get coverage for a given RNA BAM file, return read counts. """ - try: - subprocess.check_output(['bedtools', '--version']) - except OSError: - logging.error('Could not find bedtools in PATH. bedtools is ' - 'required for generating RNA coverage plot. ') - raise - logging.debug('Get RNA coverage for transcript using bedtools') # check if the RNA file exists if not os.path.exists(rna_file): msg = 'RNA-Seq BAM file "{}" does not exist'.format(rna_file) @@ -94,9 +87,7 @@ '-bg'], stdout=cov_file) except subprocess.CalledProcessError as e: # needs testing - raise core.RNACountsError('Could not generate coverage for RNA BAM file. \n{}\n'.format(e)) - logging.debug('Finished generating RNA coverage') - logging.debug('Processing coverage file') + raise ribocore.RNACountsError('Could not generate coverage for RNA BAM file. \n{}\n'.format(e)) for line in open(cov_file.name): line = line.split() if line[0] == transcript_name: @@ -104,10 +95,17 @@ rna_counts[position] = count cov_file.close() os.unlink(cov_file.name) - logging.debug('Finished processing coverage file') return rna_counts +def set_axis_color(axis, color): + """Sets the spine color of all sides of an axis (top, right, bottom, left).""" + axis.spines['top'].set_color(color) + axis.spines['right'].set_color(color) + axis.spines['bottom'].set_color(color) + axis.spines['left'].set_color(color) + + def plot_profile(ribo_counts, transcript_name, transcript_length, start_stops, read_length=None, read_offset=None, rna_counts=None, html_file='index.html', output_path='output'): @@ -115,28 +113,33 @@ single transcript. """ - gs = gridspec.GridSpec(4, 1, height_ratios=[7, 1, 1, 1]) - font_xsmall = {'family': 'sans-serif', 'color': '#555555', - 'weight': 'normal', 'size': 'x-small'} + gs = gridspec.GridSpec(6, 1, height_ratios=[0.1, 6.8, 0.1, 1, 1, 1], hspace=0.35) + font_xsmall = {'family': 'sans-serif', 'color': '#555555', 'weight': 'normal', 'size': 'x-small'} - ax1 = plt.subplot(gs[0]) + # plot for frames legend + ax1 = plt.subplot(gs[0], axisbg='white') + ax1.text(0.96, 0.1, "frame 1", size=6, ha="right", va="center", color='white', + bbox=dict(boxstyle="square", color='tomato')) + ax1.text(0.98, 0.1, "2", size=6, ha="right", va="center", color='white', + bbox=dict(boxstyle="square", color='limegreen')) + ax1.text(1, 0.1, "3", size=6, ha="right", va="center", color='white', + bbox=dict(boxstyle="square", color='deepskyblue')) + # riboseq bar plots + ax2 = plt.subplot(gs[1]) + label = 'Ribo-Seq count' + if read_length: + label = 'Ribo-Seq count ({}-mer)'.format(read_length) + ax2.set_ylabel(label, fontdict=font_xsmall, labelpad=10) + + # rna coverage if available ax_rna = None if rna_counts: - ax_rna = ax1.twinx() + ax_rna = ax2.twinx() ax_rna.set_ylabel('RNA-Seq count', fontdict=font_xsmall, labelpad=10) - leg1 = ax_rna.bar(rna_counts.keys(), rna_counts.values(), edgecolor='#e6e6e6', label='RNA') + ax_rna.bar(rna_counts.keys(), rna_counts.values(), facecolor='#e6e6e6', edgecolor='#e6e6e6', label='RNA', linewidth=0.5) ax_rna.set_zorder(1) - plt.title('Transcript - {}'.format(transcript_name), - fontdict={'family': 'sans-serif', 'color': '#333333', - 'weight': 'normal', 'size': 'x-small'}, y=1.06) - if read_length: - ax1.set_ylabel('Ribo-Seq count ({}-mer)'.format(read_length), - fontdict=font_xsmall, labelpad=10) - else: - ax1.set_ylabel('Ribo-Seq count', fontdict=font_xsmall, labelpad=10) - frame_counts = {1: {}, 2: {}, 3: {}} for k, v in ribo_counts.iteritems(): for fr in (1, 2, 3): @@ -147,40 +150,45 @@ cnts = [] [cnts.extend(item.values()) for item in frame_counts.values()] y_max = int(round(max(cnts) * 1.2)) - ax1.set_ylim(0.0, y_max) - ax1.set_zorder(2) - ax1.patch.set_facecolor('none') + ax2.set_ylim(0.0, y_max) + ax2.set_zorder(2) + ax2.patch.set_facecolor('none') for frame, color in ((1, 'tomato'), (2, 'limegreen'), (3, 'deepskyblue')): if read_offset: x_vals = [pos + read_offset for pos in frame_counts[frame].keys()] else: x_vals = frame_counts[frame].keys() - ax1.bar(x_vals, frame_counts[frame].values(), edgecolor=color) + ax2.bar(x_vals, frame_counts[frame].values(), color=color, facecolor=color, edgecolor=color, linewidth=0.5) + + ax3 = plt.subplot(gs[2], axisbg='white') + ax3.text(0.90, 0.1, "start codon", size=6, ha="right", va="center", color='#555555', + bbox=dict(boxstyle="square", facecolor='white', edgecolor='#c6c6c6')) + ax3.text(0.99, 0.1, "stop codon", size=6, ha="right", va="center", color='white', + bbox=dict(boxstyle="square", color='#777777')) - ax2 = plt.subplot(gs[1], sharex=ax1, axisbg='#c6c6c6') - ax3 = plt.subplot(gs[2], sharex=ax1, axisbg='#c6c6c6') - ax4 = plt.subplot(gs[3], sharex=ax1, axisbg='#c6c6c6') + ax4 = plt.subplot(gs[3], sharex=ax2, axisbg='#c6c6c6') + ax5 = plt.subplot(gs[4], sharex=ax2, axisbg='#c6c6c6') + ax6 = plt.subplot(gs[5], sharex=ax2, axisbg='#c6c6c6') - axes = [ax1] + for axis in (ax1, ax3): + axis.tick_params(top=False, left=False, right=False, bottom=False, labeltop=False, + labelleft=False, labelright=False, labelbottom=False) + set_axis_color(axis, 'white') + + axes = [ax2] if ax_rna: axes.append(ax_rna) fp = FontProperties(size='5') for axis in axes: - axis.spines['top'].set_color('#f7f7f7') - axis.spines['right'].set_color('#f7f7f7') - axis.spines['bottom'].set_color('#f7f7f7') - axis.spines['left'].set_color('#f7f7f7') + set_axis_color(axis, '#f7f7f7') for item in (axis.get_xticklabels() + axis.get_yticklabels()): item.set_fontproperties(fp) item.set_color('#555555') - for axis, frame in ((ax2, 1), (ax3, 2), (ax4, 3)): - axis.spines['top'].set_color('#C6C6C6') - axis.spines['right'].set_color('#C6C6C6') - axis.spines['bottom'].set_color('#C6C6C6') - axis.spines['left'].set_color('#C6C6C6') + for axis, frame in ((ax4, 1), (ax5, 2), (ax6, 3)): + set_axis_color(axis, '#C6C6C6') for item in (axis.get_xticklabels()): item.set_fontproperties(fp) item.set_color('#555555') @@ -190,23 +198,24 @@ stops = [(item, 1) for item in start_stops[frame]['stops']] start_colors = ['#ffffff' for item in starts] axis.broken_barh(starts, (0.11, 0.2), - facecolors=start_colors, edgecolors=start_colors, label='start', zorder=5) - stop_colors = ['#666666' for item in stops] + facecolors=start_colors, edgecolors=start_colors, label='start', zorder=5, linewidth=0.5) + stop_colors = ['#777777' for item in stops] axis.broken_barh(stops, (0, 0.2), facecolors=stop_colors, - edgecolors=stop_colors, label='stop', zorder=5) + edgecolors=stop_colors, label='stop', zorder=5, linewidth=0.5) axis.set_ylabel('{}'.format(frame), fontdict={'family': 'sans-serif', 'color': '#555555', 'weight': 'normal', 'size': '6'}, rotation='horizontal', labelpad=10, verticalalignment='center') axis.tick_params(top=False, left=False, right=False, labeltop=False, labelleft=False, labelright=False, direction='out') - plt.xlabel('Transcript length ({} nt)'.format(transcript_length), - fontdict=font_xsmall, labelpad=10) - + plt.xlabel('Transcript length ({} nt)'.format(transcript_length), fontdict=font_xsmall, labelpad=10) + plt.title('Transcript {}'.format(transcript_name), + fontdict={'family': 'sans-serif', 'color': '#222222', + 'weight': 'normal', 'size': 'x-small'}, y=13.0) if not os.path.exists(output_path): os.mkdir(output_path) - plt.savefig(os.path.join(output_path, 'ribograph.svg')) - plt.savefig(os.path.join(output_path, 'ribograph.png'), dpi=300) + plt.savefig(os.path.join(output_path, 'riboplot.svg')) + plt.savefig(os.path.join(output_path, 'riboplot.png'), dpi=300) with open(os.path.join(CONFIG.DATA_DIR, 'riboplot.html')) as g, open(os.path.join(output_path, html_file), 'w') as h: h.write(g.read().format(transcript_name=transcript_name)) @@ -223,99 +232,100 @@ def create_parser(): """Argument parser. """ parser = argparse.ArgumentParser( - prog='ribograph.plot', description='Plot and output read counts for a single transcript') + prog='riboplot.py', description='Plot and output read counts for a single transcript') required = parser.add_argument_group('required arguments') - required.add_argument('--ribo_file', help='Ribo-Seq alignment file in BAM format', required=True) - required.add_argument('--transcriptome_fasta', help='FASTA format file of the transcriptome', required=True) - required.add_argument('--transcript_name', help='Transcript name', metavar='TEXT', required=True) + required.add_argument('-b', '--ribo_file', help='Ribo-Seq alignment file in BAM format', required=True) + required.add_argument('-f', '--transcriptome_fasta', help='FASTA format file of the transcriptome', required=True) + required.add_argument('-t', '--transcript_name', help='Transcript name', metavar='TEXT', required=True) # plot function - optional arguments - parser.add_argument('--rna_file', help='RNA-Seq alignment file (BAM)') - parser.add_argument('--read_length', help='Read length to consider (default: %(default)s)', + parser.add_argument('-n', '--rna_file', help='RNA-Seq alignment file (BAM)') + parser.add_argument('-l', '--read_length', help='Read length to consider (default: %(default)s)', metavar='INTEGER', type=int) - parser.add_argument('--read_offset', help='Read offset (default: %(default)s)', + parser.add_argument('-s', '--read_offset', help='Read offset (default: %(default)s)', metavar='INTEGER', type=int, default=0) - parser.add_argument('--html_file', help='Output file for results (HTML)', default='index.html') - parser.add_argument('--output_path', help='Files are saved in this directory', default='output') - parser.add_argument('--debug', help='Flag. Produce debug output', action='store_true') + parser.add_argument('-m', '--html_file', help='Output file for results (HTML)', default='index.html') + parser.add_argument('-o', '--output_path', help='Files are saved in this directory', default='output') + parser.add_argument('-d', '--debug', help='Flag. Produce debug output', action='store_true') return parser -def main(): - """Start program. """ - parsed = create_parser() - args = parsed.parse_args() - +def main(args): + """Start program""" if args.debug: level = logging.DEBUG else: level = logging.INFO - logging.basicConfig(format='%(asctime)s: %(levelname)s %(message)s', + logging.basicConfig(format='%(levelname)s: %(message)s', level=level, stream=sys.stdout, datefmt='%d/%m/%Y %I:%M:%S %p') - - logging.debug('Start') - logging.debug('Supplied Arguments') - logging.debug('\n{}'.format('\n'.join(['{:<20}: {}'.format(k, v) for k, v in vars(args).items()]))) + logging.debug('Supplied arguments\n{}'.format( + '\n'.join(['{:<20}: {}'.format(k, v) for k, v in vars(args).items()]))) (ribo_file, rna_file, transcript_name, transcriptome_fasta, read_length, - read_offset, output_path) = (args.ribo_file, args.rna_file, args.transcript_name, - args.transcriptome_fasta, args.read_length, args.read_offset, args.output_path) - - logging.debug('Checking if BAM file is indexed...') - core.check_bam_file(ribo_file) + read_offset, output_path) = (args.ribo_file, args.rna_file, + args.transcript_name, args.transcriptome_fasta, + args.read_length, args.read_offset, args.output_path) - logging.debug('Get transcript information...') - transcripts = pysam.FastaFile(transcriptome_fasta) - sequence = transcripts.fetch(transcript_name) - length = len(sequence) - - if not length: - logging.error('Transcript "{}" does not exist in transcriptome ' - 'FASTA file "{}"'.format(transcript_name, os.path.basename(transcriptome_fasta))) - sys.exit(1) + logging.info('Checking if required arguments are valid...') + ribocore.check_required_arguments(ribo_file, transcriptome_fasta, transcript_name) - logging.debug('Get start/stop positions in transcript (3 frames)...') - codon_positions = get_start_stops(sequence) + logging.info('Checking if optional arguments are valid...') + ribocore.check_optional_arguments(ribo_file, rna_file, read_length, read_offset) - mrna_counts = {} - if rna_file: - try: - mrna_counts = get_rna_counts(rna_file, transcript_name) - except OSError as e: - sys.exit(e) - else: - logging.debug('No RNA-Seq data provided. Not generating coverage') - - logging.debug('Get ribo-seq read counts and total reads in Ribo-Seq...') + logging.info('Get ribo-seq read counts and total reads in Ribo-Seq...') bam_fileobj = pysam.AlignmentFile(ribo_file, 'rb') - ribo_counts, total_reads = core.get_ribo_counts(bam_fileobj, transcript_name, read_length, read_offset) + ribo_counts, total_reads = ribocore.get_ribo_counts(bam_fileobj, transcript_name, read_length) bam_fileobj.close() - if not os.path.exists(output_path): - os.mkdir(output_path) + if not ribo_counts: + msg = ('No RiboSeq read counts for transcript {}. No plot will be ' + 'generated!'.format(transcript_name)) + logging.error(msg) + raise ribocore.RiboPlotError(msg) + else: + logging.info('Get RNA counts for the given transcript...') + mrna_counts = {} + if rna_file: + try: + mrna_counts = get_rna_counts(rna_file, transcript_name) + except OSError as e: + logging.error(e) + raise + else: + logging.debug('No RNA-Seq data provided. Not generating coverage') - logging.debug('Writing counts for {}'.format(transcript_name)) - with open(os.path.join(output_path, 'RiboCounts.csv'), 'w') as f: - f.write('"Position","Frame 1","Frame 2","Frame 3"\n') + logging.info('Get sequence and length of the given transcripts from FASTA file...') + fasta_records = ribocore.get_fasta_records(transcriptome_fasta, [transcript_name]) + transcript_seq, transcript_length = (fasta_records[transcript_name]['sequence'], + fasta_records[transcript_name]['length']) - for pos in range(1, length + 1): - if pos in ribo_counts: - f.write('{0},{1},{2},{3}\n'.format( - pos, ribo_counts[pos][1], ribo_counts[pos][2], ribo_counts[pos][3])) - else: - f.write('{0},{1},{2},{3}\n'.format(pos, 0, 0, 0)) + logging.info('Get start/stop positions in transcript sequence (3 frames)...') + codon_positions = get_start_stops(transcript_seq) + + if not os.path.exists(output_path): + os.mkdir(output_path) + + logging.info('Writing RiboSeq read counts for {}'.format(transcript_name)) + with open(os.path.join(output_path, 'RiboCounts.csv'), 'w') as f: + f.write('"Position","Frame 1","Frame 2","Frame 3"\n') - logging.debug('Generating plot...') - plot_profile(ribo_counts, transcript_name, length, - codon_positions, read_length, read_offset, mrna_counts, - html_file=os.path.join(args.output_path, args.html_file), - output_path=args.output_path) - logging.debug('Finished') + for pos in range(1, transcript_length + 1): + if pos in ribo_counts: + f.write('{0},{1},{2},{3}\n'.format( + pos, ribo_counts[pos][1], ribo_counts[pos][2], ribo_counts[pos][3])) + else: + f.write('{0},{1},{2},{3}\n'.format(pos, 0, 0, 0)) + logging.info('Generating RiboPlot...') + plot_profile(ribo_counts, transcript_name, transcript_length, + codon_positions, read_length, read_offset, mrna_counts, + html_file=args.html_file, output_path=args.output_path) + logging.info('Finished!') if __name__ == '__main__': - # print timeit.timeit('main()', number=1, setup='from __main__ import main') - main() + parsed = create_parser() + args = parsed.parse_args() + main(args) diff -r b6fd86c539ea -r 8e1efafa6277 run_riboplot_sample.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run_riboplot_sample.sh Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,6 @@ +#!/bin/bash +python riboplot/riboplot.py -b tests/data/5hRPFsorted.bam \ + -f tests/data/zebrafish.fna \ + -t 'gi|148357119|ref|NM_001098396.1|' \ +# -n tests/data/5hmRNAsorted.bam + diff -r b6fd86c539ea -r 8e1efafa6277 run_tests.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run_tests.sh Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,2 @@ +#!/bin/bash +python setup.py test diff -r b6fd86c539ea -r 8e1efafa6277 setup.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.cfg Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,6 @@ +[wheel] +universal = 1 + +[pep8] +ignore = E501 +max-line-length = 160 diff -r b6fd86c539ea -r 8e1efafa6277 setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +try: + from setuptools import setup +except ImportError: + from distutils.core import setup + + +with open('README.rst') as readme_file: + readme = readme_file.read() + +with open('HISTORY.rst') as history_file: + history = history_file.read().replace('.. :changelog:', '') + +requirements = [ + # TODO: put package requirements here +] + +test_requirements = [ + # TODO: put package test requirements here +] + +setup( + name='riboplot', + version='0.1.0', + description="Plot read counts of RiboSeq data from BAM format alignment files", + long_description=readme + '\n\n' + history, + author="Vimalkumar Velayudhan", + author_email='vimalkumarvelayudhan@gmail.com', + url='https://github.com/vimalkumarvelayudhan/riboplot', + packages=[ + 'riboplot', + ], + package_dir={'riboplot': + 'riboplot'}, + include_package_data=True, + install_requires=requirements, + license="BSD", + zip_safe=False, + keywords='riboplot', + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Natural Language :: English', + "Programming Language :: Python :: 2", + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + ], + test_suite='tests', + tests_require=test_requirements +) \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 tests/data/css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/css Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +../../data/css \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 tests/data/js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/js Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +../../data/js \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 tests/data/ribocount.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/ribocount.html Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +../../data/ribocount.html \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 tests/data/ribocount_index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/ribocount_index.html Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +../../data/ribocount_index.html \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 tests/data/riboplot.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/riboplot.html Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,1 @@ +../../data/riboplot.html \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 tests/test_plot.py --- a/tests/test_plot.py Thu Jul 02 11:53:59 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -import os -import logging -import unittest - -from riboplot import core, config, plot - -# use testing configuration -CONFIG = plot.CONFIG = config.TestingConfig() -logging.disable(logging.CRITICAL) - -RIBO_FILE = os.path.join(CONFIG.DATA_DIR, '5hRPFsorted.bam') -RNA_FILE = os.path.join(CONFIG.DATA_DIR, '5hmRNAsorted.bam') -TRANSCRIPT_NAME = 'gi|148357119|ref|NM_001098396.1|' -TRANSCRIPTOME_FASTA = os.path.join(CONFIG.DATA_DIR, 'zebrafish.fna') -TRANSCRIPTOME_FASTA_MINUS1 = os.path.join(CONFIG.DATA_DIR, 'zebrafish_minus1.fna') - -class RNACountsTestCase(unittest.TestCase): - - def test_get_rna_counts(self): - """Test get RNA counts for transcript from RNA-Seq BAM file""" - counts = plot.get_rna_counts(rna_file=RNA_FILE, transcript_name=TRANSCRIPT_NAME) - self.assertIsInstance(counts, dict) - self.assertTrue(len(counts) > 0) - - def test_missing_rna_file(self): - """Exit with error if RNA BAM file does not exist. """ - self.assertRaises(OSError, plot.get_rna_counts, rna_file='{}.absent'.format(RNA_FILE), - transcript_name=TRANSCRIPT_NAME) - - def test_missing_bedtools(self): - """Exit with error if bedtools is missing.""" - # reset env temporarily - paths = os.environ['PATH'] - os.environ['PATH'] = '' - self.assertRaises(OSError, plot.get_rna_counts, rna_file=RNA_FILE, - transcript_name=TRANSCRIPT_NAME) - os.environ['PATH'] = paths - - -class PlotTestCase(unittest.TestCase): - - def test_get_codon_positions(self): - """Test get codon positions. """ - # input is the sequence obtained from get_transcript so no new lines. - fasta = ('AACCGGAGCACCCAGAGAAAACCCACGCAAACGCAGGGAGAATTTGCAAACTCCACACA' - 'GAAATGCCAGCTGATCCAGCCGAGCCTCGAGTCAGCATCCTTGCTTGTTGGATGCCTGA' - 'TTGCAGTTCAACTCCAAACTCAGTTGGACCAGCTGATCAGTG') - codon_positions = plot.get_start_stops(fasta) - expected = {1: {'starts': [], 'stops': []}, - 2: {'starts': [], 'stops': [71, 116, 152]}, - 3: {'starts': [63, 111], 'stops': []}} - self.assertEqual(codon_positions, expected) \ No newline at end of file diff -r b6fd86c539ea -r 8e1efafa6277 tests/test_riboplot.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_riboplot.py Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,165 @@ +import os +import shutil +import logging +import unittest +import tempfile + +from riboplot import ribocore, riboplot + +# use testing configuration +CONFIG = riboplot.CONFIG = riboplot.config.TestingConfig() +logging.disable(logging.CRITICAL) + +RIBO_FILE = os.path.join(CONFIG.DATA_DIR, '5hRPFsorted.bam') +RNA_FILE = os.path.join(CONFIG.DATA_DIR, '5hmRNAsorted.bam') +TRANSCRIPT_NAME = 'gi|148357119|ref|NM_001098396.1|' +TRANSCRIPTOME_FASTA = os.path.join(CONFIG.DATA_DIR, 'zebrafish.fna') +TRANSCRIPTOME_FASTA_MINUS1 = os.path.join(CONFIG.DATA_DIR, 'zebrafish_minus1.fna') + + +class CheckArgumentsTestCase(unittest.TestCase): + """Check if all arguments sent on the command line are valid.""" + parser = riboplot.create_parser() + + def test_bedtools_missing(self): + """If bedtools is not in PATH, raise an error.""" + args = self.parser.parse_args( + ['-b', RIBO_FILE, '-f', TRANSCRIPTOME_FASTA, '-t', TRANSCRIPT_NAME, '-n', RNA_FILE]) + save_path = os.environ['PATH'] + os.environ['PATH'] = '' + self.assertRaises(OSError, ribocore.check_optional_arguments, args.ribo_file, args.rna_file) + os.environ['PATH'] = save_path + + def test_is_bam_valid(self): + """Test if BAM file is valid.""" + valid = ribocore.is_bam_valid(RIBO_FILE) + self.assertTrue(valid) + + # test with a FASTA file (which is not BAM) + self.assertRaises(ValueError, ribocore.is_bam_valid, TRANSCRIPTOME_FASTA) + + def test_bam_has_index(self): + """Check if BAM file has an index.""" + # RPF file has an index + has_index = ribocore.bam_has_index(RIBO_FILE) + self.assertTrue(has_index) + + # RNA file doesn't have an index + has_index = ribocore.bam_has_index(RNA_FILE) + self.assertFalse(has_index) + + def test_create_bam_index(self): + """Index a BAM file.""" + ribocore.create_bam_index(RNA_FILE) + + # check if index exists + has_index = ribocore.bam_has_index(RNA_FILE) + self.assertTrue(has_index) + + # remove index + os.remove('{}.bai'.format(RNA_FILE)) + + def test_valid_read_length(self): + """Read length should be a valid integer.""" + args = self.parser.parse_args(['-b', RIBO_FILE, '-f', TRANSCRIPTOME_FASTA, + '-t', TRANSCRIPT_NAME, '-l', '28']) + ribocore.check_optional_arguments(ribo_file=args.ribo_file, read_length=args.read_length) + + def test_invalid_read_length(self): + """An error is raised if an invalid read length is used.""" + args = self.parser.parse_args(['-b', RIBO_FILE, '-f', TRANSCRIPTOME_FASTA, '-t', TRANSCRIPT_NAME, + '-l', '-1']) # invalid read length -1 + self.assertRaises(ribocore.ArgumentError, ribocore.check_optional_arguments, + args.ribo_file, None, args.read_length) + + args = self.parser.parse_args(['-b', RIBO_FILE, '-f', TRANSCRIPTOME_FASTA, '-t', TRANSCRIPT_NAME, + '-l', '100']) # invalid read length 100 + self.assertRaises(ribocore.ArgumentError, ribocore.check_optional_arguments, + args.ribo_file, None, args.read_length) + + def test_valid_read_offset(self): + """Read offset should be positive.""" + args = self.parser.parse_args(['-b', RIBO_FILE, '-f', TRANSCRIPTOME_FASTA, '-t', TRANSCRIPT_NAME, + '-s', '-1']) # invalid read offset -1 + self.assertRaises(ribocore.ArgumentError, ribocore.check_optional_arguments, + args.ribo_file, None, None, args.read_offset) + + def test_is_fasta_valid(self): + """A valid FASTA file can be opened with pysam.FastaFile.""" + self.assertTrue(ribocore.is_fasta_valid(TRANSCRIPTOME_FASTA)) + + def test_missing_transcript_in_fasta(self): + """If a transcript is missing in FASTA, an error is raised.""" + args = self.parser.parse_args(['-b', RIBO_FILE, '-f', TRANSCRIPTOME_FASTA, '-t', TRANSCRIPT_NAME]) # invalid read offset -1 + self.assertRaises(ribocore.ArgumentError, ribocore.check_required_arguments, + args.ribo_file, args.transcriptome_fasta, 'hello') + + def test_missing_transcript_in_bam(self): + """If a transcript is missing in BAM, an error is raised.""" + # testing with an unrelated BAM file + args = self.parser.parse_args(['-b', '/home/vimal/tmp/empty_tp/RiboSeq.bam', '-f', TRANSCRIPTOME_FASTA, + '-t', TRANSCRIPT_NAME]) + self.assertRaises(ribocore.ArgumentError, ribocore.check_required_arguments, args.ribo_file, + args.transcriptome_fasta, args.transcript_name) + + +class RNACountsTestCase(unittest.TestCase): + + def test_get_rna_counts(self): + """Test get RNA counts for transcript from RNA-Seq BAM file. Assumes bedtools is installed.""" + counts = riboplot.get_rna_counts(RNA_FILE, TRANSCRIPT_NAME) + self.assertIsInstance(counts, dict) + self.assertTrue(len(counts) > 0) + + +class RiboPlotTestCase(unittest.TestCase): + + def test_get_codon_positions(self): + """Get codon positions in all frames given a sequence.""" + # the positions on this sequence were calculated manually. + fasta = ('AACCGGAGCACCCAGAGAAAACCCACGCAAACGCAGGGAGAATTTGCAAACTCCACACA' + 'GAAATGCCAGCTGATCCAGCCGAGCCTCGAGTCAGCATCCTTGCTTGTTGGATGCCTGA' + 'TTGCAGTTCAACTCCAAACTCAGTTGGACCAGCTGATCAGTG') + codon_positions = riboplot.get_start_stops(fasta) + expected = {1: {'starts': [], 'stops': []}, + 2: {'starts': [], 'stops': [71, 116, 152]}, + 3: {'starts': [63, 111], 'stops': []}} + self.assertEqual(codon_positions, expected) + + def test_valid_riboplot_run(self): + """A good riboplot run""" + output_dir = tempfile.mkdtemp() + print 'Output path is {}'.format(output_dir) + parser = riboplot.create_parser() + args = parser.parse_args(['-b', RIBO_FILE, '-f', TRANSCRIPTOME_FASTA, '-t', TRANSCRIPT_NAME, + '-o', output_dir]) + riboplot.main(args) + for fname in ('riboplot.png', 'riboplot.svg', 'RiboCounts.csv'): + self.assertTrue(os.path.exists(os.path.join(output_dir, fname))) + shutil.rmtree(output_dir) + + def test_transcript_with_no_counts(self): + """If the transcript has no ribocounts, no plot should be produced.""" + transcript = 'gi|62955616|ref|NM_001017822.1|' # has no reads + output_dir = tempfile.mkdtemp() + parser = riboplot.create_parser() + args = parser.parse_args(['-b', RIBO_FILE, '-f', TRANSCRIPTOME_FASTA, '-t', transcript, '-o', output_dir]) + self.assertRaises(ribocore.RiboPlotError, riboplot.main, args) + for fname in ('riboplot.png', 'riboplot.svg', 'RiboCounts.csv'): + self.assertFalse(os.path.exists(os.path.join(output_dir, fname))) + shutil.rmtree(output_dir) + + @unittest.skip('todo') + def test_get_ribo_counts(self): + """Get RiboSeq read counts""" + pass + + @unittest.skip('todo') + def test_write_ribo_counts(self): + """Write RiboSeq read counts as CSV.""" + pass + + @unittest.skip('todo') + def test_plot_read_counts(self): + """Generate riboplots""" + pass diff -r b6fd86c539ea -r 8e1efafa6277 tox.ini --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tox.ini Wed Aug 12 09:27:45 2015 +0100 @@ -0,0 +1,9 @@ +[tox] +envlist = py26, py27, py33, py34 + +[testenv] +setenv = + PYTHONPATH = {toxinidir}:{toxinidir}/riboplot +commands = python setup.py test +deps = + -r{toxinidir}/requirements.txt \ No newline at end of file