dada2 icon indicating copy to clipboard operation
dada2 copied to clipboard

MergePairs Error

Open Hellomissgabby opened this issue 4 months ago • 1 comments

Hi! I'm having trouble with the mergepair function. This the code that I have so far in R,

path <-("C:/Users/andring/Documents/spring_data_research") list.files(path) fnFs <- sort(list.files(path, pattern = "_R1_001.DC01_SH.fastq", full.names = TRUE)) fnRs <- sort(list.files(path, pattern = "R2_001.DC01_SH.fastq", full.names = TRUE)) sample.names <- sapply(strsplit(basename(fnFs), ""), [,1) plotQualityProfile(fnFs[1:2]) plotQualityProfile(fnRs[1:2]) filtFs <- file.path(path, "filtered", paste0(sample.names, "_F_filt.fastq.qz")) filtRs <- file.path(path, "filtered", paste0 (sample.names, "_R_filt.fastq.gz")) out <- filterAndTrim(fnFs, filtFs, fnRs, filtRs, truncLen = c(240,160), maxN = 0, maxEE = c(2,2), truncQ = 2, rm.phix = TRUE, compress= TRUE, multithread = FALSE) head(out)

errF <- learnErrors(filtFs, multithread=TRUE) errR <- learnErrors(filtRs, multithread=TRUE) plotErrors(errF, nominalQ=TRUE) derepFs <- derepFastq(filtFs, verbose=TRUE) derepRs <- derepFastq(filtRs, verbose=TRUE) dadaFs <- dada(derepFs, err=errF, multithread=TRUE) dadaRs <- dada(derepRs, err=errR, multithread=TRUE) dadaFs[[1]] mergers <- mergePairs(dadaFs, filtFs, dadaRs, filtRs, verbose = TRUE)

After running the mergers line of code I receive the error of: Error in FUN(X[[i]], ...) : Non-corresponding derep-class and dada-class objects.

I saw someone else had a similar issue so I tried running: map.lens <- function(inputs) { lens <- sapply(inputs, function(x) length(x$map)) unname(lens) } map.lens(derepFs) map.lens(derepRs) map.lens(dadaFs) map.lens(dadaRs)

And when I run this code I receive this error, Error in x$map : $ operator is invalid for atomic vectors Called from: FUN(X[[i]], ...) Browse[1]> map.lens(derepRs) Error during wrapup: $ operator is invalid for atomic vectors Error: no more error handlers available (recursive errors?); invoking 'abort' restart Browse[1]> map.lens(dadaFs) Error during wrapup: $ operator is invalid for atomic vectors Error: no more error handlers available (recursive errors?); invoking 'abort' restart Browse[1]> map.lens(dadaRs) Error during wrapup: $ operator is invalid for atomic vectors Error: no more error handlers available (recursive errors?); invoking 'abort' restart

Any help would be greatly appreciated!

Hellomissgabby avatar Mar 04 '24 14:03 Hellomissgabby

First, I'd just leave out the explicit derepFastq calls, they aren't needed. i.e.

errF <- learnErrors(filtFs, multithread=TRUE)
errR <- learnErrors(filtRs, multithread=TRUE)
plotErrors(errF, nominalQ=TRUE)
dadaFs <- dada(filtFs, err=errF, multithread=TRUE)
dadaRs <- dada(filtRs, err=errR, multithread=TRUE)
mergers <- mergePairs(dadaFs, filtFs, dadaRs, filtRs, verbose = TRUE)

If that is still throwing the non-correponding error, you might want to check that all of of the filtered files exist.

table(file.exists(filtFs))

If no reads passed the filterAndTrim step then no corresponding filtered file will be written.

benjjneb avatar Mar 04 '24 21:03 benjjneb