multiassayexperiment package

Subpackages

Submodules

multiassayexperiment.MultiAssayExperiment module

class multiassayexperiment.MultiAssayExperiment.MultiAssayExperiment(experiments, column_data=None, sample_map=None, metadata=None, _validate=True)[source]

Bases: BiocObject

Container class for representing and managing multi-omics genomic experiments.

Checkout the R/MultiAssayExperiment for more information.

__copy__()[source]
Returns:

A shallow copy of the current MultiAssayExperiment.

__deepcopy__(memo=None, _nil=[])[source]
Returns:

A deep copy of the current MultiAssayExperiment.

__getitem__(args)[source]

Subset a MultiAssayExperiment.

Parameters:

args (tuple) –

Tuple containing slices along dimensions (rows, columns, experiments).

Each element in the tuple, might be either a integer vector (integer positions), boolean vector or slice object. Defaults to None.

Raises:

ValueError – Too many or too few slices.

Return type:

MultiAssayExperiment

Returns:

A new sliced MultiAssayExperiment object with the subsets.

__init__(experiments, column_data=None, sample_map=None, metadata=None, _validate=True)[source]

Initialize an instance of MultiAssayExperiment.

You may also initialize an MultiAssayExperiment using make_mae or by transform from from_mudata and from_anndata objects.

If both column_data and sample_map are None, the constructor naively creates sample mapping, with each experiment considered to be a independent sample. We add a sample to col_data in this pattern - unknown_sample_{experiment_name}. All cells from the same experiment are considered to be from the same sample and is reflected in sample_map.

Parameters:
  • experiments (dict[str, Any]) –

    A dictionary containing experiments, with experiment names as keys and the experiments as values.

    Each experiment may be either a SummarizedExperiment or any class that extends SummarizedExperiment.

  • column_data (BiocFrame | None) –

    Bio-specimen/sample information.

    column_data may provide information about patients, cell lines, or other biological units.

    Each row in this table represents an independent biological unit. It must contain an index that maps to the ‘primary’ in sample_map.

    Defaults to None.

  • sample_map (BiocFrame | None) –

    Map biological units from column_data to the list of experiments.

    Must contain columns “assay”, “primary”, and “colname”.

    • assay provides the names of the different experiments performed on the biological units.

      All experiment names from experiments must be present in this column.

    • primary contains the sample name. All names in this column must match with row labels from

      column_data.

    • colname is the mapping of samples/cells within each experiment back to its biosample information in

      column_data.

    Each sample in column_data may map to one or more columns per assay.

    Defaults to None.

  • metadata (dict[str, Any] | NamedList | None) – Additional study-level metadata. Defaults to None.

  • _validate (bool) – Internal use only.

__repr__()[source]
Return type:

str

Returns:

A string representation.

add_experiment(name, experiment, sample_map, column_data=None, in_place=False)[source]

Add a new experiment to MultiAssayExperiment.

sample_map must be provided to map the columns from this experiment to column_data. This will be appended to the existing sample_map.

Optionally, column_data may be provided to add new sample information.

Parameters:
  • name (str) – Name of the new experiment.

  • experiment (Any) – The experiment to add.

  • sample_map (BiocFrame) – Sample map to append to the MAE.

  • column_data (BiocFrame | None) –

    Sample data to append to the MAE.

    Defaults to None.

  • in_place (bool) – Whether to modify the MultiAssayExperiment in place. Defaults to False.

Return type:

MultiAssayExperiment

Returns:

A modified MultiAssayExperiment object, either as a copy of the original or as a reference to the (in-place-modified) original.

property assays: dict[str, Any]

Alias for get_experiments().

property colnames: dict[str, Names | None]

Alias for get_column_names, provided for back-compatibility.

property column_data: BiocFrame

Alias for get_column_data().

property column_names: dict[str, Names | None]

Alias for get_column_names, provided for back-compatibility.

property columnnames: dict[str, Names | None]

Alias for get_column_names, provided for back-compatibility.

