Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cli start-up speed #196

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading