Skip to main content
Glama

score_genes

Calculate gene scores by averaging expression levels, with options for reference sampling, expression binning, and random seed control.

Instructions

Score a set of genes based on their average expression

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ctrl_sizeNoNumber of reference genes to be sampled from each bin.
gene_poolNoGenes for sampling the reference set. Default is all genes.
n_binsNoNumber of expression level bins for sampling.
score_nameNoName of the field to be added in .obs.score
random_stateNoThe random seed for sampling.
use_rawNoWhether to use raw attribute of adata. Defaults to True if .raw is present.

Implementation Reference

  • Generic handler function that executes the score_genes tool by retrieving sc.tl.score_genes from tl_func mapping, validating parameters via inspect.signature, calling it on the active AnnData object, and logging 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 
  • Pydantic model defining the input schema and validation for the score_genes tool parameters.
    class ScoreGenesModel(JSONParsingModel):
        """Input schema for the score_genes tool that calculates gene scores based on average expression."""
        
        ctrl_size: int = Field(
            default=50,
            description="Number of reference genes to be sampled from each bin.",
            gt=0
        )
        
        gene_pool: Optional[List[str]] = Field(
            default=None,
            description="Genes for sampling the reference set. Default is all genes."
        )
        
        n_bins: int = Field(
            default=25,
            description="Number of expression level bins for sampling.",
            gt=0
        )
        
        score_name: str = Field(
            default='score',
            description="Name of the field to be added in .obs."
        )
        
        random_state: int = Field(
            default=0,
            description="The random seed for sampling."
        )
        
        use_raw: Optional[bool] = Field(
            default=None,
            description="Whether to use raw attribute of adata. Defaults to True if .raw is present."
        )
        
        @field_validator('ctrl_size', 'n_bins')
        def validate_positive_integers(cls, v: int) -> int:
            """Validate positive integers"""
            if v <= 0:
                raise ValueError("must be a positive integer")
            return v
  • Registers the score_genes tool as an MCP Tool object with name, description, and input schema reference.
    # Add score_genes tool
    score_genes_tool = types.Tool(
        name="score_genes",
        description="Score a set of genes based on their average expression",
        inputSchema=ScoreGenesModel.model_json_schema(),
    )
  • Maps the 'score_genes' tool name to the underlying scanpy function sc.tl.score_genes for execution.
    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,
    }
  • Adds the score_genes_tool to the tl_tools dictionary, which is used by the MCP server to list available tools.
    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?

With no annotations provided, the description carries full burden but offers minimal behavioral information. It mentions 'average expression' but doesn't explain what the scoring output represents, whether it modifies data in place, what format results take, or any computational characteristics. For a tool with 6 parameters and no annotations, this is inadequate.

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 a single, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized and front-loaded with the essential information.

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 tool with 6 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the scoring output means, how results are returned, or the computational behavior. The description should provide more context about what 'scoring' accomplishes in practice.

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 parameters thoroughly. The description adds no parameter-specific information beyond what's in the schema, maintaining the baseline score of 3 where the 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 verb 'score' and the resource 'genes', specifying it's based on average expression. However, it doesn't differentiate from sibling tools like 'score_genes_cell_cycle' or explain what scoring means in this context beyond the basic calculation.

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?

No guidance is provided about when to use this tool versus alternatives like 'score_genes_cell_cycle' or other scoring methods. The description only states what it does, not when it's appropriate or what prerequisites might be needed.

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