Skip to contents

Abstract

Dropout is the phenomenon by which metabolically labeled RNA or sequencing reads derived from such RNA is lost either during library preparation or during computational processing of the raw sequencing data. Several labs have independently identified and discussed the prevalence of dropout in NR-seq and other metabolic labeling RNA-seq experiments. Recent work suggests that there are three potential causes for this: 1) Loss of labeled RNA on plastic surfaces during RNA extraction, 2) RT falloff due to modifications of the metabolic labeling made by some NR-seq chemistries, and 3) loss of reads with many NR-induced mutations due to poor read alignment. While 3) is best remedied by improved alignment strategies (discussed in Zimmer et al. and Berg et al.), modified fastq processing will not address the other causes. Improved handling of RNA can help, but what if you already have data that you suspect may be biased by dropout? Version 1.0.0 of bakR introduced a strategy to correct for dropout induced biases. In this vignette, I will show how to correct for dropout with bakR. Following the demonstrations, I will also include a more thorough discussion of dropout, bakR’s dropout correction strategy, and how it differs from a strategy recently developed by the Erhard lab.

Necessary Setup

bakR version 1.0.0 or later is necessary to run this vignette.

A Brief Tutorial on Dropout Correction in bakR

bakR has a new simulation strategy as of version 1.0.0 that allows for the accurate simulation of dropout:

# Simulate a nucleotide recoding dataset
sim_data <- Simulate_relative_bakRData(1000, depth = 1000000, nreps = 2,
                                       p_do = 0.4)
  # This will simulate 500 features, 500,000 reads, 2 experimental conditions
  # and 2 replicates for each experimental condition.
  # 40% dropout is simulated.
  # See ?Simulate_relative_bakRData for details regarding tunable parameters

# Run the efficient model
Fit <- bakRFit(sim_data$bakRData)
#> Finding reliable Features
#> Filtering out unwanted or unreliable features
#> Processing data...
#> Estimating pnew with likelihood maximization
#> Estimating unlabeled mutation rate with -s4U data
#> Estimated pnews and polds for each sample are:
#> # A tibble: 4 × 4
#> # Groups:   mut [2]
#>     mut  reps   pnew    pold
#>   <int> <dbl>  <dbl>   <dbl>
#> 1     1     1 0.0497 0.00100
#> 2     1     2 0.0500 0.00100
#> 3     2     1 0.0499 0.00100
#> 4     2     2 0.0497 0.00100
#> Estimating fraction labeled
#> Estimating per replicate uncertainties
#> Estimating read count-variance relationship
#> Averaging replicate data and regularizing estimates
#> Assessing statistical significance
#> All done! Run QC_checks() on your bakRFit object to assess the 
#>             quality of your data and get recommendations for next steps.

Dropout will cause bakR to underestimate the true fraction new. In addition, low fraction new features will receive more read counts than they would have if dropout had not existed (and vice versa for high fraction new features). Both of these biases can be corrected for with a single line of code:

# Correct dropout-induced biases
Fit_c <- CorrectDropout(Fit)
#> Estimated rates of dropout are:
#>   Exp_ID Replicate       pdo
#> 1      1         1 0.4013715
#> 2      1         2 0.3841179
#> 3      2         1 0.2627656
#> 4      2         2 0.3242958
#> Mapping sample name to sample characteristics
#> Filtering out low coverage features
#> Processing data...
#> Estimating read count-variance relationship
#> Averaging replicate data and regularizing estimates
#> Assessing statistical significance
#> All done! Run QC_checks() on your bakRFit object to assess the 
#>             quality of your data and get recommendations for next steps.
  # You can also overwite the existing bakRFit object.
  # I am creating a separate bakRFit object to make comparisons later in this vignette.

Dropout will lead to a correlation between the fraction new and the difference between +s4U and -s4U read counts. This trend and the model fit can be visualized as follows:

# Correct dropout-induced biases
Vis_DO <- VisualizeDropout(Fit)
#> Estimated rates of dropout are:
#>   Exp_ID Replicate       pdo
#> 1      1         1 0.4013715
#> 2      1         2 0.3841179
#> 3      2         1 0.2627656
#> 4      2         2 0.3242958

