adata.Load.Rd
This documentation encompasses a suite of functions designed to facilitate the conversion and management of data between Seurat objects and AnnData structures. The functions cover the entire workflow from initial conversion of Seurat objects to Loom or AnnData formats, adding supplementary data like dimension reductions and metadata, and saving or loading these objects for further analysis.
adata.Load(adata.path, conda_env = "seuratextend")
adata.Save(adata.path, conda_env = "seuratextend")
adata.AddDR(
seu,
dr = NULL,
prefix = "X_",
scv.graph = FALSE,
load.adata = NULL,
save.adata = NULL,
conda_env = "seuratextend"
)
adata.AddMetadata(
seu,
col,
load.adata = NULL,
save.adata = NULL,
conda_env = "seuratextend"
)
adata.LoadLoom(loompath, save.adata = NULL, conda_env = "seuratextend")
Seu2Adata(
seu,
add.normdata = TRUE,
save.adata = NULL,
conda_env = "seuratextend"
)
Seu2Loom(
seu,
filename,
add.normdata = FALSE,
add.metadata = TRUE,
layers = NULL,
overwrite = FALSE
)
Path to the AnnData (.h5ad) file where the data is to be saved or from which data is to be loaded.
Name of the Conda environment where the necessary Python libraries are installed. This environment is used to run Python code from R, bridging Seurat and AnnData functionalities. Default: 'seuratextend'.
The Seurat object from which data is being converted or managed.
Specifies which dimension reductions from the Seurat object should be transferred to the AnnData object. If NULL, all available reductions are included. Default: NULL.
A prefix to add to the dimension reduction names when importing them into the AnnData object's 'obsm' attribute. This helps in differentiating various data types and maintaining order within the dataset. Default: 'X_'.
Optional; a boolean indicating whether to calculate the velocity graph after importing dimension reduction data. This is useful for kinetic analyses in single-cell studies. Default: FALSE.
Optional; path to a previously saved AnnData object to be loaded. Default: NULL. Useful for resuming analyses or integrating additional data without repeating preprocessing steps.
Optional; specifies the file path where the AnnData object should be saved after processing. The file will be saved in the .h5ad format. This parameter facilitates easy storage of processed data.
The name of the metadata column in the Seurat object that needs to be transferred to the AnnData object.
Path to the loom file that needs to be loaded into an AnnData object.
Boolean indicating whether to also include the normalized gene expression matrix in the loom file.
Filename for the loom file to be created or accessed. It specifies where the loom file will be stored or is stored, which is essential for data conversion tasks.
Boolean indicating whether to also include the meta.data in the loom file.
Optional; a list of additional matrices to include as layers in the loom file, such as velocyto's spliced/unspliced matrices. Each matrix must match the transposed dimensions of the Seurat object (row for cells and columns for genes). Default: NULL.
Depending on the function called, this suite returns either a modified Seurat object or an AnnData object, or it may perform save/load operations without returning an object. Specifically:
- `Seu2Adata` and `Seu2Loom` convert Seurat objects to AnnData and Loom formats, respectively.
- `adata.LoadLoom` loads a Loom file into an AnnData object.
- `adata.AddDR` and `adata.AddMetadata` enrich an AnnData object with additional dimension reduction data and metadata from a Seurat object.
- `adata.Save` and `adata.Load` handle saving to and loading from disk operations for AnnData objects.
These functions are designed to ensure seamless interoperability between R, used primarily for Seurat, and Python, used for AnnData via the reticulate package:
- `Seu2Adata` directly converts a Seurat object into an AnnData object, optionally adding normalized data and saving the result.
- `Seu2Loom` converts a Seurat object into a Loom file, allowing for intermediate storage or further conversion.
- `adata.LoadLoom` initiates an AnnData object from a Loom file, useful for integrating with Python-based analyses.
- `adata.AddDR` appends dimension reduction results from Seurat to an AnnData object, essential for preserving comprehensive analytical context.
- `adata.AddMetadata` transfers additional metadata from Seurat to AnnData, facilitating enriched data analyses.
- `adata.Save` provides functionality to save AnnData objects to disk, securing data for future use.
- `adata.Load` retrieves AnnData objects from disk, ensuring continuity of analysis across sessions.
These tools are integral for researchers employing hybrid workflows that leverage the strengths of both Seurat and Scanpy/AnnData environments, supporting a wide range of computational tasks from data preprocessing to advanced analyses.
library(Seurat)
library(SeuratExtend)
library(reticulate)
# Convert Seurat object to loom file and save it locally
pbmc_loom_path <- file.path(tempdir(), "pbmc3k_small.loom")
Seu2Loom(pbmc, filename = pbmc_loom_path, add.normdata = TRUE)
# Load the loom file into an AnnData object
adata.LoadLoom(loompath = pbmc_loom_path)
# Use reticulate to execute Python code and print the AnnData object details
py_run_string("print(adata)")
# Add dimension reduction data from Seurat to AnnData
adata.AddDR(pbmc)
py_run_string("print(adata)")
# Directly convert Seurat object to AnnData object including all processing steps
Seu2Adata(pbmc)
# Update AnnData with new metadata from Seurat
pbmc$cluster2 <- pbmc$cluster
adata.AddMetadata(pbmc, col = "cluster2")
py_run_string("print(adata)")
# Save the AnnData object to a local file
pbmc_adata_path <- file.path(tempdir(), "pbmc3k_small.h5ad")
adata.Save(pbmc_adata_path)
# Load an existing AnnData object from file
adata.Load(pbmc_adata_path)