This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Tool: [Tool] spatial-cluster-compare — stop guessing which clustering algorithm to use on your spatial proteomics / cytometry data

Hi all,

I just packaged and published spatial-cluster-compare, a small Python library I built while working on multiplex immunofluorescence imaging data (spatial proteomics) at my lab. Sharing it here in case it's useful to others it follows the same packaging effort as my other tool, macsima-qc.

The problem it addresses: picking a clustering algorithm for cell population analysis is often done by default (KMeans, tweak parameters until it "looks right") with no objective comparison. For biological data, where clusters are supposed to reflect real cell populations, this can produce plausible-looking but meaningless groupings.

What it does:

  • Tests clusterability (Hopkins statistic) before/after normalization
  • Applies normalization only if it actually improves cluster structure
  • Reduces dimensionality with PCA
  • Automatically selects the number of clusters (k) via a composite score (Silhouette, Davies-Bouldin, Calinski-Harabasz)
  • Benchmarks KMeans, Agglomerative, Spectral, GMM, and DBSCAN (eps auto-estimated via the elbow method) on the same data
  • Adds bootstrap stability (mean ARI) per method, not just a single internal index
  • Picks the best method through a transparent, reproducible composite score
  • Generates a comparison bar chart and a mean-expression heatmap per cluster

Input: any numeric feature table (one row per cell/observation, one column per marker/descriptor) works beyond spatial proteomics on any tabular clustering problem.

pip install spatial-cluster-compare
import pandas as pd
from spatial_cluster_compare import compare_clusters, plot_comparison_bars, plot_cluster_heatmap

data = pd.read_csv("Cluster_ImmuneCell.csv")
result = compare_clusters(data)

print(result.results_df)
print(f"Best method: {result.best_method}")

It's part of a small pipeline I'm building for MACSima-based multiplex imaging (segmentation QC, clustering comparison, and more to come), all linked from the showcase repo below.

Happy to get feedback, bug reports, or suggestions this is a one-person project so I can't promise fast turnaround on everything, but issues are very welcome.

Mathis

python

0 answers

No answers yet.

Log in to answer this question.