singlecellexperiment package¶
Subpackages¶
Submodules¶
singlecellexperiment.SingleCellExperiment module¶
- class singlecellexperiment.SingleCellExperiment.SingleCellExperiment(assays: Dict[str, Any] | None = None, row_ranges: GenomicRanges | GenomicRangesList | None = None, row_data: BiocFrame | None = None, column_data: BiocFrame | None = None, row_names: List[str] | None = None, column_names: List[str] | None = None, metadata: dict | None = None, reduced_dims: Dict[str, Any] | None = None, main_experiment_name: str | None = None, alternative_experiments: Dict[str, Any] | None = None, row_pairs: Any | None = None, column_pairs: Any | None = None, validate: bool = True)[source]¶
Bases:
RangedSummarizedExperiment
Container class for single-cell experiments, extending
RangedSummarizedExperiment
to provide slots for embeddings and alternative experiments that share the same cells.In contrast to R,
ndarray
or scipy matrices are unnamed and do not contain rownames and colnames. Hence, these matrices cannot be directly used as values in assays or alternative experiments. We strictly enforce type checks in these cases.To relax these restrictions for alternative experiments, set
type_check_alternative_experiments
to False.If you are using the alternative experiment slot, the number of cells must match the parent experiment. Otherwise, these cells do not share the same sample or annotations and cannot be set in alternative experiments!
Note: Validation checks do not apply to
row_pairs
orcol_pairs
.- alternative_experiment(name: str | int) Any [source]¶
Access alternative experiment by name.
- Parameters:
name – Name or index position of the alternative experiment.
- Raises:
AttributeError – If the dimension name does not exist.
IndexError – If index is greater than the number of reduced dimensions.
- Returns:
The alternative experiment.
- property alternative_experiment_names: List[str]¶
Alias for
get_alternative_experiment_names()
.
- property alternative_experiments: Dict[str, Any]¶
Alias for
get_alternative_experiments()
.
- property column_pair_names: List[str]¶
Alias for
get_column_pair_names()
.
- property column_pairs: Dict[str, Any]¶
Alias for
get_column_pairs()
.
- copy()[source]¶
Alias for
__copy__()
.
- classmethod from_anndata(input: anndata.AnnData) SingleCellExperiment [source]¶
Create a
SingleCellExperiment
fromAnnData
.- Args:
- input:
Input data.
- Returns:
A
SingleCellExperiment
object. If the input contains any data in theuns
attribute, the metadata slot of theSingleCellExperiment
will contain a keyuns
.
- get_alternative_experiment_names() List[str] [source]¶
Access alternative experiment names.
- Returns:
List of alternative experiment names.
- get_alternative_experiments() Dict[str, Any] [source]¶
Access alternative experiments.
- Returns:
A dictionary with names of the experiments as keys and value the experiment.
- get_column_pair_names() List[str] [source]¶
Access column pair names.
- Returns:
List of column pair names.
- get_column_pairs() Dict[str, Any] [source]¶
Access column pairings/relationships between cells.
- Returns:
Access column pairs.
- get_main_experiment_name() str | None [source]¶
Access main experiment name.
- Returns:
Name if available, otherwise None.
- get_reduced_dim_names() List[str] [source]¶
Access reduced dimension names.
- Returns:
List of reduced dimensionality names.
- get_reduced_dims() Dict[str, Any] [source]¶
Access dimensionality embeddings.
- Returns:
A dictionary with keys as names of embedding method and value the embedding.
- get_row_pairs() Dict[str, Any] [source]¶
Access row pairings/relationships between features.
- Returns:
Access row pairs.
- get_slice(rows: str | int | bool | Sequence | None, columns: str | int | bool | Sequence | None) SingleCellExperiment [source]¶
Alias for
__getitem__
, for back-compatibility.
- property main_experiment_name: str | None¶
Alias for
get_main_experiment_name()
.
- reduced_dim(dimension: str | int) Any [source]¶
Access an embedding by name.
- Parameters:
dimension – Name or index position of the reduced dimension.
- Raises:
AttributeError – If the dimension name does not exist.
IndexError – If index is greater than the number of reduced dimensions.
- Returns:
The embedding.
- property reduced_dim_names: List[str]¶
Alias for
get_reduced_dim_names()
.
- property reduced_dims: Dict[str, Any]¶
Alias for
get_reduced_dims()
.
- property row_pair_names: List[str]¶
Alias for
get_row_pair_names()
.
- property row_pairs: Dict[str, Any]¶
Alias for
get_row_pairs()
.
- set_alternative_experiment_names(names: List[str], in_place: bool = False) SingleCellExperiment [source]¶
Replace
alternative_experiment
’s names.- Parameters:
names – New alternative experiment names.
in_place – Whether to modify the
SingleCellExperiment
in place.
- Returns:
A modified
SingleCellExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_alternative_experiments(alternative_experiments: Dict[str, Any], in_place: bool = False) SingleCellExperiment [source]¶
Set new alternative experiments.
- Parameters:
alternative_experiments – New alternative experiments.
in_place – Whether to modify the
SingleCellExperiment
in place.
- Returns:
A modified
SingleCellExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_column_pair_names(names: List[str], in_place: bool = False) SingleCellExperiment [source]¶
Replace
column_pair
’s names.- Parameters:
names – New names.
in_place – Whether to modify the
SingleCellExperiment
in place.
- Returns:
A modified
SingleCellExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_column_pairs(pairs: Dict[str, Any], in_place: bool = False) SingleCellExperiment [source]¶
Replace
column_pairs
’s names.- Parameters:
names – New column pairs.
in_place – Whether to modify the
SingleCellExperiment
in place.
- Returns:
A modified
SingleCellExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_main_experiment_name(name: str | None, in_place: bool = False) SingleCellExperiment [source]¶
Set new experiment data (assays).
- Parameters:
name – New main experiment name.
in_place – Whether to modify the
SingleCellExperiment
in place.
- Returns:
A modified
SingleCellExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_reduced_dim_names(names: List[str], in_place: bool = False) SingleCellExperiment [source]¶
Replace
reduced_dims
’s names.- Parameters:
names – New dimensionality names.
in_place – Whether to modify the
SingleCellExperiment
in place.
- Returns:
A modified
SingleCellExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_reduced_dims(reduced_dims: Dict[str, Any], in_place: bool = False) SingleCellExperiment [source]¶
Set new reduced dimensions.
- Parameters:
reduced_dims – New embeddings.
in_place – Whether to modify the
SingleCellExperiment
in place.
- Returns:
A modified
SingleCellExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_row_pair_names(names: List[str], in_place: bool = False) SingleCellExperiment [source]¶
Replace
row_pair
’s names.- Parameters:
names – New names.
in_place – Whether to modify the
SingleCellExperiment
in place.
- Returns:
A modified
SingleCellExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- set_row_pairs(pairs: Dict[str, Any], in_place: bool = False) SingleCellExperiment [source]¶
Replace
row_pairs
’s names.- Parameters:
names – New row pairs.
in_place – Whether to modify the
SingleCellExperiment
in place.
- Returns:
A modified
SingleCellExperiment
object, either as a copy of the original or as a reference to the (in-place-modified) original.
- to_anndata(include_alternative_experiments: bool = False)[source]¶
Transform
SingleCellExperiment
-like into aAnnData
representation.- Parameters:
include_alternative_experiments – Whether to transform alternative experiments.
- Returns:
A tuple with
AnnData
main experiment and a list of alternative experiments.
- to_mudata()[source]¶
Transform
SingleCellExperiment
object intoMuData
representation.If
main_experiment_name
is None, this experiment is called Unknown Modality in theMuData
object.- Returns:
A MuData object.
- singlecellexperiment.SingleCellExperiment.combine_columns(*x: SingleCellExperiment) SingleCellExperiment [source]¶
Combine multiple
SingleCellExperiment
objects by column.All assays must contain the same assay names. If you need a flexible combine operation, checkout
relaxed_combine_columns()
.- Returns:
A combined
SingleCellExperiment
.
- singlecellexperiment.SingleCellExperiment.combine_rows(*x: SingleCellExperiment) SingleCellExperiment [source]¶
Combine multiple
SingleCellExperiment
objects by row.All assays must contain the same assay names. If you need a flexible combine operation, checkout
relaxed_combine_rows()
.- Returns:
A combined
SingleCellExperiment
.
- singlecellexperiment.SingleCellExperiment.relaxed_combine_columns(*x: SingleCellExperiment) SingleCellExperiment [source]¶
A relaxed version of the
combine_columns()
method forSingleCellExperiment
objects. Whereascombine_columns
expects that all objects have the same rows,relaxed_combine_columns
allows for different rows. Absent columns in any object are filled in with appropriate placeholder values before combining.- Parameters:
x – One or more
SingleCellExperiment
objects, possibly with differences in the number and identity of their rows.- Returns:
A
SingleCellExperiment
that combines allexperiments
along their columns and contains the union of all rows. Rows absent in anyx
are filled in with placeholders consisting of Nones or masked NumPy values.
- singlecellexperiment.SingleCellExperiment.relaxed_combine_rows(*x: SingleCellExperiment) SingleCellExperiment [source]¶
A relaxed version of the
combine_rows()
method forSingleCellExperiment
objects. Whereascombine_rows
expects that all objects have the same columns,relaxed_combine_rows
allows for different columns. Absent columns in any object are filled in with appropriate placeholder values before combining.- Parameters:
x – One or more
SingleCellExperiment
objects, possibly with differences in the number and identity of their columns.- Returns:
A
SingleCellExperiment
that combines allexperiments
along their rows and contains the union of all columns. Columns absent in anyx
are filled in with placeholders consisting of Nones or masked NumPy values.