Skip to contents

This function will try to create a pseudobulked count matrix for the bins. When a replicate has too few cells, it is discounted. If only one exists, then we sample from it twice to create the pseudobulks.

Usage

get_bins_as_bulk(
  pseudotime_sce,
  min_cells_for_bulk = 50,
  replicate_slot = "replicate"
)

Arguments

pseudotime_sce

The Single Cell Experiment object to get the bins from

min_cells_for_bulk

The minimum cells to look for per replicate and bin.

replicate_slot

The slot in the Single Cell Experiment that contains replicate information

Value

A dataframe pseudobulk counts matrix.

Examples

library(SingleCellExperiment, quietly = TRUE)
#> 
#> Attaching package: ‘MatrixGenerics’
#> The following objects are masked from ‘package:matrixStats’:
#> 
#>     colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
#>     colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
#>     colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
#>     colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
#>     colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
#>     colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
#>     colWeightedMeans, colWeightedMedians, colWeightedSds,
#>     colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
#>     rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
#>     rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
#>     rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
#>     rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
#>     rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
#>     rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
#>     rowWeightedSds, rowWeightedVars
#> 
#> Attaching package: ‘generics’
#> The following objects are masked from ‘package:base’:
#> 
#>     as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
#>     setequal, union
#> 
#> Attaching package: ‘BiocGenerics’
#> The following objects are masked from ‘package:stats’:
#> 
#>     IQR, mad, sd, var, xtabs
#> The following objects are masked from ‘package:base’:
#> 
#>     Filter, Find, Map, Position, Reduce, anyDuplicated, aperm, append,
#>     as.data.frame, basename, cbind, colnames, dirname, do.call,
#>     duplicated, eval, evalq, get, grep, grepl, is.unsorted, lapply,
#>     mapply, match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
#>     rank, rbind, rownames, sapply, saveRDS, table, tapply, unique,
#>     unsplit, which.max, which.min
#> 
#> Attaching package: ‘S4Vectors’
#> The following object is masked from ‘package:utils’:
#> 
#>     findMatches
#> The following objects are masked from ‘package:base’:
#> 
#>     I, expand.grid, unname
#> Welcome to Bioconductor
#> 
#>     Vignettes contain introductory material; view with
#>     'browseVignettes()'. To cite Bioconductor, see
#>     'citation("Biobase")', and for packages 'citation("pkgname")'.
#> 
#> Attaching package: ‘Biobase’
#> The following object is masked from ‘package:MatrixGenerics’:
#> 
#>     rowMedians
#> The following objects are masked from ‘package:matrixStats’:
#> 
#>     anyMissing, rowMedians
library(blase)
counts <- matrix(rpois(1000, lambda = 10), ncol = 100, nrow = 10)
sce <- SingleCellExperiment::SingleCellExperiment(
    assays = list(normcounts = counts, counts = counts / 2)
)
sce$pseudotime <- seq_len(100) - 1
colnames(sce) <- seq_len(100)
rownames(sce) <- as.character(seq_len(10))
sce <- assign_pseudotime_bins(sce,
    n_bins = 5,
    pseudotime_slot = "pseudotime", split_by = "cells"
)
sce$replicate <- rep(c(1, 2), 50)
result <- get_bins_as_bulk(
    sce,
    min_cells_for_bulk = 1,
    replicate_slot = "replicate"
)
result
#>    bin_1_rep_1 bin_1_rep_2 bin_2_rep_1 bin_2_rep_2 bin_3_rep_1 bin_3_rep_2
#> 1         45.0        51.5        48.0        48.0        56.5        47.5
#> 10        49.5        50.5        51.5        52.5        39.5        54.5
#> 2         44.5        50.5        47.0        55.0        44.5        46.5
#> 3         53.5        50.0        49.0        58.5        57.5        54.0
#> 4         60.0        54.5        55.5        58.0        49.0        61.5
#> 5         46.0        48.5        50.5        48.5        56.0        44.0
#> 6         54.0        49.5        56.5        51.0        47.5        46.5
#> 7         39.0        49.0        54.0        44.5        50.5        51.5
#> 8         43.0        46.5        45.0        41.5        52.0        54.5
#> 9         50.5        52.0        50.5        51.0        42.0        43.0
#>    bin_4_rep_1 bin_4_rep_2 bin_5_rep_1 bin_5_rep_2
#> 1         57.5        52.5        51.5        44.5
#> 10        61.5        50.0        49.0        38.0
#> 2         45.0        46.0        53.0        56.5
#> 3         45.5        52.0        52.5        55.0
#> 4         50.0        50.5        50.5        50.0
#> 5         50.0        54.0        50.0        48.5
#> 6         55.0        47.5        51.0        49.5
#> 7         52.0        55.0        54.0        57.5
#> 8         50.5        39.0        50.0        44.5
#> 9         47.5        49.0        45.0        52.5