[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6DTK0RTFEEFD1P31P17VXQQ":3,"skill-same:01M6DTK0RTFEEFD1P31P17VXQQ":203},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":47,"commitSha":48,"skillDirectory":49,"forksCount":50,"repositoryHtmlUrl":51,"repositoryHomepageUrl":52,"ownerHtmlUrl":53,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":54,"install":55,"resources":68},"01M6DTK0RTFEEFD1P31P17VXQQ","sc-preprocessing",null,"Load when normalising QC'd scRNA into a PCA-ready AnnData via scanpy \u002F Seurat \u002F SCTransform \u002F Pearson residuals. Skip when QC thresholds are still undecided (use sc-qc); batch correction across samples (use sc-batch-integration).","TianGzlab\u002FOmicsClaw","TianGzlab","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F150978281?v=4","01M6DT9WNJJ470ADHPSMFAA02Y","01M6DT9WSN09C5K65GB6RK18R9",161,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"sc preprocessing","preprocessing","PCA","pearson_residuals","sctransform","seurat","hvg","singlecell","single cell","thresholds","qc","batch","normalize","across","base","ready","use","normalization","scanpy","integration","2026-11-10 10:12:30",false,"---\nname: sc-preprocessing\ndescription: Load when normalising QC'd scRNA into a PCA-ready AnnData via scanpy \u002F Seurat \u002F SCTransform\n  \u002F Pearson residuals. Skip when QC thresholds are still undecided (use sc-qc); batch correction across\n  samples (use sc-batch-integration).\ntrigger: single cell preprocess, scRNA preprocessing, normalize hvg pca, base preprocessing, Seurat preprocessing, SCTransform preprocessing\ntags:\n- singlecell\n- scrna\n- preprocessing\n- normalization\n- hvg\n- pca\n- scanpy\n- seurat\n- sctransform\n- pearson_residuals\n---\n\n# sc-preprocessing\n\n## When to use\n\nThe user has a QC'd AnnData and wants the standard\n\"filter → normalise → HVG → PCA\" pipeline before clustering or batch\nintegration. Four interchangeable backends are available: `scanpy`\n(default; CP10k log + HVG seurat flavour), `seurat` (R-backed\nLogNormalize \u002F CLR \u002F RC), `sctransform` (R-backed regularised NB), and\n`pearson_residuals` (raw-count HVG selection plus Pearson residual\ntransformation). The skill stops at PCA — UMAP \u002F clustering live in\n`sc-clustering`, multi-sample correction in `sc-batch-integration`.\n\n## Use from a step\n\n```python\npre = load_skill(\"sc-preprocessing\")\nadata = read_input(\"results\u002F01_qc\u002Fintermediate\u002Fadata_qc.h5ad\")\n# max_mt_pct 10: PBMC cells above 10% mitochondrial reads are mostly damaged (agreed with the user).\nadata = pre.preprocess(adata, method=\"scanpy\", max_mt_pct=10.0)\nwrite_output(pre.run_info(adata)[\"filter_summary\"], \"tables\u002Ffilter_summary.json\")\nwrite_output(pre.pca_variance_table(adata), \"tables\u002Fpca_variance_ratio.csv\")\nwrite_output(adata, \"intermediate\u002Fadata_preprocessed.h5ad\")\n```\n\nA complete step that runs on demo data: `examples\u002Fexample_step.py`.\n\nIf the input already passed through `sc-filter`, use\n`preprocess(adata, apply_filters=False)`. This preserves that step's retained\ncells and genes, including its doublet decision, while normalization, HVG\nselection and PCA still run.\n\n## API\n\n\u003C!-- api:begin generated from _api.py; regenerate with run.py api \u003Cskill dir> --write -->\n\n### `preprocess(adata, *, method: str='scanpy', apply_filters: bool=True, min_genes: int=200, min_cells: int=3, max_mt_pct: float=20.0, n_top_hvg: int | None=None, n_pcs: int=50, normalization_target_sum: float=10000.0, scanpy_hvg_flavor: str='seurat', pearson_hvg_flavor: str='seurat_v3', pearson_theta: float=100.0, seurat_normalize_method: str='LogNormalize', seurat_scale_factor: float=10000.0, seurat_hvg_method: str='vst', sctransform_regress_mt: bool=True, remove_doublets: bool=True, doublet_score_threshold: float=0.25, preserve_var_names: bool=False)`\n\nFilter cells and genes, normalise, select highly variable genes and run PCA.\n\nThe input is first brought into the OmicsClaw scRNA contract (counts in\n``layers['counts']``, a counts snapshot in ``raw``) and QC metrics are added\nwhen missing. With apply_filters=True, cells and genes are filtered by the thresholds below,\nand doublets are dropped when ``predicted_doublet`` or ``doublet_score``\nfrom sc-doublet-detection are in ``obs``. Finally the chosen method\nnormalises ``X``, flags ``var['highly_variable']`` and writes\n``obsm['X_pca']``. What was filtered is recorded for :func:`run_info`.\n\n:param method: ``\"scanpy\"`` (normalize_total, log1p, HVG, PCA; the default),\n    ``\"pearson_residuals\"`` (analytic Pearson residuals for HVG and PCA; ``X``\n    stays log-normalised), ``\"seurat\"`` (Seurat LogNormalize in R) or\n    ``\"sctransform\"`` (Seurat SCTransform in R).\n:param apply_filters: Apply cell, gene and doublet filtering. Default True.\n    Set False after sc-filter to preserve its retained cells and genes.\n:param min_genes: Drop cells with fewer detected genes. Default 200, the\n    scanpy and Seurat tutorial value; lower it for low-depth data.\n:param min_cells: Drop genes detected in fewer cells. Default 3, the tutorial value.\n:param max_mt_pct: Drop cells above this mitochondrial percentage. Default 20.0,\n    a permissive threshold; PBMC data usually uses 5 to 10. Agree it with the user.\n:param n_top_hvg: Number of highly variable genes. Default ``None``: 3000 for\n    ``sctransform``, 2000 for the other methods (their tutorials' values).\n:param n_pcs: Principal components to compute. Default 50.\n:param normalization_target_sum: Counts per cell after ``normalize_total``\n    (``scanpy`` only). Default 10000.\n:param scanpy_hvg_flavor: HVG flavor for ``scanpy``: ``\"seurat\"`` (default),\n    ``\"cell_ranger\"`` or ``\"seurat_v3\"``.\n:param pearson_hvg_flavor: HVG flavor for ``pearson_residuals``. Default ``\"seurat_v3\"``.\n:param pearson_theta: Overdispersion for Pearson residuals. Default 100, scanpy's default.\n:param seurat_normalize_method: Seurat ``NormalizeData`` method. Default ``\"LogNormalize\"``.\n:param seurat_scale_factor: Seurat scale factor. Default 10000.\n:param seurat_hvg_method: Seurat ``FindVariableFeatures`` method. Default ``\"vst\"``.\n:param sctransform_regress_mt: Regress out mitochondrial percentage in SCTransform. Default ``True``.\n:param remove_doublets: Drop cells flagged as doublets when the flags are present. Default ``True``.\n:param doublet_score_threshold: Score above which a cell counts as a doublet when only\n    ``doublet_score`` is present. Default 0.25.\n:param preserve_var_names: Keep the input's gene identifiers instead of the\n    symbols chosen during standardisation. Default ``False``.\n:returns: A new AnnData with normalised ``X``, ``layers['counts']``, ``raw``\n    counts snapshot, ``var['highly_variable']``, ``obsm['X_pca']``, ``uns['pca']``.\n:raises ValueError: an unknown method, or input with no count-like matrix.\n:raises RuntimeError: the R methods fail, or their R packages are missing.\n\n### `run_info(adata, *, keep: bool=True) -> dict`\n\nWhat :func:`preprocess` recorded about its run.\n\nKeys: ``method``; ``filter_summary`` (cells and genes before and after\nfiltering, cells removed by each threshold under ``filter_stats``, whether QC\nmetrics were reused, and ``input_preparation``: the matrix used as counts,\ngene-name source, warnings and inferred species); ``input_contract``;\n``matrix_contract``.\n\n:param keep: Leave the record in ``adata.uns``; ``False`` removes it.\n:returns: The record, or an empty dict when ``preprocess`` has not run on *adata*.\n\n### `hvg_table(adata, *, n_top: int=50) -> pd.DataFrame`\n\nThe most variable genes with their mean and dispersion statistics.\n\n:param n_top: How many genes to return, most variable first. Default 50.\n:returns: Column ``gene`` plus whichever of ``means``, ``variances``,\n    ``variances_norm``, ``dispersions``, ``dispersions_norm`` the method wrote.\n\n### `pca_variance_table(adata) -> pd.DataFrame`\n\nVariance explained by each principal component, to choose how many to keep downstream.\n\n:returns: Columns ``pc``, ``variance_ratio`` and ``cumulative_variance_ratio``.\n\n### `pca_embedding_table(adata, *, n_components: int=5) -> pd.DataFrame`\n\nThe first principal-component coordinates of every cell.\n\n:param n_components: How many components to include. Default 5.\n:returns: Column ``cell_id`` followed by ``PC1``, ``PC2``, ...\n\n### `qc_metrics_table(adata) -> pd.DataFrame`\n\nThe QC metrics of the cells that passed filtering.\n\n:returns: Column ``cell_id`` followed by whichever of ``n_genes_by_counts``,\n    ``total_counts`` and ``pct_counts_mt`` are in ``obs``.\n\n### `pca_variance_figure(adata, *, n_pcs: int=50)`\n\nAn elbow plot of the variance ratio per principal component.\n\n:param n_pcs: How many components to show. Default 50.\n:returns: A matplotlib Figure.\n:raises KeyError: ``uns['pca']`` is missing; run :func:`preprocess` first.\n\n\u003C!-- api:end -->\n\n## Methods and parameters\n\n| Method | Use when | Notes |\n|---|---|---|\n| `scanpy` (default) | most 10x data | `normalize_total` to 10,000, `log1p`, HVG (`seurat` flavor), PCA with `arpack` |\n| `pearson_residuals` | very sparse or heterogeneous data | HVG and PCA on analytic Pearson residuals (Lause et al. 2021); `X` stays log-normalised for plotting and DE |\n| `seurat` | the user wants Seurat's LogNormalize numbers | runs `Rscript`; needs Seurat, SingleCellExperiment, zellkonverter, rhdf5 |\n| `sctransform` | the user wants SCTransform | runs `Rscript`; also needs sctransform; 3,000 HVGs by default |\n\nDefaults and where they come from:\n\n- `min_genes=200`, `min_cells=3`: the scanpy and Seurat PBMC tutorials. Lower `min_genes` for low-depth or nuclei data.\n- `max_mt_pct=20.0`: a permissive ceiling, not a recommendation. Read sc-qc's `pct_counts_mt` distribution and agree the value with the user; PBMC usually uses 5 to 10, tissues with high metabolic activity more.\n- `n_top_hvg`: 2,000 (3,000 for `sctransform`), the tutorials' values. Raise it for very heterogeneous data.\n- `n_pcs=50`: scanpy's default upper bound; later steps choose how many to use from `pca_variance_table`.\n- `remove_doublets=True`, `doublet_score_threshold=0.25`: only act when sc-doublet-detection columns are in `obs`.\n\nEvery threshold you change goes into the step with its reason.\n\n## Gotchas\n\n- **`preprocess` returns a new, filtered object.** Keep the return value; cells and genes below the thresholds are gone from it, and `run_info(adata)[\"filter_summary\"]` says how many each threshold removed.\n- **Fewer PCs than requested.** Small matrices cap `obsm[\"X_pca\"]` below `n_pcs`; use `adata.obsm[\"X_pca\"].shape[1]` when you pass `n_pcs` to sc-clustering.\n- **R methods need a working `Rscript` stack.** `preprocess(method=\"seurat\")` raises `RuntimeError` when the R packages are missing or when the R round-trip returns no overlapping cells or genes. Check `Rscript` before choosing them.\n- **Doublets are dropped whenever sc-doublet-detection ran.** Pass `remove_doublets=False` to keep the called doublets.\n- **`X` is normalised, not counts.** Raw counts stay in `layers[\"counts\"]` and `raw`; methods that need counts (pseudobulk DE) read them from there.\n\n## Inputs and outputs\n\n- Reads the count matrix from `layers['counts']`, `raw` or `X` (as sc-qc does) and the QC columns of `obs` when present.\n- Writes a new AnnData: normalised `X`; `layers['counts']`; `raw` (counts snapshot); `obs` QC columns; `var['highly_variable']` and the HVG statistics; `obsm['X_pca']`; `uns['pca']`; `layers['pearson_residuals']` for that method; contract entries in `uns`.\n- The table functions return DataFrames; `pca_variance_figure` returns a matplotlib Figure.\n\n## CLI\n\n`sc_preprocess.py` runs the same functions outside a project and writes a\nreport, figures, tables and `processed.h5ad`:\n`python \u003Cskill directory>\u002Fsc_preprocess.py --help`. `--demo` runs it on PBMC3k.\n\n## See also\n\n- `references\u002Fparameters.md` — every CLI flag and per-method tuning hint\n- `references\u002Fmethodology.md` — when each backend wins; canonicalisation contract\n- `references\u002Foutput_contract.md` — `obs` \u002F `obsm` \u002F `layers` \u002F `uns` schema + the CLI's table layouts\n- Adjacent skills: `sc-qc` \u002F `sc-filter` (upstream — produce the input), `sc-batch-integration` (parallel — multi-sample alternative path; consumes `obsm[\"X_pca\"]`), `sc-clustering` (downstream — consumes `obsm[\"X_pca\"]` for neighbour-graph + UMAP + Leiden)\n\n## Dependencies\n\nPython packages this skill's script needs. They are not installed for you — check before a long run.\n\n`anndata`, `matplotlib`, `numpy`, `pandas`, `phate`, `scanpy`, `scipy`, `seaborn`\n","# sc-preprocessing\n\n## When to use\n\nThe user has a QC'd AnnData and wants the standard\n\"filter → normalise → HVG → PCA\" pipeline before clustering or batch\nintegration. Four interchangeable backends are available: `scanpy`\n(default; CP10k log + HVG seurat flavour), `seurat` (R-backed\nLogNormalize \u002F CLR \u002F RC), `sctransform` (R-backed regularised NB), and\n`pearson_residuals` (raw-count HVG selection plus Pearson residual\ntransformation). The skill stops at PCA — UMAP \u002F clustering live in\n`sc-clustering`, multi-sample correction in `sc-batch-integration`.\n\n## Use from a step\n\n```python\npre = load_skill(\"sc-preprocessing\")\nadata = read_input(\"results\u002F01_qc\u002Fintermediate\u002Fadata_qc.h5ad\")\n# max_mt_pct 10: PBMC cells above 10% mitochondrial reads are mostly damaged (agreed with the user).\nadata = pre.preprocess(adata, method=\"scanpy\", max_mt_pct=10.0)\nwrite_output(pre.run_info(adata)[\"filter_summary\"], \"tables\u002Ffilter_summary.json\")\nwrite_output(pre.pca_variance_table(adata), \"tables\u002Fpca_variance_ratio.csv\")\nwrite_output(adata, \"intermediate\u002Fadata_preprocessed.h5ad\")\n```\n\nA complete step that runs on demo data: `examples\u002Fexample_step.py`.\n\nIf the input already passed through `sc-filter`, use\n`preprocess(adata, apply_filters=False)`. This preserves that step's retained\ncells and genes, including its doublet decision, while normalization, HVG\nselection and PCA still run.\n\n## API\n\n\u003C!-- api:begin generated from _api.py; regenerate with run.py api \u003Cskill dir> --write -->\n\n### `preprocess(adata, *, method: str='scanpy', apply_filters: bool=True, min_genes: int=200, min_cells: int=3, max_mt_pct: float=20.0, n_top_hvg: int | None=None, n_pcs: int=50, normalization_target_sum: float=10000.0, scanpy_hvg_flavor: str='seurat', pearson_hvg_flavor: str='seurat_v3', pearson_theta: float=100.0, seurat_normalize_method: str='LogNormalize', seurat_scale_factor: float=10000.0, seurat_hvg_method: str='vst', sctransform_regress_mt: bool=True, remove_doublets: bool=True, doublet_score_threshold: float=0.25, preserve_var_names: bool=False)`\n\nFilter cells and genes, normalise, select highly variable genes and run PCA.\n\nThe input is first brought into the OmicsClaw scRNA contract (counts in\n``layers['counts']``, a counts snapshot in ``raw``) and QC metrics are added\nwhen missing. With apply_filters=True, cells and genes are filtered by the thresholds below,\nand doublets are dropped when ``predicted_doublet`` or ``doublet_score``\nfrom sc-doublet-detection are in ``obs``. Finally the chosen method\nnormalises ``X``, flags ``var['highly_variable']`` and writes\n``obsm['X_pca']``. What was filtered is recorded for :func:`run_info`.\n\n:param method: ``\"scanpy\"`` (normalize_total, log1p, HVG, PCA; the default),\n    ``\"pearson_residuals\"`` (analytic Pearson residuals for HVG and PCA; ``X``\n    stays log-normalised), ``\"seurat\"`` (Seurat LogNormalize in R) or\n    ``\"sctransform\"`` (Seurat SCTransform in R).\n:param apply_filters: Apply cell, gene and doublet filtering. Default True.\n    Set False after sc-filter to preserve its retained cells and genes.\n:param min_genes: Drop cells with fewer detected genes. Default 200, the\n    scanpy and Seurat tutorial value; lower it for low-depth data.\n:param min_cells: Drop genes detected in fewer cells. Default 3, the tutorial value.\n:param max_mt_pct: Drop cells above this mitochondrial percentage. Default 20.0,\n    a permissive threshold; PBMC data usually uses 5 to 10. Agree it with the user.\n:param n_top_hvg: Number of highly variable genes. Default ``None``: 3000 for\n    ``sctransform``, 2000 for the other methods (their tutorials' values).\n:param n_pcs: Principal components to compute. Default 50.\n:param normalization_target_sum: Counts per cell after ``normalize_total``\n    (``scanpy`` only). Default 10000.\n:param scanpy_hvg_flavor: HVG flavor for ``scanpy``: ``\"seurat\"`` (default),\n    ``\"cell_ranger\"`` or ``\"seurat_v3\"``.\n:param pearson_hvg_flavor: HVG flavor for ``pearson_residuals``. Default ``\"seurat_v3\"``.\n:param pearson_theta: Overdispersion for Pearson residuals. Default 100, scanpy's default.\n:param seurat_normalize_method: Seurat ``NormalizeData`` method. Default ``\"LogNormalize\"``.\n:param seurat_scale_factor: Seurat scale factor. Default 10000.\n:param seurat_hvg_method: Seurat ``FindVariableFeatures`` method. Default ``\"vst\"``.\n:param sctransform_regress_mt: Regress out mitochondrial percentage in SCTransform. Default ``True``.\n:param remove_doublets: Drop cells flagged as doublets when the flags are present. Default ``True``.\n:param doublet_score_threshold: Score above which a cell counts as a doublet when only\n    ``doublet_score`` is present. Default 0.25.\n:param preserve_var_names: Keep the input's gene identifiers instead of the\n    symbols chosen during standardisation. Default ``False``.\n:returns: A new AnnData with normalised ``X``, ``layers['counts']``, ``raw``\n    counts snapshot, ``var['highly_variable']``, ``obsm['X_pca']``, ``uns['pca']``.\n:raises ValueError: an unknown method, or input with no count-like matrix.\n:raises RuntimeError: the R methods fail, or their R packages are missing.\n\n### `run_info(adata, *, keep: bool=True) -> dict`\n\nWhat :func:`preprocess` recorded about its run.\n\nKeys: ``method``; ``filter_summary`` (cells and genes before and after\nfiltering, cells removed by each threshold under ``filter_stats``, whether QC\nmetrics were reused, and ``input_preparation``: the matrix used as counts,\ngene-name source, warnings and inferred species); ``input_contract``;\n``matrix_contract``.\n\n:param keep: Leave the record in ``adata.uns``; ``False`` removes it.\n:returns: The record, or an empty dict when ``preprocess`` has not run on *adata*.\n\n### `hvg_table(adata, *, n_top: int=50) -> pd.DataFrame`\n\nThe most variable genes with their mean and dispersion statistics.\n\n:param n_top: How many genes to return, most variable first. Default 50.\n:returns: Column ``gene`` plus whichever of ``means``, ``variances``,\n    ``variances_norm``, ``dispersions``, ``dispersions_norm`` the method wrote.\n\n### `pca_variance_table(adata) -> pd.DataFrame`\n\nVariance explained by each principal component, to choose how many to keep downstream.\n\n:returns: Columns ``pc``, ``variance_ratio`` and ``cumulative_variance_ratio``.\n\n### `pca_embedding_table(adata, *, n_components: int=5) -> pd.DataFrame`\n\nThe first principal-component coordinates of every cell.\n\n:param n_components: How many components to include. Default 5.\n:returns: Column ``cell_id`` followed by ``PC1``, ``PC2``, ...\n\n### `qc_metrics_table(adata) -> pd.DataFrame`\n\nThe QC metrics of the cells that passed filtering.\n\n:returns: Column ``cell_id`` followed by whichever of ``n_genes_by_counts``,\n    ``total_counts`` and ``pct_counts_mt`` are in ``obs``.\n\n### `pca_variance_figure(adata, *, n_pcs: int=50)`\n\nAn elbow plot of the variance ratio per principal component.\n\n:param n_pcs: How many components to show. Default 50.\n:returns: A matplotlib Figure.\n:raises KeyError: ``uns['pca']`` is missing; run :func:`preprocess` first.\n\n\u003C!-- api:end -->\n\n## Methods and parameters\n\n| Method | Use when | Notes |\n|---|---|---|\n| `scanpy` (default) | most 10x data | `normalize_total` to 10,000, `log1p`, HVG (`seurat` flavor), PCA with `arpack` |\n| `pearson_residuals` | very sparse or heterogeneous data | HVG and PCA on analytic Pearson residuals (Lause et al. 2021); `X` stays log-normalised for plotting and DE |\n| `seurat` | the user wants Seurat's LogNormalize numbers | runs `Rscript`; needs Seurat, SingleCellExperiment, zellkonverter, rhdf5 |\n| `sctransform` | the user wants SCTransform | runs `Rscript`; also needs sctransform; 3,000 HVGs by default |\n\nDefaults and where they come from:\n\n- `min_genes=200`, `min_cells=3`: the scanpy and Seurat PBMC tutorials. Lower `min_genes` for low-depth or nuclei data.\n- `max_mt_pct=20.0`: a permissive ceiling, not a recommendation. Read sc-qc's `pct_counts_mt` distribution and agree the value with the user; PBMC usually uses 5 to 10, tissues with high metabolic activity more.\n- `n_top_hvg`: 2,000 (3,000 for `sctransform`), the tutorials' values. Raise it for very heterogeneous data.\n- `n_pcs=50`: scanpy's default upper bound; later steps choose how many to use from `pca_variance_table`.\n- `remove_doublets=True`, `doublet_score_threshold=0.25`: only act when sc-doublet-detection columns are in `obs`.\n\nEvery threshold you change goes into the step with its reason.\n\n## Gotchas\n\n- **`preprocess` returns a new, filtered object.** Keep the return value; cells and genes below the thresholds are gone from it, and `run_info(adata)[\"filter_summary\"]` says how many each threshold removed.\n- **Fewer PCs than requested.** Small matrices cap `obsm[\"X_pca\"]` below `n_pcs`; use `adata.obsm[\"X_pca\"].shape[1]` when you pass `n_pcs` to sc-clustering.\n- **R methods need a working `Rscript` stack.** `preprocess(method=\"seurat\")` raises `RuntimeError` when the R packages are missing or when the R round-trip returns no overlapping cells or genes. Check `Rscript` before choosing them.\n- **Doublets are dropped whenever sc-doublet-detection ran.** Pass `remove_doublets=False` to keep the called doublets.\n- **`X` is normalised, not counts.** Raw counts stay in `layers[\"counts\"]` and `raw`; methods that need counts (pseudobulk DE) read them from there.\n\n## Inputs and outputs\n\n- Reads the count matrix from `layers['counts']`, `raw` or `X` (as sc-qc does) and the QC columns of `obs` when present.\n- Writes a new AnnData: normalised `X`; `layers['counts']`; `raw` (counts snapshot); `obs` QC columns; `var['highly_variable']` and the HVG statistics; `obsm['X_pca']`; `uns['pca']`; `layers['pearson_residuals']` for that method; contract entries in `uns`.\n- The table functions return DataFrames; `pca_variance_figure` returns a matplotlib Figure.\n\n## CLI\n\n`sc_preprocess.py` runs the same functions outside a project and writes a\nreport, figures, tables and `processed.h5ad`:\n`python \u003Cskill directory>\u002Fsc_preprocess.py --help`. `--demo` runs it on PBMC3k.\n\n## See also\n\n- `references\u002Fparameters.md` — every CLI flag and per-method tuning hint\n- `references\u002Fmethodology.md` — when each backend wins; canonicalisation contract\n- `references\u002Foutput_contract.md` — `obs` \u002F `obsm` \u002F `layers` \u002F `uns` schema + the CLI's table layouts\n- Adjacent skills: `sc-qc` \u002F `sc-filter` (upstream — produce the input), `sc-batch-integration` (parallel — multi-sample alternative path; consumes `obsm[\"X_pca\"]`), `sc-clustering` (downstream — consumes `obsm[\"X_pca\"]` for neighbour-graph + UMAP + Leiden)\n\n## Dependencies\n\nPython packages this skill's script needs. They are not installed for you — check before a long run.\n\n`anndata`, `matplotlib`, `numpy`, `pandas`, `phate`, `scanpy`, `scipy`, `seaborn`\n",{"name":5,"tags":43,"trigger":46,"description":7},[25,44,19,35,24,45,36,23,22,21],"scrna","pca","single cell preprocess, scRNA preprocessing, normalize hvg pca, base preprocessing, Seurat preprocessing, SCTransform preprocessing","main","90a3bec3e6549bc33dddbf67e4b23869736c49d1","skills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing",27,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw","https:\u002F\u002FTianGzlab.github.io\u002FOmicsClaw\u002F","https:\u002F\u002Fgithub.com\u002FTianGzlab","2026-10-08 01:36:11",{"source":8,"skillName":5,"commands":56,"prompt":66,"zipAvailable":67},[57,60,63],{"tool":58,"command":59},"npx","npx skills add TianGzlab\u002FOmicsClaw --skill sc-preprocessing",{"tool":61,"command":62},"bunx","bunx skills add TianGzlab\u002FOmicsClaw --skill sc-preprocessing",{"tool":64,"command":65},"pnpm","pnpm dlx skills add TianGzlab\u002FOmicsClaw --skill sc-preprocessing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002FSKILL.md",true,[69,75,81,87,91,95,99,103,107,111,115,119,123,127,131,135,139,143,147,151,155,159,163,167,171,175,179,183,187,191,195,199],{"path":70,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":73,"sourceHtmlUrl":74},"_api.py","SCRIPT","脚本",23128,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002F_api.py",{"path":76,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":79,"sourceHtmlUrl":80},"data\u002Fdomain-complexity.csv","ASSET","资产文件",7324,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fdata\u002Fdomain-complexity.csv",{"path":82,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":85,"sourceHtmlUrl":86},"data\u002Fprd-purpose.md","REFERENCE","参考文档",7246,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fdata\u002Fprd-purpose.md",{"path":88,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":89,"sourceHtmlUrl":90},"data\u002Fproject-types.csv",3144,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fdata\u002Fproject-types.csv",{"path":92,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":93,"sourceHtmlUrl":94},"examples\u002Fexample_step.py",999,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Fexamples\u002Fexample_step.py",{"path":96,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":97,"sourceHtmlUrl":98},"references\u002Fmethodology.md",2637,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Freferences\u002Fmethodology.md",{"path":100,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":101,"sourceHtmlUrl":102},"references\u002Foutput_contract.md",3130,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Freferences\u002Foutput_contract.md",{"path":104,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":105,"sourceHtmlUrl":106},"references\u002Fparameters.md",2911,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Freferences\u002Fparameters.md",{"path":108,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":109,"sourceHtmlUrl":110},"references\u002Fr_visualization.md",622,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Freferences\u002Fr_visualization.md",{"path":112,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":113,"sourceHtmlUrl":114},"sc_preprocess.py",33682,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Fsc_preprocess.py",{"path":116,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":117,"sourceHtmlUrl":118},"steps-c\u002Fstep-01-init.md",7785,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-01-init.md",{"path":120,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":121,"sourceHtmlUrl":122},"steps-c\u002Fstep-01b-continue.md",5751,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-01b-continue.md",{"path":124,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":125,"sourceHtmlUrl":126},"steps-c\u002Fstep-02-discovery.md",8096,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-02-discovery.md",{"path":128,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":129,"sourceHtmlUrl":130},"steps-c\u002Fstep-02b-vision.md",6775,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-02b-vision.md",{"path":132,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":133,"sourceHtmlUrl":134},"steps-c\u002Fstep-02c-executive-summary.md",7250,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-02c-executive-summary.md",{"path":136,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":137,"sourceHtmlUrl":138},"steps-c\u002Fstep-03-success.md",9189,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-03-success.md",{"path":140,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":141,"sourceHtmlUrl":142},"steps-c\u002Fstep-04-journeys.md",9040,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-04-journeys.md",{"path":144,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":145,"sourceHtmlUrl":146},"steps-c\u002Fstep-05-domain.md",6919,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-05-domain.md",{"path":148,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":149,"sourceHtmlUrl":150},"steps-c\u002Fstep-06-innovation.md",8680,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-06-innovation.md",{"path":152,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":153,"sourceHtmlUrl":154},"steps-c\u002Fstep-07-project-type.md",8799,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-07-project-type.md",{"path":156,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":157,"sourceHtmlUrl":158},"steps-c\u002Fstep-08-scoping.md",7870,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-08-scoping.md",{"path":160,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":161,"sourceHtmlUrl":162},"steps-c\u002Fstep-09-functional.md",9199,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-09-functional.md",{"path":164,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":165,"sourceHtmlUrl":166},"steps-c\u002Fstep-10-nonfunctional.md",9000,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-10-nonfunctional.md",{"path":168,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":169,"sourceHtmlUrl":170},"steps-c\u002Fstep-11-polish.md",9329,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-11-polish.md",{"path":172,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":173,"sourceHtmlUrl":174},"steps-c\u002Fstep-12-complete.md",4861,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fsteps-c\u002Fstep-12-complete.md",{"path":176,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":177,"sourceHtmlUrl":178},"templates\u002Fprd-template.md",164,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Ftemplates\u002Fprd-template.md",{"path":180,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":181,"sourceHtmlUrl":182},"tests\u002F__init__.py",0,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Ftests\u002F__init__.py",{"path":184,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":185,"sourceHtmlUrl":186},"tests\u002Fomicbench_preprocessing.py",7491,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Ftests\u002Fomicbench_preprocessing.py",{"path":188,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":189,"sourceHtmlUrl":190},"tests\u002Ftest_apply_filters.py",2272,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Ftests\u002Ftest_apply_filters.py",{"path":192,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":193,"sourceHtmlUrl":194},"tests\u002Ftest_sc_preprocess_methods.py",1094,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Ftests\u002Ftest_sc_preprocess_methods.py",{"path":196,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":197,"sourceHtmlUrl":198},"tests\u002Ftest_sc_preprocess.py",7031,"https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fsinglecell\u002Fscrna\u002Fsc-preprocessing\u002Ftests\u002Ftest_sc_preprocess.py",{"path":200,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":201,"sourceHtmlUrl":202},"workflow.md",2923,"https:\u002F\u002Fgithub.com\u002Ftranthanhcntt\u002Fskills-agent\u002Fblob\u002Fmain\u002Fbmad-create-prd\u002Fworkflow.md",[204,222,234,251,277,300],{"skillNo":205,"name":206,"nameZh":6,"description":207,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":208,"categories":209,"keywords":215,"publishedAt":38},"01M6DTP4X225Q92RMY8XXHPCTT","demo-skill","A fixture skill for the skill environment tests. Use it for nothing else.","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Ftests\u002Fskillenv\u002Ffixtures\u002Fskills\u002Fdemo\u002Fdemo-skill\u002FSKILL.md",[210],{"categoryNo":211,"categoryName":212,"taxonomyType":213,"taxonomyTypeDesc":214},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",[216,217,218,219,220,34,221],"demo skill","demo","tests","fixture","fixture skill","environment",{"skillNo":223,"name":224,"nameZh":6,"description":225,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":226,"categories":227,"keywords":228,"publishedAt":38},"01M6DTP28JTWQK3HHXDNQV8BBV","fake-domains","Test fixture for the golden deployment in tests\u002Fentry. Load never; it has no script.","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Ftests\u002Fentry\u002Ffake_skills\u002Fspatial\u002Ffake-domains\u002FSKILL.md",[],[229,230,231,218,219,232,233],"domains","fake domains","deployment","never","test",{"skillNo":235,"name":236,"nameZh":6,"description":237,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":238,"categories":239,"keywords":241,"publishedAt":38},"01M6DTNZ4AMWKTME1T18K5C643","replace-me-skill","Load when copying this directory to bootstrap a new OmicsClaw skill. Skip when an existing skill already covers the request.","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Ftemplates\u002Fskill\u002FSKILL.md",[240],{"categoryNo":211,"categoryName":212,"taxonomyType":213,"taxonomyTypeDesc":214},[242,243,244,245,246,247,248,249,250],"me","replace me skill","template","directory","skill template","existing skill","new skill","bootstrap","scaffold",{"skillNo":252,"name":253,"nameZh":6,"description":254,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":255,"categories":256,"keywords":257,"publishedAt":38},"01M6DTNV63MTD0Q6YRC52F0B1Y","spatial-velocity","Load when estimating RNA velocity on a spatial AnnData with `layers[\"spliced\"]` + `layers[\"unspliced\"]` via scVelo (stochastic \u002F deterministic \u002F dynamical) or veloVI (deep generative). Skip when input lacks the spliced\u002Funspliced layers (must be quantified upstream by velocyto \u002F kb-python \u002F STARsolo); non-spatial scRNA velocity (use sc-velocity).","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fspatial\u002Fspatial-velocity\u002FSKILL.md",[],[258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,34,275,276],"velocity","spatial velocity","Spatial","scvelo","input","starsolo","time","deep","RNA","kb-python","via","velocyto","rna-velocity","velovi","dynamics","upstream","kb","python","deterministic",{"skillNo":278,"name":279,"nameZh":6,"description":280,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":281,"categories":282,"keywords":283,"publishedAt":38},"01M6DTNPMR227NAT8QFY620YDW","spatial-trajectory","Load when inferring pseudotime \u002F lineage trajectories on a preprocessed spatial AnnData via DPT (default — diffusion pseudotime), CellRank (terminal-state + fate-probability), or Palantir (waypoint branch probabilities). Skip when the data has spliced\u002Funspliced layers and you want velocity-driven dynamics (use spatial-velocity); non-spatial scRNA pseudotime (use sc-pseudotime).","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fspatial\u002Fspatial-trajectory\u002FSKILL.md",[],[260,284,285,286,287,288,289,290,268,291,292,293,294,295,258,296,34,297,298,299],"trajectory","spatial trajectory","state","terminal","lineage","diffusion","cellrank","palantir","dpt","pseudotime","probability","cell","default","branch","anndata","data",{"skillNo":301,"name":302,"nameZh":6,"description":303,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":304,"categories":305,"keywords":306,"publishedAt":38},"01M6DTNJEYFT33P84DGHDNXW95","spatial-statistics","Load when running spatial autocorrelation \u002F hotspot \u002F co-occurrence \u002F neighbourhood-enrichment \u002F Ripley K stats on a clustered spatial AnnData via squidpy. Skip when ranking spatially variable genes (use spatial-genes); tissue domain detection (use spatial-domains).","https:\u002F\u002Fgithub.com\u002FTianGzlab\u002FOmicsClaw\u002Fblob\u002Fmain\u002Fskills\u002Fspatial\u002Fspatial-statistics\u002FSKILL.md",[],[307,308,260,268,309,310,311,312,313,314,229,315,316,317,318,34,298,319,320,321],"spatial statistics","statistics","nhood-enrichment","co-occurrence","ripley","geary","moran","neighbourhood","ranking","autocorrelation","local","domain","detection","enrichment","stats"]