Skip to content

Commit

Permalink
Merge pull request #196 from PixelgenTechnologies/chore/dynamic-impor…
Browse files Browse the repository at this point in the history
…t-of-graspologic

Improve cli start-up speed
  • Loading branch information
johandahlberg authored Oct 28, 2024
2 parents ffa1b8d + 3027643 commit d9e4022
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/pixelator/graph/community_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@

import logging
from copy import copy
from dataclasses import dataclass
from pathlib import Path
from queue import Queue
from time import time
from typing import Optional, Tuple
from typing import Tuple

import networkx as nx
import numpy as np
import pandas as pd
import polars as pl
from graspologic.partition import leiden

from pixelator.graph.constants import (
LEIDEN_RESOLUTION,
Expand All @@ -25,7 +21,6 @@
edgelist_metrics,
map_upis_to_components,
split_remaining_and_removed_edgelist,
update_edgelist_membership,
)
from pixelator.report.models.graph import GraphSampleReport
from pixelator.types import PathType
Expand Down Expand Up @@ -297,6 +292,9 @@ def recover_technical_multiplets(
edgelist.shape[0],
)

# Import here since the import is very slow and expensive
from graspologic.partition import leiden

def id_generator(start=0):
next_id = start
while True:
Expand Down
4 changes: 3 additions & 1 deletion src/pixelator/pixeldataset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import numpy as np
import pandas as pd
from anndata import AnnData, ImplicitModificationWarning, read_h5ad
from graspologic.partition import leiden

from pixelator.graph import components_metrics
from pixelator.graph.constants import LEIDEN_RESOLUTION, RELATIVE_ANNOTATE_RESOLUTION
Expand Down Expand Up @@ -222,6 +221,9 @@ def write_anndata(adata: AnnData, filename: PathType) -> None:
def _compute_sub_communities(
component_edgelist: pd.DataFrame, n_edges_reconnect: int | None = None
) -> pd.Series:
# Import here since the import is very slow and expensive
from graspologic.partition import leiden

component_edgelist = (
component_edgelist.groupby(["upia", "upib"], observed=True)["count"]
.count()
Expand Down

0 comments on commit d9e4022

Please sign in to comment.