Answers.Body: <p>I think you are looking to <code>FindAllMarkers</code> function from <code>Seurat</code>. As you said, you just have to define your <code>ident</code>, that have to have the structure of a table (cell names as names and cluster as value):</p>
  
  <pre><code>pident=as.factor(clusters)
  names(pident)=cellNames    
  object1@ident=pident
  </code></pre>
  
  <p>And then run the <code>FindAllMarkers</code> function:</p>
  
  <pre><code>FindAllMarkers(object1, min.pct = 0.25, min.diff.pct = 0.25)
  </code></pre>
  
  <p>You can specify several parameters in this function (type of DE to perform, thresholds of expression, etc).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-08T07:46:49.747Z
Answers.LastActivityDate: 2018-05-08T07:46:49.747Z
Answers.UserDisplayName: jxx_fa
Answers.Body: <p>Seurat has functions for adding metadata and setting identities. Get unique cell names:</p>
  
  <pre><code>cell.labels &lt;- seuratobject@ident
  </code></pre>
  
  <p>Replace column and its name with your cluster labels (<a href="https://bioinformatics.stackexchange.com/a/4303/208">e.g.</a>), then:</p>
  
  <pre><code>seuratobject &lt;- AddMetaData(seuratobject, metadata=cell.labels)
  seuratobject &lt;- SetAllIdent(seuratobject, id='yourclusterlabels')
  </code></pre>
  
  <p>Because you want to contrast two clusters against each other, I suggest using <code>FindMarkers()</code> as opposed to <code>FindAllMarkers()</code>:</p>
  
  <pre><code>FindMarkers(object, ident.1, ident.2)
  </code></pre>
  
  <p>It can also compare combinations of clusters.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-15T15:49:43.123Z
Answers.LastActivityDate: 2018-05-15T16:54:50.990Z
Answers.LastEditDate: 2018-05-15T16:54:50.990Z
Answers.UserDisplayName: Peter
Body: <p>I want to define two clusters of cells in my dataset and find marker genes that are specific to one and the other. Is there a way to do this in <code>Seurat</code>? Say, if I produce two subsets by the <code>SubsetData</code> function, is there a way to feed them into some other function that would calculate marker genes? If not, what other packages would you recommend for doing that?</p>
  
  <p>If you look here:</p>
  
  <p><a href="https://satijalab.org/seurat/seurat_clustering_tutorial_part2.html" rel="nofollow noreferrer">https://satijalab.org/seurat/seurat_clustering_tutorial_part2.html</a></p>
  
  <p>I just need a way to define <code>ident</code> myself, the number of levels (2) and assign numbers to each cell (0, 1), and then run <code>DE</code> between <code>0</code> and <code>1</code> clusters which is obvious how to do afterwards.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-14T17:31:13.223Z
Comments.Text: A related issue was answered on [github](https://github.com/satijalab/seurat/issues/285). Just as an alternative reference to the excellent answers below)
Comments.UserDisplayName: Tapper
Tags: <r><single-cell><seurat>
Title: Manually define clusters in Seurat and determine marker genes
ThreadText: # Manually define clusters in Seurat and determine marker genes
  
  (Asked by: username_0 on 2018-05-07)
  
  I want to define two clusters of cells in my dataset and find marker genes that are specific to one and the other. Is there a way to do this in `Seurat`? Say, if I produce two subsets by the `SubsetData` function, is there a way to feed them into some other function that would calculate marker genes? If not, what other packages would you recommend for doing that?
  
  If you look here:
  
  <https://satijalab.org/seurat/seurat_clustering_tutorial_part2.html>
  
  I just need a way to define `ident` myself, the number of levels (2) and assign numbers to each cell (0, 1), and then run `DE` between `0` and `1` clusters which is obvious how to do afterwards.
  
  **Tags:** r, single-cell, seurat
  
  > **Comments:**
  > **username_1**: A related issue was answered on [github](https://github.com/satijalab/seurat/issues/285). Just as an alternative reference to the excellent answers below)  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-05-08. Score: 3 | Accepted answer
  
  I think you are looking to `FindAllMarkers` function from `Seurat`. As you said, you just have to define your `ident`, that have to have the structure of a table (cell names as names and cluster as value):
  
  ```
  pident=as.factor(clusters)
  names(pident)=cellNames    
  object1@ident=pident
  
  ```
  
  And then run the `FindAllMarkers` function:
  
  ```
  FindAllMarkers(object1, min.pct = 0.25, min.diff.pct = 0.25)
  
  ```
  
  You can specify several parameters in this function (type of DE to perform, thresholds of expression, etc).
  
  
  ---
  
  ### Answer by username_3 on 2018-05-15. Score: 3
  
  Seurat has functions for adding metadata and setting identities. Get unique cell names:
  
  ```
  cell.labels <- seuratobject@ident
  
  ```
  
  Replace column and its name with your cluster labels ([e.g.](https://bioinformatics.stackexchange.com/a/4303/208)), then:
  
  ```
  seuratobject <- AddMetaData(seuratobject, metadata=cell.labels)
  seuratobject <- SetAllIdent(seuratobject, id='yourclusterlabels')
  
  ```
  
  Because you want to contrast two clusters against each other, I suggest using `FindMarkers()` as opposed to `FindAllMarkers()`:
  
  ```
  FindMarkers(object, ident.1, ident.2)
  
  ```
  
  It can also compare combinations of clusters.
  
  
  ---
  
  