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.
A generic is declared here only where something implements it: the object's own
method, property or log, reached by its R name, which is the "same code path"
docs/api/generics.md promises. R's constructors (CreateSeuratObject,
CreateFOV, …) are not here, because the top-level factories take their input
by keyword and a dispatcher cannot; nor is anything the port has no counterpart
for, such as the S4 plumbing. tests/test_generics.py fails on a generic with
no implementation.