Help concatenating var for cite seq

I have a CITE seq experiment where the GEX and antibody capture were mapped separately, so that I have to load in two different matrices.

adata_adt = sc.read_10x_mtx( "data/CITESeq_381/", gex_only = False )

adata_gex = sc.read_10x_mtx( "data/GEX_381/filtered_feature_bc_matrix/", gex_only = True )

I subset to only cells with GEX and ADT

common_cells = np.intersect1d(adata_adt.obs_names, adata_gex.obs_names)
adata_adt = adata_adt[common_cells]
adata_gex = adata_gex[common_cells]

I have read the concat documents and am still not able to concat to a single adata object that has var from both objects while at the same preserving the correct obs.

What would be the best way to concat/merge these?

Thank you!

I spoke too soon. chatGPT 3.5 was no good, but I tried with chatGPT 4 and got it on the first try!

Hopefully can help other people:

import anndata
import pandas as pd

# assuming adata_gex and adata_adt are your two anndata objects
# concatenate the data matrices along variables axis
adata_X = pd.concat([pd.DataFrame(adata_gex.X.toarray(), 
  index=adata_gex.obs.index, columns=adata_gex.var.index),
                     pd.DataFrame(adata_adt.X.toarray(), 
  index=adata_adt.obs.index, columns=adata_adt.var.index)], axis=1)

# concatenate the variables
adata_var = pd.concat([adata_gex.var, adata_adt.var])

# create new AnnData object
adata = anndata.AnnData(X=adata_X.values, obs=adata_gex.obs, var=adata_var)
1 Like

Hey @bennjmo,

Iā€™m curious if muon can also be helpful for you here: it has loaders for CITE-seq data, which are then stored in a MuData object with two AnnData objects as individual modalities.