# API reference

The public API is grouped by analysis stage. Import functions through
`sctk.pp`, `sctk.tl`, `sctk.pl`, or `sctk.r`; modules beginning with an
underscore are implementation details and may change.

## Preprocessing: `sctk.pp`

| Function | Purpose |
| --- | --- |
| `calculate_qc_metrics` | Annotate mitochondrial genes and calculate standard Scanpy QC columns. |
| `is_outlier` | Detect robust MAD-based outliers, optionally within batches or samples. |
| `qc_filter_mask` | Build and record a reviewable cell-level QC decision. |
| `filter_cells_qc` | Apply QC criteria and return or write the filtered AnnData object. |
| `normalize_layer` | Normalize and log-transform a source layer into a named output layer. |
| `scanpy_preprocess` | Run selectable normalization, HVG, scaling, PCA, graph, UMAP, and Leiden stages. |
| `cell_cycle_genes` | Return packaged human or mouse cell-cycle genes. |
| `score_cell_cycle` | Add Scanpy S/G2M scores using a selected expression layer. |
| `leiden_grid` | Calculate Leiden labels over a resolution grid. |
| `silhouette_by_resolution` | Compare stored clusterings using silhouette scores. |
| `harmony_integrate` | Correct a PCA representation with Harmony. |
| `scvi_integrate` | Train scVI from raw counts and store its latent representation. |

## Analysis: `sctk.tl`

| Function | Purpose |
| --- | --- |
| `markers_in_data` | Intersect a marker dictionary with genes present in AnnData. |
| `score_gene_sets` | Calculate mean-expression or Scanpy gene-set scores. |
| `annotate_by_markers` | Produce provisional labels from marker-set scores and an ambiguity margin. |
| `rank_genes_table` | Convert Scanpy ranked-gene results to a tidy table. |
| `marker_dict_from_rank_genes` | Convert ranked-gene results to a group-to-markers mapping. |
| `grouped_obs_mean` | Calculate group-level mean expression. |
| `grouped_gene_detection_rate` | Summarize detection rate and expression for one gene by group. |
| `split_cells_by_gene` | Split cells by detection, median, quantile, Otsu, or GMM threshold. |
| `split_cells_by_gene_extremes` | Label low/high expression tails while leaving middle cells unassigned. |
| `split_groups_by_fraction` | Split sample-level fractions using median, quantile, tertile, or a fixed threshold. |
| `create_pseudobulk` | Sum raw counts per biological sample and optional cell group. |
| `pseudobulk_qc` | Summarize library size, detected genes, cells, and condition replication. |
| `run_deseq2` | Run a validated PyDESeq2 contrast on pseudobulk counts. |
| `read_gmt` | Read a GMT file into a long gene-set network. |
| `rename_net_columns` | Standardize network columns to `source` and `target`. |
| `get_resource` | Fetch and cache a decoupler/OmniPath resource. |
| `resource_cache_path` | Resolve the local resource cache file. |
| `run_ora` | Run offline hypergeometric over-representation analysis. |
| `run_gsea` | Run preranked GSEA for one ranking. |
| `integration_metrics` | Measure batch mixing and biological-label separation in a representation. |
| `run_liana` | Run LIANA cell–cell communication inference. |
| `summarize_interactions` | Filter, rank, and aggregate LIANA interaction results. |

## Plotting: `sctk.pl`

| Function | Purpose |
| --- | --- |
| `embedding` | Call Scanpy embedding plotting with project defaults. |
| `dotplot` | Plot grouped expression through Scanpy. |
| `composition`, `obs_composition` | Plot category composition within samples or groups. |
| `barplot`, `boxplot`, `stripplot`, `violinplot` | Plot tidy or AnnData-derived values. |
| `volcano` | Plot differential-expression effect size and significance. |
| `enrichment_dotplot`, `enrichment_barplot`, `plot_ora_bar` | Plot long enrichment result tables. |
| `palettes`, `get_palette` | Access built-in categorical palettes. |
| `set_colors`, `get_colors` | Store or retrieve AnnData category colors. |

Most plotting functions return a Matplotlib axes object. Pass `ax=` to compose
multi-panel figures and save through its figure:

```python
ax = sctk.pl.volcano(de)
ax.figure.savefig("volcano.pdf", bbox_inches="tight")
```

## Optional R-backed API: `sctk.r`

| Function | Purpose |
| --- | --- |
| `sctk.r.pp.scdblfinder` | Run scDblFinder and write score/class annotations. |
| `sctk.r.pp.remove_ambient` | Correct a filtered matrix using SoupX and a raw-droplet matrix. |
| `sctk.r.tl.run_voom` | Run limma-voom, optionally with repeated-sample blocking. |
| `sctk.r.require_r_package` | Fail early with the name of a missing R package. |

R and optional Python dependencies are loaded only when the corresponding
function is called. See [R Environment Guide](R_ENVIRONMENT.md) for setup and
validation.

## Stability conventions

- Public imports listed above are the supported notebook interface.
- Functions generally return result objects; mutation is documented through
  `inplace`, `copy`, or `key_added`.
- Count-based methods validate integer-like, non-negative input instead of
  silently rounding normalized values.
- Representation keys follow AnnData conventions such as `X_pca_harmony` in
  `.obsm` and neighbor graphs in `.obsp`/`.uns`.
