SuperCellCyto 0.99.3
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:
You can install stable version of SuperCellCyto from Bioconductor using:
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("SuperCellCyto")
For the latest development version, you can install it from GitHub using pak:
if (!requireNamespace("pak", quietly = TRUE))
install.packages("pak")
pak::install_github("phipsonlab/SuperCellCyto")
The function which creates supercells is called runSuperCellCyto, and it
operates on a data.table object, an enhanced version of R native
data.frame.
In addition to needing the data stored in a data.table object it also
requires:
runSuperCellCyto does not perform any data transformation or scaling.If you are not sure how to import CSV or FCS files into data.table
object, and/or how to subsequently prepare the object ready for
SuperCellCyto, please consult this vignette.
In that vignette, we also provide an explanation behind why we need to have the
cell ID and sample column.
For this vignette, we will simulate some toy data using the simCytoData function.
Specifically, we will simulate 15 markers and 3 samples,
with each sample containing 10,000 cells.
Hence in total, we will have a toy dataset containing 15 markers and
30,000 cells.
n_markers <- 15
n_samples <- 3
dat <- simCytoData(nmarkers = n_markers, ncells = rep(10000, n_samples))
head(dat)
#> Marker_1 Marker_2 Marker_3 Marker_4 Marker_5 Marker_6 Marker_7 Marker_8
#> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1: 15.61830 10.747293 14.97621 14.70614 13.39039 16.23484 4.928612 14.78183
#> 2: 15.11441 10.459148 14.43441 16.84844 11.99896 15.27718 5.224750 13.39207
#> 3: 14.20139 9.026630 14.98631 15.00848 14.04868 15.29501 5.887167 14.87116
#> 4: 13.98450 9.053166 13.93041 14.04469 14.09031 15.39033 7.426363 13.01189
#> 5: 17.05346 10.473435 15.11253 14.16243 12.77175 16.68769 5.265864 14.66819
#> 6: 14.46811 9.894809 15.16140 14.96534 15.78861 16.28734 4.734404 14.78157
#> Marker_9 Marker_10 Marker_11 Marker_12 Marker_13 Marker_14 Marker_15
#> <num> <num> <num> <num> <num> <num> <num>
#> 1: 17.14100 8.149539 19.55277 16.37546 9.989106 9.409550 17.62219
#> 2: 16.94935 7.169165 18.45021 14.98057 9.450425 8.103972 17.03214
#> 3: 15.74596 10.595922 18.60490 17.71354 8.195088 10.305446 18.18489
#> 4: 15.40574 9.513708 17.54400 16.63361 9.113852 8.074579 17.39126
#> 5: 13.92747 7.318530 17.08500 15.82687 9.109319 8.823700 18.41193
#> 6: 16.00330 7.357614 19.39107 14.69397 7.460475 8.197130 16.85170
#> Sample Cell_Id
#> <char> <char>
#> 1: Sample_1 Cell_1
#> 2: Sample_1 Cell_2
#> 3: Sample_1 Cell_3
#> 4: Sample_1 Cell_4
#> 5: Sample_1 Cell_5
#> 6: Sample_1 Cell_6
For our toy dataset, we will transform our data using arcsinh transformation.
We will use the base R asinh function to do this:
# Specify which columns are the markers to transform
marker_cols <- paste0("Marker_", seq_len(n_markers))
# The co-factor for arc-sinh
cofactor <- 5
# Do the transformation
dat_asinh <- asinh(dat[, marker_cols, with = FALSE] / cofactor)
# Rename the new columns
marker_cols_asinh <- paste0(marker_cols, "_asinh")
names(dat_asinh) <- marker_cols_asinh
# Add them our previously loaded data
dat <- cbind(dat, dat_asinh)
head(dat[, marker_cols_asinh, with = FALSE])
#> Marker_1_asinh Marker_2_asinh Marker_3_asinh Marker_4_asinh Marker_5_asinh
#> <num> <num> <num> <num> <num>
#> 1: 1.856842 1.508545 1.816941 1.799696 1.711410
#> 2: 1.825658 1.483965 1.782055 1.929291 1.609358
#> 3: 1.766690 1.353024 1.817580 1.818983 1.756499
#> 4: 1.752186 1.355593 1.748537 1.756231 1.759286
#> 5: 1.940892 1.485196 1.825539 1.764100 1.667229
#> 6: 1.784259 1.434187 1.828605 1.816252 1.867177
#> Marker_6_asinh Marker_7_asinh Marker_8_asinh Marker_9_asinh Marker_10_asinh
#> <num> <num> <num> <num> <num>
#> 1: 1.893780 0.8712416 1.804557 1.945806 1.264729
#> 2: 1.835832 0.9128036 1.711528 1.935017 1.157491
#> 3: 1.836941 1.0014458 1.810266 1.864598 1.495700
#> 4: 1.842848 1.1865661 1.684597 1.843800 1.399275
#> 5: 1.920104 0.9184772 1.797249 1.748339 1.174461
#> 6: 1.896866 0.8433095 1.804541 1.880060 1.178862
#> Marker_11_asinh Marker_12_asinh Marker_13_asinh Marker_14_asinh
#> <num> <num> <num> <num>
#> 1: 2.072787 1.902026 1.442661 1.389541
#> 2: 2.016659 1.817217 1.393371 1.259953
#> 3: 2.024720 1.977388 1.269483 1.470626
#> 4: 1.968135 1.916995 1.361446 1.256862
#> 5: 1.942665 1.869484 1.361010 1.333188
#> 6: 2.064744 1.798912 1.190370 1.269696
#> Marker_15_asinh
#> <num>
#> 1: 1.972413
#> 2: 1.939692
#> 3: 2.002686
#> 4: 1.959729
#> 5: 2.014655
#> 6: 1.929476
We will also create a column Cell_id_dummy which uniquely identify each cell.
It will have values such as Cell_1, Cell_2, all the way until Cell_x
where x is the number of cells in the dataset.
dat$Cell_id_dummy <- paste0("Cell_", seq_len(nrow(dat)))
head(dat$Cell_id_dummy, n = 10)
#> [1] "Cell_1" "Cell_2" "Cell_3" "Cell_4" "Cell_5" "Cell_6" "Cell_7"
#> [8] "Cell_8" "Cell_9" "Cell_10"
By default, the simCytoData function will generate cells for multiple samples,
and that the resulting data.table object will already have a column
called Sample that denotes the sample the cells come from.
unique(dat$Sample)
#> [1] "Sample_1" "Sample_2" "Sample_3"
Let’s take note of the sample and cell id column for later.
sample_col <- "Sample"
cell_id_col <- "Cell_id_dummy"
Now that we have our data, let’s create some supercells.
To do this, we will use runSuperCellCyto function and pass the markers,
sample and cell ID columns as parameters.
The reason why we need to specify the markers is because the function will
create supercells based on only the expression of those markers.
We highly recommend creating supercells using all markers in your data, let
that be cell type or cell state markers.
However, if for any reason you only want to only use a subset of the markers in
your data, then make sure you specify them in a vector that you later pass to
runSuperCellCyto function.
For this tutorial, we will use all the arcsinh transformed markers in the toy data.
supercells <- runSuperCellCyto(
dt = dat,
markers = marker_cols_asinh,
sample_colname = sample_col,
cell_id_colname = cell_id_col
)
Let’s dig deeper into the object it created:
class(supercells)
#> [1] "list"
It is a list containing 3 elements:
names(supercells)
#> [1] "supercell_expression_matrix" "supercell_cell_map"
#> [3] "supercell_object"
The supercell_object contains the metadata used to create the supercells.
It is a list, and each element contains the metadata used to create the
supercells for a sample.
This will come in handy if we need to either regenerate the supercells using
different gamma values (so we get more or less supercells) or do some
debugging later down the line.
More on regenerating supercells on
Controlling supercells granularity
section below.
The supercell_expression_matrix contains the marker expression of each
supercell.
These are calculated by taking the average of the marker expression of
all the cells contained within a supercell.
head(supercells$supercell_expression_matrix)
#> Marker_1_asinh Marker_2_asinh Marker_3_asinh Marker_4_asinh Marker_5_asinh
#> <num> <num> <num> <num> <num>
#> 1: 1.761446 1.399656 1.798310 1.848931 1.698032
#> 2: 1.725738 1.503113 1.837641 1.888232 1.756129
#> 3: 1.842024 1.557273 1.847091 1.822973 1.720887
#> 4: 1.773028 1.530148 1.843962 1.828993 1.704725
#> 5: 1.801849 1.459511 1.827136 1.827384 1.746303
#> 6: 1.825412 1.468334 1.826833 1.820428 1.750049
#> Marker_6_asinh Marker_7_asinh Marker_8_asinh Marker_9_asinh Marker_10_asinh
#> <num> <num> <num> <num> <num>
#> 1: 1.832025 0.8897179 1.853768 1.902936 1.337814
#> 2: 1.830787 1.1303463 1.880931 1.894937 1.351286
#> 3: 1.886069 1.1294535 1.848557 1.896863 1.443924
#> 4: 1.759883 1.2220752 1.800444 1.869527 1.433252
#> 5: 1.831570 0.8452727 1.768095 1.872332 1.267739
#> 6: 1.830732 1.1667380 1.775860 1.868477 1.381214
#> Marker_11_asinh Marker_12_asinh Marker_13_asinh Marker_14_asinh
#> <num> <num> <num> <num>
#> 1: 2.008223 1.894750 1.249716 1.335257
#> 2: 2.017565 1.889651 1.414514 1.467508
#> 3: 2.051520 1.925555 1.283913 1.407497
#> 4: 2.010820 1.873912 1.301770 1.343683
#> 5: 2.010849 1.856905 1.366676 1.286607
#> 6: 2.018921 1.876138 1.422689 1.446096
#> Marker_15_asinh Sample SuperCellId
#> <num> <char> <char>
#> 1: 1.959831 Sample_1 SuperCell_1_Sample_Sample_1
#> 2: 1.964953 Sample_1 SuperCell_2_Sample_Sample_1
#> 3: 1.998548 Sample_1 SuperCell_3_Sample_Sample_1
#> 4: 1.958512 Sample_1 SuperCell_4_Sample_Sample_1
#> 5: 1.955246 Sample_1 SuperCell_5_Sample_Sample_1
#> 6: 1.947924 Sample_1 SuperCell_6_Sample_Sample_1
Therein, we will have the following columns:
markers_col variable.
In this example, they are the arcsinh transformed markers in our toy data.Sample in this case) denoting which sample a supercell
belongs to, (note the column name is the same as what is stored in sample_col
variable).SuperCellId column denoting the unique ID of the supercell.Let’s have a look at SuperCellId:
head(unique(supercells$supercell_expression_matrix$SuperCellId))
#> [1] "SuperCell_1_Sample_Sample_1" "SuperCell_2_Sample_Sample_1"
#> [3] "SuperCell_3_Sample_Sample_1" "SuperCell_4_Sample_Sample_1"
#> [5] "SuperCell_5_Sample_Sample_1" "SuperCell_6_Sample_Sample_1"
Let’s break down one of them, SuperCell_1_Sample_Sample_1.
SuperCell_1 is a numbering (1 to however many supercells there are in
a sample) used to uniquely identify each supercell in a sample.
Notably, you may encounter this (SuperCell_1, SuperCell_2) being repeated
across different samples, e.g.,
supercell_ids <- unique(supercells$supercell_expression_matrix$SuperCellId)
supercell_ids[grep("SuperCell_1_", supercell_ids)]
#> [1] "SuperCell_1_Sample_Sample_1" "SuperCell_1_Sample_Sample_2"
#> [3] "SuperCell_1_Sample_Sample_3"
While these 3 supercells’ id are pre-fixed with SuperCell_1, it does
not make them equal to one another!
SuperCell_1_Sample_Sample_1 will only contain cells from Sample_1 while
SuperCell_1_Sample_Sample_2 will only contain cells from Sample_2.
By now, you may have noticed that we appended the sample name into each supercell id. This aids in differentiating the supercells in different samples.
supercell_cell_map maps each cell in our dataset to the supercell it
belongs to.
head(supercells$supercell_cell_map)
#> SuperCellID CellId Sample
#> <char> <char> <char>
#> 1: SuperCell_92_Sample_Sample_1 Cell_1 Sample_1
#> 2: SuperCell_191_Sample_Sample_1 Cell_2 Sample_1
#> 3: SuperCell_387_Sample_Sample_1 Cell_3 Sample_1
#> 4: SuperCell_42_Sample_Sample_1 Cell_4 Sample_1
#> 5: SuperCell_92_Sample_Sample_1 Cell_5 Sample_1
#> 6: SuperCell_74_Sample_Sample_1 Cell_6 Sample_1
This map is very useful if we later need to expand the supercells out. Additionally, this is also the reason why we need to have a column in the dataset which uniquely identify each cell.
runSuperCellCyto in parallelBy default, runSuperCellCyto will process each sample one after the other.
As each sample is processed independent of one another, strictly speaking, we
can process all of them in parallel.
To do this, we need to:
BiocParallelParam object from the BiocParallel package.
This object can either be of type MulticoreParamor SnowParam.
We highly recommend consulting their vignette for more information.BiocParallelParam object to the number of
samples we have in the dataset.load_balancing parameter for runSuperCellCyto function to TRUE.
This is to ensure even distribution of the supercell creation jobs.
As each sample will be processed by a parallel job, we don’t want a job that
processs large sample to also be assigned other smaller samples if possible.
If you want to know more how this feature works, please refer to our manuscript.supercell_par <- runSuperCellCyto(
dt = dat,
markers = marker_cols_asinh,
sample_colname = sample_col,
cell_id_colname = cell_id_col,
BPPARAM = MulticoreParam(tasks = n_samples),
load_balancing = TRUE
)
This is described in the runSuperCellCyto function’s documentation, but let’s
briefly go through it here.
The runSuperCellCyto function is equipped with various parameters which
can be customised to alter the composition of the supercells.
The one that is very likely to be used the most is the gamma parameter,
denoted as gam in the function.
By default, the value for gam is set to 20, which we found work well for
most cases.
The gamma parameter controls how many supercells to generate, and
indirectly, how many cells are captured within each supercell.
This parameter is resolved into the following formula
gamma=n_cells/n_supercells where n_cell denotes the number of cells and
n_supercells denotes the number of supercells.
In general, the larger gamma parameter is set to, the less supercells we will get. Say for instance we have 10,000 cells. If gamma is set to 10, we will end up with about 1,000 supercells, whereas if gamma is set to 50, we will end up with about 200 supercells.
You may have noticed, after reading the sections above, runSuperCellCyto
is ran on each sample independent of each other, and that we can only set
1 value as the gamma parameter.
Indeed, for now, the same gamma value will be used across all samples,
and that depending on how many cells we have in each sample, we will end up
with different number of supercells for each sample.
For instance, say we have 10,000 cells for sample 1, and 100,000 cells for
sample 2.
If gamma is set to 10, for sample 1, we will get 1,000 supercells (10,000/10)
while for sample 2, we will get 10,000 supercells (100,000/10).
Do note: whatever gamma value you chose, you should not expect each supercell to contain exactly the same number of cells. This behaviour is intentional to ensure rare cell types are not intermixed with non-rare cell types in a supercell.
If you have run runSuperCellCyto once and have not discarded the
SuperCell object it generated (no serious, please don’t!),
you can use the object to quickly
regenerate supercells using different gamma values.
As an example, using the SuperCell object we have generated for our
toy dataset, we will regenerate the supercells using gamma of 10 and 50.
The function to do this is recomputeSupercells.
We will store the output in a list, one element per gamma value.
addt_gamma_vals <- c(10, 50)
supercells_addt_gamma <- lapply(addt_gamma_vals, function(gam) {
recomputeSupercells(
dt = dat,
sc_objects = supercells$supercell_object,
markers = marker_cols_asinh,
sample_colname = sample_col,
cell_id_colname = cell_id_col,
gam = gam
)
})
We should end up with a list containing 2 elements. The 1st element contains supercells generated using gamma = 10, and the 2nd contains supercells generated using gamma = 50.
supercells_addt_gamma[[1]]
#> $supercell_expression_matrix
#> Marker_1_asinh Marker_2_asinh Marker_3_asinh Marker_4_asinh
#> <num> <num> <num> <num>
#> 1: 1.781813 1.550465 1.717706 1.861536
#> 2: 1.866993 1.559934 1.780446 1.808228
#> 3: 1.846596 1.442195 1.797789 1.852974
#> 4: 1.791255 1.500039 1.840589 1.769007
#> 5: 1.818111 1.523435 1.793217 1.867604
#> ---
#> 2996: 1.407699 2.080145 1.589188 1.514863
#> 2997: 1.514812 2.014984 1.781752 1.484108
#> 2998: 1.411950 2.040058 1.425056 1.650178
#> 2999: 1.507033 2.004448 1.747423 1.596015
#> 3000: 1.369769 2.075589 1.663297 1.488707
#> Marker_5_asinh Marker_6_asinh Marker_7_asinh Marker_8_asinh
#> <num> <num> <num> <num>
#> 1: 1.771693 1.827114 0.9553083 1.838279
#> 2: 1.668755 1.818295 1.0379486 1.773553
#> 3: 1.703203 1.841313 1.1843139 1.834552
#> 4: 1.720997 1.767936 0.9995092 1.720193
#> 5: 1.769132 1.773232 1.0270519 1.795600
#> ---
#> 2996: 1.709201 1.946554 1.3070238 1.712760
#> 2997: 1.670080 1.984727 1.2802329 1.783176
#> 2998: 1.769075 1.943085 1.3770871 1.817552
#> 2999: 1.635282 1.909335 1.3604499 1.882744
#> 3000: 1.647692 1.909066 1.2667366 1.703597
#> Marker_9_asinh Marker_10_asinh Marker_11_asinh Marker_12_asinh
#> <num> <num> <num> <num>
#> 1: 1.885853 1.3150007 2.013789 1.876504
#> 2: 1.853902 1.2935351 1.992864 1.888914
#> 3: 1.913792 1.3380104 2.002886 1.906259
#> 4: 1.845341 1.3368438 2.004285 1.878000
#> 5: 1.887785 1.2605496 2.009728 1.875609
#> ---
#> 2996: 1.783240 1.1162546 1.838377 1.952041
#> 2997: 1.745946 1.0456387 1.809748 2.014251
#> 2998: 1.764714 0.9150958 1.705292 1.904203
#> 2999: 1.807146 0.9756866 1.743278 1.933754
#> 3000: 1.782231 1.0987486 1.804440 1.954844
#> Marker_13_asinh Marker_14_asinh Marker_15_asinh Sample
#> <num> <num> <num> <char>
#> 1: 1.393719 1.365094 1.935307 Sample_1
#> 2: 1.243251 1.225594 1.936125 Sample_1
#> 3: 1.338267 1.078642 1.969332 Sample_1
#> 4: 1.347678 1.311352 1.923265 Sample_1
#> 5: 1.245527 1.426595 1.967315 Sample_1
#> ---
#> 2996: 1.571885 1.628060 1.939783 Sample_3
#> 2997: 1.708542 1.802155 1.979379 Sample_3
#> 2998: 1.599850 1.704212 1.968263 Sample_3
#> 2999: 1.627119 1.672459 1.888426 Sample_3
#> 3000: 1.564200 1.692172 1.917103 Sample_3
#> SuperCellId
#> <char>
#> 1: SuperCell_1_Sample_Sample_1
#> 2: SuperCell_2_Sample_Sample_1
#> 3: SuperCell_3_Sample_Sample_1
#> 4: SuperCell_4_Sample_Sample_1
#> 5: SuperCell_5_Sample_Sample_1
#> ---
#> 2996: SuperCell_996_Sample_Sample_3
#> 2997: SuperCell_997_Sample_Sample_3
#> 2998: SuperCell_998_Sample_Sample_3
#> 2999: SuperCell_999_Sample_Sample_3
#> 3000: SuperCell_1000_Sample_Sample_3
#>
#> $supercell_cell_map
#> SuperCellID CellId Sample
#> <char> <char> <char>
#> 1: SuperCell_476_Sample_Sample_1 Cell_1 Sample_1
#> 2: SuperCell_509_Sample_Sample_1 Cell_2 Sample_1
#> 3: SuperCell_528_Sample_Sample_1 Cell_3 Sample_1
#> 4: SuperCell_86_Sample_Sample_1 Cell_4 Sample_1
#> 5: SuperCell_8_Sample_Sample_1 Cell_5 Sample_1
#> ---
#> 29996: SuperCell_400_Sample_Sample_3 Cell_29996 Sample_3
#> 29997: SuperCell_21_Sample_Sample_3 Cell_29997 Sample_3
#> 29998: SuperCell_138_Sample_Sample_3 Cell_29998 Sample_3
#> 29999: SuperCell_9_Sample_Sample_3 Cell_29999 Sample_3
#> 30000: SuperCell_975_Sample_Sample_3 Cell_30000 Sample_3
The output generated by recomputeSupercells is essentially a list:
supercell_expression_matrix: A data.table object that contains the marker
expression for each supercell.supercell_cell_map: A data.table that maps each cell to its
corresponding supercell.As mentioned before, gamma dictates the granularity of supercells. Compared to the previous run where gamma was set to 20, we should get more supercells for gamma = 10, and less for gamma = 50. Let’s see if that’s the case.
n_supercells_gamma20 <- nrow(supercells$supercell_expression_matrix)
n_supercells_gamma10 <- nrow(
supercells_addt_gamma[[1]]$supercell_expression_matrix
)
n_supercells_gamma50 <- nrow(
supercells_addt_gamma[[2]]$supercell_expression_matrix
)
n_supercells_gamma10 > n_supercells_gamma20
#> [1] TRUE
n_supercells_gamma50 < n_supercells_gamma20
#> [1] TRUE
In the future, we may add the ability to specify different gam
value for different samples.
For now, if we want to do this, we will need to break down our data
into multiple data.table objects, each containing data from 1 sample,
and run runSuperCellCyto
function on each of them with different gam parameter value.
Something like the following:
n_markers <- 10
dat <- simCytoData(nmarkers = n_markers)
markers_col <- paste0("Marker_", seq_len(n_markers))
sample_col <- "Sample"
cell_id_col <- "Cell_Id"
samples <- unique(dat[[sample_col]])
gam_values <- c(10, 20, 10)
supercells_diff_gam <- lapply(seq_len(length(samples)), function(i) {
sample <- samples[i]
gam <- gam_values[i]
dat_samp <- dat[dat$Sample == sample, ]
supercell_samp <- runSuperCellCyto(
dt = dat_samp,
markers = markers_col,
sample_colname = sample_col,
cell_id_colname = cell_id_col,
gam = gam
)
return(supercell_samp)
})
Subsequently, to extract and combine the supercell_expression_matrix and
supercell_cell_map, we will need to use rbind:
supercell_expression_matrix <- do.call(
"rbind", lapply(
supercells_diff_gam, function(x) x[["supercell_expression_matrix"]]
)
)
supercell_cell_map <- do.call(
"rbind", lapply(
supercells_diff_gam, function(x) x[["supercell_cell_map"]]
)
)
rbind(
head(supercell_expression_matrix, n = 3),
tail(supercell_expression_matrix, n = 3)
)
#> Marker_1 Marker_2 Marker_3 Marker_4 Marker_5 Marker_6 Marker_7 Marker_8
#> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1: 9.699848 12.191342 18.62970 7.922180 10.334051 10.85028 15.55755 11.589517
#> 2: 10.056007 11.038149 16.13308 8.340124 9.842181 11.53295 16.40611 13.252795
#> 3: 9.084303 11.436632 18.59641 7.280002 12.513999 11.73508 15.47923 13.249252
#> 4: 11.037592 11.633955 12.68243 10.117406 6.201373 11.98311 19.26181 7.836104
#> 5: 12.424495 12.239210 12.06787 9.558752 6.447876 13.16513 19.48940 8.703015
#> 6: 10.647394 9.732861 11.18000 11.770144 4.807292 12.13502 20.16158 9.383161
#> Marker_9 Marker_10 Sample SuperCellId
#> <num> <num> <char> <char>
#> 1: 3.815352 7.648381 Sample_1 SuperCell_1_Sample_Sample_1
#> 2: 4.696443 7.182940 Sample_1 SuperCell_2_Sample_Sample_1
#> 3: 6.440531 8.597532 Sample_1 SuperCell_3_Sample_Sample_1
#> 4: 15.328035 7.067140 Sample_2 SuperCell_498_Sample_Sample_2
#> 5: 14.170458 9.084803 Sample_2 SuperCell_499_Sample_Sample_2
#> 6: 13.944163 7.489045 Sample_2 SuperCell_500_Sample_Sample_2
rbind(head(supercell_cell_map, n = 3), tail(supercell_cell_map, n = 3))
#> SuperCellID CellId Sample
#> <char> <char> <char>
#> 1: SuperCell_324_Sample_Sample_1 Cell_1 Sample_1
#> 2: SuperCell_649_Sample_Sample_1 Cell_2 Sample_1
#> 3: SuperCell_482_Sample_Sample_1 Cell_3 Sample_1
#> 4: SuperCell_386_Sample_Sample_2 Cell_19998 Sample_2
#> 5: SuperCell_378_Sample_Sample_2 Cell_19999 Sample_2
#> 6: SuperCell_54_Sample_Sample_2 Cell_20000 Sample_2
If for whatever reason you don’t mind (or perhaps more to the point want)
each supercell to contain cells from different biological samples,
you still need to have the sample column in your data.table.
However, what you need to do is essentially set the value in the column
to exactly one unique value.
That way, SuperCellCyto will treat all cells as coming from one sample.
Just note, the parallel processing feature in SuperCellCyto won’t work for this as you will essentially only have 1 sample and nothing for SuperCellCyto to parallelise.
Is your dataset so huge that you are constantly running out of RAM when generating supercells? This thing happens and we have a solution for it.
Since supercells are generated for each sample independent of others you can easily break up the process. For example:
supercell_expression_matrix and supercell_cell_map,
and export them out as a csv file using data.table’s fwrite function.Once you have processed all the samples, you can then load all
supercell_expression_matrix and supercell_cell_map csv files and
analyse them.
If you want to regenerate the supercells using different gamma values,
load the relevant output saved using the qs package and the relevant data
(remember to note which output belongs to which sets of samples!), and run
recomputeSupercells function.
sessionInfo()
#> R version 4.5.1 Patched (2025-09-10 r88807)
#> Platform: x86_64-apple-darwin20
#> Running under: macOS Monterey 12.7.6
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.5-x86_64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.5-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
#>
#> locale:
#> [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> time zone: America/New_York
#> tzcode source: internal
#>
#> attached base packages:
#> [1] parallel stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] BiocParallel_1.43.4 SuperCellCyto_0.99.3 BiocStyle_2.37.1
#>
#> loaded via a namespace (and not attached):
#> [1] cli_3.6.5 knitr_1.50 rlang_1.1.6
#> [4] xfun_0.53 jsonlite_2.0.0 data.table_1.17.8
#> [7] plyr_1.8.9 htmltools_0.5.8.1 sass_0.4.10
#> [10] rmarkdown_2.30 grid_4.5.1 evaluate_1.0.5
#> [13] jquerylib_0.1.4 fastmap_1.2.0 yaml_2.3.10
#> [16] lifecycle_1.0.4 bookdown_0.45 BiocManager_1.30.26
#> [19] compiler_4.5.1 igraph_2.2.0 codetools_0.2-20
#> [22] Rcpp_1.1.0 pkgconfig_2.0.3 lattice_0.22-7
#> [25] digest_0.6.37 SuperCell_1.0.1 R6_2.6.1
#> [28] RANN_2.6.2 magrittr_2.0.4 bslib_0.9.0
#> [31] Matrix_1.7-4 tools_4.5.1 cachem_1.1.0