Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ Suggests:
testthat (>= 3.0.0),
BiocSingular,
bluster,
qs,
scater,
scran,
Seurat,
SingleCellExperiment,
BiocStyle
BiocStyle,
magick,
qs2
VignetteBuilder: knitr
Config/testthat/edition: 3
URL: https://phipsonlab.github.io/SuperCellCyto/
BugReports: https://github.com/phipsonlab/SuperCellCyto/issues

2 changes: 1 addition & 1 deletion R/runSuperCellCyto.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ runSuperCellCyto <- function(
if (n_pc > length(markers)) {
warning(
sprintf(
"n_pc (%d) > number of markers (%d). Setting n_pc to %d.",
"Requested n_pc (%d) > markers (%d). Setting n_pc to %d.",
n_pc, length(markers), length(markers)
)
)
Expand Down
21 changes: 21 additions & 0 deletions inst/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# README

Data in `extdata` folder are obtained from the following sources:

* `Data23_Panel3_base_NR4_Patient9.fcs` and
`Data23_Panel3_base_R5_Patient15.fcs` are mass cytometry data from anti-PD1
immunotherapy study by [Krieg et. al](https://doi.org/10.1038/nm.4466).
FCS files are available from
[FlowRepository](
http://flowrepository.org/public_experiment_representations/1124).
* `Levine_32dim_H1_sub.csv` and `Levine_32dim_H2_sub.csv` are mass cytometry
data from AML study by
[Levine et. al](https://doi.org/10.1016/j.cell.2015.05.047).
* `Levine_32dim_seurat_sub.qs2` and `Levine_32dim_sce_sub.qs2` are
Seurat object and SingleCellExperiment object containing subsampled
mass cytometry data from AML study by
[Levine et. al](https://doi.org/10.1016/j.cell.2015.05.047).

Scripts to generate the different formats of `Levine_32dim` dataset is stored
in the `inst/scripts` directory of
[SuperCellCyto](https://github.com/phipsonlab/SuperCellCyto) repo.
235 changes: 118 additions & 117 deletions inst/extdata/Levine_32dim_H1_sub.csv

Large diffs are not rendered by default.

393 changes: 197 additions & 196 deletions inst/extdata/Levine_32dim_H2_sub.csv

Large diffs are not rendered by default.

Binary file removed inst/extdata/Levine_32dim_sce_sub.qs
Binary file not shown.
Binary file added inst/extdata/Levine_32dim_sce_sub.qs2
Binary file not shown.
Binary file removed inst/extdata/Levine_32dim_seurat_sub.qs
Binary file not shown.
Binary file added inst/extdata/Levine_32dim_seurat_sub.qs2
Binary file not shown.
66 changes: 66 additions & 0 deletions inst/scripts/make_levine_32dim.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
library(HDCytoData)
library(data.table)
library(qs2)


sce <- Levine_32dim_SE()

# isolate data from H1 and H2 patients
sce_H1 <- sce[rowData(sce)$patient_id == "H1", ]
sce_H2 <- sce[rowData(sce)$patient_id == "H2", ]

# remove unassigned
sce_H1 <- sce_H1[rowData(sce_H1)$population_id != "unassigned", ]
sce_H2 <- sce_H2[rowData(sce_H2)$population_id != "unassigned", ]

# randomly select 200 cells from each patient
set.seed(42)
sce_H1_sub <- sce_H1[sample(nrow(sce_H1), 200), ]
sce_H2_sub <- sce_H2[sample(nrow(sce_H2), 200), ]

# convert to data.table
dt_H1_sub <- data.table(assay(sce_H1_sub, "exprs"))
dt_H2_sub <- data.table(assay(sce_H2_sub, "exprs"))

# save them as csv files
fwrite(dt_H1_sub, "inst/extdata/Levine_32dim_H1_sub.csv")
fwrite(dt_H2_sub, "inst/extdata/Levine_32dim_H2_sub.csv")


# create the sce object
dt <- data.table(assay(sce, "exprs"))
dt[, population_id := rowData(sce)$population_id]
dt[, sample := rowData(sce)$patient_id]

# get 50 cells from each population and sample
set.seed(42)
n_cells <- 50
sampled_dt <- dt[, .SD[sample(.N, min(.N, n_cells))], by = c("population_id", "sample")]

# assign cell id
sampled_dt[, cell_id := paste0("cell_", .I)]

# create SCE object
exprs_mat <- t(as.matrix(sampled_dt[, !c("population_id", "sample", "cell_id"), with = FALSE]))
sce_sampled <- SingleCellExperiment::SingleCellExperiment(assays = list(counts = exprs_mat))
SummarizedExperiment::colData(sce_sampled)$population <- sampled_dt$population_id
SummarizedExperiment::colData(sce_sampled)$sample <- sampled_dt$sample
SummarizedExperiment::colData(sce_sampled)$cell_id <- sampled_dt$cell_id
colnames(sce_sampled) <- sampled_dt$cell_id

qs_save(sce_sampled, "inst/extdata/Levine_32dim_sce_sub.qs2")


# create Seurat object
seurat_obj <- Seurat::CreateSeuratObject(
counts = exprs_mat,
assay = "originalexp",
)
seurat_obj <- Seurat::AddMetaData(seurat_obj, metadata = sampled_dt[, .(population_id, sample, cell_id)])
# rename patient_id to sample


qs_save(seurat_obj, "inst/extdata/Levine_32dim_seurat_sub.qs2")



Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,42 @@ library(BiocParallel)
This vignette describes the steps to generate supercells for
cytometry data using SuperCellCyto R package.

Briefly, supercells are "mini" clusters of cells that are similar in their
marker expressions.
The motivation behind supercells is that instead of analysing millions of
individual cells, you can analyse thousands of supercells,
making downstream analysis much faster while maintaining
biological interpretability.


See other vignettes for how to:

* [Prepare your data for SuperCellCyto](how_to_prepare_data.html)
* [Use SuperCellCyto for downsampling](
using_supercellcyto_for_stratified_summarising.html)
* [Integrate SuperCellCyto output with SingleCellExperiment objects](
interoperability_with_sce.html)
* [Integrate SuperCellCyto output with Seurat objects](
interoperability_with_seurat.html)

## Installation

You can install stable version of SuperCellCyto from Bioconductor using:

```{r, eval=FALSE}
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("SuperCellCyto")
```

For the latest development version, you can install it from GitHub using `pak`:

```{r, eval=FALSE}
if (!requireNamespace("pak", quietly = TRUE))
install.packages("pak")
pak::install_github("phipsonlab/SuperCellCyto")
```

## Preparing your dataset

The function which creates supercells is called `runSuperCellCyto`, and it
Expand Down
26 changes: 11 additions & 15 deletions vignettes/how_to_prepare_data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ create supercells.
Loading CSV files into a `data.table` object is straightforward.
We can use the `fread` function from the `data.table` package.

Here's how to install it:

```{r install_datatable, eval=FALSE}
install.packages("data.table")
```

For this example, let's load two CSV files containing subsampled data from the
`Levine_32dim` dataset we used in SuperCellCyto manuscript.
Each file represents a sample (H1 and H2), with the sample name appended
Expand All @@ -143,13 +137,10 @@ to the file name:
```{r load_csv_data}
library(data.table)

csv_files <- c(
system.file(
"extdata", "Levine_32dim_H1_sub.csv", package = "SuperCellCyto"
),
system.file(
"extdata", "Levine_32dim_H2_sub.csv", package = "SuperCellCyto"
)
csv_files <- system.file(
"extdata",
c("Levine_32dim_H1_sub.csv", "Levine_32dim_H2_sub.csv"),
package = "SuperCellCyto"
)

samples <- c("H1", "H2")
Expand Down Expand Up @@ -207,7 +198,8 @@ library(data.table)

fs <- read.flowSet(
path = system.file(
"extdata", package = "SuperCellCyto"
"extdata",
package = "SuperCellCyto"
),
pattern = "\\.fcs$"
)
Expand Down Expand Up @@ -309,10 +301,14 @@ dat[, (new_cols) := lapply(.SD, function(x) asinh(x / cf)), .SDcols = markers]
After transformation, new columns with "_asinh" appended indicate the
transformed markers.

```{r}
head(dat)
```

With your data now transformed, you're ready to create supercells
using SuperCellCyto.
Please refer to
[How to create supercells](how_to_create_supercells.html) vignette
[How to create supercells](SuperCellCyto.html) vignette
for detailed instructions.

## Session information
Expand Down
20 changes: 12 additions & 8 deletions vignettes/interoperability_with_sce.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ illustrate how to create supercells and conduct downstream analyses.

```{r setup, message=FALSE, warning=FALSE}
library(SuperCellCyto)
library(qs)
library(qs2)
library(scran)
library(BiocSingular)
library(scater)
Expand All @@ -38,13 +38,17 @@ library(data.table)
## Preparing SCE object

We first load the subsampled Levine_32dim data, stored as a
[qs](https://cran.r-project.org/web/packages/qs/index.html)
using the `qread` function.

```{r load_sce_object}
sce <- qread(system.file(
"extdata", "Levine_32dim_sce_sub.qs", package = "SuperCellCyto"
))
[qs2](https://cran.r-project.org/web/packages/qs2/index.html)
using the `qs_read` function.

```{r load_sce_obj}
sce <- qs_read(
system.file(
"extdata",
"Levine_32dim_sce_sub.qs2",
package = "SuperCellCyto"
)
)
sce
```
The data is stored in the `counts` assay.
Expand Down
21 changes: 12 additions & 9 deletions vignettes/interoperability_with_seurat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ We will show how to create supercells from this data and analyse them
using [Seurat](https://satijalab.org/seurat/).

```{r setup, message=FALSE, warning=FALSE}
library(qs)
library(qs2)
library(Seurat)
library(data.table)
library(SuperCellCyto)
Expand All @@ -39,15 +39,18 @@ set.seed(42)

## Preparing Seurat object

The subsampled Levine_32dim data is stored as a
[qs](https://cran.r-project.org/web/packages/qs/index.html) object.
We begin by loading this data using the `qread` function from the qs package.

We first load the subsampled Levine_32dim data, stored as a
[qs2](https://cran.r-project.org/web/packages/qs2/index.html)
using the `qs_read` function.

```{r load_seurat_obj}
seurat_obj <- qread(system.file(
"extdata", "Levine_32dim_seurat_sub.qs", package = "SuperCellCyto"
))
seurat_obj <- qs_read(
system.file(
"extdata",
"Levine_32dim_seurat_sub.qs2",
package = "SuperCellCyto"
)
)
seurat_obj
```
The data is stored in the `originalexp` assay, with both counts and data
Expand All @@ -57,7 +60,7 @@ Before running SuperCellCyto, we will first:

1. Subset this data to retain only the markers we need to perform
downstream analysis.
2. Perform arcsinh transformation, and store the transformed data in
1. Perform arcsinh transformation, and store the transformed data in
the `data` slot of the `originalexp` assay.

```{r subset_and_transform}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ knitr::opts_chunk$set(
```

Have you been following the vignette on
[how to create supercells](how_to_create_supercells.html),
[how to create supercells](SuperCellCyto.html),
and wonder whether it is possible to use `SuperCellCyto` as a replacement for
stratified sampling to avoid overcrowding UMAP/tSNE plot?

Expand Down
Loading