Creating a UMAP plot based on custom data

Hi all,

I am trying to create a UMAP plot with custom data. I can use the function scanpy.pl.umap(AnnData_object, color = [“gene”]) to get a UMAP plot displaying the level of expression of “gene” per cell. I have generated a gene set expression score per cell and would like to display this score instead of the expression of a gene.

To solve this, I thought I could append an extra “gene” to the AnnData expression array and fill it with the gene set expression scores. I was doing this by iterating through each cell and adding the score to the expression array with this code: numpy.append(AnnData_object.X[cell_number,:], gene_set_expression_score). However, I don’t know how to access this data with the scanpy.pl.umap function. Specifically, what would I set color equal to? Is there a better way to do this?

Thanks very much for your time.

If you have an expression set score, per cell barcode, I think you can add a column to the .obs attribute of the anndata obj. Specifically:

adata.obs['genesetScore'] = listOfScores

So long as that list corresponds to the same order of cells as the order of indices of the .obs attribute.

1 Like

Then set color = 'genesetScore'

Your method worked perfectly. Gah so simple! Thanks.

No problem! Glad it worked.