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

Optimized SCC performance & fix some bugs #249

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
28 changes: 13 additions & 15 deletions spateo/tools/CCI_effects_modeling/MuSIC_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def compute_and_visualize_diagnostics(
data=df,
x="Gene",
y="Pearson coefficient",
palette=colors["Pearson coefficient"],
# palette=colors["Pearson coefficient"],
edgecolor="black",
dodge=True,
)
Expand Down Expand Up @@ -567,7 +567,7 @@ def compute_and_visualize_diagnostics(
data=df,
x="Gene",
y="Spearman coefficient",
palette=colors["Spearman coefficient"],
# palette=colors["Spearman coefficient"],
edgecolor="black",
dodge=True,
)
Expand All @@ -593,7 +593,7 @@ def compute_and_visualize_diagnostics(
data=df,
x="Gene",
y="Pearson coefficient (expressing cells)",
palette=colors["Pearson coefficient (expressing cells)"],
# palette=colors["Pearson coefficient (expressing cells)"],
edgecolor="black",
dodge=True,
)
Expand All @@ -619,7 +619,7 @@ def compute_and_visualize_diagnostics(
data=df,
x="Gene",
y="Spearman coefficient (expressing cells)",
palette=colors["Spearman coefficient (expressing cells)"],
# palette=colors["Spearman coefficient (expressing cells)"],
edgecolor="black",
dodge=True,
)
Expand Down Expand Up @@ -4173,8 +4173,8 @@ def cell_type_specific_interactions(
vmin = 0
vmax = 1 if normalize else df.max().max()

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=figsize)
divider = make_axes_locatable(ax)
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=figsize)
divider = make_axes_locatable(axes)
ax2 = divider.append_axes("right", size=ax2_size, pad=0)

# Keep track of groups:
Expand Down Expand Up @@ -4212,7 +4212,7 @@ def cell_type_specific_interactions(
vmin=vmin,
vmax=vmax,
mask=mask,
ax=ax,
ax=axes,
)

# Outer frame:
Expand All @@ -4221,7 +4221,7 @@ def cell_type_specific_interactions(
spine.set_linewidth(thickness * 2.5)

# Adjust colorbar settings:
divider = make_axes_locatable(ax)
divider = make_axes_locatable(axes)
# Append axes to the top of the plot, where the colorbar will be placed
if df.shape[0] > df.shape[1]:
cax = divider.append_axes("top", size="30%", pad=0)
Expand All @@ -4236,11 +4236,11 @@ def cell_type_specific_interactions(
cbar.ax.tick_params(labelsize=fontsize * 1.5)
cbar.ax.set_aspect(0.02)

ax.set_xlabel(x_label, fontsize=fontsize * 1.25)
ax.set_ylabel("Cell Type-Specific Target", fontsize=fontsize * 1.25)
ax.tick_params(axis="x", labelsize=fontsize, rotation=90)
ax.tick_params(axis="y", labelsize=fontsize)
ax.set_title(title, fontsize=fontsize * 1.5, pad=20)
axes.set_xlabel(x_label, fontsize=fontsize * 1.25)
axes.set_ylabel("Cell Type-Specific Target", fontsize=fontsize * 1.25)
axes.tick_params(axis="x", labelsize=fontsize, rotation=90)
axes.tick_params(axis="y", labelsize=fontsize)
axes.set_title(title, fontsize=fontsize * 1.5, pad=20)

# Use the saved name for the AnnData object to define part of the name of the saved file:
base_name = os.path.basename(self.adata_path)
Expand Down Expand Up @@ -6908,7 +6908,6 @@ def CCI_deg_detection_setup(
if scipy.sparse.issparse(adata.X):
nnz_counts = np.array(adata[:, all_TFs].X.getnnz(axis=0)).flatten()
else:
# nnz_counts = np.array(adata[:, all_TFs].X.getnnz(axis=0)).flatten()
nnz_counts = np.count_nonzero(
adata[:, all_TFs].X, axis=0
).flatten() # np.ndarray have no getnnz attributes
Expand Down Expand Up @@ -7637,7 +7636,6 @@ def deg_effect_heatmap(
all_cells_affected = dm[dm[f"regulator_{interaction}"] > 0]
else:
all_cells_affected = dm[dm[interaction] > 0]

specificity = (all_coeffs_target.loc[all_cells_affected.index, interaction] != 0).mean()
all_plot_values.loc[interaction, target] = specificity
all_plot_values.index = [replace_col_with_collagens(f) for f in all_plot_values.index]
Expand Down
3 changes: 3 additions & 0 deletions spateo/tools/cluster/leiden.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import leidenalg
import numpy as np
import scipy
import scipy.sparse
from sklearn.neighbors import kneighbors_graph

from ...configuration import SKM
Expand Down Expand Up @@ -87,6 +88,8 @@ def calculate_leiden_partition(
if adj is not None:
if isinstance(adj, np.ndarray):
G = adj_to_igraph(adj.tolist())
elif scipy.sparse.issparse(adj):
G = adj_to_igraph(adj.A.tolist())
else:
G = igraph.Graph(n=adj.shape[0])
for i, j in zip(*adj.nonzero()):
Expand Down
3 changes: 2 additions & 1 deletion spateo/tools/cluster/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ def spatial_adj(
_, adata = neighbors(
adata,
n_neighbors=s_neigh,
basis=spatial_key,
basis="spatial",
spatial_key=spatial_key,
n_pca_components=n_pca_components,
)

Expand Down
Loading