Contents

1 Introduction

LineagePulse is a differential expression algorithm for single-cell RNA-seq (scRNA-seq) data. LineagePulse is based on zero-inflated negative binomial noise model and can capture both discrete and continuous population structures: Discrete population structures are groups of cells (e.g. condition of an experiment or tSNE clusters). Continous population structures can for example be pseudotemporal orderings of cells or temporal orderings of cells. The main use and novelty of LineagePulse lies in its ability to fit gene expression trajectories on pseudotemporal orderings of cells well. Note that LineagePulse does not infer a pseudotemporal ordering but is a downstream analytic tool to analyse gene expression trajectories on a given pseudotemporal ordering (such as from diffusion pseudotime or monocle2).

To run LineagPulse on scRNA-seq data, the user needs to use a minimal input parameter set for the wrapper function runLineagePulse, which then performs all normalisation, model fitting and differential expression analysis steps without any more user interaction required:

Additionally, one can provide:

Lastly, the experienced user who has a solid grasp of the mathematical and algorithmic basis of LineagePulse may change the defaults of these advanced input options:

2 Differential expression analysis

Here, we present a differential expression analysis scenario on a longitudinal ordering. The differential expression results are in a data frame which can be accessed from the output object via list like properties ($). The core differential expression analysis result are p-value and false-discovery-rate corrected p-value of differential expression which are the result of a gene-wise hypothesis test of a non-constant expression model (impulse, splines or groups) versus a constant expression model.

library(LineagePulse)
lsSimulatedData <- simulateContinuousDataSet(
  scaNCells = 100,
  scaNConst = 10,
  scaNLin = 10,
  scaNImp = 10,
  scaMumax = 100,
  scaSDMuAmplitude = 3,
  vecNormConstExternal=NULL,
  vecDispExternal=rep(20, 30),
  vecGeneWiseDropoutRates = rep(0.1, 30))
## Draw mean trajectories
## Setting size factors uniformly =1
## Draw dispersion
## Simulate negative binomial noise
## Simulate drop-out
objLP <- runLineagePulse(
  counts = lsSimulatedData$counts,
  dfAnnotation = lsSimulatedData$annot)
## LineagePulse for count data: v1.16.0
## --- Data preprocessing
## # 0 out of 100 cells did not have a continuous covariate and were excluded.
## # 0 out of 30 genes did not contain non-zero observations and are excluded from analysis.
## # 0 out of 100 cells did not contain non-zero observations and are excluded from analysis.
## --- Compute normalisation constants:
## # All size factors are set to one.
## --- Fit ZINB model for both H1 and H0.
## ### a) Fit ZINB model A (H0: mu=constant disp=constant) with noise model.
## #  .   Initialisation: ll -25466.989690739
## # 1.  Iteration with ll   -13480.3342141242 in 0.02 min.
## # 2.  Iteration with ll   -13449.2884782678 in 0.03 min.
## # 3.  Iteration with ll   -13449.2883200965 in 0.02 min.
## Finished fitting zero-inflated negative binomial model A with noise model in 0.1 min.
## ### b) Fit ZINB model B (H1: mu=splines disp=constant).
## #  .   Initialisation: ll -14747.4182639005
## # 1.  Iteration with ll   -12988.1391612747 in 0.02 min.
## Finished fitting zero-inflated negative binomial model B in 0.03 min.
## ### c) Fit NB model A (H0: mu=constant disp=constant).
## #  .   Initialisation: ll -14595.0339370632
## # 1.  Iteration with ll   -14417.9506371215 in 0.01 min.
## Finished fitting NB model B in 0.02 min.
## ### d) Fit NB model B (H1: mu=splines disp=constant).
## #  .   Initialisation: ll -14771.3808260255
## # 1.  Iteration with ll   -14276.496182478 in 0.02 min.
## Finished fitting NB model B in 0.03 min.
## Time elapsed during ZINB fitting: 0.21 min
## --- Run differential expression analysis.
## Finished runLineagePulse().
head(objLP$dfResults)
##          gene            p         padj  mean_H0         p_nb   padj_nb
## gene_1 gene_1 2.694267e-01 3.848953e-01 67.88027 2.694267e-01 0.9825922
## gene_2 gene_2 2.167855e-01 3.422929e-01 75.69052 2.167855e-01 0.9825922
## gene_3 gene_3 9.812963e-01 9.812963e-01 66.27091 9.812963e-01 0.9825922
## gene_4 gene_4 8.945261e-01 9.766310e-01 42.16047 8.945261e-01 0.9825922
## gene_5 gene_5 1.014803e-11 6.088818e-11 33.14987 1.014803e-11 0.9825922
## gene_6 gene_6 5.864351e-01 7.330439e-01 44.67844 5.864351e-01 0.3296105
##        df_full_zinb df_red_zinb df_full_nb df_red_nb loglik_full_zinb
## gene_1            7           2          7         2        -452.3610
## gene_2            7           2          7         2        -456.5874
## gene_3            7           2          7         2        -519.0699
## gene_4            7           2          7         2        -471.2009
## gene_5            7           2          7         2        -384.3331
## gene_6            7           2          7         2        -413.8381
##        loglik_red_zinb loglik_full_nb loglik_red_nb allZero
## gene_1       -455.5598      -520.2513     -520.6047   FALSE
## gene_2       -460.1135      -529.3854     -530.2338   FALSE
## gene_3       -519.4348      -519.7584     -520.1188   FALSE
## gene_4       -472.0284      -474.3749     -475.3037   FALSE
## gene_5       -414.5226      -426.2930     -426.6623   FALSE
## gene_6       -415.7114      -467.2982     -472.0905   FALSE

