Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Seurat <-> SCE conversion sections #668

Merged
merged 13 commits into from
Mar 7, 2023
45 changes: 45 additions & 0 deletions module-cheatsheets/scRNA-seq-advanced-cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,51 @@ Read the full documentation and download cheatsheets (where available) for these

### `Seurat` and `SCE` object conversion

This [vignette](https://satijalab.org/seurat/articles/conversion_vignette.html) from the `Seurat` documentation explains how to convert between `SCE` and `Seurat` formats.
sjspielman marked this conversation as resolved.
Show resolved Hide resolved

In addition, we provide some code examples below for how you can accomplish these conversions.
For all code examples below, it is assumed that `SingleCellExperiment` and `Seurat` libraries have been loaded in your R environment:

```r
library(Seurat)
library(SingleCellExperiment)
```
sjspielman marked this conversation as resolved.
Show resolved Hide resolved


#### Converting from `Seurat` to `SCE`

The following example code assumes you have a `Seurat` object called `seurat_obj`.

```r
# Convert Seurat object to SCE object using the
# Seurat function `as.SingleCellExperiment()
sce_object <- as.SingleCellExperiment(seurat_obj)
```

Alternatively, you can extract individual slots from the `Seurat` object and build your `SCE` object from scratch.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like introducing this without a reason why we want to do it is not particularly helpful. Is there any case where we would want to extract just one assay with no metadata? If there is a specific case that we feel is worth illustrating, we should do that, but I don't want to encourage people to drop metadata as part of the conversion.

If there is something that the conversion does not handle automatically, we might want to show how to add that to an existing SCE, or rename things that might end up in unexpected locations, but I'm not sure linking to building an SCE is useful here, especially without the matching docs for how to extract each part of a Seurat object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe this isn't needed at all. I included it as a way to offer some kind of direction if conversion goes wrong, but really if conversion goes wrong, a few small details won't help (that's what consultations/office hours are more reasonably for).
Based on the Seurat source, it seems like all the bits do get converted, so I'm thinking just call it a day with Seurat::as.SingleCellExperiment().

You can refer to the ["The `SingleCellExperiment` class" chapter in _Orchestrating Single Cell Analyses_](http://bioconductor.org/books/release/OSCA.intro/the-singlecellexperiment-class.html) for approaches to constructing `SCE` objects.
For example, to obtain an SCE object that contains only the raw counts stored in the `Seurat` object's "RNA" assay:

```r
# First, extract the counts matrix from the Seurat object
counts_matrix <- GetAssayData(seurat_obj[["RNA"]])

# Create an SCE object from the counts matrix
sce_object <- SingleCellExperiment(assays = list(counts = counts_matrix))
```

#### Converting from `SCE` to `Seurat`

This [documentation from the `ScPCA`](https://scpca.readthedocs.io/en/latest/faq.html#what-if-i-want-to-use-seurat-instead-of-bioconductor) introduces how to convert `SCE` objects to `Seurat` objects.
Although this documentation was written for `ScPCA` datasets, the steps generally apply to any `SCE object`.
Briefly, here is how you can convert a `Seurat` to `SCE` object, focusing on porting over _assays_.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will to show the steps to add at least the cell and feature metadata here. We present it as "optional" in the docs, but we probably shouldn't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something else I also thought about is whether we should straight-up recommend scpcaTools::sce_to_seurat() here, in addition to or instead of individual steps.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe not ^, since our function only allows one assay to get ported over... But I've stubbed something out already so we'll see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can point people to it as an example, but I would not exactly recommend it.

We provide `"RNA"` as the argument to `assay`, as this `Seurat`'s default name for raw count matrices.
```r
sjspielman marked this conversation as resolved.
Show resolved Hide resolved
# Create seurat object from the existing `sce_object`'s counts matrix,
# using the Seurat function `CreateSeuratObject`
seurat_object <- CreateSeuratObject(counts = counts(sce_object),
assay = "RNA",
project = "name of your project goes here")
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to note that we are not using Seurat::as.Seurat() though that may be an option (it didn't used to work very well, but maybe works better now?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it out on whatever versions we have in the training renv, haven't use that function yet.

For further conversion steps, please see the [associated `ScPCA` documentation](https://scpca.readthedocs.io/en/latest/faq.html#what-if-i-want-to-use-seurat-instead-of-bioconductor).