# Visualize dropout for 1st replicate of reference condition
Vis_DO$ExpID_1_Rep_1

We can assess the impact of dropout correction by comparing the known simulated truth to the fraction new estimates, before and after dropout correction.

Before correction:


# Extract simualted ground truths
sim_truth <- sim_data$sim_list

# Features that made it past filtering
XFs <- unique(Fit$Fast_Fit$Effects_df$XF)

# Simulated logit(fraction news) from features making it past filtering
true_fn <- sim_truth$Fn_rep_sim$Logit_fn[sim_truth$Fn_rep_sim$Feature_ID %in% XFs]

# Estimated logit(fraction news)
est_fn <- Fit$Fast_Fit$Fn_Estimates$logit_fn

# Compare estimate to truth
plot(true_fn, est_fn, xlab = "True logit(fn)", ylab = "Estimated logit(fn)")
abline(0, 1, col = "red")

After correction:


# Features that made it past filtering
XFs <- unique(Fit_c$Fast_Fit$Effects_df$XF)

# Simulated logit(fraction news) from features making it past filtering
true_fn <- sim_truth$Fn_rep_sim$Logit_fn[sim_truth$Fn_rep_sim$Feature_ID %in% XFs]

# Estimated logit(fraction news)
est_fn <- Fit_c$Fast_Fit$Fn_Estimates$logit_fn

# Compare estimate to truth
plot(true_fn, est_fn, xlab = "True logit(fn)", ylab = "Estimated logit(fn)")
abline(0, 1, col = "red")

RNA dropout and bakR’s correction strategy

As discussed in the Abstract for this vignette, dropout refers to the loss of metabolically labeled RNA, or reads from said RNA. Dropout correction in the context of bakR is specifically designed to address biases due to the loss of metabolically labeled RNA during library preparation.

bakR’s strategy for correcting dropout involves formalizing a model for dropout, using that model to infer a parametric relationship between the biased fraction new estimate and the ratio of +s4U to -s4U read counts for a feature, and then fitting that model to data with nonlinear least squares. bakR’s model of dropout makes several simplifying assumptions to ensure tractability of parameter estimation while still capturing important features of the process:

  1. The average number of reads that will come from an RNA feature is related to the fraction of sequenced RNA molecules derived from that feature.
  2. All labeled RNA is equally likely to get lost during library preparation, with the probability of losing a molecule of labeled RNA referred to as pdo.

These assumptions lead to the following expressions for the expected number of sequencing reads coming from a feature (index i) in +s4U and -s4U NR-seq data:

E[reads from feature i in +s4U sample]=number of molecules from feature itotal number of molecules in +s4U sample*R+s4U=ni*θi*(1pdo)+ni*(1θi)j=1NFnj*θj*(1pdo)+nj*(1θj)*R+s4UE[reads from feature i in -s4U sample]=number of molecules from feature itotal number of molecules in -s4U sample*R-s4U=nij=1NFnj*R-s4U \begin{align} \text{E[reads from feature i in +s}^{\text{4}}\text{U sample]} &= \frac{\text{number of molecules from feature i}}{\text{total number of molecules in +s}^{\text{4}}\text{U sample}}*\text{R}_{\text{+s}^{\text{4}}\text{U}} \\ &= \frac{\text{n}_{\text{i}}*\theta_{\text{i}}*(1 - \text{pdo}) + \text{n}_{\text{i}}*(1 - \theta_{\text{i}}) }{\sum_{\text{j}=1}^{\text{NF}}\text{n}_{\text{j}}*\theta_{\text{j}}*(1 - \text{pdo}) + \text{n}_{\text{j}}*(1 - \theta_{\text{j}}) }*\text{R}_{\text{+s}^{\text{4}}\text{U}} \\ \\ \\ \text{E[reads from feature i in -s}^{\text{4}}\text{U sample]} &= \frac{\text{number of molecules from feature i}}{\text{total number of molecules in -s}^{\text{4}}\text{U sample}}*\text{R}_{\text{-s}^{\text{4}}\text{U}} \\ &= \frac{\text{n}_{\text{i}}}{\sum_{\text{j}=1}^{\text{NF}}\text{n}_{\text{j}}}*\text{R}_{\text{-s}^{\text{4}}\text{U}} \end{align}

