Skip to content

Commit

Permalink
Add drug normalization function
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Mar 12, 2019
1 parent cb0fa19 commit 6d24ce8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/bio2bel_drugbank/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import logging
import os
import time
from bio2bel import AbstractManager
from bio2bel.manager.bel_manager import BELManagerMixin
from bio2bel.manager.flask_manager import FlaskMixin
from bio2bel.manager.namespace_manager import BELNamespaceManagerMixin
from bio2bel_uniprot import get_slim_mappings_df
from collections import Counter, defaultdict
from typing import Dict, Iterable, List, Mapping, Optional, Tuple

import networkx as nx
from sqlalchemy import func
from tqdm import tqdm
from typing import Dict, Iterable, List, Mapping, Optional, Tuple

import bio2bel_hgnc
from bio2bel import AbstractManager
from bio2bel.manager.bel_manager import BELManagerMixin
from bio2bel.manager.flask_manager import FlaskMixin
from bio2bel.manager.namespace_manager import BELNamespaceManagerMixin
from pybel import BELGraph
from pybel.constants import ABUNDANCE, FUNCTION, IDENTIFIER, NAME, NAMESPACE, PROTEIN
from pybel.dsl import BaseEntity, abundance
Expand Down Expand Up @@ -483,11 +484,20 @@ def lookup_drug(self, node: BaseEntity) -> Optional[Drug]:
return self.get_drug_by_drugbank_id(name)

def iter_drugs(self, graph: BELGraph) -> Iterable[Tuple[BaseEntity, Drug]]:
"""Iterate over the drugs in the graph."""
for node in graph:
drug_model = self.lookup_drug(node)
if drug_model is not None:
yield node, drug_model

def normalize_drugs(self, graph: BELGraph) -> None:
"""Normalize the drugs in the graph."""
mapping = {
node: drug_model.as_bel()
for node, drug_model in self.iter_drugs(graph)
}
nx.relabel_nodes(graph, mapping, copy=False)

def enrich_drug_inchi(self, graph: BELGraph) -> None:
"""Enrich drugs in the graph with their InChI equivalent nodes."""
self.add_namespace_to_graph(graph)
Expand Down

0 comments on commit 6d24ce8

Please sign in to comment.