pl_rank_genes_groups_dotplot
Visualize ranked differentially expressed genes (DEGs) using dot plots to analyze gene expression patterns across groups. Configure color maps, gene lists, and group comparisons for detailed insights in single-cell RNA sequencing studies.
Instructions
Plot ranking of genes(DEGs) using dotplot visualization. Defualt plot DEGs for rank_genes_groups tool
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| color_map | No | Color map to use for continuous variables. | |
| dendrogram | No | If True or a valid dendrogram key, a dendrogram based on the hierarchical clustering between the groupby categories is added. | |
| figsize | No | Figure size. Format is (width, height). | |
| gene_symbols | No | Column name in .var DataFrame that stores gene symbols. | |
| groupby | Yes | The key of the observation grouping to consider. | |
| groups | No | The groups for which to show the gene ranking. | |
| key | No | Key used to store the ranking results in adata.uns. | |
| 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 |
| log | No | Plot on logarithmic axis. | |
| min_logfoldchange | No | Value to filter genes in groups if their logfoldchange is less than the min_logfoldchange. | |
| n_genes | No | Number of genes to show. This can be a negative number to show down regulated genes. Ignored if var_names is passed. | |
| palette | No | Colors to use for plotting categorical annotation groups. | |
| use_raw | No | Use raw attribute of adata if present. | |
| values_to_plot | No | Instead of the mean gene value, plot the values computed by sc.rank_genes_groups. | |
| var_group_labels | No | Labels for each of the var_group_positions that want to be highlighted. | |
| var_group_positions | No | Use this parameter to highlight groups of var_names with brackets or color blocks between the given start and end positions. | |
| var_names | No | Genes to plot. Sometimes is useful to pass a specific list of var names (e.g. genes) to check their fold changes or p-values | |
| 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-216 (handler)Handler function that executes the tool logic by dispatching to scanpy's sc.pl.rank_genes_groups_dotplot via pl_func mapping, processes arguments, generates the plot, saves 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
- src/scmcp/schema/pl.py:839-871 (schema)Pydantic model defining the input schema (parameters and validation) for the pl_rank_genes_groups_dotplot tool.class RankGenesGroupsDotplotModel(BaseMatrixModel): """Input schema for the rank_genes_groups_dotplot plotting tool.""" groups: Optional[Union[str, List[str]]] = Field( default=None, description="The groups for which to show the gene ranking." ) n_genes: Optional[int] = Field( default=None, description="Number of genes to show. This can be a negative number to show down regulated genes. Ignored if var_names is passed." ) values_to_plot: Optional[Literal['scores', 'logfoldchanges', 'pvals', 'pvals_adj', 'log10_pvals', 'log10_pvals_adj']] = Field( default=None, description="Instead of the mean gene value, plot the values computed by sc.rank_genes_groups." ) min_logfoldchange: Optional[float] = Field( default=None, description="Value to filter genes in groups if their logfoldchange is less than the min_logfoldchange." ) key: Optional[str] = Field( default=None, description="Key used to store the ranking results in adata.uns." ) var_names: Union[List[str], Mapping[str, List[str]]] = Field( default=None, description="Genes to plot. Sometimes is useful to pass a specific list of var names (e.g. genes) to check their fold changes or p-values" ) @field_validator('n_genes') def validate_n_genes(cls, v: Optional[int]) -> Optional[int]: """Validate n_genes""" # n_genes can be positive or negative, so no validation needed return v
- src/scmcp/tool/pl.py:141-159 (registration)pl_tools dictionary registers the Tool instances (schemas) for pl_ tools, including pl_rank_genes_groups_dotplot, exposed via tool/__init__.py for MCP server registration.pl_tools = { "pl_pca": pl_pca_tool, "pl_embedding": pl_embedding, # Add the new embedding tool # "diffmap": diffmap, "pl_violin": pl_violin, "pl_stacked_violin": pl_stacked_violin, "pl_heatmap": pl_heatmap, "pl_dotplot": pl_dotplot, "pl_matrixplot": pl_matrixplot, "pl_tracksplot": pl_tracksplot, "pl_scatter": pl_scatter, # "embedding_density": embedding_density, # "spatial": spatial, # "rank_genes_groups": rank_genes_groups, "pl_rank_genes_groups_dotplot": pl_rank_genes_groups_dotplot, # Add tool mapping # "pl_clustermap": pl_clustermap, "pl_highly_variable_genes": pl_highly_variable_genes, "pl_pca_variance_ratio": pl_pca_variance_ratio, }
- src/scmcp/tool/pl.py:121-138 (registration)pl_func dictionary maps tool names to the corresponding scanpy plotting functions for dispatch in the handler.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, }
- src/scmcp/util.py:29-58 (helper)Utility function set_fig_path with special case for pl_rank_genes_groups_dotplot to handle figure file path and renaming.def set_fig_path(func, **kwargs): fig_dir = Path(os.getcwd()) / "figures" if func == "pl_rank_genes_groups_dotplot": old_path = fig_dir / 'dotplot_.png' fig_path = fig_dir / f"{func[3:]}.png" elif func in ["pl_scatter", "pl_embedding"]: if "basis" in kwargs and kwargs['basis'] is not None: old_path = fig_dir / f"{kwargs['basis']}.png" fig_path = fig_dir / f"{func[3:]}_{kwargs['basis']}.png" else: old_path = fig_dir / f"{func[3:]}_.png" fig_path = fig_dir / f"{func[3:]}.png" try: os.rename(old_path, fig_path) except FileNotFoundError: print(f"The file {old_path} does not exist") except FileExistsError: print(f"The file {fig_path} already exists") except PermissionError: print("You don't have permission to rename this file") if os.environ.get("SCMCP_TRANSPORT") == "stdio": return fig_path else: host = os.environ.get("SCMCP_HOST") port = os.environ.get("SCMCP_PORT") fig_path = f"http://{host}:{port}/figures/{Path(fig_path).name}" return fig_path