where the parameters are defined as follows:

ni=Number of molecules from feature iθi=True fraction new for feature ipdo=Probability that a labeled RNA molecule is preferentially lost during library prepNF=Total number of RNA features that contribute sequencable moleculesR=Total number of sequencing reads. \begin{align} \text{n}_{\text{i}} &= \text{Number of molecules from feature i} \\ \theta_{\text{i}} &= \text{True fraction new for feature i} \\ \text{pdo} &= \text{Probability that a labeled RNA molecule is preferentially lost during library prep} \\ \text{NF} &= \text{Total number of RNA features that contribute sequencable molecules} \\ \text{R} &= \text{Total number of sequencing reads.} \end{align}

Defining “dropout” to be the ratio of the RPM normalized expected read counts yields the following relationship between “dropout”, the fraction new, and the rate of dropout:

Dropout=E[reads from feature i in +s4U sample]/R+s4UE[reads from feature i in -s4U sample]/R-s4U=ni*θi*(1pdo)+ni*(1θi)ni*j=1NFnjj=1NFnj*θj*(1pdo)+nj*(1θj)=[θi*(1pdo)+(1θi)]*scale=[1θi*pdo]*scale \begin{align} \text{Dropout} &= \frac{\text{E[reads from feature i in +s}^{\text{4}}\text{U sample]/}\text{R}_{\text{+s}^{\text{4}}\text{U}}}{\text{E[reads from feature i in -s}^{\text{4}}\text{U sample]/}\text{R}_{\text{-s}^{\text{4}}\text{U}}} \\ \\ &= \frac{\text{n}_{\text{i}}*\theta_{\text{i}}*(1 - \text{pdo}) + \text{n}_{\text{i}}*(1 - \theta_{\text{i}}) }{\text{n}_{\text{i}}}*\frac{\sum_{\text{j}=1}^{\text{NF}}\text{n}_{\text{j}}}{ \sum_{\text{j}=1}^{\text{NF}}\text{n}_{\text{j}}*\theta_{\text{j}}*(1 - \text{pdo}) + \text{n}_{\text{j}}*(1 - \theta_{\text{j}}) } \\ \\ &= [\theta_{\text{i}}*(1 - \text{pdo}) + (1 - \theta_{\text{i}})]*\text{scale} \\ &= [1 - \theta_{\text{i}}*\text{pdo}]*\text{scale} \end{align}

where scale\text{scale} is a constant scale factor that represents the factor difference in the number of sequencable molecules with and without dropout.

Currently, the relationship between the quantification of dropout and pdo\text{pdo} includes θi\theta_{\text{i}}, which is the true, unbiased fraction new. Unfortunately, the presence of dropout means that we do not have access to this quantify. Rather, we estimate a dropout biased fraction of sequencing reads that are new (θido\theta_{\text{i}}^{\text{do}}), which on average will represent an underestimation of θi\theta_{\text{i}}. Therefore, we need to relate the quantity we estimate (θido\theta_{\text{i}}^{\text{do}}) and the parameter we wish to estimate (pdo\text{pdo}) to θi\theta_{\text{i}}. In the context of this model, such a relationship can be derived as follows:

