text: user8563: I am relatively new to Bioinformatics and scRNA-seq data analysis. I am using Seurat V3 to analyze a scRNA-seq dataset in R. Currently, I have merged three scRNA-seq samples from the same donor into one Seurat object, All_Samples. We'll call them:
  
  Uninfected
  Virus1
  Virus2
  All_Samples <- merge(x = Uninfected, y = c(Virus1, Virus2))
  
  
  Uninfected cells did not receive virus (i.e. express no viral genes), the other two samples were infected with a virus introducing new genes into the cells. I would like to accomplish two things. 
  First: I want to create a new Ident for Virus1 and Virus2 samples based on expression of a viral gene  of interest: "GeneA". All cells from Virus1 and Virus2 samples that have "GeneA" expression > 0.5 would be labeled "Pos", those with "GeneA" < 0.5 would be labeled "Neg" in a  the new Column called GeneA. 
  I am able to subset the objects based on GeneA expression that applies to all samples in the object. For example:
  All_Samples_GeneA_Pos <- subset(All_Samples, subset = GeneA > 0.5)
  All_Samples_GeneA_Neg <- subset(All_Samples, subset = GeneA < 0.5)
  
  I assume I would have to modify All_Samples@meta.data based on this post and this post, but I admit I'm not entirely sure how to implement the suggested answers into my data. 
  Second: Once I have separated the data from Virus1 and Virus2 into "Pos" and "Neg" cells for "GeneA", I want to look for differentially expressed genes between all Uninfected cells and "Pos" cells from Virus1 or Virus2. I have been using something like this to compare samples:
   FindMarkers(object = All_Samples, group.by = 'virus', ident.1 = "1", ident.2 = "2")
  
  But how would I do something equivalent to this: 
   FindMarkers(object = All_Samples, ident.1 = "Uninfected", ident.2 = "Virus1_GeneA_Pos")
  
  Or maybe
   FindMarkers(object = All_Samples, ident.1 = "Uninfected_GeneA_Neg", ident.2 = "Virus1_GeneA_Pos")
  
  Let me know if I can clarify any points. I appreciate any help!
  
  user3541: For the first question, you can use ifelse() to create a new column in the meta.data slot:
  All_Samples@meta.data$new_column <-
    ifelse(
      rownames(All_Samples@meta.data) %in% colnames(All_Samples_GeneA_Pos),
      "GeneA_Pos",
      "GeneB_Pos"
    )
  
  colnames(seurat_object) provides a vector of cell names in a given Seurat object. Here whatever cell that is in the All_Samples_GeneA_Pos object would be GeneA_Pos and whatever is not GeneB_Pos. To better control the behavior, you can use a "nested" ifelse(); you can have another ifelse() instead of the "GeneB_Pos" bit above.
  For the second question, the rationale is the same as above, you can define an extra column with the "identities of interest", then use these identities with SetIdent() and then in turn using two identities of interest in the differential expression call.
  
original_text: 8563: <p>I am relatively new to Bioinformatics and scRNA-seq data analysis. I am using Seurat V3 to analyze a scRNA-seq dataset in R. Currently, I have merged three scRNA-seq samples from the same donor into one Seurat object, <em>All_Samples</em>. We'll call them:</p>
  
  <ol>
  <li>Uninfected</li>
  <li>Virus1</li>
  <li><p>Virus2</p>
  
  <pre><code>All_Samples &lt;- merge(x = Uninfected, y = c(Virus1, Virus2))
  </code></pre></li>
  </ol>
  
  <p>Uninfected cells did not receive virus (i.e. express no viral genes), the other two samples were infected with a virus introducing new genes into the cells. I would like to accomplish two things. </p>
  
  <p><strong>First</strong>: I want to create a new Ident for Virus1 and Virus2 samples based on expression of a viral gene  of interest: "GeneA". All cells from Virus1 and Virus2 samples that have "GeneA" expression > 0.5 would be labeled "Pos", those with "GeneA" &lt; 0.5 would be labeled "Neg" in a  the new Column called GeneA. </p>
  
  <p>I am able to subset the objects based on GeneA expression that applies to all samples in the object. For example:</p>
  
  <pre><code>All_Samples_GeneA_Pos &lt;- subset(All_Samples, subset = GeneA &gt; 0.5)
  All_Samples_GeneA_Neg &lt;- subset(All_Samples, subset = GeneA &lt; 0.5)
  </code></pre>
  
  <p>I assume I would have to modify All_Samples@meta.data based on <a href="https://bioinformatics.stackexchange.com/questions/4249/manually-define-clusters-in-seurat-and-determine-marker-genes">this</a> post and <a href="https://bioinformatics.stackexchange.com/questions/8658/how-to-set-new-identities-for-new-clusters-based-on-a-gene-expression-in-seurat">this</a> post, but I admit I'm not entirely sure how to implement the suggested answers into my data. </p>
  
  <p><strong>Second</strong>: Once I have separated the data from Virus1 and Virus2 into "Pos" and "Neg" cells for "GeneA", I want to look for differentially expressed genes between all Uninfected cells and "Pos" cells from Virus1 or Virus2. I have been using something like this to compare samples:</p>
  
  <pre><code> FindMarkers(object = All_Samples, group.by = 'virus', ident.1 = "1", ident.2 = "2")
  </code></pre>
  
  <p>But how would I do something equivalent to this: </p>
  
  <pre><code> FindMarkers(object = All_Samples, ident.1 = "Uninfected", ident.2 = "Virus1_GeneA_Pos")
  </code></pre>
  
  <p>Or maybe</p>
  
  <pre><code> FindMarkers(object = All_Samples, ident.1 = "Uninfected_GeneA_Neg", ident.2 = "Virus1_GeneA_Pos")
  </code></pre>
  
  <p>Let me know if I can clarify any points. I appreciate any help!</p>
   3541: <p>For the first question, you can use <code>ifelse()</code> to create a new column in the <code>meta.data</code> slot:</p>
  
  <pre><code>All_Samples@meta.data$new_column &lt;-
    ifelse(
      rownames(All_Samples@meta.data) %in% colnames(All_Samples_GeneA_Pos),
      "GeneA_Pos",
      "GeneB_Pos"
    )
  </code></pre>
  
  <p><code>colnames(seurat_object)</code> provides a vector of cell names in a given <code>Seurat</code> object. Here whatever cell that is in the <code>All_Samples_GeneA_Pos</code> object would be <code>GeneA_Pos</code> and whatever is not <code>GeneB_Pos</code>. To better control the behavior, you can use a "nested" <code>ifelse()</code>; you can have another <code>ifelse()</code> instead of the <code>"GeneB_Pos"</code> bit above.</p>
  
  <p>For the second question, the rationale is the same as above, you can define an extra column with the "identities of interest", then use these identities with <code>SetIdent()</code> and then in turn using two identities of interest in the differential expression call.</p>
  