scale
Standardize single-cell RNA sequencing data by scaling to unit variance and zero mean for preprocessing and analysis.
Instructions
Scale data to unit variance and zero mean
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "scale"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| zero_center | No | If False, omit zero-centering variables to handle sparse input efficiently. | |
| max_value | No | Clip (truncate) to this value after scaling. If None, do not clip. | |
| layer | No | If provided, which element of layers to scale. | |
| obsm | No | If provided, which element of obsm to scale. | |
| mask_obs | No | Boolean mask or string referring to obs column for subsetting observations. |
Implementation Reference
- src/scmcp/tool/pp.py:120-137 (handler)Generic handler that executes sc.pp.scale (via pp_func['scale']) on the active AnnData object for the 'scale' tool.
def run_pp_func(ads, func, arguments): adata = ads.adata_dic[ads.active] if func not in pp_func: raise ValueError(f"不支持的函数: {func}") run_func = pp_func[func] parameters = inspect.signature(run_func).parameters arguments["inplace"] = True 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 KeyError as e: raise KeyError(f"Can not foud {e} column in adata.obs or adata.var") except Exception as e: raise e return res - src/scmcp/schema/pp.py:327-361 (schema)Pydantic input schema model for the 'scale' tool, defining parameters and validation.
class ScaleModel(JSONParsingModel): """Input schema for the scale preprocessing tool.""" zero_center: bool = Field( default=True, description="If False, omit zero-centering variables to handle sparse input efficiently." ) max_value: Optional[float] = Field( default=None, description="Clip (truncate) to this value after scaling. If None, do not clip." ) layer: Optional[str] = Field( default=None, description="If provided, which element of layers to scale." ) obsm: Optional[str] = Field( default=None, description="If provided, which element of obsm to scale." ) mask_obs: Optional[Union[str, bool]] = Field( default=None, description="Boolean mask or string referring to obs column for subsetting observations." ) @field_validator('max_value') def validate_max_value(cls, v: Optional[float]) -> Optional[float]: """Validate max_value is positive if provided""" if v is not None and v <= 0: raise ValueError("max_value must be positive if provided") return v - src/scmcp/tool/pp.py:63-67 (registration)MCP tool registration defining the 'scale' tool name, description, and input schema.
scale = types.Tool( name="scale", description="Scale data to unit variance and zero mean", inputSchema=ScaleModel.model_json_schema(), ) - src/scmcp/tool/pp.py:88-101 (helper)Dictionary mapping tool names to Scanpy functions, with 'scale' mapped to sc.pp.scale used by the handler.
pp_func = { "filter_genes": sc.pp.filter_genes, "filter_cells": sc.pp.filter_cells, "calculate_qc_metrics": partial(sc.pp.calculate_qc_metrics, inplace=True), "log1p": sc.pp.log1p, "normalize_total": sc.pp.normalize_total, "pca": sc.pp.pca, "highly_variable_genes": sc.pp.highly_variable_genes, "regress_out": sc.pp.regress_out, "scale": sc.pp.scale, "combat": sc.pp.combat, "scrublet": sc.pp.scrublet, "neighbors": sc.pp.neighbors, } - src/scmcp/tool/pp.py:104-117 (helper)Dictionary of registered MCP tools, including the 'scale' tool instance.
pp_tools = { "filter_genes": filter_genes, "filter_cells": filter_cells, "calculate_qc_metrics": calculate_qc_metrics, "log1p": log1p, "normalize_total": normalize_total, "pca": pca, "highly_variable_genes": highly_variable_genes, "regress_out": regress_out, "scale": scale, "combat": combat, "scrublet": scrublet, "neighbors": neighbors, }