calculate_qc_metrics
Calculate quality control metrics for single-cell RNA sequencing data, including total counts, gene numbers, and mitochondrial/ribosomal percentages to assess data quality.
Instructions
Calculate quality control metrics(common metrics: total counts, gene number, percentage of counts in ribosomal and mitochondrial) for AnnData.
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": "calculate_qc_metrics"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expr_type | No | Name of kind of values in X. | counts |
| var_type | No | The kind of thing the variables are. | genes |
| qc_vars | No | Keys for boolean columns of .var which identify variables you could want to control for mark_var tool should be called frist when you want to calculate mt, ribo, hb, and check tool output for var columns | |
| percent_top | No | List of ranks (where genes are ranked by expression) at which the cumulative proportion of expression will be reported as a percentage. | |
| layer | No | If provided, use adata.layers[layer] for expression values instead of adata.X | |
| use_raw | No | If True, use adata.raw.X for expression values instead of adata.X | |
| log1p | No | Set to False to skip computing log1p transformed annotations. |
Implementation Reference
- src/scmcp/tool/pp.py:120-137 (handler)Handler function that executes the calculate_qc_metrics tool logic by calling the mapped scanpy.pp.calculate_qc_metrics function on the active AnnData object with provided arguments and inplace=True.
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:76-124 (schema)Pydantic input schema model for the calculate_qc_metrics tool, including fields like qc_vars, percent_top, layer, use_raw, log1p with validation.
class CalculateQCMetrics(JSONParsingModel): """Input schema for the calculate_qc_metrics preprocessing tool.""" expr_type: str = Field( default="counts", description="Name of kind of values in X." ) var_type: str = Field( default="genes", description="The kind of thing the variables are." ) qc_vars: Optional[Union[List[str], str]] = Field( default=[], description=( "Keys for boolean columns of .var which identify variables you could want to control for " "mark_var tool should be called frist when you want to calculate mt, ribo, hb, and check tool output for var columns" ) ) percent_top: Optional[List[int]] = Field( default=[50, 100, 200, 500], description="List of ranks (where genes are ranked by expression) at which the cumulative proportion of expression will be reported as a percentage." ) layer: Optional[str] = Field( default=None, description="If provided, use adata.layers[layer] for expression values instead of adata.X" ) use_raw: bool = Field( default=False, description="If True, use adata.raw.X for expression values instead of adata.X" ) log1p: bool = Field( default=True, description="Set to False to skip computing log1p transformed annotations." ) @field_validator('percent_top') def validate_percent_top(cls, v: Optional[List[int]]) -> Optional[List[int]]: """验证 percent_top 中的值为正整数""" if v is not None: for rank in v: if not isinstance(rank, int) or rank <= 0: raise ValueError("percent_top 中的所有值必须是正整数") return v - src/scmcp/tool/pp.py:27-31 (registration)MCP Tool object registration defining the name, description, and input schema for calculate_qc_metrics.
calculate_qc_metrics = types.Tool( name="calculate_qc_metrics", description="Calculate quality control metrics(common metrics: total counts, gene number, percentage of counts in ribosomal and mitochondrial) for AnnData.", inputSchema=CalculateQCMetrics.model_json_schema(), ) - src/scmcp/tool/pp.py:91-91 (helper)pp_func dictionary entry mapping the tool name to the wrapped scanpy function partial(sc.pp.calculate_qc_metrics, inplace=True).
"calculate_qc_metrics": partial(sc.pp.calculate_qc_metrics, inplace=True), - src/scmcp/tool/pp.py:104-117 (registration)pp_tools dictionary that includes the calculate_qc_metrics tool, used by server.list_tools() to expose the tool.
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, }