mdhewei/bioinfor-claw/clustering-analysis

Claude Code and agent skill by mdhewei/bioinfor-claw

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Cluster samples or features in omics data using K-means, hierarchical agglomerative clustering, DBSCAN, or consensus clustering. Evaluates cluster quality, assigns cluster labels, and generates heatmaps, dendrograms, and silhouette plots.

Install

npx vskill@latest install mdhewei/bioinfor-claw/clustering-analysis

SKILL.md

Clustering Analysis for Omics Data

Purpose

Partition samples (or features) into groups based on expression similarity. Enables unsupervised discovery of cell types, disease subtypes, co-expressed gene modules. Provides cluster quality metrics and consensus-based robustness assessment.

Use When

  • Discovering cell types or disease subtypes in single-cell or bulk RNA-seq
  • Finding co-expressed gene modules
  • Validating cell population predictions
  • Generating sample labels for downstream analysis
  • Assessing clustering robustness via consensus methods
  • Determining optimal number of clusters

Do Not Use When

  • Sample count < 10 (unreliable clustering)
  • Ground truth labels exist; use supervised classification instead
  • Data is categorical (use appropriate clustering for categorical data)
  • Real-time clustering needed (consensus clustering is slow)

Expected Inputs

Required
  • --input: TSV numeric matrix (rows = features, columns = samples OR features to cluster). First column = feature/sample IDs. No missing values.
Optional
  • --metadata: Sample metadata TSV for heatmap annotations
  • --color-by: Metadata column for heatmap sidebar colors
  • --consensus-n: Number of consensus iterations (default: 100; increase for more robust assessment)

Expected Outputs

  • cluster_labels.tsv: sample_id, cluster_id, silhouette_score per sample
  • cluster_summary.tsv: cluster_id, n_samples, centroid_distance_to_global_centroid
  • silhouette_plot.png: Per-sample silhouette coefficient plot, sorted by cluster
  • cluster_heatmap.png: Hierarchical clustered heatmap of expression, samples ordered by cluster
  • dendrogram.png: Dendrogram for hierarchical method
  • consensus_matrix.png: Heatmap of consensus co-clustering frequencies (if consensus method)
  • elbow_plot.png: Silhouette scores for k in --k-range (if auto k-selection)

Procedure

  1. Load and validate data: Read TSV, check for missing values. Optionally transpose (if --transpose flag).
  2. Normalize: Apply scaling (standard = z-score, minmax = [0,1], none = no scaling).
  3. Auto k-selection (if --n-clusters 0):
  • Try each k in --k-range
  • Compute mean silhouette score for each k
  • Select k with highest silhouette score
  • Plot elbow/silhouette curve
  1. Clustering (apply selected method(s)):
  • K-means: Lloyd's algorithm with k-means++ initialization, 100 iterations, 10 restarts, keep best inertia
  • Hierarchical: Build distance matrix, apply linkage (ward/complete/average/single), cut dendrogram at --n-clusters
  • DBSCAN: Compute pairwise distances, identify core points (eps-neighbors >= min-samples), expand clusters
  • Consensus: Run hierarchical clustering --consensus-n times on subsampled data (--consensus-subsample fraction), build consensus matrix, cluster consensus matrix
  1. Compute cluster quality metrics:
  • Silhouette score per sample: s_i = (b_i - a_i) / max(a_i, b_i), where a_i = mean intra-cluster distance, b_i = min mean inter-cluster distance
  • Mean silhouette per cluster
  • Inertia (K-means only)
  • Cophenetic correlation (hierarchical only)
  • Consensus score (consensus clustering only)
  1. Generate visualizations:
  • Silhouette plot: horizontal bars per sample, sorted by cluster
  • Heatmap: samples (columns) ordered by cluster assignment, rows = features, metadata sidebar
  • Dendrogram: hierarchical clustering tree
  • Elbow plot: silhouette vs k
  • Consensus matrix: heatmap of co-clustering frequencies

