filter_cells
Filter single-cell RNA sequencing data by setting thresholds for gene expression counts and number of genes expressed to identify high-quality cells for analysis.
Instructions
Filter cells based on counts and numbers of genes expressed.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "filter_cells"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| min_counts | No | Minimum number of counts required for a cell to pass filtering. | |
| min_genes | No | Minimum number of genes expressed required for a cell to pass filtering. | |
| max_counts | No | Maximum number of counts required for a cell to pass filtering. | |
| max_genes | No | Maximum number of genes expressed required for a cell to pass filtering. |
Implementation Reference
- src/scmcp/tool/pp.py:120-137 (handler)Generic handler function for all preprocessing tools, including filter_cells. Retrieves the scanpy function from pp_func, prepares arguments with inplace=True, executes on active adata, handles exceptions, and logs the operation.
def run_pp_func(ads, func, arguments): adata = ads.adata_dic[ads.active] if func not in pp_func: raise ValueError(f"不支持的函数: {func}") run_func = pp_func[func] parameters = inspect.signature(run_func).parameters arguments["inplace"] = True 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 KeyError as e: raise KeyError(f"Can not foud {e} column in adata.obs or adata.var") except Exception as e: raise e return res - src/scmcp/schema/pp.py:15-44 (schema)Pydantic model defining the input parameters and validation for the filter_cells tool.
class FilterCells(JSONParsingModel): """Input schema for the filter_cells preprocessing tool.""" min_counts: Optional[int] = Field( default=None, description="Minimum number of counts required for a cell to pass filtering." ) min_genes: Optional[int] = Field( default=None, description="Minimum number of genes expressed required for a cell to pass filtering." ) max_counts: Optional[int] = Field( default=None, description="Maximum number of counts required for a cell to pass filtering." ) max_genes: Optional[int] = Field( default=None, description="Maximum number of genes expressed required for a cell to pass filtering." ) @field_validator('min_counts', 'min_genes', 'max_counts', 'max_genes') def validate_positive_integers(cls, v: Optional[int]) -> Optional[int]: """验证整数参数为正数""" if v is not None and v <= 0: raise ValueError("过滤参数必须是正整数") return v - src/scmcp/tool/pp.py:15-19 (registration)Creates the MCP types.Tool instance for filter_cells, specifying name, description, and input schema.
filter_cells = types.Tool( name="filter_cells", description="Filter cells based on counts and numbers of genes expressed.", inputSchema=FilterCells.model_json_schema(), ) - src/scmcp/tool/pp.py:106-106 (registration)Registers the filter_cells Tool object in the pp_tools dictionary, which is exposed via server.list_tools().
"filter_cells": filter_cells, - src/scmcp/tool/pp.py:90-90 (helper)Maps the 'filter_cells' tool name to scanpy's sc.pp.filter_cells function used by the handler.
"filter_cells": sc.pp.filter_cells,