daf.storage.views

Storage views allow slicing the data and/or renaming and/or hiding specific axes or data.

A view is just a light-weight read-only adapter of some underlying storage; a common idiom for exporting a subset of the data is to create a view, then copy its contents into an empty new persistent storage (such as FilesWriter) to save just this data to the disk. This is crucial when converting daf data to AnnData, as AnnData requires specific axes names, and is not capable of “reasonably” dealing with too many axes.

Classes:

AxisView([name, entries, track, overwrite])

Describe how to expose an axis of some base StorageReader from a StorageView:

StorageView(base, *[, axes, data, name, ...])

A read-only view of some base StorageReader.

class daf.storage.views.AxisView(name: Optional[str] = None, entries: Optional[AnyData] = None, track: Optional[str] = None, overwrite: bool = False)[source]

Bases: tuple

Describe how to expose an axis of some base StorageReader from a StorageView:

Create new instance of AxisView(name, entries, track, overwrite)

Attributes:

name

The name to expose the axis as, or None to keep the same name.

entries

Which entries of the axis to expose (how to slice the axis).

track

Whether to create new data for the axis which tracks the index of each entry in the base data.

overwrite

If creating new data to track the axis entry indices, whether to overwrite existing data of the same name.

property name

The name to expose the axis as, or None to keep the same name.

property entries

Which entries of the axis to expose (how to slice the axis).

  • If None, expose all the entries (no slicing).

  • A vector of strings contains the names of the entries to expose.

  • A vector of integers contains the indices of the entries to expose.

  • A vector of Booleans contains a mask of the entries to expose.

property track

Whether to create new data for the axis which tracks the index of each entry in the base data. If None, no such data is created. Otherwise, axis#track will be created and will contain the integer index of each exposed axis entry in the original base data.

property overwrite

If creating new data to track the axis entry indices, whether to overwrite existing data of the same name.

class daf.storage.views.StorageView(base: StorageReader, *, axes: Optional[Mapping[str, Union[None, str, daf.typing.unions.AnyData, AxisView]]] = None, data: Optional[Mapping[str, Optional[str]]] = None, name: str = '.view#', cache: Optional[StorageWriter] = None, hide_implicit: bool = False)[source]

Bases: StorageReader

A read-only view of some base StorageReader.

If the name starts with ., it is appended to the base name. If it ends with # we append the object id to it to make it unique.

A view is defined by describing how to expose each existing axis or data, that is, the keys to the axes and data dictionaries are the names in the base storage, not the exposed names of the storage view.

For 2D data, specify only one of the two foo,bar#baz and bar,foo#baz names, and it will automatically also apply to its transpose.

If the explicit of some axis or data is None, than that axis or data are hidden. If an axis or some data is not listed, then by default it is exposed as is; if hide_implicit, it is hidden. Hiding an axis hides all the data based on that axis.

If the value of some axis or data is a string, it is the property name to use to expose the data or axis.

If the value of an axis is the entries of the axis to expose, it will be sliced (using the same name).

If the value of an axis is an AxisView, it describes in detail how to expose the axis.

By default, sliced data is stored in a cache using MemoryStorage. To disable caching, specify a NO_STORAGE value for it.

Note

Do not modify the base storage after creating a view. Modifications may or may not be visible in the view, causing subtle problems.

Attributes:

base

The base storage.

cache

Cached storage for sliced data.

Methods:

axis_slice_indices(exposed_axis)

Return the original indices of the entries of the exposed_axis, or None if the base axis was not sliced.

exposed_axis(base_axis)

Given the base_axis in the base StorageReader, return the name it is exposed as in the view, or None if it is hidden.

exposed_item(base_item)

Given the name of a base_item in the base StorageReader, return the name it is exposed as in the view, or None if it is hidden.

exposed_data1d(base_data1d)

Given the name of an base_data1d in the base StorageReader, return the name it is exposed as in the view, or None if it is hidden.

exposed_data2d(base_data2d)

Given the name of an base_data2d in the base StorageReader, return the name it is exposed as in the view, or None if it is hidden.

base_axis(exposed_axis)

Given the name of an exposed_axis (which must exist), return its name in the base StorageReader.

base_item(exposed_item)

Given the name of an exposed_item (which must exist), return its name in the base StorageReader.

base_data1d(exposed_data1d)

Given the name of an exposed_data1d (which must exist), return its name in the base StorageReader.

base_data2d(exposed_data2d)

Given the name of an exposed_data2d (which must exist), return its name in the base StorageReader.

base

The base storage.

cache

Cached storage for sliced data.

axis_slice_indices(exposed_axis: str) Optional[Vector][source]

Return the original indices of the entries of the exposed_axis, or None if the base axis was not sliced.

exposed_axis(base_axis: str) Optional[str][source]

Given the base_axis in the base StorageReader, return the name it is exposed as in the view, or None if it is hidden.

exposed_item(base_item: str) Optional[str][source]

Given the name of a base_item in the base StorageReader, return the name it is exposed as in the view, or None if it is hidden.

exposed_data1d(base_data1d: str) Optional[str][source]

Given the name of an base_data1d in the base StorageReader, return the name it is exposed as in the view, or None if it is hidden.

The exposed name of tracked entry indices of an axis, if any, are available using axis# as the base_data1d name.

exposed_data2d(base_data2d: str) Optional[str][source]

Given the name of an base_data2d in the base StorageReader, return the name it is exposed as in the view, or None if it is hidden.

base_axis(exposed_axis: str) str[source]

Given the name of an exposed_axis (which must exist), return its name in the base StorageReader.

base_item(exposed_item: str) str[source]

Given the name of an exposed_item (which must exist), return its name in the base StorageReader.

base_data1d(exposed_data1d: str) str[source]

Given the name of an exposed_data1d (which must exist), return its name in the base StorageReader.

The base name of tracked entry indices of an axis is reported as axis#.

base_data2d(exposed_data2d: str) str[source]

Given the name of an exposed_data2d (which must exist), return its name in the base StorageReader.