Answers.Body: <p>With a little bit of workaround:</p>
  <p>i) Add a new column to the data slot (only because your original subset() call  does so but it can be raw counts or any other data matrix in your Seurat object). <code>rowSums()</code> determines how many non-zero counts you have.</p>
  <pre><code>df<span class="math-container">$non_zero &lt;- rowSums(cbind(df$</span>gene1 &gt; 0, df<span class="math-container">$gene2 &gt; 0, df$</span>gene3 &gt; 0, ...)) &gt; 1
  </code></pre>
  <p>Change df with the your data slot, should be sth like <code>YourSeuratObject@...$data</code>.</p>
  <p>ii) Subset the newly modified data slot, basically treating the new column as another gene. Be careful not to use this column in preprocessing steps like normalization.</p>
  <pre><code>YourSeuratObject &lt;- subset(YourSeuratObject, non_zero &gt; 1), slot = &quot;data&quot;)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-24T08:44:41.603Z
Answers.Text: Hi, Thanks so much for your quick response. I've tried many many combinations with my seurat object data slot -myData@assays$RNA@data$KIR2DL1 - but I dont know how to access the information via the gene name. Thanks again!!
Answers.UserDisplayName: Tirza Doniger
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-28T06:01:29.893Z
Answers.Text: Hi, Does anyone know how to access the gene name via the Seurat data sctructure as descibed in the answer above.
Answers.UserDisplayName: Tirza Doniger
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-28T13:13:22.400Z
Answers.Text: https://github.com/satijalab/seurat/wiki/Seurat#slots goes over how to interact with Seurat objects. Think of a Seurat object as a container and within it there are several assays (RNA, DNA, ...) and within each of these assays there are different (data) slots, for example one for raw counts, one for normalized counts... You might need sth like: `GetAssayData(object = seurat_object, slot = 'data')[1:5, 1:5]`. Check the manual for `GetAssayData()`, you can get a specific data slot from a specific assay.
Answers.UserDisplayName: haci
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-14T13:44:06.607Z
Answers.LastActivityDate: 2021-06-14T13:44:06.607Z
Answers.UserDisplayName: haci
Body: <p>Originally- I was looking if in at least one of these genes were expressed:</p>
  <pre><code>test1 &lt;- subset(myData,
                    (KLRC1 &gt; 0) | (KIR2DL1 &gt; 0) | 
                  (KIR2DL3 &gt; 0) | (KIR2DL4 &gt; 0) |
                  (KIR3DL1 &gt; 0) | (KIR3DL2 &gt; 0) | (KIR3DL3 &gt; 0), slot = &quot;data&quot;)
  </code></pre>
  <p>Now- I would like to subset if expressed in at least two of these genes- is this possible with the subset function?</p>
  
Tags: <seurat><single-cell>
Title: Seurat - subsetting by genes expressed
ThreadText: # Seurat - subsetting by genes expressed
  
  (Asked by: username_0 on 2021-06-14)
  
  Originally- I was looking if in at least one of these genes were expressed:
  
  ```
  test1 <- subset(myData,
                    (KLRC1 > 0) | (KIR2DL1 > 0) | 
                  (KIR2DL3 > 0) | (KIR2DL4 > 0) |
                  (KIR3DL1 > 0) | (KIR3DL2 > 0) | (KIR3DL3 > 0), slot = "data")
  
  ```
  
  Now- I would like to subset if expressed in at least two of these genes- is this possible with the subset function?
  
  **Tags:** seurat, single-cell
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-06-14. Score: 1
  
  With a little bit of workaround:
  
  i) Add a new column to the data slot (only because your original subset() call does so but it can be raw counts or any other data matrix in your Seurat object). `rowSums()` determines how many non-zero counts you have.
  
  ```
  df$non_zero <- rowSums(cbind(df$gene1 > 0, df$gene2 > 0, df$gene3 > 0, ...)) > 1
  
  ```
  
  Change df with the your data slot, should be sth like `YourSeuratObject@...$data`.
  
  ii) Subset the newly modified data slot, basically treating the new column as another gene. Be careful not to use this column in preprocessing steps like normalization.
  
  ```
  YourSeuratObject <- subset(YourSeuratObject, non_zero > 1), slot = "data")
  
  ```
  
  > **Comments:**
  > **username_0**: Hi, Thanks so much for your quick response. I've tried many many combinations with my seurat object data slot -myData@assays$RNA@data$KIR2DL1 - but I dont know how to access the information via the gene name. Thanks again!!  
  > **username_0**: Hi, Does anyone know how to access the gene name via the Seurat data sctructure as descibed in the answer above.  
  > **username_1**: https://github.com/satijalab/seurat/wiki/Seurat#slots goes over how to interact with Seurat objects. Think of a Seurat object as a container and within it there are several assays (RNA, DNA, ...) and within each of these assays there are different (data) slots, for example one for raw counts, one for normalized counts... You might need sth like: `GetAssayData(object = seurat_object, slot = 'data')[1:5, 1:5]`. Check the manual for `GetAssayData()`, you can get a specific data slot from a specific assay.  
  
  ---
  
  