Contents

0.1 Introduction

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:

0.2 Installation

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")

0.3 Preparing your dataset

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:

  1. The markers you will be using to create supercells to have been appropriately transformed, typically using either arcsinh transformation or linear binning (using FlowJo). runSuperCellCyto does not perform any data transformation or scaling.
  2. The object to have a column denoting the unique ID of each cell. You most likely have to create this column yourself, and it can simply just be a numerical value ranging from 1 to however many cells you have in your data.
  3. The object to have a column denoting the biological sample each cell comes from. This column is critical to ensure that cells from different samples will not be mixed in a supercell.

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: 16.02147  9.665714 20.07521 18.95338 16.36956 19.17502 18.93025 5.483087
#> 2: 17.84389 10.813134 19.46955 16.47262 16.47183 19.62496 19.44706 6.919907
#> 3: 17.35161  7.857990 18.27935 18.00392 18.63058 18.41366 18.81734 6.848037
#> 4: 16.91265 10.280195 19.62963 17.64729 15.34937 20.91894 18.50223 6.659876
#> 5: 14.90102 12.370804 19.84432 16.63240 19.11749 19.29528 20.28415 5.172794
#> 6: 19.08373 10.713221 19.87704 16.29290 17.00544 19.27205 18.30448 8.787981
#>    Marker_9 Marker_10 Marker_11 Marker_12 Marker_13 Marker_14 Marker_15
#>       <num>     <num>     <num>     <num>     <num>     <num>     <num>
#> 1: 18.65806  10.56727  9.641828  17.13593  11.67704  13.31070  15.52357
#> 2: 16.38351  11.63270  9.663402  17.25296  12.35570  13.65461  13.34887
#> 3: 16.44475  11.56164 11.025854  17.57198  11.68267  14.16155  12.85354
#> 4: 17.56152  10.68987 11.603791  18.66415  11.54000  16.77939  14.04442
#> 5: 15.60395  10.92818  9.990438  17.30933  11.10581  16.36861  11.99225
#> 6: 15.60444  10.75254 11.195035  19.05595  10.59314  18.73976  13.67985
#>      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.881144       1.413330       2.098354       2.042653       1.901681
#> 2:       1.984445       1.514086       2.068655       1.907685       1.907639
#> 3:       1.957535       1.233834       2.007682       1.993046       2.026052
#> 4:       1.932938       1.468420       2.076589       1.973782       1.840314
#> 5:       1.812168       1.637592       2.087133       1.916925       2.050991
#> 6:       2.049281       1.505667       2.088731       1.897193       1.938186
#>    Marker_6_asinh Marker_7_asinh Marker_8_asinh Marker_9_asinh Marker_10_asinh
#>             <num>          <num>          <num>          <num>           <num>
#> 1:       2.053899       2.041472      0.9480696       2.027476        1.493252
#> 2:       2.076358       2.067536      1.1286361       1.902496        1.580809
#> 3:       2.014746       2.035689      1.1201888       1.906064        1.575183
#> 4:       2.138350       2.019377      1.0977971       1.969095        1.503690
#> 5:       2.059950       2.108404      0.9056004       1.855967        1.523701
#> 6:       2.058783       2.009008      1.3296604       1.855997        1.508987
#>    Marker_11_asinh Marker_12_asinh Marker_13_asinh Marker_14_asinh
#>              <num>           <num>           <num>           <num>
#> 1:        1.411133        1.945522        1.584306        1.705821
#> 2:        1.413117        1.952057        1.636459        1.729738
#> 3:        1.531798        1.969668        1.584749        1.764040
#> 4:        1.578524        2.027791        1.573464        1.925354
#> 5:        1.442780        1.955191        1.538383        1.901625
#> 6:        1.545684        2.047872        1.495463        2.031697
#>    Marker_15_asinh
#>              <num>
#> 1:        1.851050
#> 2:        1.708502
#> 3:        1.673176
#> 4:        1.756213
#> 5:        1.608842
#> 6:        1.731472

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"

