From e69a6f28b60b201bc80dfc334f0329f02d5b9887 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Fri, 26 Jan 2018 11:16:50 +0100 Subject: [PATCH] Update docs --- docs/Makefile | 20 +++++++++++ docs/source/conf.py | 64 +++++++++++++++++++++++++++++++++++ docs/source/constants.rst | 4 +++ docs/source/enrichment.rst | 4 +++ docs/source/index.rst | 18 ++++++++++ docs/source/manager.rst | 4 +++ requirements.txt | 2 ++ src/bio2bel_chebi/__init__.py | 8 +++-- src/bio2bel_chebi/enrich.py | 46 +++++++++++++++++++++++++ src/bio2bel_chebi/manager.py | 5 +++ src/bio2bel_chebi/models.py | 8 +++++ 11 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 docs/Makefile create mode 100644 docs/source/conf.py create mode 100644 docs/source/constants.rst create mode 100644 docs/source/enrichment.rst create mode 100644 docs/source/index.rst create mode 100644 docs/source/manager.rst create mode 100644 src/bio2bel_chebi/enrich.py diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..efc59a3 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = Bio2BELCHEBI +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..fdc21ea --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- + +import os +import re +import sys + +sys.path.insert(0, os.path.abspath('../../src')) + +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.viewcode' +] +templates_path = ['_templates'] +source_suffix = '.rst' +master_doc = 'index' +project = 'Bio2BEL ChEBI' +copyright = '2017-2018, Charles Tapley Hoyt' +author = 'Charles Tapley Hoyt' + +release = '0.0.1-dev' + +parsed_version = re.match( + '(?P\d+)\.(?P\d+)\.(?P\d+)(?:-(?P[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+(?P[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?', + release +) +version = parsed_version.expand('\g.\g.\g') + +if parsed_version.group('release'): + tags.add('prerelease') + +language = None +exclude_patterns = [] +pygments_style = 'sphinx' +todo_include_todos = True +html_theme = 'sphinx_rtd_theme' +html_static_path = [] +htmlhelp_basename = 'bioebel_chebidoc' +latex_elements = {} +latex_documents = [ + (master_doc, 'bio2bel_chebi.tex', 'Bio2BEL ChEBI Documentation', 'Charles Tapley Hoyt', 'manual'), +] +man_pages = [ + (master_doc, 'Bio2BEL ChEBI', 'Bio2BEL ChEBI Documentation', [author], 1) +] +texinfo_documents = [ + (master_doc, 'Bio2BEL ChEBI', 'Bio2BEL ChEBI Documentation', author, 'Bio2BEL ChEBI', 'Serialize ChEBI to BEL', 'Miscellaneous'), +] + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + 'python': ('https://docs.python.org/3', None), + 'networkx': ('https://networkx.github.io/', None), + 'sqlalchemy': ('https://docs.sqlalchemy.org/en/latest', None), + 'pybel': ('https://pybel.readthedocs.io/en/latest/', None), +} + +autodoc_member_order = 'bysource' +autoclass_content = 'both' + +if os.environ.get('READTHEDOCS'): + tags.add('readthedocs') diff --git a/docs/source/constants.rst b/docs/source/constants.rst new file mode 100644 index 0000000..8743a4a --- /dev/null +++ b/docs/source/constants.rst @@ -0,0 +1,4 @@ +Constants +========= +.. automodule:: bio2bel_chebi.constants + :members: diff --git a/docs/source/enrichment.rst b/docs/source/enrichment.rst new file mode 100644 index 0000000..c7eec1d --- /dev/null +++ b/docs/source/enrichment.rst @@ -0,0 +1,4 @@ +Enrichment +========== +.. automodule:: bio2bel_chebi.enrich + :members: diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..204d69d --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,18 @@ +Bio2BEL ChEBI +============= +.. automodule:: bio2bel_chebi + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + enrichment + manager + constants + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/source/manager.rst b/docs/source/manager.rst new file mode 100644 index 0000000..686dd1a --- /dev/null +++ b/docs/source/manager.rst @@ -0,0 +1,4 @@ +Manager +========== +.. automodule:: bio2bel_chebi.manager + :members: diff --git a/requirements.txt b/requirements.txt index 988e507..ca01db8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,5 @@ tqdm pybel>=0.9.5 pybel_tools>=0.4.5 bio2bel +flask[web] +flask_admin[web] diff --git a/src/bio2bel_chebi/__init__.py b/src/bio2bel_chebi/__init__.py index f303cfc..8bbbbe1 100644 --- a/src/bio2bel_chebi/__init__.py +++ b/src/bio2bel_chebi/__init__.py @@ -1,7 +1,11 @@ # -*- coding: utf-8 -*- -from . import models -from .manager import Manager +from . import enrich, manager, models +from .enrich import * +from .manager import * +from .models import * + +__all__ = (manager.__all__ + enrich.__all__ + models.__all__) __version__ = '0.0.1' diff --git a/src/bio2bel_chebi/enrich.py b/src/bio2bel_chebi/enrich.py new file mode 100644 index 0000000..4af66b4 --- /dev/null +++ b/src/bio2bel_chebi/enrich.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +import logging + +from pybel import to_database +from .manager import Manager + +__all__ = [ + 'enrich_chemical_hierarchy', + 'to_bel', + 'upload_bel' +] + +log = logging.getLogger(__name__) + + +def enrich_chemical_hierarchy(graph, manager=None): + """Enriches the biological processses in a BEL graph + + :type graph: pybel.BELGraph + :type manager: Optional[bio2bel_chebi.Manager] + """ + manager = manager or Manager() + manager.enrich_chemical_hierarchy(graph) + + +def to_bel(manager=None): + """Creates a BEL graph from the Gene Ontology + + :type manager: Optional[bio2bel_chebi.Manager] + """ + manager = manager or Manager() + return manager.to_bel() + + +def upload_bel(manager=None, pybel_manager=None): + """Creates a BEL graph from the Gene Ontology and uplopads it to the PyBEL edge store + + :type manager: Optional[bio2bel_chebi.Manager] + :type pybel_manager: Optional[pybel.Manager] + :rtype: pybel.manager.models.Network + """ + log.info('converting bel') + graph = to_bel(manager=manager) + log.info('storing') + return to_database(graph, connection=pybel_manager) diff --git a/src/bio2bel_chebi/manager.py b/src/bio2bel_chebi/manager.py index f6dc846..0bbd545 100644 --- a/src/bio2bel_chebi/manager.py +++ b/src/bio2bel_chebi/manager.py @@ -16,6 +16,8 @@ from .parser.inchis import get_inchis_df from .parser.names import get_names_df +__all__ = ['Manager'] + log = logging.getLogger(__name__) @@ -222,3 +224,6 @@ def enrich_chemical_hierarchy(self, graph): parent.as_bel(), IS_A ) + + def to_bel(self): + raise NotImplementedError diff --git a/src/bio2bel_chebi/models.py b/src/bio2bel_chebi/models.py index f7d12fe..a44855c 100644 --- a/src/bio2bel_chebi/models.py +++ b/src/bio2bel_chebi/models.py @@ -5,8 +5,16 @@ from sqlalchemy import Column, ForeignKey, Integer, String, Text from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import backref, relationship + from pybel.dsl import abundance +__all__ = [ + 'Base', + 'Chemical', + 'Synonym', + 'Accession', +] + Base = declarative_base() TABLE_PREFIX = 'chebi'