In addition to the raw p-values, one may be interested in further details of the expression models such as shape of the expression mean as a function of pseudotime, log fold changes (LFC) and global expression trends as function of pseudotime. We address each of these follow-up questions with separate sections in the following. Note that all of these follow-up questions are answered based on the model that were fit to compute the p-value of differential expression. Therefore, once runLineagePulse() was called once, no further model fitting is required.

# Further inspection of results ## Plot gene-wise trajectories

Multiple options are available for gene-wise expression trajectory plotting: Observations can be coloured by the posterior probability of drop-out (boolColourByDropout). Observations can be normalized based on the alternative expression model or taken as raw observerations for the scatter plot (boolH1NormCounts). Lineage contours can be added to aid visual interpretation of non-uniform population density in pseudotime related effects (boolLineageContour). Log counts can be displayed instead of counts if the fold changes are large (boolLogPlot). In any case, the output object of the gene-wise expression trajectors plotting function plotGene is a ggplot2 object which can then be printed or modified.

# plot the gene with the lowest p-value of differential expression
gplotExprProfile <- plotGene(
objLP = objLP, boolLogPlot = FALSE,
strGeneID = objLP$dfResults[which.min(objLP$dfResults$p),]$gene,
boolLineageContour = FALSE)
gplotExprProfile

The function plotGene also shows the H1 model fit under a negative binomial noise model (“H1(NB)”) as a reference to show what the model fit looks like if drop-out is not accounted for.

2.1 Manual analysis of expression trajectories

LineagePulse provides the user with parameter extraction functions that allow the user to interact directly with the raw model fits for analytic tasks or questions not addressed above.

# extract the mean parameter fits per cell of the gene with the lowest p-value.
matMeanParamFit <- getFitsMean(
    lsMuModel = lsMuModelH1(objLP),
    vecGeneIDs = objLP$dfResults[which.min(objLP$dfResults$p),]$gene)
cat("Minimum fitted mean parameter: ", round(min(matMeanParamFit),1) )
## Minimum fitted mean parameter:  1.1
cat("Mean fitted mean parameter: ", round(mean(matMeanParamFit),1) )
## Mean fitted mean parameter:  29.2

2.2 Fold changes

Given a discrete population structure, such as tSNE cluster or experimental conditions, a fold change is the ratio of the mean expression value of both groups. The definition of a fold change is less clear if a continous expression trajector is considered: Of interest may be for example the fold change from the first to the last cell on the expression trajectory or from the minimum to the maximum expression value. Note that in both cases, we compute fold changes on the model fit of the expression mean parameter which is corrected for noise and therefore more stable than the estimate based on the raw expression count observation.

# first, extract the model fits for a given gene again
vecMeanParamFit <- getFitsMean(
    lsMuModel = lsMuModelH1(objLP),
    vecGeneIDs = objLP$dfResults[which.min(objLP$dfResults$p),]$gene)
# compute log2-fold change from first to last cell on trajectory
idxFirstCell <- which.min(dfAnnotationProc(objLP)$pseudotime)
idxLastCell <- which.max(dfAnnotationProc(objLP)$pseudotime)
cat("LFC first to last cell on trajectory: ",
    round( (log(vecMeanParamFit[idxLastCell]) - 
                log(vecMeanParamFit[idxFirstCell])) / log(2) ,1) )
