Skip to content

Commit

Permalink
add flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahbeenie committed Nov 14, 2019
1 parent d9b6b30 commit 97005f0
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/pathme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"""
The goal of this package is to facilitate the evaluation of pathway knowledge across three of the major pathway databases by harmozing and consolidating different formats.
PathMe does that by converting KEGG, Reactome, and WikiPathways to Biological Expression Language (BEL).
Once the three databases are harmonized into BEL, we can evaluate the consensus and gaps in pathway knowledge.
For that, PathMe is complemented with a web application (`PathMe Viewer <https://github.com/ComPath/PathMe-Viewer>`_)
Expand Down Expand Up @@ -59,4 +60,4 @@
.. code-block:: python
python3 -m pathme kegg download
"""
"""
2 changes: 1 addition & 1 deletion src/pathme/mappings_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

"""This module contains the methods that handle the mappings stored in ComPath resources"""
"""This module contains the methods that handle the mappings stored in ComPath resources."""

import pandas as pd

Expand Down
3 changes: 2 additions & 1 deletion src/pathme/normalize_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from typing import List

from networkx import relabel_nodes

from pathme.constants import REACTOME, WIKIPATHWAYS
from pathme.pybel_utils import multi_relabel
from pybel import BELGraph

from pybel.dsl import Abundance, BiologicalProcess, CentralDogma, ListAbundance, Reaction, MicroRna, Protein

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -121,7 +123,6 @@ def munge_reactome_gene(gene):

def normalize_graph_names(graph: BELGraph, database: str) -> None:
"""Normalize graph names."""

# Victim to Survivor (one to one node) mapping
one_to_one_mapping = {}
# Victim to Survivors (one to many nodes) mapping
Expand Down
8 changes: 4 additions & 4 deletions src/pathme/pybel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import logging
from typing import Mapping, Iterable

from pybel.dsl import BaseEntity

logger = logging.getLogger(__name__)

from pybel import BELGraph
from pybel.dsl import BaseEntity

from pybel_tools.node_utils import list_abundance_cartesian_expansion, reaction_cartesian_expansion

logger = logging.getLogger(__name__)


def flatten_complex_nodes(graph: BELGraph) -> None:
"""Flatten complex nodes"""
logger.info("Flat complexes and composites")
list_abundance_cartesian_expansion(graph)
reaction_cartesian_expansion(graph)
Expand Down
18 changes: 10 additions & 8 deletions src/pathme/reactome/rdf_sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
from typing import Any, Dict, List, Set, Tuple, Union

import rdflib

from pathme.constants import REACTOME_BEL
from pathme.reactome.convert_to_bel import convert_to_bel
from pathme.utils import get_pathway_statitics, parse_rdf, query_result_to_dict
from pybel import to_pickle
from rdflib import URIRef
from rdflib.namespace import DC, DCTERMS, Namespace, OWL, RDF, RDFS, SKOS, XSD

from tqdm import tqdm

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -65,10 +67,10 @@

#: SPARQL query string to get all participants in an interaction and its controlType (ACTIVATION or INHIBITION).
GET_INTERACTION_PARTICIPANTS_AND_TYPE = """
SELECT DISTINCT
(STRAFTER(STR(?component), '#') AS ?identifier)
?reactant
?product
SELECT DISTINCT
(STRAFTER(STR(?component), '#') AS ?identifier)
?reactant
?product
(STR(?control_type) AS ?interaction_type)
WHERE {
?component biopax3:left ?reactant .
Expand All @@ -92,7 +94,7 @@
?display_name
?complex_components
?comment
WHERE {
WHERE {
?entity rdf:type ?uri_type .
optional {?entity biopax3:comment ?comment .}
optional {?entity biopax3:entityReference ?entity_reference .}
Expand Down Expand Up @@ -176,7 +178,7 @@ def _get_entity_metadata(entity: rdflib.URIRef, rdf_graph: rdflib.Graph) -> Dict


def _get_reaction_participants(component_uri: str, component, rdf_graph: rdflib.Graph) -> Tuple[
Dict[Union[str, Set[str]], Dict[str, Union[str, Set[str]]]], Dict[Any, Dict[str, Any]]]:
Dict[Union[str, Set[str]], Dict[str, Union[str, Set[str]]]], Dict[Any, Dict[str, Any]]]:
"""Get reaction participants (nodes and interactions) for a given reaction.
:param component_uri: URI reference of the queried reaction component
Expand Down Expand Up @@ -227,13 +229,13 @@ def _get_reaction_participants(component_uri: str, component, rdf_graph: rdflib.


def _get_pathway_components(pathway_uri: rdflib.URIRef, rdf_graph: rdflib.Graph) -> Tuple[
Dict[str, Dict[str, Union[str, Set[str]]]], List[Dict[str, Union[str, Set[str]]]]]:
Dict[str, Dict[str, Union[str, Set[str]]]], List[Dict[str, Union[str, Set[str]]]]]:
"""Get components (nodes and interactions) for a given pathway.
:param pathway_uri: URI reference of the queried pathway
:param rdf_graph: RDF Reactome Universe graph object
:return: returns the pathway components as entities (Proteins, Complex, SmallMolecule...) and proteins (their links)
"""
"""
interactions = {}
nodes = {}

Expand Down
1 change: 1 addition & 0 deletions src/pathme/reactome/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def get_valid_node_parameters(
hgnc_manager: HgncManager,
chebi_manager: ChebiManager,
) -> Tuple[str, str, str]:
"""Get valid node parameters."""
namespace = None

if 'uri_id' in node:
Expand Down
1 change: 0 additions & 1 deletion src/pathme/wikipathways/convert_to_bel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from bio2bel_hgnc import Manager
from pybel import BELGraph
from pybel.dsl import BaseEntity, abundance, activity, bioprocess, complex_abundance, gene, protein, rna
from typing import Collection
from .utils import check_multiple, evaluate_wikipathways_metadata, get_valid_gene_identifier
from ..constants import ACTIVITY_ALLOWED_MODIFIERS, HGNC
from ..utils import add_bel_metadata, parse_id_uri
Expand Down
2 changes: 2 additions & 0 deletions src/pathme/wikipathways/json_rdf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def parse_entries(entries):

return graph


def convert_json(graph: rdflib.Graph):
"""Convert from rdflib importated graph object to python data structure (list of dicts of each entry).
Expand All @@ -354,6 +355,7 @@ def convert_json(graph: rdflib.Graph):

return json_wp_pathway


def parse_pathway(pathway_path):
"""After importing the indicated pathway from text file resources into a graph rdflib object(import_pathway), calls the diferent data types transformations (convert_json function) and the first statement of the parser that will return a graph data structure (parse_entries function). This retrieved graph will be converted to a networX graph (convert_to_nx function).
Expand Down
26 changes: 14 additions & 12 deletions src/pathme/wikipathways/rdf_sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import bio2bel_hgnc
import rdflib
import tqdm

from pathme.utils import get_pathway_statitics, parse_rdf, query_result_to_dict
from pathme.wikipathways.convert_to_bel import convert_to_bel
from pathme.wikipathways.utils import debug_pathway_info

from pybel import BELGraph, to_pickle
from rdflib.namespace import DC, DCTERMS, Namespace, RDF, RDFS

Expand Down Expand Up @@ -49,7 +51,7 @@

#: SPARQL query to get all data nodes in a pathway network with some arguments.
GET_ALL_DATA_NODES_SPARQL = """
SELECT DISTINCT
SELECT DISTINCT
?uri_id
?name
(STRAFTER(STR(?uri_type), str(wp:)) AS ?node_types)
Expand Down Expand Up @@ -92,8 +94,8 @@

#: SPARQL query to get all data nodes in a pathway network with some arguments.
GET_ALL_COMPLEXES_SPARQL = """
SELECT DISTINCT
?uri_id
SELECT DISTINCT
?uri_id
(STRAFTER(STR(?uri_type), str(wp:)) AS ?node_types)
(?participants_entry AS ?participants)
(?participants_id AS ?participants)
Expand All @@ -113,15 +115,15 @@
# TODO: Check interaction complexes.
#: SPARQL query to get all directed interactions in a pathway network with source and target.
GET_ALL_DIRECTED_INTERACTIONS_SPARQL = """
SELECT DISTINCT
(?source_entry AS ?source)
(?dc_source AS ?source)
(?target_entry AS ?target)
(?dc_target AS ?target)
SELECT DISTINCT
(?source_entry AS ?source)
(?dc_source AS ?source)
(?target_entry AS ?target)
(?dc_target AS ?target)
?uri_id
(STRAFTER(STR(?uri_id), "/Interaction/") AS ?identifier)
(STRAFTER(STR(?uri_type), str(wp:)) AS ?interaction_types)
(STRAFTER(STR(?ncbigene_source), str(ncbigene:)) AS ?source )
(STRAFTER(STR(?uri_id), "/Interaction/") AS ?identifier)
(STRAFTER(STR(?uri_type), str(wp:)) AS ?interaction_types)
(STRAFTER(STR(?ncbigene_source), str(ncbigene:)) AS ?source )
(STRAFTER(STR(?ncbigene_target), str(ncbigene:)) AS ?target )
WHERE {
?pathway a wp:Pathway .
Expand Down Expand Up @@ -214,7 +216,7 @@ def _get_pathway_components(graph) -> Tuple[

def get_wp_statistics(resource_files, resource_folder, hgnc_manager) -> Tuple[
Dict[str, Dict[str, int]], Dict[str, Dict[str, Dict[str, int]]]]:
"""Load WikiPathways RDF to BELGraph
"""Load WikiPathways RDF to BELGraph.
:param iter[str] resource_files: RDF file path
:param str resource_folder: RDF file path
Expand Down
2 changes: 1 addition & 1 deletion src/pathme/wikipathways/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


def evaluate_wikipathways_metadata(metadata: Union[str, Set[str]]) -> str:
"""Evaluates metadata in wikipathways and returns the string representation."""
"""Evaluate metadata in wikipathways and return the string representation."""
if isinstance(metadata, set):
return ','.join(metadata)

Expand Down
3 changes: 1 addition & 2 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class KeggTest(TemporaryConnectionMixin):

@classmethod
def setUpClass(cls):
"""Create temporary file"""

"""Create temporary file."""
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(name)s - %(message)s")
log.setLevel(logging.INFO)

Expand Down

0 comments on commit 97005f0

Please sign in to comment.