Skip to content

Commit

Permalink
refactor codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
YojanaGadiya committed Oct 14, 2024
1 parent ddded6b commit a1b74d4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/pyBiodatafuse/analyzer/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def __init__(self, graph=None, graph_path=None, graph_format="pickle"):

self.node_count = self.count_nodes_by_type()
self.edge_count = self.count_edge_by_type()
self.node_source_count = self.get_node_counts_by_source()
self.edge_source_count = self.get_edge_counts_by_source()
self.node_source_count = self.count_nodes_by_source()
self.edge_source_count = self.count_edge_by_source()
self.graph_summary = self.get_graph_summary()

def get_graph_summary(self) -> str:
Expand Down Expand Up @@ -88,6 +88,7 @@ def count_nodes_by_type(

if plot:
self._plot_type_count(node_count, interactive, count_type="Node")
return None

return node_count

Expand All @@ -102,6 +103,7 @@ def count_edge_by_type(

if plot:
self._plot_type_count(edge_count, interactive, count_type="Edge")
return None

return edge_count

Expand All @@ -122,7 +124,7 @@ def _plot_source_count(self, source_count_df: pd.DataFrame, count_type: str = "N
)
fig.show()

def get_node_counts_by_source(self, plot: bool = False) -> Optional[pd.DataFrame]:
def count_nodes_by_source(self, plot: bool = False) -> Optional[pd.DataFrame]:
"""Get the count of nodes by data source."""
node_data = pd.DataFrame(self.graph.nodes(data=True), columns=["node", "data"])
node_data["node_type"] = node_data["data"].apply(lambda x: x["labels"])
Expand All @@ -133,10 +135,11 @@ def get_node_counts_by_source(self, plot: bool = False) -> Optional[pd.DataFrame

if plot:
self._plot_source_count(node_source_count, count_type="Node")
return None

return node_source_count

def get_edge_counts_by_source(self, plot: bool = False) -> Optional[pd.DataFrame]:
def count_edge_by_source(self, plot: bool = False) -> Optional[pd.DataFrame]:
"""Get the count of edges by data source."""
edge_data = pd.DataFrame(self.graph.edges(data=True), columns=["source", "target", "data"])
edge_data["edge_type"] = edge_data["data"].apply(lambda x: x["label"])
Expand All @@ -148,6 +151,7 @@ def get_edge_counts_by_source(self, plot: bool = False) -> Optional[pd.DataFrame

if plot:
self._plot_source_count(edge_source_count, count_type="Edge")
return None

return edge_source_count

Expand Down
2 changes: 1 addition & 1 deletion src/pyBiodatafuse/annotators/wikipathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from typing import Any, Dict

import pandas as pd
from tqdm import tqdm
from SPARQLWrapper import JSON, SPARQLWrapper
from SPARQLWrapper.SPARQLExceptions import SPARQLWrapperException
from tqdm import tqdm

from pyBiodatafuse.constants import (
WIKIPATHWAYS,
Expand Down
2 changes: 1 addition & 1 deletion src/pyBiodatafuse/graph/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from logging import Logger
from typing import Any, Dict

from tqdm import tqdm
import networkx as nx
import pandas as pd
from tqdm import tqdm

from pyBiodatafuse.constants import (
BGEE_ANATOMICAL_NODE_ATTRS,
Expand Down
6 changes: 3 additions & 3 deletions src/pyBiodatafuse/id_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

"""Python file for mapping identifiers using BridgeDb."""

import os
import json
import csv
import datetime
import json
import logging
import os
import time
from importlib import resources
from tqdm import tqdm
from typing import List, Optional, Tuple

import pandas as pd
import requests
from pubchempy import BadRequestError, PubChemHTTPError, get_compounds, get_synonyms
from rdkit.Chem import CanonSmiles
from tqdm import tqdm

from pyBiodatafuse.constants import BRIDGEDB_ENDPOINT

Expand Down

0 comments on commit a1b74d4

Please sign in to comment.