θido=number of new sequencable moleculestotal number of sequencable moleculesθido=ni*θi*(1pdo)ni*θi*(1pdo)+ni*(1θi)θido=θi*(1pdo)θi*(1pdo)+(1θi)θido*[1θi*pdo]=θi*(1pdo)θido=θi*(1pdo)+θi*θido*pdoθido(1pdo)+θido*pdo=θi \begin{align} \theta_{\text{i}}^{\text{do}} &= \frac{\text{number of new sequencable molecules}}{\text{total number of sequencable molecules}} \\ \theta_{\text{i}}^{\text{do}} &= \frac{\text{n}_{\text{i}}*\theta_{\text{i}}*(1 - \text{pdo}) }{\text{n}_{\text{i}}*\theta_{\text{i}}*(1 - \text{pdo}) + \text{n}_{\text{i}}*(1-\theta_{\text{i}})} \\ \theta_{\text{i}}^{\text{do}} &= \frac{\theta_{\text{i}}*(1 - \text{pdo}) }{\theta_{\text{i}}*(1 - \text{pdo}) + (1-\theta_{\text{i}})} \\ \theta_{\text{i}}^{\text{do}}*[1 - \theta_{\text{i}}*\text{pdo}] &= \theta_{\text{i}}*(1 - \text{pdo}) \\ \theta_{\text{i}}^{\text{do}} &= \theta_{\text{i}}*(1 - \text{pdo}) + \theta_{\text{i}}*\theta_{\text{i}}^{\text{do}}*\text{pdo} \\ \frac{\theta_{\text{i}}^{\text{do}}}{(1 - \text{pdo}) + \theta_{\text{i}}^{\text{do}}*\text{pdo}} &= \theta_{\text{i}} \end{align}

We can then use this relationship to substite θi\theta_{\text{i}} for a function of θido\theta_{\text{i}}^{\text{do}} and pdo\text{pdo} in our dropout quantification equation:

Dropout=[1θi*pdo]*scaleDropout=scalescale*pdo*θido(1pdo)+θido*pdo \begin{align} \text{Dropout} &= [1 - \theta_{\text{i}}*\text{pdo}]*\text{scale}\\ \text{Dropout} &= \text{scale} - \frac{\text{scale}*\text{pdo}*\theta_{\text{i}}^{\text{do}}}{(1 - \text{pdo}) + \theta_{\text{i}}^{\text{do}}*\text{pdo}} \end{align}

bakR’s CorrectDropout function fits this predicted relationship between the ratio of +s4U to -s4U reads (Dropout\text{Dropout}) and the uncorrected fraction new estimates (θido\theta_{\text{i}}^{\text{do}}) to infer pdopdo. Corrected fraction new estimates can then be inferred from the relationship between θido\theta_{\text{i}}^{\text{do}}, pdo\text{pdo}, and θi\theta_{\text{i}}. Finally, bakR redistributes read counts according to what the estimated relative proportions of each feature would have been if no dropout had existed. The key insight is that:

E[number of reads without dropout]E[number of reads with dropout]=Dropout=ni*θi*(1pdo)+ni*(1θi)ni*j=1NFnjj=1NFnj*θj*(1pdo)+nj*(1θj)=θi*(1pdo)+(1θi)1*NN*θG*(1pdo)+N*(1θG)=θi*(1pdo)+(1θi)1*1θG*(1pdo)+(1θG)=fraction of feature i molecules remaining after dropoutfraction of total molecules remaining after dropout \begin{align} \frac{\text{E[number of reads without dropout]}}{\text{E[number of reads with dropout]}} &= \text{Dropout}\\ &= \frac{\text{n}_{\text{i}}*\theta_{\text{i}}*(1 - \text{pdo}) + \text{n}_{\text{i}}*(1 - \theta_{\text{i}}) }{\text{n}_{\text{i}}}*\frac{\sum_{\text{j}=1}^{\text{NF}}\text{n}_{\text{j}}}{ \sum_{\text{j}=1}^{\text{NF}}\text{n}_{\text{j}}*\theta_{\text{j}}*(1 - \text{pdo}) + \text{n}_{\text{j}}*(1 - \theta_{\text{j}}) } \\ &= \frac{\theta_{\text{i}}*(1 - \text{pdo}) + (1 - \theta_{\text{i}}) }{1}*\frac{\text{N}}{\text{N}*\theta_{\text{G}}*(1-\text{pdo}) + \text{N}*(1 - \theta_{\text{G}})}\\ &= \frac{\theta_{\text{i}}*(1 - \text{pdo}) + (1 - \theta_{\text{i}}) }{1}*\frac{1}{\theta_{\text{G}}*(1 - \text{pdo}) + (1 - \theta_{\text{G}}) } \\ \\ &= \frac{\text{fraction of feature i molecules remaining after dropout}}{\text{fraction of total molecules remaining after dropout}} \\ \end{align}

