Skip to main content
Glama

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyNoKey to a categorical annotation from adata.obs that will be used for batch effect removal.batch
covariatesNoAdditional covariates besides the batch variable such as adjustment variables or biological condition.

Implementation Reference

  • 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
  • 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
  • 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(),
    )
  • 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,
    }
  • 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,
    }

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