Skip to main content
Glama

rank_genes_groups

Identify differentially expressed genes between cell groups in single-cell RNA-seq data to characterize biological differences.

Instructions

Rank genes for characterizing groups, perform differentially expressison analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
groupbyYesThe key of the observations grouping to consider.
mask_varNoSelect subset of genes to use in statistical tests.
use_rawNoUse raw attribute of adata if present.
groupsNoSubset of groups to which comparison shall be restricted, or 'all' for all groups.all
referenceNoIf 'rest', compare each group to the union of the rest of the group. If a group identifier, compare with respect to this group.rest
n_genesNoThe number of genes that appear in the returned tables. Defaults to all genes.
rankby_absNoRank genes by the absolute value of the score, not by the score.
ptsNoCompute the fraction of cells expressing the genes.
key_addedNoThe key in adata.uns information is saved to.
methodNoMethod for differential expression analysis. Default is 't-test'.
corr_methodNop-value correction method. Used only for 't-test', 't-test_overestim_var', and 'wilcoxon'.benjamini-hochberg
tie_correctNoUse tie correction for 'wilcoxon' scores. Used only for 'wilcoxon'.
layerNoKey from adata.layers whose value will be used to perform tests on.

Implementation Reference

  • Pydantic model defining the input schema and validation for the rank_genes_groups tool.
    class RankGenesGroupsModel(JSONParsingModel):
        """Input schema for the rank_genes_groups tool."""
        
        groupby: str = Field(
            ...,  # Required field
            description="The key of the observations grouping to consider."
        )
        mask_var: Optional[Union[str, List[bool]]] = Field(
            default=None,
            description="Select subset of genes to use in statistical tests."
        )
        use_raw: Optional[bool] = Field(
            default=None,
            description="Use raw attribute of adata if present."
        )
        groups: Union[Literal['all'], List[str]] = Field(
            default='all',
            description="Subset of groups to which comparison shall be restricted, or 'all' for all groups."
        )
        reference: str = Field(
            default='rest',
            description="If 'rest', compare each group to the union of the rest of the group. If a group identifier, compare with respect to this group."
        )
        n_genes: Optional[int] = Field(
            default=None,
            description="The number of genes that appear in the returned tables. Defaults to all genes.",
            gt=0
        )
        rankby_abs: bool = Field(
            default=False,
            description="Rank genes by the absolute value of the score, not by the score."
        )
        pts: bool = Field(
            default=False,
            description="Compute the fraction of cells expressing the genes."
        )
        key_added: Optional[str] = Field(
            default=None,
            description="The key in adata.uns information is saved to."
        )
        method: Optional[str] = Field(
            default=None,
            description="Method for differential expression analysis. Default is 't-test'."
        )
        corr_method: str = Field(
            default='benjamini-hochberg',
            description="p-value correction method. Used only for 't-test', 't-test_overestim_var', and 'wilcoxon'."
        )
        tie_correct: bool = Field(
            default=False,
            description="Use tie correction for 'wilcoxon' scores. Used only for 'wilcoxon'."
        )
        layer: Optional[str] = Field(
            default=None,
            description="Key from adata.layers whose value will be used to perform tests on."
        )
        
        @field_validator('method')
        def validate_method(cls, v: Optional[str]) -> Optional[str]:
            """Validate method is supported"""
            if v is not None:
                valid_methods = ['t-test', 't-test_overestim_var', 'wilcoxon', 'logreg']
                if v not in valid_methods:
                    raise ValueError(f"method must be one of {valid_methods}")
            return v
        
        @field_validator('corr_method')
        def validate_corr_method(cls, v: str) -> str:
            """Validate correction method is supported"""
            valid_methods = ['benjamini-hochberg', 'bonferroni']
            if v not in valid_methods:
                raise ValueError(f"corr_method must be one of {valid_methods}")
            return v
        
        @field_validator('n_genes')
        def validate_n_genes(cls, v: Optional[int]) -> Optional[int]:
            """Validate n_genes is positive"""
            if v is not None and v <= 0:
                raise ValueError("n_genes must be a positive integer")
            return v
  • MCP Tool registration for rank_genes_groups, linking to the schema.
    # Add rank_genes_groups tool
    rank_genes_groups_tool = types.Tool(
        name="rank_genes_groups",
        description="Rank genes for characterizing groups, perform differentially expressison analysis",
        inputSchema=RankGenesGroupsModel.model_json_schema(),
    )
  • Mapping of tool names to Scanpy tl functions, including rank_genes_groups to sc.tl.rank_genes_groups.
    tl_func = {
        "tsne": sc.tl.tsne,
        "umap": sc.tl.umap,
        "draw_graph": sc.tl.draw_graph,
        "diffmap": sc.tl.diffmap,
        "embedding_density": sc.tl.embedding_density,
        "leiden": sc.tl.leiden,
        "louvain": sc.tl.louvain,
        "dendrogram": sc.tl.dendrogram,
        "dpt": sc.tl.dpt,
        "paga": sc.tl.paga,
        "ingest": sc.tl.ingest,
        "rank_genes_groups": sc.tl.rank_genes_groups,
        "filter_rank_genes_groups": sc.tl.filter_rank_genes_groups,
        "marker_gene_overlap": sc.tl.marker_gene_overlap,
        "score_genes": sc.tl.score_genes,
        "score_genes_cell_cycle": sc.tl.score_genes_cell_cycle,
    }
  • Generic handler function that dispatches to the specific Scanpy tl function based on func name, filters arguments, executes, and logs the operation.
    def run_tl_func(ads, func, arguments):
        adata = ads.adata_dic[ads.active]
        if func not in tl_func:
            raise ValueError(f"Unsupported function: {func}")
        run_func = tl_func[func]
        parameters = inspect.signature(run_func).parameters
        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 Exception as e:
            logger.error(f"Error running function {func}: {e}")
            raise
        return 
  • Registration of tl tools dictionary, including rank_genes_groups_tool for MCP server usage.
    tl_tools = {
        "tsne": tsne_tool,
        "umap": umap_tool,
        "draw_graph": draw_graph_tool,
        "diffmap": diffmap_tool,
        "embedding_density": embedding_density_tool,
        "leiden": leiden_tool,
        "louvain": louvain_tool,
        "dendrogram": dendrogram_tool,
        "dpt": dpt_tool,
        "paga": paga_tool,
        "ingest": ingest_tool,
        "rank_genes_groups": rank_genes_groups_tool,
        "filter_rank_genes_groups": filter_rank_genes_groups_tool,
        "marker_gene_overlap": marker_gene_overlap_tool,
        "score_genes": score_genes_tool,
        "score_genes_cell_cycle": score_genes_cell_cycle_tool,
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'perform differentially expression analysis,' which implies statistical computation and potential data modification, but doesn't specify whether this tool mutates data, requires specific permissions, has performance considerations, or what the output entails. For a tool with 13 parameters and no annotations, this is a significant gap in transparency.

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—just one sentence with two clauses. It front-loads the core purpose without unnecessary elaboration. Every word earns its place, making it efficient and easy to parse, though this conciseness may contribute to gaps in other dimensions.

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 tool's complexity (13 parameters, no output schema, no annotations), the description is insufficient. It doesn't explain the output format, how results are stored or accessed, or the implications of the analysis. For a differential expression tool with many parameters, more context is needed to guide effective use, especially without annotations or output schema.

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%, meaning all parameters are documented in the input schema. The description adds no additional parameter semantics beyond what's in the schema—it doesn't explain how parameters interact or provide usage examples. Given the high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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: 'Rank genes for characterizing groups, perform differentially expression analysis.' It specifies the action ('rank genes') and the goal ('characterizing groups' and 'differentially expression analysis'), which is more specific than just restating the name. However, it doesn't explicitly differentiate from sibling tools like 'filter_rank_genes_groups' or 'pl_rank_genes_groups_dotplot', which appear related but serve different purposes.

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 no guidance on when to use this tool versus alternatives. With sibling tools like 'filter_rank_genes_groups' and 'pl_rank_genes_groups_dotplot' available, there's no indication of how this tool fits into a workflow or when it should be chosen over others. The description only states what it does, not when to apply it.

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