annsel.AnnselAccessor.pipe#
- AnnselAccessor.pipe(self, func, *args, **kwargs)[source]#
Apply chainable functions
func(self, *args, **kwargs)that expectAnnData.- Parameters:
- func
Callable[...,TypeVar(T)] |tuple[Callable[...,TypeVar(T)],str] Function to apply to this
AnnDataobject.args, andkwargsare passed intofunc. Alternatively a(callable, data_keyword)tuple wheredata_keywordis a string indicating the keyword ofcallablethat expects the xarray object.- *args
Any Positional arguments passed into
func.- **kwargs
Any Keyword arguments passed into
func.
- func
- Return type:
- Returns:
The return type of
func.- Raises:
ValueError – When the data target is both the pipe target and a keyword argument.
Notes
Use
.pipewhen chaining together functions that expect AnnData objects, e.g., instead of writingf(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
ftakes its data asarg2(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")