This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Locating cells in a tSNE or Featureplot based on the defined threshold

Hi,

I have 209 cells, I have clustered them by Seurat to 4 clusters. By Featureplot

> FeaturePlot(object = seuset_16,
+             features.plot = "DDB_G0273311")
+             )
>

I am able to track this gene in clusters like this picture:

https://ibb.co/nDRRZd

Higher color shows higher expression and vice versa, however I don't know the threshold, so I don't know when two different genes become yellow which of them really express more.

So, for some genes I want to highlight some cells in Featureplot so that apart from yellow or red colours I want to colour a subsets of cells with another color. I mean I want to map a list of cells in Featureplot or tSNE plot. Let's say I want to know the location of cells 1, 4, 80 and highlight them with another color. My Seurat object in this link

https://drive.google.com/file/d/1rLsRXrxJPYm8cSzSqa5WUR6NYaUr-e9f/view?usp=sharing.

Featureplot or whatever are in this object but unfortunately I am not able to manipulate them

Seurat itself beautifully maps the cells in Featureplot for defined genes with a gradient of colours showing the level of expression. Saying I have genes A and B, in excel https://drive.google.com/file/d/1sks1fwe2yWCQp8n7WFUB480pnECBdhPk/view?usp=sharing

I have coloured cells that express a gene > mean + se, < mean - se or between these values. For instance, for this gene, 36 cells express this gene > mean + se, I want to map these cells in Featureplot or tSNE plot in distinct colour so I can locate them in clusters easily. Something like binary (on off) expression to relative expression.

How I can change the colour of some cells based on my threshold for this gene please?

single cell r seurat featureplot tsne

1 answer

Perhaps you can have a column $gene.threshold in object@data.info$gene.threshold where you give cells with a certain level of expression for the gene a distinct name.

object<-SetIdent(object,ident.use=object@data.info$gene.threshold)

Then once you plot Seurat should label and color by these identities.

Sorry

> seuset_h16@hvg.info
                gene.mean gene.dispersion gene.dispersion.scaled
DDB_G0270154 1.4858490971    5.5021196865           6.751459e+00
DDB_G0294034 7.2490053075    5.2312526037           0.000000e+00
DDB_G0277845 1.3339219089    5.2149818741           5.848234e+00

I am not good here at all, how I can ask seurat to give me the threshold I want e.g. man+se mean-se, etc?? I tested with and without the below code but the density of color in Featureplot was the same

object<-SetIdent(seuset_h16,ident.use=seuset_h16@hvg.info$gene.mean)

May you please help me more?

What I would do is obtain the cells with the threshold you want and then set the identity name based on this, then I would do a tsne plot with these labels. I'm getting an error when I try to do a tsne plot with your data though, have you been able to do this? I'm not sure if you can label a feature plot, since this is showing expression of an individual gene. Here is the code I used:

#set this to the cutoff gene expression you want, in this case I am using it for scale.data
cutoff=1
seuset_h16@ident=as.factor(seuset_h16@scale.data["DDB_G0270154",]>cutoff)

seuset_h16@ident<-as.factor(ifelse(seuset_h16@ident == "TRUE", "High", "Low"))

head(seuset_h16@scale.data["DDB_G0270154",]>1,100)
s1.1   s1.2   s1.3   s1.4   s1.5   s1.6   s1.7   s1.8   s1.9  s1.10  s1.11 
FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE 
s1.12  s1.13  s1.14  s1.15  s1.16  s1.17  s1.18  s1.19  s1.20  s1.21  s1.22 
TRUE  FALSE  FALSE  FALSE   TRUE  FALSE   TRUE  FALSE  FALSE  FALSE  FALSE 
s1.23  s1.24  s1.25  s1.26  s1.27  s1.28  s1.29  s1.30  s1.31  s1.32  s1.33 
FALSE  FALSE   TRUE  FALSE  FALSE  FALSE   TRUE   TRUE  FALSE  FALSE  FALSE 
s1.34  s1.35  s1.36  s1.37  s1.38  s1.39  s1.40  s1.41  s1.42  s1.43  s1.44 
FALSE  FALSE  FALSE   TRUE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE 
s1.45  s1.46  s1.47  s1.48  s1.49  s1.50  s1.51  s1.52  s1.53  s1.54  s1.55 
TRUE   TRUE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE 
s1.56  s1.57  s1.58  s1.59  s1.60  s1.61  s1.62  s1.63  s1.64  s1.65  s1.66 
FALSE   TRUE   TRUE   TRUE  FALSE   TRUE  FALSE   TRUE  FALSE  FALSE  FALSE 
s1.67  s1.68  s1.69  s1.70  s1.71  s1.72  s1.73  s1.74  s1.75  s1.76  s1.77 
FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE 
s1.78  s1.79  s1.80  s1.81  s1.82  s1.83  s1.84  s1.85  s1.86  s1.87  s1.88 
FALSE  FALSE  FALSE  FALSE  FALSE  FALSE   TRUE   TRUE  FALSE  FALSE   TRUE 
s1.89  s1.90  s1.91  s1.92  s1.93  s1.94  s1.95  s1.96  s1.97  s1.98  s1.99 
FALSE   TRUE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE 
s1.100 
FALSE 

head(seuset_h16@ident,100)
[1] Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  High Low  Low  Low 
[16] High Low  High Low  Low  Low  Low  Low  Low  High Low  Low  Low  High High
[31] Low  Low  Low  Low  Low  Low  High Low  Low  Low  Low  Low  Low  Low  High
[46] High Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  High High High Low 
[61] High Low  High Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low  Low 
[76] Low  Low  Low  Low  Low  Low  Low  Low  High High Low  Low  High Low  High
[91] Low  Low  Low  Low  Low  Low  Low  Low  Low  Low 
Levels: High Low


#seuset_h16 <- RunTSNE(object = seuset_h16, dims.use = 1:10, do.fast = TRUE)


TSNEPlot(object = seuset_h16, do.label = TRUE, pt.size = 0.5)
#Error in seq.default(h[1], h[2], length.out = n) :  'to' must be a finite number

Thank you for your time, I plotted.

Thank you for your time, I plotted. Sorry, by doing hover I noticed all of cells have been labelled by 1, and FALSE or TRUE identS. That means I can't differentiate the cluster identities anymore (clusters 0, 1, 2, 3) as link

https://drive.google.com/file/d/1ipXg2Nb9lM_JgIH6WgVV-PoLhEtzLWif/view?usp=sharing

How can I color the cells with preserving their cluster identities?

You can save the identities and go back to these if necessary by setting the identity again, or you can change the code to create identities based on the previous identity and the value of the gene, for example:

Low_4, Low_3, etc as done here:

I would still suggest saving the original identities in a vector so you can always go back to these in case you want to analyze a different gene.

Log in to answer this question.