Skip to main content
Glama

pl_pca_variance_ratio

Visualize PCA variance ratios to identify principal components that explain the most variance in single-cell RNA sequencing data.

Instructions

Plot the PCA variance ratio to visualize explained variance.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
figsizeNoFigure size. Format is (width, height).
color_mapNoColor map to use for continuous variables.
paletteNoColors to use for plotting categorical annotation groups.
vmaxNoThe value representing the upper limit of the color scale.
vminNoThe value representing the lower limit of the color scale.
vcenterNoThe value representing the center of the color scale.
legend_fontsizeNoNumeric size in pt or string describing the size.
legend_fontweightNoLegend font weight. A numeric value in range 0-1000 or a string.bold
legend_locNoLocation of legend, either 'on data', 'right margin' or a valid keyword for the loc parameter.right margin
legend_fontoutlineNoLine width of the legend font outline in pt.
n_pcsNoNumber of PCs to show.
logNoPlot on logarithmic scale.

Implementation Reference

  • Generic handler function that executes the tool logic for pl_pca_variance_ratio by calling sc.pl.pca_variance_ratio with validated arguments, saves the figure, and logs the operation.
    def run_pl_func(ads, func, arguments):
        """
        Execute a Scanpy plotting function with the given arguments.
        
        Parameters
        ----------
        adata : AnnData
            Annotated data matrix.
        func : str
            Name of the plotting function to execute.
        arguments : dict
            Arguments to pass to the plotting function.
            
        Returns
        -------
        The result of the plotting function.
        """
        adata = ads.adata_dic[ads.active]
        if func not in pl_func:
            raise ValueError(f"Unsupported function: {func}")
    
        run_func = pl_func[func]
        parameters = inspect.signature(run_func).parameters
        kwargs = {k: arguments.get(k) for k in parameters if k in arguments}    
    
        if "title" not in parameters:
            kwargs.pop("title", False)    
        kwargs.pop("return_fig", True)
        kwargs["show"] = False
        kwargs["save"] = ".png"
        try:
            fig = run_func(adata, **kwargs)
            fig_path = set_fig_path(func, **kwargs)
            add_op_log(adata, run_func, kwargs)
            return fig_path 
        except Exception as e:
            raise e
        return fig_path
  • Pydantic model defining the input schema (parameters like n_pcs, log) for the pl_pca_variance_ratio tool.
    class PCAVarianceRatioModel(BaseVisualizationModel):
        """Input schema for the pca_variance_ratio plotting tool."""
        
        n_pcs: int = Field(
            default=30,
            description="Number of PCs to show.",
            gt=0
        )
        
        log: bool = Field(
            default=False,
            description="Plot on logarithmic scale."
        )
        
        @field_validator('n_pcs')
        def validate_n_pcs(cls, v: int) -> int:
            """Validate n_pcs is positive"""
            if v <= 0:
                raise ValueError("n_pcs must be a positive integer")
            return v
  • Creates the MCP types.Tool instance for pl_pca_variance_ratio, specifying name, description, and input schema.
    pl_pca_variance_ratio = types.Tool(
        name="pl_pca_variance_ratio",
        description="Plot the PCA variance ratio to visualize explained variance.",
        inputSchema=PCAVarianceRatioModel.model_json_schema(),
    )
  • Maps the tool name 'pl_pca_variance_ratio' to the underlying scanpy function sc.pl.pca_variance_ratio for execution.
    pl_func = {
        "pl_pca": sc.pl.pca,
        "pl_embedding": sc.pl.embedding,  # Add the new embedding function
        "diffmap": sc.pl.diffmap,
        "pl_violin": sc.pl.violin,
        "pl_stacked_violin": sc.pl.stacked_violin,
        "pl_heatmap": sc.pl.heatmap,
        "pl_dotplot": sc.pl.dotplot,
        "pl_matrixplot": sc.pl.matrixplot,
        "pl_tracksplot": sc.pl.tracksplot,
        "pl_scatter": sc.pl.scatter,
        "embedding_density": sc.pl.embedding_density,
        "rank_genes_groups": sc.pl.rank_genes_groups,
        "pl_rank_genes_groups_dotplot": sc.pl.rank_genes_groups_dotplot,  # Add function mapping
        "pl_clustermap": sc.pl.clustermap,
        "pl_highly_variable_genes": sc.pl.highly_variable_genes,
        "pl_pca_variance_ratio": sc.pl.pca_variance_ratio,
    }
  • In the MCP call_tool handler, checks if the tool name is in pl_tools and dispatches to run_pl_func.
    elif name in pl_tools.keys():
        res = run_pl_func(ads, name, arguments)
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'plot' implies a read-only visualization operation, the description doesn't specify whether this creates a new plot, modifies existing data, requires specific preconditions (like having PCA already computed), or what the output format is. For a visualization tool with 12 parameters, this is inadequate behavioral context.

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 gets straight to the point: 'Plot the PCA variance ratio to visualize explained variance.' There's no wasted language or unnecessary elaboration.

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 visualization tool with 12 parameters and no annotations or output schema, the description is insufficient. It doesn't explain what the tool actually produces (plot type, output format), what data it operates on, or any prerequisites. The context signals show this is a moderately complex tool (12 parameters) that needs more complete documentation.

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. The description adds no parameter-specific information beyond what's in the schema. According to the scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

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: 'Plot the PCA variance ratio to visualize explained variance.' It specifies the action (plot), the statistical concept (PCA variance ratio), and the visualization goal (explained variance). However, it doesn't differentiate from sibling tools like 'pl_pca' or 'pca' that might also handle PCA-related visualizations.

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 'pl_pca', 'pca', and various other plotting tools, there's no indication of when this specific variance ratio visualization is appropriate versus other PCA visualizations or analysis tools.

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