'DADA2 - Calculating percent of reads that merged

I have been following the tutorial for DADA2 in R for a 16S data-set, and everything runs smoothly; however, I do have a question on how to calculate the total percent of merged reads. After the step to track reads through the pipeline with the following code:

merger <- mergePairs(dadaF1, derepF1, dadaR1, derepR1, verbose=TRUE) 

and then tracking the reads through each step:

getN <- function(x) sum(getUniques(x))
track <- cbind(out_2, sapply(dadaFs, getN), sapply(dadaRs, getN), sapply(mergers, getN), rowSums(seqtab.nochim))

I get a table that looks like this, here I am viewing the resuling track data-frame made w/ the above code:

enter image description here

Where input is the total sequences I put in (after demuxing) and filtered is the total sequences after they were filtered based on a parameter of my choosing. The denoisedF and denoisedR are sequences that have been denoised (one for forward reads and another for reverse reads), the total number of merged reads (from the mergePairs command above) and the nonchim are the total sequences that are not chimeras.

My question is this .... to calculate the percent of merged reads - is this a simple division? Say take the first row - (417/908) * 100 = 46% or should I somehow incorporate the denoisedF and denoisedR columns in this calculation?

Thank you very much in advance!



Solution 1:[1]

The track object is a matrix (see class(track)), thus you can run operations accordingly. In your case:

track[, "merged"]/track[, "input"] * 100

Or, you could convert the track object into a data frame for a "table" output.

However, I usually export the track output as an excel file and then do my modification there. It is easier to be shared and commented on with non-R users. I find the write_xlsx function from the writexl package particularly convenient. Cheers

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zina