pl_violin
Create violin plots to visualize distribution patterns of single-cell RNA sequencing variables, enabling comparison across groups with customizable aesthetics and statistical insights.
Instructions
Plot violin plot of one or more variables.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| figsize | No | Figure size. Format is (width, height). | |
| color_map | No | Color map to use for continuous variables. | |
| palette | No | Colors to use for plotting categorical annotation groups. | |
| vmax | No | The value representing the upper limit of the color scale. | |
| vmin | No | The value representing the lower limit of the color scale. | |
| vcenter | No | The value representing the center of the color scale. | |
| 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 |
| legend_fontoutline | No | Line width of the legend font outline in pt. | |
| groupby | No | The key of the observation grouping to consider. | |
| log | No | Plot on logarithmic axis. | |
| use_raw | No | Use raw attribute of adata if present. | |
| var_names | No | var_names should be a valid subset of adata.var_names. | |
| layer | No | Name of the AnnData object layer that wants to be plotted. | |
| gene_symbols | No | Column name in .var DataFrame that stores gene symbols. | |
| stripplot | No | Add a stripplot on top of the violin plot. | |
| jitter | No | Add jitter to the stripplot (only when stripplot is True). | |
| size | No | Size of the jitter points. | |
| order | No | Order in which to show the categories. | |
| scale | No | The method used to scale the width of each violin. | width |
| keys | Yes | Keys for accessing variables of .var_names or fields of .obs. | |
| multi_panel | No | Display keys in multiple panels also when groupby is not None. | |
| xlabel | No | Label of the x axis. Defaults to groupby if rotation is None, otherwise, no label is shown. | |
| ylabel | No | Label of the y axis. | |
| rotation | No | Rotation of xtick labels. |
Implementation Reference
- src/scmcp/tool/pl.py:179-216 (handler)Handler function that executes the pl_violin tool by dispatching to sc.pl.violin with processed arguments, handles figure saving and logging.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:426-478 (schema)Pydantic model defining the input schema and validation for the pl_violin tool.class ViolinModel(BaseStatPlotModel): """Input schema for the violin plotting tool.""" keys: Union[str, List[str]] = Field( ..., # Required field description="Keys for accessing variables of .var_names or fields of .obs." ) stripplot: bool = Field( default=True, description="Add a stripplot on top of the violin plot." ) jitter: Union[float, bool] = Field( default=True, description="Add jitter to the stripplot (only when stripplot is True)." ) size: int = Field( default=1, description="Size of the jitter points.", gt=0 ) scale: Literal['area', 'count', 'width'] = Field( default='width', description="The method used to scale the width of each violin." ) order: Optional[List[str]] = Field( default=None, description="Order in which to show the categories." ) multi_panel: Optional[bool] = Field( default=None, description="Display keys in multiple panels also when groupby is not None." ) xlabel: str = Field( default='', description="Label of the x axis. Defaults to groupby if rotation is None, otherwise, no label is shown." ) ylabel: Optional[Union[str, List[str]]] = Field( default=None, description="Label of the y axis." ) rotation: Optional[float] = Field( default=None, description="Rotation of xtick labels." ) @field_validator('size') def validate_size(cls, v: int) -> int: """Validate size is positive""" if v <= 0: raise ValueError("size must be a positive integer") return v
- src/scmcp/tool/pl.py:29-33 (registration)Definition of the pl_violin Tool object, including attachment of the input schema.pl_violin = types.Tool( name="pl_violin", description="Plot violin plot of one or more variables.", inputSchema=ViolinModel.model_json_schema(), )
- src/scmcp/tool/pl.py:125-125 (registration)Mapping of 'pl_violin' to the underlying Scanpy function sc.pl.violin in the pl_func dispatch dictionary."pl_violin": sc.pl.violin,
- src/scmcp/tool/pl.py:145-145 (registration)Registration of the pl_violin tool in the pl_tools dictionary, used by server.list_tools()."pl_violin": pl_violin,
- src/scmcp/server.py:71-72 (registration)MCP server call_tool handler dispatches pl_violin (and other pl_tools) to run_pl_func.elif name in pl_tools.keys(): res = run_pl_func(ads, name, arguments)