complete_cases()[source]

Identify samples that have data across all experiments.

Return type:

Sequence[bool]

Returns:

A boolean vector same as the number of samples in ‘column_data’, where each element is True if sample is present in all experiments or False.

copy()[source]

Alias for __copy__().

experiment(name, with_sample_data=False)[source]

Get an experiment by name.

Parameters:
  • name (int | str) – Name or index position of the experiment.

  • with_sample_data (bool) –

    Whether to merge column data of the experiment with sample_data from the MAE.

    Defaults to False.

Raises:
  • AttributeError – If the experiment name does not exist.

  • IndexError – If index is greater than the number of experiments.

Return type:

Any

Returns:

The experiment object.

If with_sample_data is True, a copy of the experiment object is returned.

property experiment_names: list[str]

Alias for get_experiment_names().

property experiments: dict[str, Any]

Alias for get_experiments().

find_common_row_names()[source]

Finds common row names across all experiments.

Return type:

list[str]

classmethod from_anndata(input, name='unknown')[source]

Create a MultiAssayExperiment from AnnData.

Since AnnData does not contain sample information, sample named "unknown_sample" will be added to col_data. All cells are considered to be extracted from this sample and is reflected in sample_map.

Parameters:
  • input (anndata.AnnData) – An AnnData object.

  • name (str) –

    Name for the experiment.

    Defaults to “unknown”.

Return type:

MultiAssayExperiment

Returns:

An MultiAssayExperiment.

classmethod from_mudata(input)[source]

Create a MultiAssayExperiment object from MuData.

The import naively creates sample mapping, each experiment is considered to be a sample. We add a sample with the following pattern - "unknown_sample_{experiment_name}" to col_data. All cells from the same experiment are considered to be extracted from the same sample and is reflected in sample_map.

Parameters:

input (mudata.MuData) – MuData object.

Raises:

Exception – If mudata object is read in backed mode isbacked.

Return type:

MultiAssayExperiment

Returns:

MultiAssayExperiment object.

get_column_data()[source]

Get sample metadata.

Return type:

BiocFrame

Returns:

A BiocFrame containing sample metadata.

get_column_names()[source]
Return type:

dict[str, Names | None]

Returns:

Dictionary, with experiment names as keys, and the column names as values.

get_experiment(name, with_sample_data=False)[source]

Alias for experiment().

Return type:

Any

get_experiment_names()[source]

Get experiment names.

Return type:

list[str]

Returns:

List of experiment names.

get_experiments()[source]

Access experiments.

Return type:

dict[str, Any]

Returns:

A dictionary of all experiments, with experiment names as keys and experiment data as value.

get_row_names()[source]
Return type:

dict[str, Names | None]

Returns:

Dictionary, with experiment names as keys, and row names as values.

get_sample_map()[source]

Acess sample map.

Return type:

BiocFrame

Returns:

A BiocFrame with sample mapping information.

get_with_column_data(name)[source]

Alias to experiment().

Consistency with Bioconductor’s naming of the same function.

Return type:

Any

intersect_rows()[source]

Finds common row names across all experiments and filters the MAE to these rows.

Return type:

MultiAssayExperiment

Returns:

A new sliced MultiAssayExperiment object with the filtered rows.

replicated()[source]

Identify samples with replicates within each experiment.

Return type:

dict[str, dict[str, Sequence[bool]]]

Returns:

A dictionary where experiment names are keys and values specify if the sample is replicated within each experiment.

property rownames: dict[str, Names | None]

Alias for get_row_names, provided for back-compatibility.

property sample_map: BiocFrame

Alias for get_sample_map().

set_column_data(column_data, in_place=False)[source]

Set new sample metadata.

Parameters:
  • column_data (BiocFrame) – New sample metadata.

  • in_place (bool) – Whether to modify the MultiAssayExperiment in place.

Return type:

MultiAssayExperiment

Returns:

A modified MultiAssayExperiment object, either as a copy of the original or as a reference to the (in-place-modified) original.

