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.
celltypes
Juscan.get_celltypes
— Functionget_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
.
subset adata
Juscan.subset_adata
— Functionsubset_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 subsetsubset_inds
: tuple of vectors of integers, UnitRanges, or vectors of Booleansdims
: dimension to subset, either:cells
,:genes
, or:both
Returns
- a copy of the
AnnData
object with the subsetted data
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 subsetsubset_inds
: vector of integers or booleans or UnitRangedims
: dimension to subset, either:cells
or:genes
Returns
- a copy of the
AnnData
object with the subsetted data
Juscan.subset_adata!
— Functionsubset_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 subsetsubset_inds
: tuple of vectors of integers, UnitRanges, or vectors of Booleans or vector of integers or booleans or UnitRangedims
: dimension to subset, either:cells
,:genes
, or:both
Returns
- the
AnnData
object with the subsetted data
insert
Juscan.insert_obs!
— Functioninsert_obs!(adata::AnnData, obs::DataFrame)
Insert new columns into the obs
DataFrame of an AnnData
object.
Arguments
adata
: TheAnnData
object to modify.obs
: A DataFrame containing the new columns to be inserted. The number of rows inobs
must match the number of cells inadata
.
Returns
nothing
: Modifies theadata.obs
DataFrame in place.
Notes
- This function assumes that the number of rows in
obs
matches the number of cells inadata
. If they do not match, an error will be thrown. - This function modifies the
adata.obs
DataFrame directly. If you want to keep the originaladata
unchanged, make a copy before calling this function.
Juscan.insert_var!
— Functioninsert_var!(adata::AnnData, var::DataFrame)
Insert new columns into the var
DataFrame of an AnnData
object.
Arguments
adata
: TheAnnData
object to modify.var
: A DataFrame containing the new columns to be inserted. The number of rows invar
must match the number of genes inadata
.
Returns
nothing
: Modifies theadata.var
DataFrame in place.
Notes
- This function assumes that the number of rows in
var
matches the number of genes inadata
. If they do not match, an error will be thrown. - This function modifies the
adata.var
DataFrame directly. If you want to keep the originaladata
unchanged, make a copy before calling this function.