Skip to content

Generics

R's Seurat is built on S4 generics — Cells(x), Idents(x), LayerData(x, ...) — that dispatch on whatever object you hand them. truecell.generics is the same surface as free functions, so code ported from R reads the way it did in R.

Everything here also exists as a method or property on the objects themselves. Use whichever fits; they are the same code path.

from truecell import generics as g

g.cells(pbmc)            # Cells(pbmc)
g.idents(pbmc)           # Idents(pbmc)
g.layer_data(pbmc, "counts")   # LayerData(pbmc, layer = "counts")

Generic functions via @singledispatch, mirroring R's generics.R.

Each public function dispatches on the first argument's type. The base (object) implementation raises NotImplementedError so unregistered types get a clear message.