## LFC first to last cell on trajectory:
# compute log2-fold change from minimum to maximum value of expression trajectory
cat("LFC minimum to maximum expression value of model fit: ", 
    round( (log(max(vecMeanParamFit)) - 
                log(min(vecMeanParamFit))) / log(2),1) )
## LFC minimum to maximum expression value of model fit:  5.7

2.3 Global expression profiles

Global expression profiles or expression profiles across large groups of genes can be visualised via heatmaps of expression z-scores. One could extract the expression mean parameter fits as described above and create such heatmaps from scratch. LineaegePulse also offers a wrapper for creating such a heatmap:

# create heatmap with all differentially expressed genes
lsHeatmaps <- sortGeneTrajectories(
    vecIDs = objLP$dfResults[which(objLP$dfResults$padj < 0.01),]$gene,
    lsMuModel = lsMuModelH1(objLP),
    dirHeatmap=NULL)
print(lsHeatmaps$hmGeneSorted)

3 Session information

sessionInfo()
## R version 4.2.0 RC (2022-04-19 r82224)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.15-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.15-bioc/R/lib/libRlapack.so
## 
## 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       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] LineagePulse_1.16.0 BiocStyle_2.24.0   
## 
## loaded via a namespace (and not attached):
##  [1] bitops_1.0-7                matrixStats_0.62.0         
##  [3] doParallel_1.0.17           RColorBrewer_1.1-3         
##  [5] GenomeInfoDb_1.32.0         tools_4.2.0                
##  [7] bslib_0.3.1                 utf8_1.2.2                 
##  [9] R6_2.5.1                    KernSmooth_2.23-20         
## [11] DBI_1.1.2                   BiocGenerics_0.42.0        
## [13] colorspace_2.0-3            GetoptLong_1.0.5           
## [15] tidyselect_1.1.2            compiler_4.2.0             
## [17] cli_3.3.0                   Biobase_2.56.0             
## [19] Cairo_1.5-15                DelayedArray_0.22.0        
## [21] labeling_0.4.2              bookdown_0.26              
## [23] sass_0.4.1                  caTools_1.18.2             
## [25] scales_1.2.0                stringr_1.4.0              
## [27] digest_0.6.29               rmarkdown_2.14             
## [29] XVector_0.36.0              pkgconfig_2.0.3            
## [31] htmltools_0.5.2             MatrixGenerics_1.8.0       
## [33] fastmap_1.1.0               highr_0.9                  
## [35] rlang_1.0.2                 GlobalOptions_0.1.2        
## [37] shape_1.4.6                 jquerylib_0.1.4            
## [39] generics_0.1.2              farver_2.1.0               
## [41] jsonlite_1.8.0              BiocParallel_1.30.0        
## [43] gtools_3.9.2                dplyr_1.0.8                
## [45] RCurl_1.98-1.6              magrittr_2.0.3             
## [47] GenomeInfoDbData_1.2.8      Matrix_1.4-1               
## [49] Rcpp_1.0.8.3                munsell_0.5.0              
## [51] S4Vectors_0.34.0            fansi_1.0.3                
## [53] lifecycle_1.0.1             stringi_1.7.6              
## [55] yaml_2.3.5                  SummarizedExperiment_1.26.0
## [57] zlibbioc_1.42.0             gplots_3.1.3               
## [59] grid_4.2.0                  parallel_4.2.0             
## [61] crayon_1.5.1                lattice_0.20-45            
## [63] splines_4.2.0               circlize_0.4.14            
## [65] magick_2.7.3                knitr_1.38                 
## [67] ComplexHeatmap_2.12.0       pillar_1.7.0               
## [69] GenomicRanges_1.48.0        rjson_0.2.21               
## [71] codetools_0.2-18            stats4_4.2.0               
## [73] glue_1.6.2                  evaluate_0.15              
## [75] BiocManager_1.30.17         png_0.1-7                  
## [77] vctrs_0.4.1                 foreach_1.5.2              
## [79] gtable_0.3.0                purrr_0.3.4                
## [81] clue_0.3-60                 assertthat_0.2.1           
## [83] ggplot2_3.3.5               xfun_0.30                  
## [85] SingleCellExperiment_1.18.0 tibble_3.1.6               
## [87] iterators_1.0.14            IRanges_2.30.0             
## [89] cluster_2.1.3               ellipsis_0.3.2