DecodedIntensityTable

class starfish.core.intensity_table.decoded_intensity_table.DecodedIntensityTable(data: ~typing.Any = <NA>, coords: ~typing.Optional[~typing.Union[~collections.abc.Sequence[collections.abc.Sequence | pandas.core.indexes.base.Index | xarray.core.dataarray.DataArray | xarray.core.variable.Variable | numpy.ndarray], ~collections.abc.Mapping]] = None, dims: ~typing.Optional[~typing.Union[str, ~collections.abc.Iterable[~collections.abc.Hashable]]] = None, name: ~typing.Optional[~collections.abc.Hashable] = None, attrs: ~typing.Optional[~collections.abc.Mapping] = None, indexes: ~typing.Optional[~collections.abc.Mapping[~collections.abc.Hashable, ~xarray.core.indexes.Index]] = None, fastpath: bool = False)[source]

DecodedIntensityTable is a container for spot or pixel features extracted from image data that have been decoded. It is the primary output from starfish Decode methods.

An IntensityTable records the numeric intensity of a set of features in each (round, channel) tile in which the feature is identified. The IntensityTable has shape (n_feature, n_channel, n_round).

Some SpotFinder methods identify a position and search for Gaussian blobs in a small radius, only recording intensities if they are found in a given tile. Other :py:class:SpotFinder: approaches find blobs in a max-projection and measure them everywhere. As a result, some IntensityTables will be dense, and others will contain np.nan entries where no feature was detected.

Examples

Create an IntensityTable using the synthetic_intensities method:

>>> from starfish.core.test.factories import SyntheticData
>>> sd = SyntheticData(n_ch=3, n_round=4, n_codes=2)
>>> codes = sd.codebook()
>>> sd.intensities(codebook=codes)
<xarray.IntensityTable (features: 2, c: 3, h: 4)>
array([[[    0.,     0.,     0.,     0.],
        [    0.,     0.,  8022., 12412.],
        [11160.,  9546.,     0.,     0.]],

       [[    0.,     0.,     0.,     0.],
        [    0.,     0., 10506., 10830.],
        [11172., 12331.,     0.,     0.]]])
Coordinates:
* features   (features) MultiIndex
- z          (features) int64 7 3
- y          (features) int64 14 32
- x          (features) int64 32 15
- r          (features) float64 nan nan
* c          (c) int64 0 1 2
* h          (h) int64 0 1 2 3
 target     (features) object 08b1a822-a1b4-4e06-81ea-8a4bd2b004a9 ...

Methods

from_intensity_table(intensities, targets[, ...])

Assign target values to intensities.

item(*args)

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

searchsorted(v[, side, sorter])

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

to_decoded_dataframe()

Generates a dataframe containing decoded spot information.

to_expression_matrix()

Generates a cell x gene count matrix where each cell is annotated with spatial metadata.

to_mermaid(filename)

Writes a .csv.gz file in columnar format that is readable by MERMAID visualization software.

classmethod from_intensity_table(intensities: IntensityTable, targets: Tuple[str, ndarray], distances: Optional[Tuple[str, ndarray]] = None, passes_threshold: Optional[Tuple[str, ndarray]] = None, rounds_used: Optional[Tuple[str, ndarray]] = None)[source]

Assign target values to intensities.

Parameters:
intensitiesIntensityTable

intensity_table to assign target values to

targetsTuple[str, np.ndarray]

Target values to assign

distancesOptional[Tuple[str, np.ndarray]]

Corresponding array of distances from target for each feature

passes_thresholdOptional[Tuple[str, np.ndarray]]

Corresponding array of boolean values indicating if each itensity passed given thresholds.

rounds_used: Optional[Tuple[str, np.ndarray]]

Corresponding array of integers indicated the number of rounds this decoded intensity was found in

Returns:
DecodedIntensityTable
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

>>> import numpy as np
>>> 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

For an array with object dtype, elements are returned as-is.

>>> a = np.array([np.int64(1)], dtype=object)
>>> a.item() #return np.int64
np.int64(1)
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

to_decoded_dataframe() DecodedSpots[source]

Generates a dataframe containing decoded spot information. Guaranteed to contain physical spot coordinates (z, y, x) and gene target. Does not contain pixel coordinates.

to_expression_matrix() ExpressionMatrix[source]

Generates a cell x gene count matrix where each cell is annotated with spatial metadata.

Requires that spots in the IntensityTable have been assigned to cells.

Returns:
ExpressionMatrix

cell x gene expression table

to_mermaid(filename: str) DataFrame[source]

Writes a .csv.gz file in columnar format that is readable by MERMAID visualization software.

To run MERMAID, follow the installation instructions for that repository and simply replace the data.csv.gz file with the output of this function.

Parameters:
filenamestr

Name for compressed-gzipped MERMAID data file. Should end in ‘.csv.gz’.

Notes

See also https://github.com/JEFworks/MERmaid