Quickstart¶
The minimal steps. See Toy Example for a full walkthrough, Run Clumppling for running Clumppling, and the PBMC3k and HBC examples for real data.
Setup¶
In [ ]:
Copied!
from importlib.resources import files
import ace_of_clust as aoc
from importlib.resources import files
import ace_of_clust as aoc
Run Clumppling¶
Input: one .Q file per run in cls_dir (plus a .P file per run for mixed-membership clustering), all with the same number of rows. Each row of Q holds K memberships that sum to 1 (one-hot for hard clustering).
In [ ]:
Copied!
cls_dir = "path/to/clustering_results"
align_dir = "path/to/alignment_results"
aoc.run_clumppling(
input_dir=cls_dir,
output_dir=align_dir,
fmt="generalQ",
extension=".Q",
vis=False,
)
cls_dir = "path/to/clustering_results"
align_dir = "path/to/alignment_results"
aoc.run_clumppling(
input_dir=cls_dir,
output_dir=align_dir,
fmt="generalQ",
extension=".Q",
vis=False,
)
Load Clumppling Results¶
In [ ]:
Copied!
results = aoc.load_clumppling_results(
align_dir=align_dir,
suffix="rep",
cls_dir=cls_dir,
load_P=True,
)
results = aoc.load_clumppling_results(
align_dir=align_dir,
suffix="rep",
cls_dir=cls_dir,
load_P=True,
)
Pairwise Cluster Mappings¶
In [ ]:
Copied!
pair_mappings = aoc.get_mode_pair_mappings(
mode_names=results.modes,
all_modes_alignment=results.all_modes_alignment,
alignment_acrossK=results.alignment_acrossK,
)
pair_mappings = aoc.get_mode_pair_mappings(
mode_names=results.modes,
all_modes_alignment=results.all_modes_alignment,
alignment_acrossK=results.alignment_acrossK,
)
Feature Metrics¶
Mixed-membership clustering only. feature_names: names of the P-matrix rows (e.g. genes).
In [ ]:
Copied!
feature_names = [...]
df_by_mode = aoc.compute_all_feature_metrics(results, feature_names=feature_names)
feature_names = [...]
df_by_mode = aoc.compute_all_feature_metrics(results, feature_names=feature_names)
Top Features¶
By weighted_Psum quantile across modes.
In [ ]:
Copied!
selected_by_mode, df_selected_all, overlap = aoc.select_top_features(
df_by_mode,
top_quantile=0.1,
)
selected_by_mode, df_selected_all, overlap = aoc.select_top_features(
df_by_mode,
top_quantile=0.1,
)
Cluster Memberships¶
X_coords: 2D coordinates of the data points (e.g. UMAP or spatial coordinates).
In [ ]:
Copied!
colors = files("ace_of_clust").joinpath("resources/default_colors.txt").read_text().splitlines()
fig, axes = aoc.plot_cluster_overlay(
results,
coords=X_coords,
cluster_colors=colors[:results.K_max],
val_threshold=0.5,
s=5,
)
colors = files("ace_of_clust").joinpath("resources/default_colors.txt").read_text().splitlines()
fig, axes = aoc.plot_cluster_overlay(
results,
coords=X_coords,
cluster_colors=colors[:results.K_max],
val_threshold=0.5,
s=5,
)