dendrogram
Generate hierarchical clustering dendrograms for single-cell RNA sequencing data. Group observations, specify correlation methods, and customize clustering parameters to visualize relationships in SCMCP MCP server.
Instructions
Hierarchical clustering dendrogram
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cor_method | No | Correlation method to use: 'pearson', 'kendall', or 'spearman'. | pearson |
| groupby | Yes | The categorical observation annotation to use for grouping. | |
| key_added | No | By default, the dendrogram information is added to .uns[f'dendrogram_{groupby}']. | |
| linkage_method | No | Linkage method to use for hierarchical clustering. | complete |
| n_pcs | No | Use this many PCs. If n_pcs==0 use .X if use_rep is None. | |
| optimal_ordering | No | Reorders the linkage matrix so that the distance between successive leaves is minimal. | |
| use_raw | No | Only when var_names is not None. Use raw attribute of adata if present. | |
| use_rep | No | Use the indicated representation. 'X' or any key for .obsm is valid. | |
| var_names | No | List of var_names to use for computing the hierarchical clustering. If provided, use_rep and n_pcs are ignored. |
Implementation Reference
- src/scmcp/tool/tl.py:164-177 (handler)Handler function that executes the tool logic for 'dendrogram' by calling the mapped Scanpy function sc.tl.dendrogram with input parameters.def run_tl_func(ads, func, arguments): adata = ads.adata_dic[ads.active] if func not in tl_func: raise ValueError(f"Unsupported function: {func}") run_func = tl_func[func] parameters = inspect.signature(run_func).parameters kwargs = {k: arguments.get(k) for k in parameters if k in arguments} try: res = run_func(adata, **kwargs) add_op_log(adata, run_func, kwargs) except Exception as e: logger.error(f"Error running function {func}: {e}") raise return
- src/scmcp/schema/tl.py:416-479 (schema)Pydantic model defining the input schema and validation for the dendrogram tool.class DendrogramModel(JSONParsingModel): """Input schema for the hierarchical clustering dendrogram tool.""" groupby: str = Field( ..., # Required field description="The categorical observation annotation to use for grouping." ) n_pcs: Optional[int] = Field( default=None, description="Use this many PCs. If n_pcs==0 use .X if use_rep is None.", ge=0 ) use_rep: Optional[str] = Field( default=None, description="Use the indicated representation. 'X' or any key for .obsm is valid." ) var_names: Optional[List[str]] = Field( default=None, description="List of var_names to use for computing the hierarchical clustering. If provided, use_rep and n_pcs are ignored." ) use_raw: Optional[bool] = Field( default=None, description="Only when var_names is not None. Use raw attribute of adata if present." ) cor_method: str = Field( default='pearson', description="Correlation method to use: 'pearson', 'kendall', or 'spearman'." ) linkage_method: str = Field( default='complete', description="Linkage method to use for hierarchical clustering." ) optimal_ordering: bool = Field( default=False, description="Reorders the linkage matrix so that the distance between successive leaves is minimal." ) key_added: Optional[str] = Field( default=None, description="By default, the dendrogram information is added to .uns[f'dendrogram_{groupby}']." ) @field_validator('cor_method') def validate_cor_method(cls, v: str) -> str: """Validate correlation method is supported""" valid_methods = ['pearson', 'kendall', 'spearman'] if v.lower() not in valid_methods: raise ValueError(f"cor_method must be one of {valid_methods}") return v.lower() @field_validator('linkage_method') def validate_linkage_method(cls, v: str) -> str: """Validate linkage method is supported""" valid_methods = ['single', 'complete', 'average', 'weighted', 'centroid', 'median', 'ward'] if v.lower() not in valid_methods: raise ValueError(f"linkage_method must be one of {valid_methods}") return v.lower() @field_validator('n_pcs') def validate_n_pcs(cls, v: Optional[int]) -> Optional[int]: """Validate n_pcs is non-negative""" if v is not None and v < 0: raise ValueError("n_pcs must be a non-negative integer") return v
- src/scmcp/tool/tl.py:61-66 (registration)Registration of the MCP tool object for 'dendrogram', specifying name, description, and input schema.# Add dendrogram tool dendrogram_tool = types.Tool( name="dendrogram", description="Hierarchical clustering dendrogram", inputSchema=DendrogramModel.model_json_schema(), )
- src/scmcp/tool/tl.py:153-153 (registration)Addition of the dendrogram tool to the tl_tools dictionary for registration."dendrogram": dendrogram_tool,
- src/scmcp/tool/tl.py:133-133 (helper)Mapping of the 'dendrogram' tool name to the underlying Scanpy function sc.tl.dendrogram used by the handler."dendrogram": sc.tl.dendrogram,