AnnData Module

The AnnData struct is imported from Muon.jl. The package provides read and write functions for .h5ad and .h5mu files, the typical H5-based format for storing Python anndata objects. The AnnData object stores datasets together with metadata, such as information on the variables (genes in scRNA-seq data) and observations (cells), as well as different kinds of annotations and transformations of the original count matrix, such as PCA or UMAP embeddings, or graphs of observations or variables.

For details on the Julia implementation in Muon.jl, see the documentation.

For more details on the original Python implementation of the anndata object, see the documentation and preprint.

anndata

celltypes

Juscan.get_celltypesFunction
get_celltypes(a::AnnData)

Tries to infer the cell types of cells in an AnnData object.

Returns a vector of cell type names if the cell types are stored in adata.obs["cell_type"], adata.obs["celltype"], adata.obs["celltypes"], or adata.obs["cell_types"]. Otherwise, returns nothing.

source

subset adata

Juscan.subset_adataFunction
subset_adata(adata::AnnData, subset_inds::Tuple, dims::Symbol=:both)

Subset an AnnData object by indices passed as a tuple of vectors of integers, UnitRanges, or vectors of Booleans. If dims is set to :both, the first element of subset_inds is used to subset cells and the second element is used to subset genes.

Arguments

  • adata: AnnData object to subset
  • subset_inds: tuple of vectors of integers, UnitRanges, or vectors of Booleans
  • dims: dimension to subset, either :cells, :genes, or :both

Returns

  • a copy of the AnnData object with the subsetted data
source
subset_adata(adata::AnnData, subset_inds::Union{Int, Vector{Int}, UnitRange, Vector{Bool}}, dims::Symbol)

Subset an AnnData object by indices passed as a vector of integers or booleans or as a UnitRange. The dims argument can be set to either :cells or :genes to specify which dimension to subset.

Arguments

  • adata: AnnData object to subset
  • subset_inds: vector of integers or booleans or UnitRange
  • dims: dimension to subset, either :cells or :genes

Returns

  • a copy of the AnnData object with the subsetted data
source
Juscan.subset_adata!Function
subset_adata!(adata::AnnData, subset_inds, dims::Symbol)

In-place version of subset_adata, see ?subset_adata for more details.

For subset_inds, either a tuple of vectors or ranges can be passed with dims set to :both, for subsetting both cells and genes, or a single vector or range can be passed with dims set to either :cells or :genes.

Arguments

  • adata: AnnData object to subset
  • subset_inds: tuple of vectors of integers, UnitRanges, or vectors of Booleans or vector of integers or booleans or UnitRange
  • dims: dimension to subset, either :cells, :genes, or :both

Returns

  • the AnnData object with the subsetted data
source

insert

Juscan.insert_obs!Function
insert_obs!(adata::AnnData, obs::DataFrame)

Insert new columns into the obs DataFrame of an AnnData object.

Arguments

  • adata: The AnnData object to modify.
  • obs: A DataFrame containing the new columns to be inserted. The number of rows in obs must match the number of cells in adata.

Returns

  • nothing: Modifies the adata.obs DataFrame in place.

Notes

  • This function assumes that the number of rows in obs matches the number of cells in adata. If they do not match, an error will be thrown.
  • This function modifies the adata.obs DataFrame directly. If you want to keep the original adata unchanged, make a copy before calling this function.
source
Juscan.insert_var!Function
insert_var!(adata::AnnData, var::DataFrame)

Insert new columns into the var DataFrame of an AnnData object.

Arguments

  • adata: The AnnData object to modify.
  • var: A DataFrame containing the new columns to be inserted. The number of rows in var must match the number of genes in adata.

Returns

  • nothing: Modifies the adata.var DataFrame in place.

Notes

  • This function assumes that the number of rows in var matches the number of genes in adata. If they do not match, an error will be thrown.
  • This function modifies the adata.var DataFrame directly. If you want to keep the original adata unchanged, make a copy before calling this function.
source