0.4 Creating supercells

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"

0.4.1 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.

0.4.2 Supercell expression matrix

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.932820       1.480497       2.058012       1.937650       1.929839
#> 2:       1.936512       1.485028       2.074785       1.954942       1.953790
#> 3:       1.973196       1.525851       2.049503       1.940442       1.892497
#> 4:       1.955466       1.492706       2.067551       1.950164       1.879232
#> 5:       1.921443       1.471462       2.049233       1.927321       1.938555
#> 6:       1.898232       1.400150       2.059138       1.970396       1.911499
#>    Marker_6_asinh Marker_7_asinh Marker_8_asinh Marker_9_asinh Marker_10_asinh
#>             <num>          <num>          <num>          <num>           <num>
#> 1:       2.079345       2.059833      1.0623579       1.943595        1.517058
#> 2:       2.086344       2.075719      1.1488808       1.950763        1.449382
#> 3:       2.093484       2.079907      1.0728252       1.936111        1.419302
#> 4:       2.079585       2.063560      1.2367329       1.940097        1.537562
#> 5:       2.075175       2.052380      0.8468998       1.939486        1.482768
#> 6:       2.057188       2.051707      1.1587265       1.937750        1.603007
#>    Marker_11_asinh Marker_12_asinh Marker_13_asinh Marker_14_asinh
#>              <num>           <num>           <num>           <num>
#> 1:        1.372098        1.949501        1.641735        1.820812
#> 2:        1.448354        1.958714        1.699883        1.827952
#> 3:        1.318964        1.958896        1.604196        1.828739
#> 4:        1.452024        1.955299        1.668953        1.865154
#> 5:        1.414072        1.940696        1.559365        1.862229
#> 6:        1.544456        1.956759        1.585963        1.795965
#>    Marker_15_asinh   Sample                 SuperCellId
#>              <num>   <char>                      <char>
#> 1:        1.756996 Sample_1 SuperCell_1_Sample_Sample_1
#> 2:        1.793143 Sample_1 SuperCell_2_Sample_Sample_1
#> 3:        1.723557 Sample_1 SuperCell_3_Sample_Sample_1
#> 4:        1.755623 Sample_1 SuperCell_4_Sample_Sample_1
#> 5:        1.803753 Sample_1 SuperCell_5_Sample_Sample_1
#> 6:        1.799024 Sample_1 SuperCell_6_Sample_Sample_1

Therein, we will have the following columns:

  1. All the markers we previously specified in the markers_col variable. In this example, they are the arcsinh transformed markers in our toy data.
  2. A column (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).
  3. The SuperCellId column denoting the unique ID of the supercell.

0.4.2.1 SuperCellId

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.

0.4.3 Supercell cell map

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_153_Sample_Sample_1 Cell_1 Sample_1
#> 2: SuperCell_147_Sample_Sample_1 Cell_2 Sample_1
#> 3:  SuperCell_13_Sample_Sample_1 Cell_3 Sample_1
#> 4: SuperCell_204_Sample_Sample_1 Cell_4 Sample_1
#> 5: SuperCell_306_Sample_Sample_1 Cell_5 Sample_1
#> 6:  SuperCell_98_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.

0.5 Running runSuperCellCyto in parallel

By 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:

  1. Create a BiocParallelParam object from the BiocParallel package. This object can either be of type MulticoreParamor SnowParam. We highly recommend consulting their vignette for more information.
  2. Set the number of tasks for the BiocParallelParam object to the number of samples we have in the dataset.
  3. Set the 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
)

0.6 Controlling supercells granularity

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.

