pl_pca
Visualize PCA components in scatter plots to analyze single-cell RNA sequencing data, with customizable figure size, color mapping, and annotations for easy interpretation.
Instructions
Scatter plot in PCA coordinates. default figure for PCA plot
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| add_outline | No | Add outline to scatter plot points. | |
| annotate_var_explained | No | Annotate the explained variance. | |
| arrows | No | Show arrows. | |
| color | No | Keys for annotations of observations/cells or variables/genes. | |
| color_map | No | Color map to use for continuous variables. | |
| components | No | For instance, ['1,2', '2,3']. To plot all available components use components='all'. | |
| dimensions | No | 0-indexed dimensions of the embedding to plot as integers. E.g. [(0, 1), (1, 2)]. | |
| edges | No | Show edges between nodes. | |
| edges_color | No | Color of edges. | grey |
| edges_width | No | Width of edges. | |
| figsize | No | Figure size. Format is (width, height). | |
| frameon | No | Draw a frame around the scatter plot. | |
| gene_symbols | No | Column name in .var DataFrame that stores gene symbols. | |
| groups | No | Restrict to a few categories in categorical observation annotation. | |
| layer | No | Name of the AnnData object layer that wants to be plotted. | |
| legend_fontoutline | No | Line width of the legend font outline in pt. | |
| legend_fontsize | No | Numeric size in pt or string describing the size. | |
| legend_fontweight | No | Legend font weight. A numeric value in range 0-1000 or a string. | bold |
| legend_loc | No | Location of legend, either 'on data', 'right margin' or a valid keyword for the loc parameter. | right margin |
| marker | No | Matplotlib marker style for points. | . |
| ncols | No | Number of columns for multiple plots. | |
| neighbors_key | No | Where to look for neighbors connectivities. | |
| palette | No | Colors to use for plotting categorical annotation groups. | |
| projection | No | Projection of plot. | 2d |
| size | No | Point size. If None, is automatically computed. | |
| sort_order | No | For continuous annotations used as color parameter, plot data points with higher values on top of others. | |
| use_raw | No | Use .raw attribute of adata for coloring with gene expression. | |
| vcenter | No | The value representing the center of the color scale. | |
| vmax | No | The value representing the upper limit of the color scale. | |
| vmin | No | The value representing the lower limit of the color scale. |
Implementation Reference
- src/scmcp/tool/pl.py:179-217 (handler)The run_pl_func function is the handler that executes the 'pl_pca' tool. It looks up sc.pl.pca from the pl_func dictionary based on the tool name, processes arguments, calls the plotting function on the active AnnData, saves the figure, logs the operation, and returns the figure path.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
- src/scmcp/schema/pl.py:751-758 (schema)PCAModel defines the input schema for the pl_pca tool, inheriting from BaseEmbeddingModel which provides common embedding plot parameters like color, components, use_raw, etc., with an additional annotate_var_explained field.class PCAModel(BaseEmbeddingModel): """Input schema for the PCA plotting tool.""" annotate_var_explained: bool = Field( default=False, description="Annotate the explained variance." )
- src/scmcp/tool/pl.py:15-19 (registration)Creation of the pl_pca_tool object using mcp.types.Tool, specifying name, description, and input schema from PCAModel.pl_pca_tool = types.Tool( name="pl_pca", description="Scatter plot in PCA coordinates. default figure for PCA plot", inputSchema=PCAModel.model_json_schema(), )
- src/scmcp/tool/pl.py:142-142 (registration)Inclusion of pl_pca_tool in the pl_tools dictionary, which collects all plotting tools for further registration in the MCP server."pl_pca": pl_pca_tool,
- src/scmcp/tool/pl.py:121-138 (helper)pl_func dictionary maps tool names like 'pl_pca' to the corresponding scanpy plotting functions (sc.pl.pca), used by the handler to dispatch 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, }