combat
Correct batch effects in single-cell RNA sequencing data to improve analysis accuracy by removing technical variations between experimental batches.
Instructions
ComBat function for batch effect correction
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": "combat"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | No | Key to a categorical annotation from adata.obs that will be used for batch effect removal. | batch |
| covariates | No | Additional covariates besides the batch variable such as adjustment variables or biological condition. |
Implementation Reference
- src/scmcp/tool/pp.py:120-137 (handler)Generic handler that executes the 'combat' tool by retrieving sc.pp.combat from pp_func, preparing arguments (including inplace=True), calling it on the active adata, handling errors, and logging 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 - src/scmcp/schema/pp.py:363-390 (schema)Pydantic model defining the input schema for the 'combat' tool: 'key' (default 'batch') for the batch annotation column in adata.obs, and optional 'covariates' list of additional adjustment variables.
class CombatModel(JSONParsingModel): """Input schema for the combat batch effect correction tool.""" key: str = Field( default='batch', description="Key to a categorical annotation from adata.obs that will be used for batch effect removal." ) covariates: Optional[List[str]] = Field( default=None, description="Additional covariates besides the batch variable such as adjustment variables or biological condition." ) @field_validator('key') def validate_key(cls, v: str) -> str: """Validate key is not empty""" if not v.strip(): raise ValueError("key cannot be empty") return v @field_validator('covariates') def validate_covariates(cls, v: Optional[List[str]]) -> Optional[List[str]]: """Validate covariates are non-empty strings if provided""" if v is not None: if not all(isinstance(item, str) and item.strip() for item in v): raise ValueError("covariates must be non-empty strings") return v - src/scmcp/tool/pp.py:69-73 (registration)Creates the MCP Tool instance for 'combat' with description and input schema from CombatModel.
combat = types.Tool( name="combat", description="ComBat function for batch effect correction", inputSchema=CombatModel.model_json_schema(), ) - src/scmcp/tool/pp.py:88-101 (helper)Dictionary mapping tool names to their corresponding scanpy preprocessing functions; 'combat' maps to sc.pp.combat, the core batch correction function.
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:103-117 (registration)Registers all preprocessing tools including 'combat' in the pp_tools dictionary for tool dispatching.
# 模型与函数名称的映射 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, }