0.6.1 Adjusting gamma value after one run of runSuperCellCyto

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.966033       1.498529      2.0357649       1.875689
#>    2:       1.987857       1.521825      2.0495605       1.905934
#>    3:       1.948563       1.567672      2.0537981       1.910958
#>    4:       1.941276       1.294234      2.0566815       1.941687
#>    5:       1.959315       1.497885      2.0508264       1.926955
#>   ---                                                            
#> 2996:       1.564810       1.991354      0.9299923       1.811137
#> 2997:       1.526339       2.021093      0.9759130       1.804676
#> 2998:       1.545802       2.001022      0.6211983       1.670878
#> 2999:       1.619286       1.914016      0.8676866       1.830238
#> 3000:       1.467894       1.889117      1.0645811       1.812514
#>       Marker_5_asinh Marker_6_asinh Marker_7_asinh Marker_8_asinh
#>                <num>          <num>          <num>          <num>
#>    1:       1.989588       2.083423       2.067489      0.9866744
#>    2:       1.932190       2.079977       2.086276      0.8109540
#>    3:       1.896260       2.086951       2.069867      1.2768396
#>    4:       1.886893       2.061378       2.046539      0.9907007
#>    5:       1.942538       2.043696       2.092040      1.1783588
#>   ---                                                            
#> 2996:       2.055630       1.388798       1.419864      1.6495179
#> 2997:       2.022616       1.449560       1.414669      1.8563935
#> 2998:       2.078607       1.436432       1.345458      1.8021779
#> 2999:       2.004825       1.274004       1.051146      1.8570334
#> 3000:       1.998411       1.402740       1.532735      1.8433925
#>       Marker_9_asinh Marker_10_asinh Marker_11_asinh Marker_12_asinh
#>                <num>           <num>           <num>           <num>
#>    1:       1.928584        1.496017        1.371279       1.9643747
#>    2:       1.972614        1.596139        1.503115       1.9678731
#>    3:       1.918370        1.489218        1.372938       1.9386963
#>    4:       1.933867        1.570289        1.288454       1.9400816
#>    5:       1.944525        1.471230        1.346888       1.9556928
#>   ---                                                               
#> 2996:       1.932314        2.025406        1.464150       1.1129370
#> 2997:       1.937151        2.125049        1.639787       1.0887742
#> 2998:       1.968430        2.077343        1.646797       1.1470190
#> 2999:       1.910147        2.059178        1.478915       0.9957697
#> 3000:       1.855005        2.054094        1.629205       0.9921347
#>       Marker_13_asinh Marker_14_asinh Marker_15_asinh   Sample
#>                 <num>           <num>           <num>   <char>
#>    1:        1.680754        1.866696        1.697916 Sample_1
#>    2:        1.537443        1.842517        1.743457 Sample_1
#>    3:        1.602236        1.829044        1.804996 Sample_1
#>    4:        1.673736        1.872762        1.741451 Sample_1
#>    5:        1.719615        1.685824        1.836090 Sample_1
#>   ---                                                         
#> 2996:        1.765969        1.942131        1.926786 Sample_3
#> 2997:        1.598867        1.900420        1.976469 Sample_3
#> 2998:        1.667868        1.956398        1.970898 Sample_3
#> 2999:        1.685161        1.864153        1.897200 Sample_3
#> 3000:        1.567858        1.828556        1.948766 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_412_Sample_Sample_1     Cell_1 Sample_1
#>     2: SuperCell_288_Sample_Sample_1     Cell_2 Sample_1
#>     3: SuperCell_117_Sample_Sample_1     Cell_3 Sample_1
#>     4: SuperCell_633_Sample_Sample_1     Cell_4 Sample_1
#>     5:  SuperCell_38_Sample_Sample_1     Cell_5 Sample_1
#>    ---                                                  
#> 29996: SuperCell_164_Sample_Sample_3 Cell_29996 Sample_3
#> 29997: SuperCell_831_Sample_Sample_3 Cell_29997 Sample_3
#> 29998:  SuperCell_35_Sample_Sample_3 Cell_29998 Sample_3
#> 29999: SuperCell_355_Sample_Sample_3 Cell_29999 Sample_3
#> 30000: SuperCell_395_Sample_Sample_3 Cell_30000 Sample_3

The output generated by recomputeSupercells is essentially a list:

  1. supercell_expression_matrix: A data.table object that contains the marker expression for each supercell.
  2. 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

