Skip to main content
Glama

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expr_typeNoName of kind of values in X.counts
var_typeNoThe kind of thing the variables are.genes
qc_varsNoKeys 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_topNoList of ranks (where genes are ranked by expression) at which the cumulative proportion of expression will be reported as a percentage.
layerNoIf provided, use adata.layers[layer] for expression values instead of adata.X
use_rawNoIf True, use adata.raw.X for expression values instead of adata.X
log1pNoSet to False to skip computing log1p transformed annotations.

Implementation Reference

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

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers limited behavioral insight. It mentions that metrics are calculated for AnnData but doesn't describe what happens to the data (mutates AnnData? creates new object?), performance characteristics, or error conditions. The qc_vars parameter hint about calling mark_var first is useful but insufficient for full transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise - a single sentence that states the core purpose with examples. However, it could be more front-loaded with clearer usage context. The parameter descriptions in the schema are detailed but that's separate from the main description text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 7-parameter tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the tool returns, how results are stored, whether it modifies the input AnnData, or provide context about when this tool fits in a workflow. The mention of calling mark_var first is helpful but doesn't compensate for major gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 7 parameters thoroughly. The description adds minimal value beyond the schema - it mentions common metrics but doesn't explain how parameters relate to those metrics or provide additional semantic context. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: calculating quality control metrics for AnnData, with specific examples of metrics (total counts, gene number, percentage in ribosomal and mitochondrial). It distinguishes from siblings by focusing on QC metrics calculation, though it doesn't explicitly compare to alternatives like 'filter_cells' or 'filter_genes'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal usage guidance. It mentions that 'mark_var tool should be called first when you want to calculate mt, ribo, hb' in the qc_vars parameter description, but this is buried in parameter details rather than clear when-to-use guidance. No explicit alternatives or exclusions are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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