Getting from the 2nd line to the third line involved a bit of algebraic trickery (multiplying by 1) and defining the “global fraction new” (θG\theta_{\text{G}}), which is the fraction of all sequenced molecules that are new (where N\text{N} is the total number of sequenced molecules if none are lost due to dropout). θG\theta_{\text{G}} can be calculated as a weighted average of dropout biased fraction news for each feature, weighted by the uncorrected number of reads each feature has, and then dropout correcting:

θGdo=j=1NFθjdo*nreadsjj=1NFnreadsjθG=θGdo(1pdo)+θGdo*pdo \begin{align} \theta_{\text{G}}^{\text{do}} &= \frac{\sum_{\text{j=1}}^{\text{NF}}\theta_{\text{j}}^{\text{do}}*\text{nreads}_{\text{j}} }{\sum_{\text{j=1}}^{\text{NF}}\text{nreads}_{\text{j}}} \\ \theta_{\text{G}} &= \frac{\theta_{\text{G}}^{\text{do}}}{(1 - \text{pdo}) + \theta_{\text{G}}^{\text{do}}*\text{pdo}} \end{align}

Thus, the dropout corrected read counts can be obtained as follows:

Corrected read count for feature i=nreadsi*θG*(1pdo)+(1θG)θi*(1pdo)+(1θi) \begin{align} \text{Corrected read count for feature i} &= \text{nreads}_{\text{i}}*\frac{\theta_{\text{G}}*(1 - \text{pdo}) + (1 - \theta_{\text{G}})}{\theta_{\text{i}}*(1 - \text{pdo}) + (1 - \theta_{\text{i}})} \end{align}

Differences between bakR and grandR’s strategies

Florian Erhard’s group was the first to implement a strategy for dropout correction in an NR-seq analysis tool (their R package grandR). The strategy used by grandR is discussed here. In short, a factor ff is found such that if the number of new reads (inferred as the fraction new * total reads) is multiplied by ff, then the Spearman correlation between the fraction new and the difference in -s4U and +s4U is 0. The dropout rate is then calculated as:

pdo=ff+1 \begin{align} \text{pdo} &= \frac{f}{f + 1} \end{align}

We note that this definition is not derived from an explicit model. The adjusted fraction new is then calculated as:

corrected fn=f*(number of reads from new RNA)f*(number of reads from new RNA)+(number of reads from old RNA) \begin{align} \text{corrected fn} = \frac{f*(\text{number of reads from new RNA})}{f*(\text{number of reads from new RNA}) + (\text{number of reads from old RNA})} \end{align}

NOTE: previous versions of this vignette included some inaccuracies about the Erhard lab’s method. These have been corrected and we apologize for the mistakes. While the explanation of their method here is not identical to that provided in the methods section of their paper, our explanation follows from grandR’s source code. A bit of algebra shows that this relationship between the inferred pdo\text{pdo} and the corrected fraction new is identical to that derived from the model above:

θi=f*(number of reads from new RNA)f*(number of reads from new RNA)+(number of reads from old RNA)=f*θido*nreadsif*θido*nreadsi+(1θido)*nreadsi=θido(1pdo)θido(1pdo)+(1θido)=θido(1pdo)+θido*pdo \begin{align} \theta_{\text{i}} &= \frac{f*(\text{number of reads from new RNA})}{f*(\text{number of reads from new RNA}) + (\text{number of reads from old RNA})} \\ &= \frac{f*\theta_{\text{i}}^{\text{do}}*\text{nreads}_{\text{i}}}{f*\theta_{\text{i}}^{\text{do}}*\text{nreads}_{\text{i}} + (1 - \theta_{\text{i}}^{\text{do}})*\text{nreads}_{\text{i}}} \\ &= \frac{\frac{\theta_{\text{i}}^{\text{do}}}{(1 - \text{pdo})}}{\frac{\theta_{\text{i}}^{\text{do}}}{(1 - \text{pdo})} + (1 - \theta_{\text{i}}^{\text{do}})} \\ &= \frac{\theta_{\text{i}}^{\text{do}}}{(1 - \text{pdo}) + \theta_{\text{i}}^{\text{do}}*\text{pdo}} \end{align}

Thus, grandR is implicitly making assumptions similar to those laid out in the model above that is used by bakR.

