tiledbsoma.ExperimentAxisQuery

class tiledbsoma.ExperimentAxisQuery(experiment: ~somacore.query.query._Exp, measurement_name: str, *, obs_query: ~somacore.query.axis.AxisQuery = AxisQuery(value_filter=None, coords=()), var_query: ~somacore.query.axis.AxisQuery = AxisQuery(value_filter=None, coords=()), index_factory: ~typing.Callable[[~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy.int64]]], IndexLike] = <class 'pandas.core.indexes.base.Index'>)

Axis-based query against a SOMA Experiment.

ExperimentAxisQuery allows easy selection and extraction of data from a single Measurement in an Experiment, by obs/var (axis) coordinates and/or value filter.

The primary use for this class is slicing Experiment X layers by obs or var value and/or coordinates. Slicing on SparseNDArray X matrices is supported; DenseNDArray is not supported at this time.

IMPORTANT: this class is not thread-safe.

IMPORTANT: this query class assumes it can store the full result of both axis dataframe queries in memory, and only provides incremental access to the underlying X NDArray. API features such as n_obs and n_vars codify this in the API.

IMPORTANT: you must call close() on any instance of this class to release underlying resources. The ExperimentAxisQuery is a context manager, and it is recommended that you use the following pattern to make this easy and safe:

with ExperimentAxisQuery(...) as query:
    ...

This base query implementation is designed to work against any SOMA implementation that fulfills the basic APIs. A SOMA implementation may include a custom query implementation optimized for its own use.

Lifecycle: maturing

__init__(experiment: ~somacore.query.query._Exp, measurement_name: str, *, obs_query: ~somacore.query.axis.AxisQuery = AxisQuery(value_filter=None, coords=()), var_query: ~somacore.query.axis.AxisQuery = AxisQuery(value_filter=None, coords=()), index_factory: ~typing.Callable[[~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy.int64]]], IndexLike] = <class 'pandas.core.indexes.base.Index'>)

Methods

X(layer_name, *[, batch_size, partitions, ...])

Returns an X layer as a sparse read.

__init__(experiment, measurement_name, *[, ...])

close()

Releases resources associated with this query.

obs(*[, column_names, batch_size, ...])

Returns obs as an Arrow table iterator.

obs_joinids()

Returns obs soma_joinids as an Arrow array.

obsm(layer)

Returns an obsm layer as a sparse read.

obsp(layer)

Returns an obsp layer as a sparse read.

to_anndata(X_name, *[, column_names, ...])

Executes the query and return result as an AnnData in-memory object.

var(*[, column_names, batch_size, ...])

Returns var as an Arrow table iterator.

var_joinids()

Returns var soma_joinids as an Arrow array.

varm(layer)

Returns a varm layer as a sparse read.

varp(layer)

Returns a varp layer as a sparse read.

Attributes

indexer

A soma_joinid indexer for both obs and var axes.

n_obs

The number of obs axis query results.

n_vars

The number of var axis query results.