ExpressionMatrix

Expression Matrix is a wrapper for xarray.DataArray that provides serialization adapters to netCDF, loom, and AnnData to enable it to be used with single-cell analysis software packages such as scanpy (python) and seurat (R).

class starfish.core.expression_matrix.expression_matrix.ExpressionMatrix(data: ~typing.Any = <NA>, coords: ~collections.abc.Sequence[~collections.abc.Sequence[~typing.Any] | ~pandas.core.indexes.base.Index | ~xarray.core.dataarray.DataArray] | ~collections.abc.Mapping[~typing.Any, ~typing.Any] | None = None, dims: ~collections.abc.Hashable | ~collections.abc.Sequence[~collections.abc.Hashable] | None = None, name: ~collections.abc.Hashable | None = None, attrs: ~collections.abc.Mapping | None = None, indexes: ~collections.abc.Mapping[~typing.Any, ~xarray.core.indexes.Index] | None = None, fastpath: bool = False)[source]

Container for expression data extracted from an IntensityTable

An ExpressionMatrix is a 2-dimensional cells x genes array whose values are the number of spots observed for each gene observed by the experiment. In addition to the basic xarray methods, ExpressionMatrix implements:

Methods

save(filename)

save the ExpressionMatrix to netCDF

save_loom(filename)

save the ExpressionMatrix to loom for use in R or python

save_anndata(filename)

save the ExpressionMatrix to AnnData for use in Scanpy

load(filename)

load an ExpressionMatrix from netCDF

item(*args)

Copy an element of an array to a standard Python scalar and return it.

Parameters:
*argsArguments (variable number and type)
  • none: in this case, the method only works for arrays with one element (a.size == 1), which element is copied into a standard Python scalar object and returned.

  • int_type: this argument is interpreted as a flat index into the array, specifying which element to copy and return.

  • tuple of int_types: functions as does a single int_type argument, except that the argument is interpreted as an nd-index into the array.

Returns:
zStandard Python scalar object

A copy of the specified element of the array as a suitable Python scalar

Notes

When the data type of a is longdouble or clongdouble, item() returns a scalar array object because there is no available Python scalar that would not lose information. Void arrays return a buffer object for item(), unless fields are defined, in which case a tuple is returned.

item is very similar to a[args], except, instead of an array scalar, a standard Python scalar is returned. This can be useful for speeding up access to elements of the array and doing arithmetic on elements of the array using Python’s optimized math.

Examples

>>> np.random.seed(123)
>>> x = np.random.randint(9, size=(3, 3))
>>> x
array([[2, 2, 6],
       [1, 3, 6],
       [1, 0, 1]])
>>> x.item(3)
1
>>> x.item(7)
0
>>> x.item((0, 1))
2
>>> x.item((2, 2))
1
classmethod load(filename: str) ExpressionMatrix[source]

load an ExpressionMatrix from Netcdf

Parameters:
filenamestr

File to load

Returns:
ExpressionMatrix
save(filename: str) None[source]

Save an ExpressionMatrix as a Netcdf File

Parameters:
filenamestr

Name of Netcdf file

save_anndata(filename: str) None[source]

Save an ExpressionMatrix as an AnnData file

Parameters:
filenamestr

Name of AnnData file

save_loom(filename: str) None[source]

Save an ExpressionMatrix as a loom file

Parameters:
filenamestr

Name of loom file

searchsorted(v, side='left', sorter=None)

Find indices where elements of v should be inserted in a to maintain order.

For full documentation, see numpy.searchsorted

See also

numpy.searchsorted

equivalent function