set_experiment_names(names, in_place=False)[source]

Replace experiments’s names.

Parameters:
  • names (list[str]) – New names.

  • in_place (bool) – Whether to modify the MultiAssayExperiment in place.

Return type:

MultiAssayExperiment

Returns:

A modified MultiAssayExperiment object, either as a copy of the original or as a reference to the (in-place-modified) original.

set_experiments(experiments, in_place=False)[source]

Set new experiments.

Parameters:
  • experiments (dict[str, Any]) –

    New experiments to set. A dictionary of experiments with experiment names as keys and the experiments as values.

    Each experiment may be either a SummarizedExperiment or any class that extends SummarizedExperiment.

  • in_place (bool) – Whether to modify the MultiAssayExperiment in place.

Return type:

MultiAssayExperiment

Returns:

A modified MultiAssayExperiment object, either as a copy of the original or as a reference to the (in-place-modified) original.

set_sample_map(sample_map, in_place=False)[source]

Set new sample mapping.

Parameters:
  • sample_map (BiocFrame) – New sample map.

  • in_place (bool) – Whether to modify the MultiAssayExperiment in place.

Return type:

MultiAssayExperiment

Returns:

A modified MultiAssayExperiment object, either as a copy of the original or as a reference to the (in-place-modified) original.

subset_by_column(columns)[source]

Subset by column.

Parameters:

columns (str | int | bool | Sequence) –

Columns to be extracted.

Integer indices, a boolean filter, or (if the current object is named) names specifying the ranges to be extracted, see normalize_subscript().

Return type:

MultiAssayExperiment

Returns:

A new MultiAssayExperiment with the subsetted columns.

subset_by_experiments(experiments)[source]

Subset by experiment(s).

Parameters:

experiments (str | int | bool | Sequence) –

Experiments to extract.

Integer indices, a boolean filter, or (if the current object is named) names specifying the ranges to be extracted, see normalize_subscript().

Check experiment_names for a list of valid experiment names.

Return type:

MultiAssayExperiment

Returns:

A new MultiAssayExperiment with the subset experiments.

subset_by_row(rows)[source]

Subset by rows.

Parameters:

rows (str | int | bool | Sequence) –

Rows to be extracted.

Integer indices, a boolean filter, or (if the current object is named) names specifying the ranges to be extracted, see normalize_subscript().

Return type:

MultiAssayExperiment

Returns:

A new MultiAssayExperiment with the subsetted rows.

subset_experiments(rows, columns, experiment_names)[source]

Subset experiments.

Parameters:
  • rows (str | int | bool | Sequence | None) –

    Row indices to subset.

    Integer indices, a boolean filter, or (if the current object is named) names specifying the ranges to be extracted, see normalize_subscript().

  • columns (str | int | bool | Sequence | None) –

    Column indices (from column_data) to subset.

    Integer indices, a boolean filter, or (if the current object is named) names specifying the ranges to be extracted, see normalize_subscript().

  • experiment_names (str | int | bool | Sequence) –

    Experiment names to keep.

    Integer indices, a boolean filter, or (if the current object is named) names specifying the ranges to be extracted, see normalize_subscript().

    Check experiment_names for a list of valid experiment names.

Return type:

dict[str, Any]

Returns:

A dictionary with experiment names as keys and the subsetted experiment data as value.

to_mudata()[source]

Transform MultiAssayExperiment object to MuData.

Returns:

A MuData representation.

class multiassayexperiment.MultiAssayExperiment.SlicerResult(experiments, sample_map, column_data)

Bases: tuple

__annotations__ = {}
__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__match_args__ = ('experiments', 'sample_map', 'column_data')
static __new__(_cls, experiments, sample_map, column_data)

Create new instance of SlicerResult(experiments, sample_map, column_data)

__repr__()

Return a nicely formatted representation string

__slots__ = ()
column_data

Alias for field number 2

experiments

Alias for field number 0

sample_map

Alias for field number 1

Module contents