Key Execution Patterns

bash
# Hierarchical clustering, auto k-selection by silhouette
python clustering_analysis.py \
--input expression_matrix.tsv \
--method hierarchical \
--n-clusters 0 \
--k-range 2,10 \
--outdir results/
# K-means with fixed k=5, colored heatmap by cell type
python clustering_analysis.py \
--input expression_matrix.tsv \
--method kmeans \
--n-clusters 5 \
--metadata sample_metadata.tsv \
--color-by cell_type \
--outdir results/
# Consensus clustering for robustness (100 iterations)
python clustering_analysis.py \
--input expression_matrix.tsv \
--method consensus \
--n-clusters 5 \
--consensus-n 100 \
--consensus-subsample 0.8 \
--outdir results/
# All methods for comparison
python clustering_analysis.py \
--input expression_matrix.tsv \
--method all \
--n-clusters 4 \
--linkage ward \
--metadata metadata.tsv \
--color-by treatment \
--outdir results/
# Cluster genes (features) instead of samples
python clustering_analysis.py \
--input expression_matrix.tsv \
--method hierarchical \
--transpose \
--n-clusters 10 \
--linkage complete \
--outdir results/
# DBSCAN with custom epsilon
python clustering_analysis.py \
--input expression_matrix.tsv \
--method dbscan \
--eps 0.5 \
--min-samples 5 \
--distance-metric euclidean \
--outdir results/

Parameter Decision Guide

ScenarioMethodKey ParamsRationale
Know desired k; want interpretable resultsK-means--n-clusters K, --distance-metric euclideanFast, deterministic, interpretable centroids
Unknown k; want hierarchical explorationHierarchical--n-clusters 0, --linkage wardDendrogram enables visual k selection
Variable cluster sizes; unknown kDBSCAN--eps auto-tuned, --min-samples 5Finds density-based clusters of arbitrary shape/size
Want robustness assessmentConsensus--consensus-n 200, --consensus-subsample 0.8Evaluates stability across resamples
Gene co-expression modulesHierarchical--transpose, --linkage average, --distance-metric correlationCorrelation captures co-expression; average linkage less prone to chaining
Single-cell data (large n)K-means--n-clusters high (20-30), --distance-metric euclideanScalable to 100k cells
Small sample size (n < 50)Hierarchical--linkage completeComplete linkage robust to outliers
Outlier-rich dataDBSCAN--eps, --min-samples tunedLabels outliers as noise (-1)
Exploratory; want all perspectivesallAll defaults; compare outputsIdentify consensus across methods

Failure Modes

ErrorCauseSolution
"K-means failed to converge"Incompatible data scale or initializationIncrease max_iterations (code default: 100) or rescale data
"Silhouette score is negative"Clusters overlap significantlyIncrease --n-clusters or try different method
"Dendrogram is unreadable (many leaves)"Too many samples for dendrogramUse heatmap instead; subset samples for visualization
"DBSCAN found only 1 cluster + noise"Epsilon too largeDecrease --eps or compute optimal eps via k-distance plot
"Consensus matrix is blank/uniform"All subsamples produce identical clusters--consensus-subsample fraction too high; reduce to 0.7 or lower
"Memory error on large matrix"Dataset exceeds RAMPre-filter by variance or subset samples
"Hierarchical clustering tree is a star"Linkage inappropriate for data (e.g., single linkage, chaining effect)Switch to --linkage ward or complete
"Heatmap colors don't match metadata"Metadata column mismatchVerify --color-by column exists and matches sample IDs
"No silhouette plot generated"DBSCAN produced noise points onlyTune --eps and --min-samples; try k-means instead

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/mdhewei/bioinfor-claw/clustering-analysis/badge)](https://verified-skill.com/skills/mdhewei/bioinfor-claw/clustering-analysis)

Something wrong with this skill or its page? Tell us.