Skip to contents

Impute missing transcript counts using a shared nearest neighbor graph

Usage

sc_impute_transcript(combined_sce, dimred = "PCA", ...)

Arguments

combined_sce

A SingleCellExperiment object with gene counts and a "transcript" altExp slot.

dimred

The name of the reduced dimension to use for building the shared nearest neighbor graph.

...

Additional arguments to pass to scran::buildSNNGraph. E.g. k = 30.

Value

A SingleCellExperiment object with imputed logcounts assay in the "transcript" altExp slot.

Details

For cells with NA values in the "transcript" altExp slot, this function imputes the missing values from cells with non-missing values. A shared nearest neighbor graph is built using reduced dimensions from the SingleCellExperiment object, and the imputation is done where the imputed value for a cell is the weighted sum of the transcript counts of its neighbors. Imputed values are stored in the "logcounts" assay of the "transcript" altExp slot. The "counts" assay is used to obtain logcounts but left unchanged.

Examples

sce <- SingleCellExperiment::SingleCellExperiment(assays = list(counts = matrix(rpois(50, 5), ncol = 10)))
long_read <- SingleCellExperiment::SingleCellExperiment(assays = list(counts = matrix(rpois(40, 5), ncol = 10)))
SingleCellExperiment::altExp(sce, "transcript") <- long_read
SingleCellExperiment::counts(SingleCellExperiment::altExp(sce))[,1:2] <- NA
SingleCellExperiment::counts(SingleCellExperiment::altExp(sce))
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,]   NA   NA    9    3    7    1    2    2    6     4
#> [2,]   NA   NA    4    2    3    2    3    6    5     3
#> [3,]   NA   NA    4    4    4    2    3    4    0     9
#> [4,]   NA   NA    3    4    5    5    2    5    8     5
imputed_sce <- sc_impute_transcript(sce, k = 4)
#> Warning: more singular values/vectors requested than available
#> Warning: You're computing too large a percentage of total singular values, use a standard svd instead.
#> Imputing transcript counts ...
SingleCellExperiment::logcounts(SingleCellExperiment::altExp(imputed_sce))
#> 4 x 10 Matrix of class "dgeMatrix"
#>          [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]     [,8]
#> [1,] 2.176712 2.284185 3.045487 2.239139 2.795100 1.385431 2.078951 1.534589
#> [2,] 2.102268 2.281027 2.078951 1.799406 1.826214 2.078951 2.545351 2.742260
#> [3,] 2.110705 1.821672 2.078951 2.575685 2.135777 2.078951 2.545351 2.261265
#> [4,] 2.513752 2.474709 1.773469 2.575685 2.390508 3.179909 2.078951 2.521716
#>          [,9]    [,10]
#> [1,] 2.606941 2.025535
#> [2,] 2.390508 1.724027
#> [3,] 0.000000 2.983808
#> [4,] 2.961526 2.274794