Skip to main content
Glama

diffmap

Apply diffusion maps to reduce dimensionality in single-cell RNA sequencing data, enabling visualization and analysis of high-dimensional biological datasets.

Instructions

Diffusion Maps for dimensionality reduction

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
n_compsNoThe number of dimensions of the representation.
neighbors_keyNoIf not specified, diffmap looks .uns['neighbors'] for neighbors settings and .obsp['connectivities'], .obsp['distances'] for connectivities and distances respectively. If specified, diffmap looks .uns[neighbors_key] for neighbors settings and uses the corresponding connectivities and distances.
random_stateNoRandom seed for reproducibility.

Implementation Reference

  • Handler function that executes the tool logic for 'diffmap' by dispatching to sc.tl.diffmap with input arguments, adds operation log, and handles errors.
    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 rules for the 'diffmap' tool.
    class DiffMapModel(JSONParsingModel):
        """Input schema for the Diffusion Maps dimensionality reduction tool."""
        
        n_comps: int = Field(
            default=15,
            description="The number of dimensions of the representation.",
            gt=0
        )
        neighbors_key: Optional[str] = Field(
            default=None,
            description=(
                "If not specified, diffmap looks .uns['neighbors'] for neighbors settings "
                "and .obsp['connectivities'], .obsp['distances'] for connectivities and "
                "distances respectively. If specified, diffmap looks .uns[neighbors_key] for "
                "neighbors settings and uses the corresponding connectivities and distances."
            )
        )
        random_state: int = Field(
            default=0,
            description="Random seed for reproducibility."
        )
        
        @field_validator('n_comps')
        def validate_positive_integers(cls, v: int) -> int:
            """Validate positive integers"""
            if v <= 0:
                raise ValueError("n_comps must be a positive integer")
            return v
  • Registration of the 'diffmap' tool as an MCP Tool object with name, description, and reference to the input schema.
    # Add diffmap tool
    diffmap_tool = types.Tool(
        name="diffmap",
        description="Diffusion Maps for dimensionality reduction",
        inputSchema=DiffMapModel.model_json_schema(),
    )
  • Mapping from tool name 'diffmap' to the underlying scanpy function sc.tl.diffmap used by the handler.
    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,
    }
  • MCP server list_tools method that includes tl_tools.values(), thereby registering the 'diffmap' tool when MODULE includes 'tl'.
    @server.list_tools()
    async def list_tools() -> list[types.Tool]:
        if MODULE == "io":
            tools = io_tools.values()
        elif MODULE == "pp":
            tools = pp_tools.values()
        elif MODULE == "tl":
            tools = tl_tools.values()
        elif MODULE == "pl":
            tools = pl_tools.values()
        elif MODULE == "util":
            tools = util_tools.values()
        else:
            tools = [
                *io_tools.values(),
                *pp_tools.values(),
                *tl_tools.values(),
                *pl_tools.values(),
                *util_tools.values(),
                *ccc_tools.values(),
            ]
        return 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