satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.29k stars 915 forks source link

Getting the AverageExpression per CLUSTER per EXPERIMENTAL CONDITION #4458

Closed tanasa closed 3 years ago

tanasa commented 3 years ago

Dear all, i would appreciate having your answer please to a simple question : is there a way to write the R code for AverageExpression() in such a way that we obtain the AverageExpression per CLUSTER per EXPERIMENT ? We do have 54 clusters in our data and 10 experimental conditions. Thanks a lot,

-- bogdan

samuel-marsh commented 3 years ago

Hi,

Not member of dev team but hopefully can be helpful. Please refer to the manual entry for AverageExpression. You just need to specify your groups to the group.by parameter.

Best, Sam

tanasa commented 3 years ago

Thank you Sam. yes, both the commands below work fine :

cluster.averages.CLUSTER.SEURAT <- AverageExpression(samples.combined.list.combined, slot = "data", group.by = "seurat_clusters" , return.seurat = TRUE)

head(cluster.averages.CLUSTER.SEURAT@assays$RNA@counts)

or

cluster.averages.CLUSTER <- AverageExpression(samples.combined.list.combined, slot = "data", group.by = "seurat_clusters" , return.seurat = FALSE)

head(cluster.averages.CLUSTER$RNA)

and provide the same results. I was wondering if there is a fast way to compute the average expression based on 2 criteria; in other words, is the command below syntactically correct ? just to double check :

AverageExpression(samples.combined.list.combined, slot = "data", group.by = c("seurat_clusters", "celltype.stim") , return.seurat = FALSE)

samuel-marsh commented 3 years ago

Hi,

Yes, as the manual says: group.by: Categories for grouping (e.g, ident, replicate, celltype); 'ident' by default

You easily see this by passing the return of AverageExpression to a data.frame:

avg_test <- data.frame(AverageExpression(object = obj, group.by = c("ident", "Treatment")))

avg_expression

In my case this groups by both ident (i.e. Astrocyte 1 and Astrocyte 2) and Treatment (INHIB and NO_INHIB).

Best, Sam

tanasa commented 3 years ago

thank you Sam ! interesting - are you working on A1 and A2 astrocytes in the context of neurodegeneration ? We have a project on A1 and A2 astrocytes in the context of optical nerve crush, although we can possibly talk more offline about these.

and thank you for your suggestions :) !

samuel-marsh commented 3 years ago

Hi,

Not specifically no. The astrocyte 1 and 2 here are just two different homeostatic clusters of astrocytes in one of my datasets.

Best, Sam