0
$\begingroup$

I am analysing my single cell RNA seq data with the Seurat package. I want to know if there is a possibilty to obtain the percentage expression of a list of genes per identity class, as actual numbers (e.g. a matrix) which I can write out to say an excel file. For example I want to be able to say gene X is expressed in 30% of cell A, 10% of cell B etc.

I can generate something comparable with:

DotPlot(object = my_object, genes.plot = "my_gene")

However the results are only graphic and I wish to have further processible numbers.

Furthermore:

AverageExpression(object, genes.use = "my_gene")

Produces expression values which I cannot transform to percentages.

I will be very grateful on any hints.

$\endgroup$
  • $\begingroup$ Did you read the tutorials of seurat? Why you cannot transform to percentage expression values? $\endgroup$ – llrs Feb 15 '19 at 8:49
  • $\begingroup$ @IIrs I will be very grateful for any hint. I am not able to figure a way how I can convert expression values for one cell type into percentage expression for that cell type. To say X% of my cell type C expresses this gene G. $\endgroup$ – Charles Feb 15 '19 at 9:21
3
$\begingroup$

This can be solved like this:

library(Seurat)

my_genes <- c("gene1", "gene2", "gene3")

exp <- FetchData(object, my_genes)

matrix <- as.matrix(colMeans(exp  > 0))*100
|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ Glad you found your way! Perhaps explaining how did you find this solution (what did you look up and where) will help your future self or other people in the same situation. Also are you sure that FetchData retrieve the expession data? (Also which one, the raw data, the scaled data or the imputed data?) $\endgroup$ – llrs Feb 15 '19 at 11:18
2
$\begingroup$

You can get the table that is used to make the dot plot if you modify the DotPlot function to return it instead of the ggplot, and use the argument do.return=T.

To edit the function, the command is:

trace("DotPlot",edit=TRUE)

Then replace the last line "return(p)" by "return(data.to.plot)" and save the edit.

You can call the function and store the return in a variable.

The editing doesn't affect the source code, so the function will be untouched at your next R session.

Best,

|improve this answer|||||
$\endgroup$
0
$\begingroup$

Also potentially useful is the solution proposed here: https://github.com/satijalab/seurat/issues/1888

Basically, save DotPlot to an object, and your percentages are found within.

|improve this answer|||||
New contributor
David Garfield is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.