You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please describe your wishes and possible alternatives to achieve the desired result.
Hi,
I would like to propose adding built-in support for custom accessors in AnnData. This feature would allow users to register and use dedicated namespaces on AnnData objects without the need for subclassing or mixins, similar to the mechanisms available in Polars and Xarray.
Motivation
Custom accessors provide a clean and modular way to extend the functionality of a core class. For example, in both Polars and Xarray, users can define custom functionality and then access it through a dedicated namespace (e.g., df.my_accessor.my_method()).
This enables:
Enhanced Modularity: Custom functionality can be isolated in separate modules.
Ease of Use: Users extend AnnData objects with additional methods without modifying or subclassing the core class.
Extensibility: Third-party developers can integrate domain-specific functionality that naturally augments the core AnnData behavior.
Example
importanndataasad@ad.extensions.register_anndata_namespace("transforms")classTransforms:
def__init__(self, adata: ad.AnnData):
self._adata=adatadefarcsinh(
self, shift: float, scale: float, layer: str, inplace: bool=False
) ->ad.AnnData|None:
"""Apply an arcsinh transformation to the X matrix."""importnumpyasnp# Example transformation logictransformed=np.arcsinh(self._adata.X/scale) +shiftreturnNoneifinplaceelseself._adata
Please describe your wishes and possible alternatives to achieve the desired result.
Hi,
I would like to propose adding built-in support for custom accessors in AnnData. This feature would allow users to register and use dedicated namespaces on AnnData objects without the need for subclassing or mixins, similar to the mechanisms available in Polars and Xarray.
Motivation
Custom accessors provide a clean and modular way to extend the functionality of a core class. For example, in both Polars and Xarray, users can define custom functionality and then access it through a dedicated namespace (e.g.,
df.my_accessor.my_method())
.This enables:
Example
and you'd use it like so:
Existing examples out in the scverse
Similar accessor functionality has been implemented in other scverse projects:
Spatialdata-Plot implements accessors using Xarray’s approach, providing a nice to use API for plotting functionality.
holoviz-topics/hv-anndata uses holoviz's interface solution to extend AnnData.
The text was updated successfully, but these errors were encountered: