Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

CyteArc for Scanpy users

Find the CyteArc call for each step of a Scanpy analysis, the settings where the two give different results, and how counts and results move between them through H5AD files. Where Scanpy writes each result into an AnnData object, CyteArc saves it in the store as an artifact and returns an ArtifactRef, a reference that the next step takes as its input. The data model comparison explains how the two models differ.

Translate each step

In the calls below, ds is a cytearc.DataStore, the object that opens a store. ds.pipeline.rna() runs the standard RNA workflow in one call, from quality-control filtering to marker genes, and ds.pipeline.atac() and ds.pipeline.adt() do the same for peak and antibody counts. Each returns a PipelineRun, a saved record of the run’s settings and results, and leaves ds.cells, the cell table that plays the role of obs, unchanged. Each stage of a recipe takes the keywords of the method it runs, such as ds.pipeline.rna(hvg={"top_n": 2000}, pca={"dims": 30}, neighbors={"k": 14}). The methods in the table run the same steps one at a time:

StepScanpyCyteArc
Load countssc.read_h5ad, sc.read_10x_h5A reader and a writer, such as H5adReader and H5adToZarr, write a store that cytearc.DataStore opens
Call cells in raw dropletsNo Scanpy functionds.qc.call_cells, which implements EmptyDrops (Cell calling)
Compute QC metricssc.pp.calculate_qc_metricsOpening a new store adds each cell’s total counts, detected genes, and mitochondrial and ribosomal percentages, such as RNA_nCounts and RNA_percentMito
Filter cellssc.pp.filter_cells, or a mask on obsds.qc.filter with fixed bounds, or ds.qc.auto_filter with bounds from the median absolute deviation; both return a cell selection and delete no cells
Select and normalize genessc.pp.normalize_total, sc.pp.log1p, sc.pp.highly_variable_genesds.features.hvgs, then ds.features.normalize over the same cell selection
Select genes on raw counts or Pearson residualssc.pp.highly_variable_genes(flavor="seurat_v3"), sc.experimental.pp.highly_variable_genes(flavor="pearson_residuals")ds.features.hvgs(cells, flavor="seurat_v3") or flavor="pearson_residuals"; batch= takes the place of batch_key, with a cell column or a label artifact
Normalize to Pearson residualssc.experimental.pp.normalize_pearson_residualsds.RNA.normMethod = cytearc.assay.norm_pearson_residuals, then ds.features.normalize and ds.reduction.pca(..., feat_scaling=False); in a recipe, ds.pipeline.rna(normalization={"method": "pearson_residuals"}), whose PCA scales no gene (Normalization method)
Scale and reducesc.pp.scale, sc.pp.pcads.reduction.pca, which standardizes each gene unless feat_scaling=False
Correct batches with Harmonysc.external.pp.harmony_integrateds.reduction.harmony after PCA, then the graph steps
Build the neighbor graphsc.pp.neighborsds.graph.ann_index, ds.graph.neighbors, then ds.graph.connectivity
Embed the graphsc.tl.umapds.embeddings.umap
Cluster cellssc.tl.leidends.clusters.leiden (Compare clusterings and check the clusters)
Find marker genessc.tl.rank_genes_groupsds.markers.search, then ds.markers.load
Plotsc.pl.umap, sc.pl.dotplotds.plots.embedding, ds.plots.dotplot
Write an H5AD fileadata.write_h5adcytearc.to_h5ad, or ds.to_anndata() for an AnnData object in memory

The neighbor graph tutorial runs the chain from PCA to clusters one call at a time, and the PBMC analysis names the populations of a saved run from their marker genes.

Which settings give different results

Move data through H5AD

cytearc.inspect_h5ad reads the layout of an H5AD file, and H5adReader.from_inspect with H5adToZarr writes the file to a store. Each part of an AnnData object has a counterpart in the store:

AnnDataImportExport
X, raw/X, layersThe raw counts: inspection ranks the matrices that hold counts first, preferring raw/X and layers/counts to X, and matrix_key picks another. A file that holds only normalized values imports too; H5adToZarr(..., values=...) names their kind when CyteArc cannot tell it from the valuesX holds raw counts; a run export with matrix="normed" holds the normalized values that the run’s PCA read
obs, varThe cell and feature tables; categorical columns keep their categories, order and uns["<column>_colors"]The cell and feature tables
Label columns of obscluster_keys imports them as clusterings instead of table columns, with the same categories, order and colorsobs={"leiden": leiden} writes a clustering as a categorical column
obsmembedding_roles imports "umap" and "tsne" layouts, and latent spaces such as X_scVI as "coordinates" that a neighbor graph can be built onobsm={"X_pca": pca, "X_umap": umap}; X_pca also writes the PCA loadings to varm["PCs"]
obsp, uns["neighbors"]Not imported; build the graph in CyteArcgraph= writes obsp["connectivities"], obsp["distances"] and uns["neighbors"] in Scanpy’s layout
Cell orderThe store writes the cells in a random order and keeps each cell’s row in the file in sourceRow (cell order)The cells in the order of the imported file; cell_order="stored" writes them in the store’s order

A completed run exports in one call: cytearc.to_h5ad(ds.RNA, "analysis.h5ad", run=run) writes the raw counts of the run’s cells with its PCA, UMAP and cluster labels, and the colors of its labels in uns. After adata = sc.read_h5ad("analysis.h5ad"), sc.pl.umap(adata, color="clusters") runs without changes. Because X holds raw counts, run sc.pp.normalize_total and sc.pp.log1p before sc.tl.rank_genes_groups(adata, "clusters"), which expects log-normalized values. Without a run, pass the artifacts to export with the cell_selection that they cover, because each artifact must hold every exported cell. cytearc.to_h5ad streams the file block by block and needs neither the anndata package nor memory for the whole matrix, and ds.to_anndata returns the same content as an AnnData object. Import and export converts a pancreas H5AD file with its UMAP and cell types and exports it again, and the export reference lists every exported field.

Import a latent space from another tool

Import a latent space computed outside CyteArc, such as an scVI embedding, as coordinates that a neighbor graph, a UMAP and clusters can build on. cells is the cell selection whose cells the latent space describes, such as run["analysis_cell_selection"] for the cells of an exported run:

import pandas as pd

# Import the latent space for the cells it describes, with a record of the tool that made it.
latent = ds.reduction.import_coordinates(
    pd.DataFrame(adata.obsm["X_scVI"], index=adata.obs_names),
    cell_selection=cells,
    name="X_scVI",
    source={"tool": "scvi-tools", "version": "1.2.0"},
)

# Build a neighbor graph and Leiden clusters on the imported coordinates.
graph = ds.graph.connectivity(ds.graph.neighbors(ds.graph.ann_index(latent), k=14))
leiden = ds.clusters.leiden(graph)

The rows of the DataFrame are matched to cells by cell ID. The source record and a fingerprint of the values become part of the artifact’s provenance, so lineage reports show where the coordinates came from. Import and export imports a latent space computed with scikit-learn and compares its clusters with those of CyteArc’s PCA.