Plotting UMAPS For Multiple .mtx Files Overlayed

Hi I am relatively new to using scanpy and I was recently trying to figure out how to plot a UMAP for multiple .mtx files. I have been able to color specific genes and number the umap leiden cluster for a single .mtx but I am unable to overlay two .mtx files for a singular UMAP without getting a positional argument error. I have tried the following to concatenate my .mtx files as so:

adata_healthy_raw_rna = sc.read_10x_mtx(‘healthy_MTX/healthy_raw_rna’, var_names=‘gene_symbols’, cache=True)

adata_cll_rna_raw = sc.read_10x_mtx(‘cll_MTX/cll_rna_raw’,var_names=‘gene_symbols’, cache=True)

adataFiles = [adata_healthy_raw_rna, adata_cll_rna_raw ]

adata_concatenated = adataFiles [0].concatenate(adataFiles [1:], index_unique=None)

and after doing so tried plotting the UMAP as such:

sc.pl.umap(adata_concatenated, color=[adata_healthy_raw_rna, adata_cll_rna_raw )

However, I am getting this error:

/usr/local/lib/python3.7/dist-packages/anndata/_core/anndata.py:1785: FutureWarning: X.dtype being converted to np.float32 from float64. In the next version of anndata (0.9) conversion will not be automatic. Pass dtype explicitly to avoid this warning. Pass AnnData(X, dtype=X.dtype, ...) to get the future behavour.
[AnnData(sparse.csr_matrix(a.shape), obs=a.obs) for a in all_adatas],

KeyError: “Could not find ‘umap’ or ‘X_umap’ in .obsm”

The data successfully concatenates the two .mtx files but how do I correctly plot a UMAP with a concatenated .mtx file such that I can differentiate the two files by color?

Hey @kparakul,

You would need to first compute a UMAP of your combined files (see sc.tl.umap).

If you want to color by experiment, you should make sure there is a column in obs annotating that. I’d recommend something like:

import anndata as ad, scanpy as sc

# Load and concat
adata = sc.concat(
    {
        "healthy": sc.read_10x_mtx(‘healthy_MTX/healthy_raw_rna’, var_names=‘gene_symbols’),
        "cll": sc.read_10x_mtx(‘cll_MTX/cll_rna_raw’,var_names=‘gene_symbols’)
    },
    merge="unique",
    label="condition",
)

# preprocess + compute umap
# not shown, but you can find this in https://scanpy-tutorials.readthedocs.io/en/latest/pbmc3k.html

# plot
sc.pl.umap(adata, color="condition")

I can’t thank you enough I appreciate the help, that worked perfectly!

1 Like