regress_out
Remove unwanted sources of variation in single-cell RNA sequencing data by regressing out specified observation annotations, enhancing downstream analysis accuracy.
Instructions
Regress out (mostly) unwanted sources of variation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keys | Yes | Keys for observation annotation on which to regress on. | |
| layer | No | If provided, which element of layers to regress on. | |
| n_jobs | No | Number of jobs for parallel computation. |
Implementation Reference
- src/scmcp/tool/pp.py:120-137 (handler)Handler function that executes the regress_out tool by retrieving sc.pp.regress_out from pp_func and calling it with validated arguments on the active AnnData object.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:294-325 (schema)Pydantic model defining the input parameters and validation for the regress_out tool.class RegressOutModel(JSONParsingModel): """Input schema for the regress_out preprocessing tool.""" keys: Union[str, List[str]] = Field( description="Keys for observation annotation on which to regress on." ) layer: Optional[str] = Field( default=None, description="If provided, which element of layers to regress on." ) n_jobs: Optional[int] = Field( default=None, description="Number of jobs for parallel computation.", gt=0 ) @field_validator('n_jobs') def validate_n_jobs(cls, v: Optional[int]) -> Optional[int]: """Validate n_jobs is positive integer""" if v is not None and v <= 0: raise ValueError("n_jobs must be a positive integer") return v @field_validator('keys') def validate_keys(cls, v: Union[str, List[str]]) -> Union[str, List[str]]: """Ensure keys is either a string or list of strings""" if isinstance(v, str): return v elif isinstance(v, list) and all(isinstance(item, str) for item in v): return v raise ValueError("keys must be a string or list of strings")
- src/scmcp/tool/pp.py:57-61 (registration)Registration of the regress_out tool using mcp.types.Tool with name, description, and schema.regress_out = types.Tool( name="regress_out", description="Regress out (mostly) unwanted sources of variation.", inputSchema=RegressOutModel.model_json_schema(), )
- src/scmcp/tool/pp.py:104-117 (registration)Dictionary registering the regress_out tool object for use in the MCP server, likely imported and used for tool registration.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, }
- src/scmcp/tool/pp.py:88-101 (helper)Helper dictionary mapping tool names like 'regress_out' to their underlying Scanpy functions (sc.pp.regress_out), 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, }