Perform an axis-based query against a SOMAExperiment
.
SOMAExperimentAxisQuery
allows easy selection and extraction of data from a
single SOMAMeasurement
in a SOMAExperiment
, by obs
/var
(axis)
coordinates and/or value filter. The primary use for this class is slicing
SOMAExperiment
X
layers by obs
or var
value and/or coordinates.
(lifecycle: maturing)
X Layer Support
Slicing on SOMASparseNDArray
X
matrices is supported;
slicing on SOMADenseNDArray
is not supported at this time.
Active bindings
experiment
The parent
SOMAExperiment
object.indexer
The
SOMAAxisIndexer
object.obs_query
The
obs
SOMAAxisQuery
object.var_query
The
var
SOMAAxisQuery
object.n_obs
The number of
obs
axis query results.n_vars
The number of
var
axis query results.obs_df
The
obs
SOMADataFrame
object.var_df
The
var
SOMADataFrame
object for the specifiedmeasurement_name
.ms
The
SOMAMeasurement
object for the specifiedmeasurement_name
.
Methods
Method new()
Create a new SOMAExperimentAxisQuery
object.
Usage
SOMAExperimentAxisQuery$new(
experiment,
measurement_name,
obs_query = NULL,
var_query = NULL
)
Arguments
experiment
A
SOMAExperiment
object.measurement_name
The name of the measurement to query.
obs_query, var_query
An
SOMAAxisQuery
object for the obs/var axis.
Method obs()
Retrieve obs TableReadIter
Method var()
Retrieve var arrow::Table
Method obs_joinids()
Retrieve soma_joinids
as an arrow::Array
for obs
.
Method var_joinids()
Retrieve soma_joinids
as an arrow::Array
for var
.
Method X()
Retrieves an X
layer as a SOMASparseNDArrayRead
Method obsm()
Retrieves an obsm
layer as a SOMASparseNDArrayRead
Method varm()
Retrieves a varm
layer as a SOMASparseNDArrayRead
Method obsp()
Retrieves an obsp
layer as a SOMASparseNDArrayRead
Method varp()
Retrieves a varp
layer as a SOMASparseNDArrayRead
Method read()
Reads the entire query result as a list of
arrow::Table
s. This is a low-level routine intended to be used by
loaders for other in-core formats, such as Seurat
, which can be created
from the resulting Tables.
Method to_sparse_matrix()
Retrieve a collection layer as a sparse matrix with named dimensions.
Load any layer from the X
, obsm
, varm
, obsp
, or varp
collections as a sparse matrix.
By default the matrix dimensions are named using the soma_joinid
values
in the specified layer's dimensions (e.g., soma_dim_0
). However,
dimensions can be named using values from any obs
or var
column that
uniquely identifies each record by specifying the obs_index
and
var_index
arguments.
For layers in obsm
or varm
, the column axis (the axis not
indexed by “obs
” or “var
”) is set to the
range of values present in “soma_dim_1
”; this ensures
that gaps in this axis are preserved (eg. when a query for
“obs
” that results in selecting entries that are all zero
for a given PC)
Usage
SOMAExperimentAxisQuery$to_sparse_matrix(
collection,
layer_name,
obs_index = NULL,
var_index = NULL
)
Arguments
collection
The
SOMACollection
containing the layer of interest, either:"X"
,"obsm"
,"varm"
,"obsp"
, or"varp"
.layer_name
Name of the layer to retrieve from the
collection
.obs_index, var_index
Name of the column in
obs
orvar
(var_index
) containing values that should be used as dimension labels in the resulting matrix. Whether the values are used as row or column labels depends on the selectedcollection
:Collection obs_index
var_index
X
row names column names obsm
row names ignored varm
ignored row names obsp
row and column names ignored varp
ignored row and column names
Method to_seurat()
Loads the query as a Seurat
object
Usage
SOMAExperimentAxisQuery$to_seurat(
X_layers = c(counts = "counts", data = "logcounts"),
obs_index = NULL,
var_index = NULL,
obs_column_names = NULL,
var_column_names = NULL,
obsm_layers = NULL,
varm_layers = NULL,
obsp_layers = NULL,
drop_levels = FALSE
)
Arguments
X_layers
A named character of X layers to add to the Seurat assay where the names are the names of Seurat slots and the values are the names of layers within
X
; names should be one of:“
counts
” to add the layer ascounts
“
data
” to add the layer asdata
“
scale.data
” to add the layer asscale.data
counts
” or “data
” is requiredobs_index
Name of column in
obs
to add as cell names; usespaste0("cell", obs_joinids())
by defaultvar_index
Name of column in
var
to add as feature names; usespaste0("feature", var_joinids())
by defaultobs_column_names
Names of columns in
obs
to add as cell-level meta data; by default, loads all columnsvar_column_names
Names of columns in
var
to add as feature-level meta data; by default, loads all columnsobsm_layers
Names of arrays in
obsm
to add as the cell embeddings; passFALSE
to suppress loading in any dimensional reductions; by default, loads all dimensional reduction informationvarm_layers
Named vector of arrays in
varm
to load in as the feature loadings; names must be names of arrays inobsm
(eg.varm_layers = c(X_pca = "PCs")
); passFALSE
to suppress loading in any feature loadings; will try to determinevarm_layers
fromobsm_layers
obsp_layers
Names of arrays in
obsp
to load in asGraphs
; by default, loads all graphsdrop_levels
Drop unused levels from
obs
andvar
factor columns
Returns
A Seurat
object
Method to_seurat_assay()
Loads the query as a Seurat Assay
Usage
SOMAExperimentAxisQuery$to_seurat_assay(
X_layers = c(counts = "counts", data = "logcounts"),
obs_index = NULL,
var_index = NULL,
var_column_names = NULL,
drop_levels = FALSE
)
Arguments
X_layers
A named character of X layers to add to the Seurat assay where the names are the names of Seurat slots and the values are the names of layers within
X
; names should be one of:“
counts
” to add the layer ascounts
“
data
” to add the layer asdata
“
scale.data
” to add the layer asscale.data
counts
” or “data
” is requiredobs_index
Name of column in
obs
to add as cell names; usespaste0("cell", obs_joinids())
by defaultvar_index
Name of column in
var
to add as feature names; usespaste0("feature", var_joinids())
by defaultvar_column_names
Names of columns in
var
to add as feature-level meta data; by default, loads all columnsdrop_levels
Drop unused levels from
var
factor columns
Returns
An Assay
object
Method to_seurat_reduction()
Loads the query as a Seurat dimensional reduction
Usage
SOMAExperimentAxisQuery$to_seurat_reduction(
obsm_layer,
varm_layer = NULL,
obs_index = NULL,
var_index = NULL
)
Arguments
obsm_layer
Name of array in
obsm
to load as the cell embeddingsvarm_layer
Name of the array in
varm
to load as the feature loadings; by default, will try to determinevarm_layer
fromobsm_layer
obs_index
Name of column in
obs
to add as cell names; usespaste0("cell", obs_joinids())
by defaultvar_index
Name of column in
var
to add as feature names; usespaste0("feature", var_joinids())
by default
Returns
A DimReduc
object
Method to_seurat_graph()
Loads the query as a Seurat graph
Arguments
obsp_layer
Name of array in
obsp
to load as the graphobs_index
Name of column in
obs
to add as cell names; usespaste0("cell", obs_joinids())
by default
Returns
A Graph
object
Method to_single_cell_experiment()
Loads the query as a
SingleCellExperiment
object
Usage
SOMAExperimentAxisQuery$to_single_cell_experiment(
X_layers = NULL,
obs_index = NULL,
var_index = NULL,
obs_column_names = NULL,
var_column_names = NULL,
obsm_layers = NULL,
obsp_layers = NULL,
varp_layers = NULL,
drop_levels = FALSE
)
Arguments
X_layers
A character vector of X layers to add as assays in the main experiment; may optionally be named to set the name of the resulting assay (eg.
X_layers = c(counts = "raw")
will load in X layer “raw
” as assay “counts
”); by default, loads in all X layersobs_index
Name of column in
obs
to add as cell names; usespaste0("cell", obs_joinids())
by defaultvar_index
Name of column in
var
to add as feature names; usespaste0("feature", var_joinids())
by defaultobs_column_names
Names of columns in
obs
to add ascolData
; by default, loads all columnsvar_column_names
Names of columns in
var
to add asrowData
; by default, loads all columnsobsm_layers
Names of arrays in
obsm
to add as the reduced dimensions; passFALSE
to suppress loading in any reduced dimensions; by default, loads all reduced dimensionsobsp_layers
Names of arrays in
obsp
to load in asSelfHits
; by default, loads all graphsvarp_layers
Names of arrays in
varp
to load in asSelfHits
; by default, loads all networksdrop_levels
Drop unused levels from
obs
andvar
factor columns