<p>It will not improve your correlation most likely, unless the zeros are not missing at random:</p>

<pre><code>library(Seurat)
data &lt;- pbmc_small
data[["percent.mt"]] &lt;- PercentageFeatureSet(data, pattern = "^MT-")
data &lt;- NormalizeData(data)
genes &lt;-c("HLA-DRA","LYZ")
countdata = pbmc_small[["RNA"]]@data
countdata &lt;- t(as.matrix(countdata)[genes,])
plot(countdata)
</code></pre>

<p><a href="https://i.sstatic.net/Ku1se.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Ku1se.png" alt="enter image description here"></a></p>

<p>Now you need to subset the matrix, and remove the rows where at least one of the entries is 0, you can use rowSums(..==0)==0, meaning no zeros in the rows:</p>

<pre><code>plot(countdata[rowSums(countdata==0)==0,])
</code></pre>

<p><a href="https://i.sstatic.net/Xsbyw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Xsbyw.png" alt="enter image description here"></a></p>

<pre><code>cor(countdata[rowSums(countdata==0)==0,])
          HLA-DRA       LYZ
HLA-DRA 1.0000000 0.2338371
LYZ     0.2338371 1.0000000
</code></pre>

CC BY-SA 4.0
2020-05-21T17:39:36.977Z
Thank you very much, SmartWolf. 
I tried to put your code on R.
I put a series of commands as follows. 

(1) Tumors.data <- Read10X(data.dir = “…/filtered_feature_bc_matrix")
(2) Tumors <- CreateSeuratObject(counts = Tumors.data, project = "Tumors", min.cells = 3, min.features = 200)
(3) Tumors[["percent.mt"]] <- PercentageFeatureSet(Tumors, pattern = "^MT-")
(4) Tumors <- subset(Tumors, subset= nFeature_RNA >200 & nFeature_RNA <2500)
(5) Tumors <- NormalizeData(Tumors)
(6) genes <- c(“Cd4”, “Foxp3”)
raiora
CC BY-SA 4.0
2020-05-21T17:40:05.500Z
When I put the command “countdata <- t(as.matrix(countdata)[genes,]),
it showed me that “Error in as.matrix(countdata) : object 'countdata' not found”

I tried to put another command as follows. 
“countdata <-t(as.matrix(Tumors.data)[genes,])”, which at least worked with no error occurred.
raiora
CC BY-SA 4.0
2020-05-21T17:40:26.960Z
sorry @raiora, was missing a line.. in your case, do ```countdata = Tumors[["RNA"]]@data```
StupidWolf
CC BY-SA 4.0
2020-05-21T17:49:02.613Z
You are welcome. So, I am now working on it. However, in the command "countdata = pbmc_small[["RNA"]]@data", I am little bit confused. In my case, should the "countdata = Tumors[["RNA"]]@data? Sorry.
raiora
CC BY-SA 4.0
2020-05-21T17:50:20.197Z
In my understanding, data refers to Tumors (seurat object) and pbmc_small would be Tumors.data
raiora
CC BY-SA 4.0
2020-05-21T17:52:16.593Z
I put the command "countdata = Tumors[["RNA"]]@data", which worked.
raiora
CC BY-SA 4.0
2020-05-21T17:54:40.193Z
Thank you so much @SmartWolf (Your ID does not work here for me:))
raiora
CC BY-SA 4.0
2020-05-21T17:56:16.257Z
you're welcome :) sorry for the hiccup. have fun with analysis
StupidWolf
CC BY-SA 4.0
2020-05-21T17:57:16.277Z
One more question, how can I select your answer in my question? I am familiar with StackExchange site. Thank you.
raiora
CC BY-SA 4.0
2020-05-21T14:37:27.003Z
2020-05-21T17:41:29.003Z
2020-05-21T17:41:29.003Z
StupidWolf
<p>Nowadays, I am trying to calculate Pearson correlation values between two genes of my interest from single-cell RNA-data (features.tsv, barcodes.tsv, and matrix.mtx files) which are obtained from the 10xgenomics cellranger. I am interested in tumor-infiltrating Tregs. I downloaded fastq files from a published paper that describes tumor-infiltrating Tregs with IL10+IL35+ (<a href="https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE126184" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE126184</a>), and ran "cellranger count".</p>

<p>Yesterday, I learned how to get a Pearson correlation value from a kind guy. I made a graph below.
<a href="https://i.sstatic.net/bgVbh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bgVbh.png" alt="enter image description here"></a></p>

<p>In general, Tregs are defined by CD4 and Foxp3 expression. As a trial, I want to find the correlation between two genes. The correlation value was 0.05, which might have been due to the presence of Tregs that have zero value of either CD4 or Foxp3. So, my question is that can we remove cells with 0 value of genes to get more high correlation value? My data looks like this.</p>

<pre><code>
&gt; Treg.data[c("Cd4", "Foxp3"), 1:30]

------------------------------------- # results

2 x 30 sparse Matrix of class "dgCMatrix"
   [[ suppressing 30 column names ‘AAACCTGAGAAACCAT-1’, ‘AAACCTGAGAAACCGC-1’, ‘AAACCTGAGAAACCTA-1’ ... ]]

Cd4   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Foxp3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


