Skip to content

Commit

Permalink
Update for Bio2BEL v0.2.0 (#10)
Browse files Browse the repository at this point in the history
* Update for bio2bel v0.2.0

* Update .travis.yml

* Update formatting

* Update .flake8

[skip ci]

* Update BEL export

* Update MANIFEST.in

* Update src/bio2bel_reactome/manager.py

* Update tests/test_all.py
  • Loading branch information
cthoyt authored Nov 13, 2018
1 parent 48db787 commit 47f8879
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 170 deletions.
26 changes: 26 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[flake8]
ignore =
C901 # too complex methods
max-line-length = 120
exclude =
.tox,
.git,
__pycache__,
docs/source/conf.py,
build,
dist,
tests/fixtures/*,
*.pyc,
*.egg-info,
.cache,
.eggs
max-complexity = 10
import-order-style = pycharm
application-import-names =
bio2bel_reactome
bio2bel_hgnc
bio2bel
compath_utils
pybel
tests
format = ${cyan}%(path)s${reset}:${yellow_bold}%(row)d${reset}:${green_bold}%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s
44 changes: 29 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,41 @@ cache: pip
language: python
python:
- 3.6
matrix:
stages:
- lint
- docs
- test
env:
- TOXENV=py
jobs:
include:
- env: TOXENV=py
- env: TOXENV=docs
- env: TOXENV=manifest
- env: TOXENV=rst-lint
# lint stage
- stage: lint
env: TOXENV=manifest
- env: TOXENV=flake8
- env: TOXENV=doc8
- env: TOXENV=pylint
- env: TOXENV=vulture
- env: TOXENV=mypy
- env: TOXENV=pyroma
- env: TOXENV=xenon
# docs stage
- stage: docs
env: TOXENV=doc8
- env: TOXENV=readme
- env: TOXENV=docs
# test stage
- stage: test
env: TOXENV=py
matrix:
allow_failures:
- env: TOXENV=flake8
- env: TOXENV=doc8
- env: TOXENV=pylint
- env: TOXENV=vulture
- env: TOXENV=mypy
- env: TOXENV=flake8
- env: TOXENV=xenon
install:
- pip install tox
- pip install codecov
- pip install coverage
- sh -c 'if [ "$TOXENV" = "py" ]; then pip install tox codecov; else pip install tox; fi'
script:
- tox
after_success:
- tox -e coverage-report
- codecov
- sh -c 'if [ "$TOXENV" = "py" ]; then tox -e coverage-report; codecov; fi'
notifications:
slack: pybel:n2KbWKBum3musnBg3L76gGwq
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ recursive-include docs Makefile
global-exclude *.py[cod] __pycache__ *.so *.dylib .DS_Store *.gpickle

exclude .bumpversion.cfg
include *.rst *.txt *.yml LICENSE tox.ini .coveragerc
include *.rst *.txt *.yml LICENSE *.ini .coveragerc .flake8
12 changes: 8 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
Bio2BEL Reactome |build| |coverage| |documentation| |zenodo|
============================================================
This package allows the enrichment of BEL networks with Reactome information by wrapping its RESTful API.
Furthermore, it is integrated in the `ComPath environment <https://github.com/ComPath>`_ for pathway database comparison.
Furthermore, it is integrated in the `ComPath environment <https://github.com/ComPath>`_ for pathway database
comparison.

Installation
------------
This code can be installed with :code:`pip3 install git+https://github.com/bio2bel/reactome.git`


These two resources will be installed together with this package and can be quickly loaded by running the following commands in your terminal:
These two resources will be installed together with this package and can be quickly loaded by running the following
commands in your terminal:

- :code:`python3 -m bio2bel_hgnc populate`
- :code:`python3 -m bio2bel_chebi populate`
Expand Down Expand Up @@ -60,8 +62,10 @@ Other Command Line Utilities

Citation
--------
- Fabregat, Antonio et al. “The Reactome Pathway Knowledgebase.” Nucleic Acids Research 44.Database issue (2016): D481–D487. PMC. Web. 6 Oct. 2017.
- Croft, David et al. “The Reactome Pathway Knowledgebase.” Nucleic Acids Research 42.Database issue (2014): D472–D477. PMC. Web. 6 Oct. 2017.
- Fabregat, Antonio et al. “The Reactome Pathway Knowledgebase.” Nucleic Acids Research 44.Database issue (2016):
D481–D487. PMC. Web. 6 Oct. 2017.
- Croft, David et al. “The Reactome Pathway Knowledgebase.” Nucleic Acids Research 42.Database issue (2014): D472–D477.
PMC. Web. 6 Oct. 2017.

.. |build| image:: https://travis-ci.org/bio2bel/reactome.svg?branch=master
:target: https://travis-ci.org/bio2bel/reactome
Expand Down
2 changes: 2 additions & 0 deletions doc8.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[doc8]
max-line-length = 120
14 changes: 11 additions & 3 deletions docs/source/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ Command Line Interface
======================
The command line interface allows you to communicate with the package and perform basic functions such as:

* Populate the database: :code:`python3 -m bio2bel_reactome populate`. By default this command populates the database only with human information. In order to populate all species pathway information you can add the "--not-only-human" argument. By default the database is reset every time is populated. However, another optional parameter "--reset-db=False", allows you to avoid the reset. More logging can be activated by added "-vv" or "-v" as an argument.
* Populate the database: :code:`python3 -m bio2bel_reactome populate`. By default this command populates the database
only with human information. In order to populate all species pathway information you can add the "--not-only-human"
argument. By default the database is reset every time is populated. However, another optional parameter
"--reset-db=False", allows you to avoid the reset. More logging can be activated by added "-vv" or "-v" as an
argument.

* Drop the database: :code:`python3 -m bio2bel_reactome drop`. More logging can be activated by added "-vv" or "-v" as an argument.
* Drop the database: :code:`python3 -m bio2bel_reactome drop`. More logging can be activated by added "-vv" or "-v" as
an argument.

* Export gene sets as an excel file: :code:`python3 -m bio2bel_reactome export`. By default, the excel will contain all pathways from all species. However, you can add the argument "species" and type the name of a particular one to get only those pathways (e.g., "--species='Homo sapiens'""). Since Reactome has a hierarchy pathway structure, you can get only the major pathways with the optional parameter "--top-hierarchy".
* Export gene sets as an excel file: :code:`python3 -m bio2bel_reactome export`. By default, the excel will contain
all pathways from all species. However, you can add the argument "species" and type the name of a particular one to
get only those pathways (e.g., "--species='Homo sapiens'""). Since Reactome has a hierarchy pathway structure, you can
get only the major pathways with the optional parameter "--top-hierarchy".
12 changes: 0 additions & 12 deletions requirements.txt

This file was deleted.

43 changes: 35 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

"""Setup.py for Bio2BEL Reactome."""

import codecs
import os
import re
Expand All @@ -8,32 +10,54 @@

BIO2BEL_MODULE = 'reactome'
PACKAGES = setuptools.find_packages(where='src')
META_PATH = os.path.join('src', 'bio2bel_{}'.format(BIO2BEL_MODULE), '__init__.py')
META_PATH = os.path.join('src', f'bio2bel_{BIO2BEL_MODULE}', '__init__.py')
KEYWORDS = ['Biological Expression Language', 'BEL', 'Reactome', 'Systems Biology', 'Networks Biology']
CLASSIFIERS = [
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Scientific/Engineering :: Bio-Informatics',
]
INSTALL_REQUIRES = [
'click',
'bio2bel>=0.1.0',
'bio2bel>=0.2.0,<0.3.0',
'compath_utils>=0.1.0',
'bio2bel_hgnc>=0.1.0',
'bio2bel_chebi>=0.1.0',
'pybel>=0.11.2',
'pybel>=0.12.0,<0.13.0',
'sqlalchemy',
'pandas',
'tqdm',
'flask',
'flask_admin',
]
EXTRAS_REQUIRE = {
'web': ['flask', 'flask_admin'],
'web': [
'flask',
'flask_admin',
],
'docs': [
'sphinx',
'sphinx-rtd-theme',
'sphinx-click',
],
}
ENTRY_POINTS = {
'bio2bel': [
'{mname} = bio2bel_{mname}'.format(mname=BIO2BEL_MODULE),
f'{BIO2BEL_MODULE} = bio2bel_{BIO2BEL_MODULE}',
],
'compath': [
'{mname} = bio2bel_{mname}'.format(mname=BIO2BEL_MODULE)
f'{BIO2BEL_MODULE} = bio2bel_{BIO2BEL_MODULE}',
],
'console_scripts': [
'bio2bel_{mname} = bio2bel_{mname}.cli:main'.format(mname=BIO2BEL_MODULE),
f'bio2bel_{BIO2BEL_MODULE} = bio2bel_{BIO2BEL_MODULE}.cli:main',
]
}

Expand All @@ -50,7 +74,7 @@ def read(*parts):


def find_meta(meta):
"""Extract __*meta*__ from META_FILE"""
"""Extract __*meta*__ from META_FILE."""
meta_match = re.search(
r'^__{meta}__ = ["\']([^"\']*)["\']'.format(meta=meta),
META_FILE, re.M
Expand Down Expand Up @@ -80,8 +104,11 @@ def get_long_description():
maintainer_email=find_meta('email'),
license=find_meta('license'),
packages=PACKAGES,
classifiers=CLASSIFIERS,
keywords=KEYWORDS,
package_dir={'': 'src'},
install_requires=INSTALL_REQUIRES,
extras_require=EXTRAS_REQUIRE,
entry_points=ENTRY_POINTS,
zip_safe=False,
)
8 changes: 4 additions & 4 deletions src/bio2bel_reactome/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# Namespace constants

REACTOME = 'REACTOME'
HGNC = 'HGNC'
UNIPROT = 'UNIPROT'
CHEBI = 'CHEBI'
REACTOME = 'reactome'
HGNC = 'hgnc'
UNIPROT = 'uniprot'
CHEBI = 'chebi'
56 changes: 21 additions & 35 deletions src/bio2bel_reactome/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

"""This module populates the tables of bio2bel_reactome."""

import itertools as itt
import logging
from collections import Counter
from typing import Mapping, Optional

import itertools as itt
from sqlalchemy import and_
from tqdm import tqdm

import bio2bel_chebi
import bio2bel_hgnc
from bio2bel.manager.bel_manager import BELManagerMixin
from bio2bel.manager.flask_manager import FlaskMixin
from bio2bel.manager.namespace_manager import BELNamespaceManagerMixin
from pybel.manager.models import NamespaceEntry
from pybel import BELGraph
from sqlalchemy import and_
from tqdm import tqdm

from compath_utils import CompathManager
from pybel import BELGraph
from pybel.manager.models import NamespaceEntry
from .constants import MODULE_NAME
from .models import Base, Chemical, Pathway, Protein, Species
from .parsers import *

log = logging.getLogger(__name__)

__all__ = [
'Manager'
'Manager',
]


Expand All @@ -49,44 +50,29 @@ def __init__(self, *args, **kwargs):
def _base(self):
return Base

def summarize(self):
"""Summarize the database.
:rtype: dict[str,int]
"""
def summarize(self) -> Mapping[str, int]:
"""Summarize the database."""
return dict(
pathways=self._count_model(Pathway),
proteins=self._count_model(Protein),
chemicals=self.count_chemicals(),
species=self.count_species()
)

def count_pathways(self):
"""Count the pathways in the database.
:rtype: int
"""
def count_pathways(self) -> int:
"""Count the pathways in the database."""
return self.session.query(Pathway).count()

def count_chemicals(self):
"""Count the chemicals in the database.
:rtype: int
"""
def count_chemicals(self) -> int:
"""Count the chemicals in the database."""
return self.session.query(Chemical).count()

def count_proteins(self):
"""Count the proteins in the database.
:rtype: int
"""
def count_proteins(self) -> int:
"""Count the proteins in the database."""
return self.session.query(Protein).count()

def count_species(self):
"""Count the species in the database.
:rtype: int
"""
def count_species(self) -> int:
"""Count the species in the database."""
return self.session.query(Species).count()

"""Custom query methods"""
Expand Down Expand Up @@ -472,10 +458,10 @@ def to_bel(self) -> BELGraph:

"""Custom Methods to Populate the DB"""

def _populate_pathways(self, url=None):
""" Populate pathway table
def _populate_pathways(self, url: Optional[str] = None):
"""Populate the pathway table.
:param url: Optional[str] url: url from pathway table file
:param url: url from pathway table file
"""

df = get_pathway_names_df(url=url)
Expand Down
Loading

0 comments on commit 47f8879

Please sign in to comment.