stat-cluster-samples
Cluster samples or features using k-means or hierarchical clustering, evaluate cluster quality with silhouette scores, and produce a dendrogram or cluster plot.
- License 许可
- MIT
- 最近更新
- 2026-11-03
- Stars
- ★ 4
- Forks
- 1
01 前言 Front Matter
- name
- stat-cluster-samples
- description
- Cluster samples or features using k-means or hierarchical clustering, evaluate cluster quality with silhouette scores, and produce a dendrogram or cluster plot.
02 资源文件 3
- 参考文档agents/claude.yaml373 B
- 参考文档agents/openai.yaml374 B
- 参考文档config.yaml332 B
03 SKILL.md 正文
Skill: Sample Clustering
Use When
- User wants to discover groups of similar samples or features in high-dimensional data
- User wants to create a heatmap with hierarchical clustering of genes and samples
- User wants to determine the optimal number of clusters for k-means
- Use cases: gene expression pattern discovery, cell type grouping, patient stratification
Inputs
- Required:
- Data matrix (CSV or TSV): rows = samples (or features), columns = features (or samples)
- Optional:
- Matrix orientation:
samples_as_rows(default) orsamples_as_columns - Clustering method:
hierarchical(default) orkmeans - For hierarchical: linkage method (
warddefault,complete,average,single) - Distance metric:
euclidean(default),correlation, orcosine - For k-means: number of clusters k (default: auto-select using elbow method, k = 2–10)
- Scale features before clustering:
true(default) orfalse - Metadata table for heatmap annotation (optional)
- Output directory (default:
./cluster_output)
- Matrix orientation:
Workflow
- Read data matrix; scale features if requested.
- If hierarchical clustering: a. Compute distance matrix using specified metric. b. Perform hierarchical clustering on both rows (samples) and columns (features). c. Generate a clustered heatmap with dendrogram.
- If k-means: a. If k not specified: compute within-cluster sum of squares for k = 2–10; plot elbow curve; select k at elbow. b. Fit k-means with selected k; report cluster assignments. c. Generate PCA-based cluster scatter plot.
- Compute silhouette score for final cluster solution; report mean and per-sample scores.
- Assign and report cluster labels for each sample.
- Write cluster assignments (TSV), silhouette scores (TSV), heatmap or cluster plot (PDF) to output directory.
- Save the executable analysis script (
analysis_code.pyoranalysis_code.R) and software version manifest (session_info.txt) used to produce results.
Output Contract
- Cluster assignments table (TSV): sample_id, cluster_label
- Silhouette scores table (TSV): sample_id, silhouette_score, cluster_label
- Clustered heatmap (PDF, hierarchical) or cluster scatter plot (PDF, k-means)
- Elbow curve (PDF, k-means only when k is auto-selected)
- Mean silhouette score (printed to stdout)
- Reproducibility artifacts:
analysis_code.pyoranalysis_code.R, plussession_info.txt
Limits
- K-means assumes spherical, similarly sized clusters; performs poorly on elongated or irregular shapes.
- Hierarchical clustering with Ward linkage and Euclidean distance is sensitive to outliers; remove outliers before clustering.
- Very large matrices (> 10k samples or > 50k features) may be slow; consider subsampling or running PCA first.
- Common failure: data with many zero entries (e.g., single-cell) — apply dimensionality reduction first.
04 同仓库更多 Skills
structured-intelligence-skill-creator
Create or update repository skills that conform to local templates, provider metadata requirements, registry rules, and validation workflows.
stat-survival-analysis
Estimate and compare survival functions using Kaplan-Meier curves and log-rank test, with optional Cox proportional hazards regression.
stat-pca
Perform PCA on a numeric data matrix to reduce dimensionality, visualize sample structure, and identify top contributing features.
stat-pairwise-correlation
Compute pairwise correlations and significance tests across all numeric variables, and produce a correlation heatmap.
stat-nonlinear-embedding
Embed high-dimensional data into 2D using t-SNE or UMAP for exploratory visualization of sample or cell relationships.
stat-logistic-regression
Fit a logistic regression model for binary outcomes, report odds ratios and model performance (AUC-ROC, confusion matrix).