spatialfeatureexperiment package¶
Submodules¶
spatialfeatureexperiment.SpatialFeatureExperiment module¶
- class spatialfeatureexperiment.SpatialFeatureExperiment.SpatialFeatureExperiment(assays=None, row_ranges=None, row_data=None, column_data=None, row_names=None, column_names=None, metadata=None, reduced_dims=None, main_experiment_name=None, alternative_experiments=None, alternative_experiment_check_dim_names=True, row_pairs=None, column_pairs=None, spatial_coords=None, img_data=None, col_geometries=None, row_geometries=None, annot_geometries=None, spatial_graphs=None, unit='full_res_image_pixel', validate=True, **kwargs)[source]¶
Bases:
SpatialExperiment
Container class for storing data from spatial-omics experiments with feature geometries.
This class extends SpatialExperiment to provide slots for geometries of spots/cells, tissue boundaries, pathologist annotations and other spatial features.
- __init__(assays=None, row_ranges=None, row_data=None, column_data=None, row_names=None, column_names=None, metadata=None, reduced_dims=None, main_experiment_name=None, alternative_experiments=None, alternative_experiment_check_dim_names=True, row_pairs=None, column_pairs=None, spatial_coords=None, img_data=None, col_geometries=None, row_geometries=None, annot_geometries=None, spatial_graphs=None, unit='full_res_image_pixel', validate=True, **kwargs)[source]¶
Initialize a spatial feature class.
- Parameters:
A dictionary containing matrices, with assay names as keys and 2-dimensional matrices represented as either
ndarray
orspmatrix
.Alternatively, you may use any 2-dimensional matrix that has the
shape
property and implements the slice operation using the__getitem__
dunder method.All matrices in assays must be 2-dimensional and have the same shape (number of rows, number of columns).
row_ranges (
Union
[GenomicRanges
,GenomicRangesList
,None
]) – Genomic features, must be the same length as the number of rows of the matrices in assays.row_data (
Optional
[BiocFrame
]) –Features, must be the same length as the number of rows of the matrices in assays.
Feature information is coerced to a
BiocFrame
. Defaults to None.column_data (
Optional
[BiocFrame
]) –Sample data, must be the same length as the number of columns of the matrices in assays. For instances of the
SpatialExperiment
class, the sample data must include a column named sample_id. If any ‘sample_id’ in the sample data is not present in the ‘sample_id’s of ‘img_data’, a warning will be issued.If sample_id is not present, a column with this name will be created and filled with the default value sample01.
Sample information is coerced to a
BiocFrame
. Defaults to None.row_names (
Optional
[List
[str
]]) – A list of strings, same as the number of rows.Defaults to None.column_names (
Optional
[List
[str
]]) – A list of strings, same as the number of columns. Defaults to None.metadata (
Optional
[dict
]) – Additional experimental metadata describing the methods. Defaults to None.reduced_dims (
Optional
[Dict
[str
,Any
]]) –Slot for low-dimensionality embeddings.
Usually a dictionary with the embedding method as keys (e.g., t-SNE, UMAP) and the dimensions as values.
Embeddings may be represented as a matrix or a data frame, must contain a shape.
main_experiment_name (
Optional
[str
]) – A string, specifying the main experiment name.alternative_experiments (
Optional
[Dict
[str
,Any
]]) –Used to manage multi-modal experiments performed on the same sample/cells.
Alternative experiments must contain the same cells (rows) as the primary experiment. It’s a dictionary with keys as the names of the alternative experiments (e.g., sc-atac, crispr) and values as subclasses of
SummarizedExperiment
.alternative_experiment_check_dim_names (
bool
) –Whether to check if the column names of the alternative experiment match the column names of the main experiment. This is the equivalent to the
withDimnames
parameter in the R implementation.Defaults to True.
Row pairings/relationships between features.
Defaults to None.
column_pairs (
Optional
[Any
]) –Column pairings/relationships between cells.
Defaults to None.
spatial_coords (
Union
[BiocFrame
,ndarray
,None
]) –Optional
ndarray
orBiocFrame
containing columns of spatial coordinates. Must be the same length as column_data.If spatial_coords is a
BiocFrame
, typical column names might include:[‘x’, ‘y’]: For simple 2D coordinates.
[‘pxl_col_in_fullres’, ‘pxl_row_in_fullres’]: For pixel-based
coordinates in full-resolution images.
If spatial coordinates is a
DataFrame
or None, it is coerced to aBiocFrame
. Defaults to None.img_data (
Optional
[BiocFrame
]) –- Optional
BiocFrame
containing the image data, structured with the following columns: sample_id (str): A string identifier for the sample to which an image corresponds.
image_id (str): A unique string identifier for each image within each sample.
data (VirtualSpatialImage): The image itself, represented as a VirtualSpatialImage object or one of its subclasses.
scale_factor (float): A numerical value that indicates the scaling factor applied to the image.
All ‘sample_id’s in ‘img_data’ must be present in the ‘sample_id’s of ‘column_data’.
Image data are coerced to a
BiocFrame
. Defaults to None.- Optional
col_geometries (
Optional
[Dict
[str
,GeoDataFrame
]]) – Dictionary of GeoDataFrames containing geometries for columns (e.g. cells, spots).row_geometries (
Optional
[Dict
[str
,GeoDataFrame
]]) – Dictionary of GeoDataFrames containing geometries for rows (e.g. genes).annot_geometries (
Optional
[Dict
[str
,GeoDataFrame
]]) – Dictionary of GeoDataFrames containing annotation geometries (e.g. tissue boundaries).spatial_graphs (
Optional
[BiocFrame
]) – BiocFrame containing spatial neighborhood graphs.unit (
str
) – Unit for spatial coordinates (‘full_res_image_pixel’ or ‘micron’).validate (
bool
) – Internal use only.
- copy()[source]¶
Alias for
__copy__()
.
- set_annot_geometries(geometries, in_place=False)[source]¶
Set annotation geometries.
- Parameters:
- Return type:
ProxySpatialFeatureExperiment
- Returns:
A modified
ProxySpatialFeatureExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_col_geometries(geometries, in_place=False)[source]¶
Set column geometries.
- Parameters:
- Return type:
ProxySpatialFeatureExperiment
- Returns:
A modified
ProxySpatialFeatureExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_column_data(cols, replace_column_names=False, in_place=False)[source]¶
Override: Set sample data.
- Parameters:
cols (
Optional
[BiocFrame
]) –New sample data. If ‘cols’ contains a column named ‘sample_id’s, a check is performed to ensure that all ‘sample_id’s in the ‘img_data’ are present. If any ‘sample_id’ in the ‘cols’ is not present in the ‘sample_id’s of ‘img_data’, a warning will be issued.
If ‘sample_id’ is not present or ‘cols’ is None, the original ‘sample_id’s are retained.
replace_column_names (
bool
) – Whether to replace experiment’s column_names with the names from the new object. Defaults to False.in_place (
bool
) – Whether to modify theProxySpatialFeatureExperiment
in place. Defaults to False.
- Return type:
ProxySpatialFeatureExperiment
- Returns:
A modified
ProxySpatialFeatureExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_row_geometries(geometries, in_place=False)[source]¶
Set row geometries.
- Parameters:
- Return type:
ProxySpatialFeatureExperiment
- Returns:
A modified
ProxySpatialFeatureExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_spatial_graphs(graphs, in_place=False)[source]¶
Set spatial neighborhood graphs.
- Parameters:
- Return type:
ProxySpatialFeatureExperiment
- Returns:
A modified
ProxySpatialFeatureExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.