Skip to main content
Glama

highly_variable_genes

Identify and annotate highly variable genes in single-cell RNA-seq data to focus analysis on biologically relevant features using dispersion and expression cutoffs.

Instructions

Annotate highly variable genes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
layerNoIf provided, use adata.layers[layer] for expression values.
n_top_genesNoNumber of highly-variable genes to keep. Mandatory if `flavor='seurat_v3'
min_dispNoMinimum dispersion cutoff for gene selection.
max_dispNoMaximum dispersion cutoff for gene selection.
min_meanNoMinimum mean expression cutoff for gene selection.
max_meanNoMaximum mean expression cutoff for gene selection.
spanNoFraction of data used for loess model fit in seurat_v3.
n_binsNoNumber of bins for mean expression binning.
flavorNoMethod for identifying highly variable genes.seurat
subsetNoInplace subset to highly-variable genes if True.
batch_keyNoKey in adata.obs for batch information.
check_valuesNoCheck if counts are integers for seurat_v3 flavor.

Implementation Reference

  • Handler function that executes the preprocessing tools, including highly_variable_genes, by dispatching to the corresponding scanpy.pp function (sc.pp.highly_variable_genes).
    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
  • Registration of the 'highly_variable_genes' tool using MCP types.Tool, linking to its schema.
    highly_variable_genes = types.Tool(
        name="highly_variable_genes",
        description="Annotate highly variable genes",
        inputSchema=HighlyVariableGenesModel.model_json_schema(),
    )
  • Pydantic model defining the input schema and validation for the highly_variable_genes tool.
    class HighlyVariableGenesModel(JSONParsingModel):
        """Input schema for the highly_variable_genes preprocessing tool."""
        
        layer: Optional[str] = Field(
            default=None,
            description="If provided, use adata.layers[layer] for expression values."
        )
        
        n_top_genes: Optional[int] = Field(
            default=None,
            description="Number of highly-variable genes to keep. Mandatory if `flavor='seurat_v3'",
        )
        
        min_disp: float = Field(
            default=0.5,
            description="Minimum dispersion cutoff for gene selection."
        )
        
        max_disp: float = Field(
            default=float('inf'),
            description="Maximum dispersion cutoff for gene selection."
        )
        min_mean: float = Field(
            default=0.0125,
            description="Minimum mean expression cutoff for gene selection."
        )
        max_mean: float = Field(
            default=3,
            description="Maximum mean expression cutoff for gene selection."
        )
        span: float = Field(
            default=0.3,
            description="Fraction of data used for loess model fit in seurat_v3.",
            gt=0,
            lt=1
        )
        n_bins: int = Field(
            default=20,
            description="Number of bins for mean expression binning.",
            gt=0
        )
        flavor: Literal['seurat', 'cell_ranger', 'seurat_v3', 'seurat_v3_paper'] = Field(
            default='seurat',
            description="Method for identifying highly variable genes."
        )
        subset: bool = Field(
            default=False,
            description="Inplace subset to highly-variable genes if True."
        )
        batch_key: Optional[str] = Field(
            default=None,
            description="Key in adata.obs for batch information."
        )
        
        check_values: bool = Field(
            default=True,
            description="Check if counts are integers for seurat_v3 flavor."
        )
        
        @field_validator('n_top_genes', 'n_bins')
        def validate_positive_integers(cls, v: Optional[int]) -> Optional[int]:
            """Validate positive integers"""
            if v is not None and v <= 0:
                raise ValueError("must be a positive integer")
            return v
        
        @field_validator('span')
        def validate_span(cls, v: float) -> float:
            """Validate span is between 0 and 1"""
            if v <= 0 or v >= 1:
                raise ValueError("span must be between 0 and 1")
            return v
  • Mapping dictionary that associates the 'highly_variable_genes' tool name to the scanpy implementation sc.pp.highly_variable_genes, 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,
    }
  • Dictionary registering the tool objects by name, including highly_variable_genes.
    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 for behavioral disclosure but offers minimal information. 'Annotate' implies a write/mutation operation that modifies data, but it doesn't specify whether this is destructive (e.g., adds annotations to existing objects, creates new objects, or filters datasets). It doesn't mention performance characteristics, error conditions, or what the output looks like (especially problematic since there's no output schema).

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

Conciseness5/5

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

The description is extremely concise at just three words, with zero wasted text. It's front-loaded with the core action ('Annotate') though lacking detail. For conciseness alone, it's optimal, but this comes at the cost of being under-specified.

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?

Given the complexity (12 parameters, statistical gene selection tool), absence of annotations, and no output schema, the description is severely incomplete. It doesn't explain what 'annotation' entails, what the tool returns, how it affects the data object, or its role in a typical analysis pipeline. For a tool with this many parameters and no structured output documentation, the description should provide much more context.

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 12 parameters thoroughly with descriptions, defaults, and constraints. The description adds no parameter information beyond what's in the schema, not even high-level context about how parameters interact (e.g., that 'flavor' choice affects which other parameters are relevant). This meets the baseline of 3 when schema coverage is high.

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

Purpose2/5

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

The description 'Annotate highly variable genes' is a tautology that essentially restates the tool name 'highly_variable_genes'. It provides the verb 'annotate' but doesn't specify what annotation means in this context (e.g., marking genes in a dataset, calculating statistical metrics, or filtering). While it distinguishes from some siblings like 'filter_genes' or 'score_genes', it doesn't clearly differentiate from 'pl_highly_variable_genes' which appears to be a visualization sibling.

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

Usage Guidelines1/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., requires normalized data), when it's appropriate in a workflow, or what alternatives exist among the many sibling tools (e.g., 'filter_genes', 'score_genes', 'pl_highly_variable_genes'). The agent must infer usage solely from the name and parameters.

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