0.6.2 Specifying different gamma value for different samples

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
#>        <num>     <num>     <num>    <num>     <num>     <num>     <num>
#> 1: 20.576492 12.895426 12.058159 17.69414 19.367288  8.587771  6.072020
#> 2: 18.748417 12.096891 11.256737 18.71173 19.365508  8.136212  6.383784
#> 3: 19.966136 12.992951 11.258375 19.19777 17.561494  8.676664  6.589757
#> 4:  8.914410  6.826572  7.137058 18.29560  3.918064 10.696056 11.522164
#> 5:  9.944244  6.259583  5.238068 17.80621  6.406734 10.740183 11.757373
#> 6:  9.295328  8.794751  7.551064 18.36383  5.865644 10.809500 13.152245
#>    Marker_8 Marker_9 Marker_10   Sample                   SuperCellId
#>       <num>    <num>     <num>   <char>                        <char>
#> 1: 12.02414 7.265951  14.11890 Sample_1   SuperCell_1_Sample_Sample_1
#> 2: 10.87218 6.534252  15.32553 Sample_1   SuperCell_2_Sample_Sample_1
#> 3: 11.34325 8.215873  14.51615 Sample_1   SuperCell_3_Sample_Sample_1
#> 4: 19.54265 6.347091  14.45929 Sample_2 SuperCell_498_Sample_Sample_2
#> 5: 14.29674 6.293049  17.82189 Sample_2 SuperCell_499_Sample_Sample_2
#> 6: 17.51596 5.179615  16.12847 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_691_Sample_Sample_1     Cell_1 Sample_1
#> 2: SuperCell_315_Sample_Sample_1     Cell_2 Sample_1
#> 3: SuperCell_896_Sample_Sample_1     Cell_3 Sample_1
#> 4: SuperCell_159_Sample_Sample_2 Cell_19998 Sample_2
#> 5: SuperCell_187_Sample_Sample_2 Cell_19999 Sample_2
#> 6:  SuperCell_57_Sample_Sample_2 Cell_20000 Sample_2

0.7 Mixing cells from different samples in a supercell

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.

0.8 I have more cells than RAM in my computer

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:

  1. Load up a subset of the samples (say 1-10).
  2. Generate supercells for those samples.
  3. Save the output using the qs package.
  4. Extract the supercell_expression_matrix and supercell_cell_map, and export them out as a csv file using data.table’s fwrite function.
  5. Load another sets of samples (say 11-20), rinse and repeat step 2-4.

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.

0.9 Session information

sessionInfo()
#> R version 4.6.0 RC (2026-04-17 r89917)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.24-bioc/R/lib/libRblas.so 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0  LAPACK version 3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB              LC_COLLATE=C              
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: America/New_York
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] parallel  stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#> [1] BiocParallel_1.47.0 SuperCellCyto_1.3.0 BiocStyle_2.41.0   
#> 
#> loaded via a namespace (and not attached):
#>  [1] cli_3.6.6           knitr_1.51          rlang_1.2.0        
#>  [4] xfun_0.57           otel_0.2.0          data.table_1.18.2.1
#>  [7] jsonlite_2.0.0      plyr_1.8.9          htmltools_0.5.9    
#> [10] sass_0.4.10         rmarkdown_2.31      grid_4.6.0         
#> [13] evaluate_1.0.5      jquerylib_0.1.4     fastmap_1.2.0      
#> [16] yaml_2.3.12         lifecycle_1.0.5     bookdown_0.46      
#> [19] BiocManager_1.30.27 compiler_4.6.0      igraph_2.3.0       
#> [22] codetools_0.2-20    Rcpp_1.1.1-1.1      pkgconfig_2.0.3    
#> [25] lattice_0.22-9      digest_0.6.39       SuperCell_1.1      
#> [28] R6_2.6.1            RANN_2.6.2          magrittr_2.0.5     
#> [31] bslib_0.10.0        Matrix_1.7-5        tools_4.6.0        
#> [34] cachem_1.1.0