------------------------------------- # results
</code></pre>

<p>Each dot represents 0 value. </p>

<p>Meanwhile, I performed to standard pre-processing workflow, as suggested in Seural Tutorial. For example, </p>

<pre><code>&gt; Treg[["percent.mt"]] &lt;- PercentageFeatureSet(Treg, pattern = "^MT-")

&gt; Treg &lt;- subset(Treg, subset = nFeature_RNA &gt; 200 &amp; nFeature_RNA &lt; 2500 &amp; percent.mt &lt; 5)
</code></pre>

<p>Can you help me? Thank you very much.</p>

<r><scrnaseq><seurat><correlation>
How to remove zero value of gene on FeatureScatter plot using Seurat?
# How to remove zero value of gene on FeatureScatter plot using Seurat?

(Asked by: username_0 on 2020-05-20)

Nowadays, I am trying to calculate Pearson correlation values between two genes of my interest from single-cell RNA-data (features.tsv, barcodes.tsv, and matrix.mtx files) which are obtained from the 10xgenomics cellranger. I am interested in tumor-infiltrating Tregs. I downloaded fastq files from a published paper that describes tumor-infiltrating Tregs with IL10+IL35+ (https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE126184), and ran "cellranger count".
Yesterday, I learned how to get a Pearson correlation value from a kind guy. I made a graph below.

In general, Tregs are defined by CD4 and Foxp3 expression. As a trial, I want to find the correlation between two genes. The correlation value was 0.05, which might have been due to the presence of Tregs that have zero value of either CD4 or Foxp3. So, my question is that can we remove cells with 0 value of genes to get more high correlation value? My data looks like this.

> Treg.data[c("Cd4", "Foxp3"), 1:30]

------------------------------------- # results

2 x 30 sparse Matrix of class "dgCMatrix"
   [[ suppressing 30 column names ‘AAACCTGAGAAACCAT-1’, ‘AAACCTGAGAAACCGC-1’, ‘AAACCTGAGAAACCTA-1’ ... ]]

Cd4   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Foxp3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


------------------------------------- # results

Each dot represents 0 value. 
Meanwhile, I performed to standard pre-processing workflow, as suggested in Seural Tutorial. For example, 
> Treg[["percent.mt"]] <- PercentageFeatureSet(Treg, pattern = "^MT-")

> Treg <- subset(Treg, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5)

Can you help me? Thank you very much.

**Tags:** r, scrnaseq, seurat, correlation

---

## 1 answers

### Answer by username_1 on 2020-05-21. Score: 1 | Accepted answer

It will not improve your correlation most likely, unless the zeros are not missing at random:
library(Seurat)
data <- pbmc_small
data[["percent.mt"]] <- PercentageFeatureSet(data, pattern = "^MT-")
data <- NormalizeData(data)
genes <-c("HLA-DRA","LYZ")
countdata = pbmc_small[["RNA"]]@data
countdata <- t(as.matrix(countdata)[genes,])
plot(countdata)


Now you need to subset the matrix, and remove the rows where at least one of the entries is 0, you can use rowSums(..==0)==0, meaning no zeros in the rows:
plot(countdata[rowSums(countdata==0)==0,])


cor(countdata[rowSums(countdata==0)==0,])
          HLA-DRA       LYZ
HLA-DRA 1.0000000 0.2338371
LYZ     0.2338371 1.0000000

> **Comments:**
> **username_0**: Thank you very much, SmartWolf.  I tried to put your code on R. I put a series of commands as follows.   (1) Tumors.data <- Read10X(data.dir = “…/filtered_feature_bc_matrix") (2) Tumors <- CreateSeuratObject(counts = Tumors.data, project = "Tumors", min.cells = 3, min.features = 200) (3) Tumors[["percent.mt"]] <- PercentageFeatureSet(Tumors, pattern = "^MT-") (4) Tumors <- subset(Tumors, subset= nFeature_RNA >200 & nFeature_RNA <2500) (5) Tumors <- NormalizeData(Tumors) (6) genes <- c(“Cd4”, “Foxp3”)  
> **username_0**: When I put the command “countdata <- t(as.matrix(countdata)[genes,]), it showed me that “Error in as.matrix(countdata) : object 'countdata' not found”  I tried to put another command as follows.  “countdata <-t(as.matrix(Tumors.data)[genes,])”, which at least worked with no error occurred.  
> **username_1**: sorry @raiora, was missing a line.. in your case, do ```countdata = Tumors[["RNA"]]@data```  
> **username_0**: You are welcome. So, I am now working on it. However, in the command "countdata = pbmc_small[["RNA"]]@data", I am little bit confused. In my case, should the "countdata = Tumors[["RNA"]]@data? Sorry.  
> **username_0**: In my understanding, data refers to Tumors (seurat object) and pbmc_small would be Tumors.data  
> **username_0**: I put the command "countdata = Tumors[["RNA"]]@data", which worked.  
> **username_0**: Thank you so much @SmartWolf (Your ID does not work here for me:))  
> **username_1**: you're welcome :) sorry for the hiccup. have fun with analysis  
> **username_0**: One more question, how can I select your answer in my question? I am familiar with StackExchange site. Thank you.  

---

