diffmap
Reduce data dimensionality using Diffusion Maps on the SCMCP server. Specify components, neighbors, and random states for precise, reproducible single-cell RNA sequencing analysis.
Instructions
Diffusion Maps for dimensionality reduction
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| n_comps | No | The number of dimensions of the representation. | |
| neighbors_key | No | 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 | No | Random seed for reproducibility. |
Implementation Reference
- src/scmcp/tool/tl.py:164-177 (handler)Handler function that executes tl tools including diffmap by dynamically calling sc.tl.diffmap with validated arguments on the active AnnData object.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
- src/scmcp/schema/tl.py:209-237 (schema)Pydantic model defining the input schema for the diffmap tool, including parameters like n_comps, neighbors_key, random_state with validation.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
- src/scmcp/tool/tl.py:145-162 (registration)Registration of the diffmap tool in the tl_tools dictionary, mapping 'diffmap' to the Tool instance with schema.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, }
- src/scmcp/tool/tl.py:125-142 (registration)Mapping of 'diffmap' tool name 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, }
- src/scmcp/tool/tl.py:33-38 (registration)Creation of the MCP Tool instance for diffmap with name, description, and input schema from DiffMapModel.# Add diffmap tool diffmap_tool = types.Tool( name="diffmap", description="Diffusion Maps for dimensionality reduction", inputSchema=DiffMapModel.model_json_schema(), )