Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed May 5, 2019
1 parent 64bde5b commit 79d838a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 49 deletions.
74 changes: 25 additions & 49 deletions src/bio2bel_wikipathways/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""This module populates the tables of bio2bel_wikipathways."""

import logging
from typing import Optional
from typing import List, Mapping, Optional

from tqdm import tqdm

Expand All @@ -13,7 +13,7 @@
from bio2bel.manager.namespace_manager import BELNamespaceManagerMixin
from compath_utils import CompathManager
from pybel.constants import BIOPROCESS, NAME, PROTEIN
from pybel.manager.models import NamespaceEntry
from pybel.manager.models import Namespace, NamespaceEntry
from pybel.struct.graph import BELGraph
from .constants import MODULE_NAME, WIKIPATHWAYS
from .models import Base, Pathway, Protein, protein_pathway
Expand Down Expand Up @@ -72,22 +72,18 @@ class ProteinView(ModelView):
admin.add_view(ProteinView(Protein, self.session))
return admin

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),
)

def query_pathway_by_name(self, query, limit=None):
def query_pathway_by_name(self, query: str, limit: Optional[int] = None) -> List[Pathway]:
"""Return all pathways having the query in their names.
:param query: query string
:param Optional[int] limit: limit result query
:rtype: list[Pathway]
:param limit: limit result query
"""
q = self.session.query(Pathway).filter(Pathway.name.contains(query))

Expand All @@ -96,12 +92,11 @@ def query_pathway_by_name(self, query, limit=None):

return q.all()

def get_or_create_pathway(self, wikipathways_id, name=None):
def get_or_create_pathway(self, wikipathways_id: str, name: Optional[str] = None) -> Pathway:
"""Get an pathway from the database or creates it.
:param str wikipathways_id: wikipathways identifier
:param Optional[str] name: name of the pathway
:rtype: Pathway
:param wikipathways_id: WikiPathways identifier
:param name: name of the pathway
"""
pathway = self.get_pathway_by_id(wikipathways_id)

Expand All @@ -114,13 +109,12 @@ def get_or_create_pathway(self, wikipathways_id, name=None):

return pathway

def get_or_create_protein(self, entrez_id, hgnc_symbol, hgnc_id):
def get_or_create_protein(self, entrez_id: str, hgnc_symbol: str, hgnc_id: str) -> Protein:
"""Get an pathway from the database or creates it.
:param str entrez_id: entrez identifier
:param str hgnc_symbol: hgnc symbol
:param str hgnc_id: hgnc identifier
:rtype: Protein
:param entrez_id: entrez identifier
:param hgnc_symbol: hgnc symbol
:param hgnc_id: hgnc identifier
"""
protein = self.get_protein_by_entrez_id(entrez_id)

Expand All @@ -135,36 +129,24 @@ def get_or_create_protein(self, entrez_id, hgnc_symbol, hgnc_id):

return protein

def get_protein_by_entrez_id(self, entrez_id):
"""Get a protein by its wikipathways id.
:param entrez_id: entrez identifier
:rtype: Optional[Protein]
"""
def get_protein_by_entrez_id(self, entrez_id: str) -> Optional[Protein]:
"""Get a protein by its Entrez gene identifier."""
return self.session.query(Protein).filter(Protein.entrez_id == entrez_id).one_or_none()

def get_protein_by_hgnc_id(self, hgnc_id):
"""Get a protein by its hgnc_id.
:param hgnc_id: hgnc_id
:rtype: Optional[Protein]
"""
def get_protein_by_hgnc_id(self, hgnc_id: str) -> Optional[Protein]:
"""Get a protein by its HGNC identifier."""
return self.session.query(Protein).filter(Protein.hgnc_id == hgnc_id).one_or_none()

def get_protein_by_hgnc_symbol(self, hgnc_symbol):
"""Get a protein by its hgnc symbol.
:param hgnc_symbol: hgnc identifier
:rtype: Optional[Protein]
"""
def get_protein_by_hgnc_symbol(self, hgnc_symbol: str) -> Optional[Protein]:
"""Get a protein by its HGNC gene symbol."""
return self.session.query(Protein).filter(Protein.hgnc_symbol == hgnc_symbol).one_or_none()

"""Methods to populate the DB"""

def populate(self, url=None):
def populate(self, url: Optional[str] = None):
"""Populate the database.
:param Optional[str] url: url from a GMT file
:param url: url from a GMT file
"""
hgnc_manager = bio2bel_hgnc.Manager(engine=self.engine, session=self.session)
if not hgnc_manager.is_populated():
Expand Down Expand Up @@ -239,9 +221,8 @@ def to_bel(self) -> BELGraph:
def get_pathway_graph_by_id(self, wikipathways_id: str) -> Optional[BELGraph]:
"""Return a new graph corresponding to the pathway.
:param wikipathways_id: wikipathways identifier
:rtype: Optional[pybel.BELGraph]
:return: A BEL Graph corresponding to the wikipathway id
:param wikipathways_id: WikiPathways identifier
:return: A BEL Graph corresponding to the WikiPathways identifier
Example Usage:
Expand Down Expand Up @@ -288,13 +269,8 @@ def enrich_wikipathways_protein(self, graph: BELGraph) -> None:
for pathway in protein.pathways:
graph.add_part_of(node, pathway.serialize_to_pathway_node())

def _create_namespace_entry_from_model(self, model, namespace):
"""Create a namespace entry from the model.
:param Pathway model: The model to convert
:type namespace: pybel.manager.models.Namespace
:rtype: Optional[pybel.manager.models.NamespaceEntry]
"""
def _create_namespace_entry_from_model(self, model: Pathway, namespace: Namespace) -> NamespaceEntry:
"""Create a namespace entry from the model."""
return NamespaceEntry(encoding='B', name=model.name, identifier=model.wikipathways_id, namespace=namespace)

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions src/bio2bel_wikipathways/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Protein(Base):
entrez_id = Column(String(255), doc='entrez id of the protein')
hgnc_id = Column(String(255), doc='hgnc id of the protein')
hgnc_symbol = Column(String(255), doc='hgnc symbol of the protein')
uniprot_id = Column()
uniprot_accession = Column()

def __repr__(self): # noqa: D105
return self.hgnc_id
Expand Down

0 comments on commit 79d838a

Please sign in to comment.