Skip to main content
Glama

scale

Normalize single-cell RNA sequencing data by scaling to unit variance and zero mean. Adjust parameters like zero-centering, clipping, and layer selection for efficient preprocessing.

Instructions

Scale data to unit variance and zero mean

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
layerNoIf provided, which element of layers to scale.
mask_obsNoBoolean mask or string referring to obs column for subsetting observations.
max_valueNoClip (truncate) to this value after scaling. If None, do not clip.
obsmNoIf provided, which element of obsm to scale.
zero_centerNoIf False, omit zero-centering variables to handle sparse input efficiently.

Implementation Reference

  • Pydantic input schema (ScaleModel) for the 'scale' tool, defining parameters such as zero_center, max_value, layer, obsm, and mask_obs with 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
  • MCP tool registration for 'scale', specifying name, description, and linking to ScaleModel input schema.
    scale = types.Tool( name="scale", description="Scale data to unit variance and zero mean", inputSchema=ScaleModel.model_json_schema(), )
  • Mapping dictionary pp_func that associates the 'scale' tool name with scanpy's sc.pp.scale function for execution.
    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, }
  • run_pp_func: Generic handler that dispatches to the appropriate scanpy function (sc.pp.scale for 'scale') based on func name, executes it on the active AnnData with validated arguments, and logs the operation.
    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
  • pp_tools dictionary that collects all preprocessing Tool objects, including the 'scale' tool, for exposure via tool/__init__.py.
    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, }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/huang-sh/scmcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server