Notable differences between bakR and grandR’s dropout correction approaches are:

  1. bakR defines an explicit model of dropout and derives a strategy to estimate the dropout rate from data. grandR defines an ad hoc relationship between a fraction new vs. dropout correlation coefficient and the dropout rate.
  2. When correcting for read counts, grandR seems to use a different correction strategy than is derived from the model above. New read counts are multiplied by the inferred factor ff discussed earlier. bakR on the other hand redistributes read counts, thus preserving the total library size.
  3. bakR fits an explicit parametric model derived from assumptions made either explicitly or implicitly by both grandR and bakR. This allows users to assess the quality of the model fit and thus the likelihood that these assumptions are valid on any given dataset.

Appendix

A1: Algebraic aside

One potentially non-obvious step in the derivations above is when determining how to correct read counts. In that section, I had the following set of relationships:

E[number of reads without dropout]E[number of reads with dropout]=Dropout=ni*θi*(1pdo)+ni*(1θi)ni*j=1NFnjj=1NFnj*θj*(1pdo)+nj*(1θj)=θi*(1pdo)+(1θi)1*NN*θG*(1pdo)+N*(1θG)=... \begin{align} \frac{\text{E[number of reads without dropout]}}{\text{E[number of reads with dropout]}} &= \text{Dropout}\\ &= \frac{\text{n}_{\text{i}}*\theta_{\text{i}}*(1 - \text{pdo}) + \text{n}_{\text{i}}*(1 - \theta_{\text{i}}) }{\text{n}_{\text{i}}}*\frac{\sum_{\text{j}=1}^{\text{NF}}\text{n}_{\text{j}}}{ \sum_{\text{j}=1}^{\text{NF}}\text{n}_{\text{j}}*\theta_{\text{j}}*(1 - \text{pdo}) + \text{n}_{\text{j}}*(1 - \theta_{\text{j}}) } \\ &= \frac{\theta_{\text{i}}*(1 - \text{pdo}) + (1 - \theta_{\text{i}}) }{1}*\frac{\text{N}}{\text{N}*\theta_{\text{G}}*(1-\text{pdo}) + \text{N}*(1 - \theta_{\text{G}})} \\ &=\text{...} \end{align}

where:

N=j=1NFnjθG=j=1NFnj*θij=1NFnj \begin{align} \text{N} &= \sum_{\text{j=1}}^{\text{NF}}{\text{n}_{\text{j}}} \\ \theta_{\text{G}} &= \frac{\sum_{\text{j=1}}^{\text{NF}}\text{n}_{\text{j}}*\theta_{\text{i}}}{\sum_{\text{j=1}}^{\text{NF}}\text{n}_{\text{j}}} \end{align}

The algebraic trick to get from line 2 to line 3 is to multiply by 1 (or rather N\text{N}/N\text{N}):

j=1NFni*θj=j=1NFnj*j=1NFni*θjj=1NFnj=N*θG \begin{align} \sum_{\text{j=1}}^{\text{NF}}\text{n}_{\text{i}}*\theta_{\text{j}} &= \sum_{\text{j=1}}^{\text{NF}}{\text{n}_{\text{j}}}*\frac{\sum_{\text{j=1}}^{\text{NF}}\text{n}_{\text{i}}*\theta_{\text{j}}}{\sum_{\text{j=1}}^{\text{NF}}{\text{n}_{\text{j}}}} \\ &= \text{N}*\theta_{\text{G}} \end{align}

A2: U-content dependence

Given hypotheses about how dropout arises, you may expect the extent of dropout to be correlated with the U-content of the RNA feature. In fact, this does seem to be the case in real datasets. bakR currently does not attempt to account for this correlation for a few reasons:

  1. U-content is not typically correlated with estimated fraction new. Thus, the U-content dropout biases are often evenly represented throughout the fraction new vs. dropout trend. This means that their influence is to add scatter to the data while not perturbing the mean of the trend.
  2. A rigorous empirical relationship between U-content and dropout is difficult to derive from first principles given existing data. An ad hoc correction factor can be added, but so far we have found it to have minimal impact on dropout rate estimation.