annsel.AnnselAccessor.pipe

annsel.AnnselAccessor.pipe#

AnnselAccessor.pipe(self, func, *args, **kwargs)[source]#

Apply chainable functions func(self, *args, **kwargs) that expect AnnData.

Parameters:
func Callable[..., TypeVar(T)] | tuple[Callable[..., TypeVar(T)], str]

Function to apply to this AnnData object. args, and kwargs are passed into func. Alternatively a (callable, data_keyword) tuple where data_keyword is a string indicating the keyword of callable that expects the xarray object.

*args Any

Positional arguments passed into func.

**kwargs Any

Keyword arguments passed into func.

Return type:

Any

Returns:

The return type of func.

Raises:

ValueError – When the data target is both the pipe target and a keyword argument.

Notes

Use .pipe when chaining together functions that expect AnnData objects, e.g., instead of writing

f(g(h(adata), arg1=a), arg2=b, arg3=cs)

You can write

(adata.an.pipe(h).pipe(g, arg1=a).an.pipe(f, arg2=b, arg3=c))

If you have a function that takes the data as (say) the second argument, pass a tuple indicating which keyword expects the data. For example suppose f takes its data as arg2

(adata.an.pipe(h).pipe(g, arg1=a).an.pipe((f, "arg2"), arg1=a, arg3=c))

Examples

>>> import annsel as an
>>> adata = an.datasets.leukemic_bone_marrow_dataset()
>>> adata.an.pipe(sc.pl.embedding, basis="X_tsneni", color="Cell_label")