Showing the expression of a set of genes as 0 , 1 binaries
0
0
Entering edit mode
6.2 years ago

Hi,

Usually, when we are trying to plot the marker intensities in a heat map or feature plot, they have strongly skewed distributions with varying ranges of expression, thus making it difficult to distinguish between the negative and positive cell populations. It is common practice to transform marker intensities with a cofactor. For example like below but this gets quantile while I need binary

library(matrixStats)
rng <- colQuantiles(expr, probs = c(0.01, 0.99))
expr01 <- t((t(expr) - rng[, 1]) / (rng[, 2] - rng[, 1]))
expr01[expr01 < 0] <- 0
expr01[expr01 > 1] <- 1

Assuming I have a list of 10 genes A,B,C,D,E,F,G,H,I and J. I want to set expression of each of them to 0.1 so when all of 10 genes are exist in a cluster of cells (showing by heat map or feature plot) I obtain 1 (10*0.1), when none of them are exist I obtain 0, when 9 of them exist in an expression matrix I obtain 0.9, so on. I mean converting expression values to 0 or 1 (off, on) only to be able distinguish cell populations. But I don't have any idea how to do that, any help please?

R seurat heatmap featureplot • 1.8k views
ADD COMMENT
0
Entering edit mode

Okay, but please show the formatting of your data. In which data-type is your gene list stored?; in which data-type is your cluster of cells stored?

ADD REPLY
0
Entering edit mode

Thanks a lot, for example we have cells 1 to 3 and genes A to E

      CELL1 CELL2 CELL3
A       0.0   1.0   1.0
B       0.0   1.0   0.0
C       0.0   1.0   0.0
D       1.0   0.0   1.0
E       1.0   1.0   1.0
Ratio   0.4   0.8   0.6
>

Based on a threshold the ratio of the expression of genes A,B,C,D,E in CELL1 is 0.4 (2/5), 0.8 in CELL2 (4/5) and 0.6 in CELL3 (3/5). So when in heat map or feature plot we are colouring these genes in these cells, CELL1, CELL2 and CELL3 would show distinct colours not noisy. 0 and 1 are not nessacarily numbers rather each binary phase can gets this matrix but I am not sure how produce this matrix. By codes provided above I produce such a matrix and by colSum/number of genes I have a vector of ratios in each cell like

> print(a)
      cell1       cell2       cell3       cell5       cell6       cell7      cell8       cell9       cell10      cell11      cell12      cell13      cell13      cell14      cell15      cell16 
0.06410152 0.07752379 0.06369479 0.07459530 0.06719271 0.05856992 0.06727406 0.07044660 0.04799479 0.07052794 0.05279427 0.07736110 0.07166680 0.06938908 0.07239893 0.06637924

Now I want to color the cells in my seurat object based this vector but nothing in googling I am finding for that

ADD REPLY
0
Entering edit mode

Maybe this practical example will help:

df <- data.frame(CELL1=c(0.0,0.5,0.6,0.5), CELL2=c(0.5,0.2,0.1,0.4), CELL3=c(1.0,0.6,0.77,0.2), row.names=c("A","B","C","D"))
df
  CELL1 CELL2 CELL3
A   0.0   0.5  1.00
B   0.5   0.2  0.60
C   0.6   0.1  0.77
D   0.5   0.4  0.20

thresholds <- c(CELL1=0.4, CELL2=0.8, CELL3=0.6)
thresholds
CELL1 CELL2 CELL3 
  0.4   0.8   0.6 

t(apply(df, 1, function (x) ifelse(x>thresholds, 1, 0)))
  CELL1 CELL2 CELL3
A     0     0     1
B     1     0     0
C     1     0     1
D     1     0     0
ADD REPLY
0
Entering edit mode

Thanks a lot, I think we are somehow close to the solution; You know, I can not put a distinct threshold for each cell in a big matrix as you defined for 3 cells. matrixStats package either by colQuantiles, colRanges or colRanks functions returns values between 0 and 1 while I need either 0 or 1. Now, my problem is, given an expression matrix how change your or below code or provide a new function that transform my matrix to 0 and 1 values (100% binary)

rng <- colQuantiles(expr, probs = c(0.01, 0.99))
expr01 <- t((t(expr) - rng[, 1]) / (rng[, 2] - rng[, 1]))
expr01[expr01 < 0] <- 0
expr01[expr01 > 1] <- 1

https://ibb.co/jPDRqU

ADD REPLY

Login before adding your answer.

Traffic: 2131 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6