Dada2: assigntaxonomy and IdTaxa

Created on 12 May 2020  路  3Comments  路  Source: benjjneb/dada2

Hi,
I am currently using the code from the tutorial and I have tried both assigning methods:
1)IdTaxa
2)assigntaxonomy

I have created from both methods the corresponding ASV files (count, tax, and sequence) following the tutorial. And also created a phyloseq object for each method. I have compared the phyloseq objects, and I don't spot any difference in dimensions.

Everything works right until I want to apply to following code:

ASV_physeq_prevalencedf = apply(X = otu_table(ASV_physeq),
                 MARGIN = 1,
                 FUN = function(x){sum(x > 0)})

Add taxonomy and total read counts to this data.frame

ASV_physeq_prevalencedf = data.frame(Prevalence = ASV_physeq_prevalencedf,
                      TotalAbundance = taxa_sums(ASV_physeq),
                      tax_table(ASV_physeq))

Wwhen I used the IdTaxa-created object, it fails showing the following error:

OUTPUT:
Error in dimnames(x) <- dn : 

  length of 'dimnames' [1] not equal to array extent

But when I used the assigtaxanomy-created it worked perfectly. Any idea why? Is there any additional information I can provide to understand the problem?

Thanks

Most helpful comment

Hi again,

I would to also know if anybody else encounter this problem while working with the DECIPHER taxonomy code. In case anybody actually has this problem, I would like to post the solution to this issue. The credit for this solution is to @AstrobioMike :thumbsup:

I will copy and paste his solution:

The attached R script has the whole process i went through, but the answer is just that the entire species column was all NAs. So the problem command:

prevelancedf = data.frame(Prevalence = prevelancedf,
                      TotalAbundance = taxa_sums(ASV_physeq),
                      tax_table(ASV_physeq))

Was trying converting the string columns to factors (side note: data.frame() has done this by default for a long time, and it has been a fight for a long time. Crazily enough, the functionality was just changed a couple weeks ago with the newest R release).

But anyway, it was converting the species column to a factor, but since all values were NA, it was a factor with 0 levels, and that was causing the problem. Adding the stringsAsFactors=FALSE argument to the data.frame() function like so solves the problem :)

prevelancedf = data.frame(Prevalence = prevelancedf,
                      TotalAbundance = taxa_sums(ASV_physeq),
                      tax_table(ASV_physeq), stringsAsFactors=FALSE)

If anybody would like to check the whole process and break-down, I am attaching a file with it.

finding-prevalence-problem.txt

Good luck everybody.

All 3 comments

Hi again,

I would to also know if anybody else encounter this problem while working with the DECIPHER taxonomy code. In case anybody actually has this problem, I would like to post the solution to this issue. The credit for this solution is to @AstrobioMike :thumbsup:

I will copy and paste his solution:

The attached R script has the whole process i went through, but the answer is just that the entire species column was all NAs. So the problem command:

prevelancedf = data.frame(Prevalence = prevelancedf,
                      TotalAbundance = taxa_sums(ASV_physeq),
                      tax_table(ASV_physeq))

Was trying converting the string columns to factors (side note: data.frame() has done this by default for a long time, and it has been a fight for a long time. Crazily enough, the functionality was just changed a couple weeks ago with the newest R release).

But anyway, it was converting the species column to a factor, but since all values were NA, it was a factor with 0 levels, and that was causing the problem. Adding the stringsAsFactors=FALSE argument to the data.frame() function like so solves the problem :)

prevelancedf = data.frame(Prevalence = prevelancedf,
                      TotalAbundance = taxa_sums(ASV_physeq),
                      tax_table(ASV_physeq), stringsAsFactors=FALSE)

If anybody would like to check the whole process and break-down, I am attaching a file with it.

finding-prevalence-problem.txt

Good luck everybody.

Thanks @AstroBioMike !

Was trying converting the string columns to factors (side note: data.frame() has done this by default for a long time, and it has been a fight for a long time.

The single worst "feature" of R in my opinion. That implicit conversion of strings to factors, and then to integers when used as an index (instead of character "names" as you'd expect) is pernicious and silent, a terrible combination.

Crazily enough, the functionality was just changed a couple weeks ago with the newest R release).

Hallelujah!

BTW, could a tibble do the trick? I prefer tibbles to data.frames (besides other things) because they use stringsAsFactors=FALSE trick by default.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnchase picture johnchase  路  14Comments

rebbec picture rebbec  路  9Comments

FelixErnst picture FelixErnst  路  10Comments

dcat4 picture dcat4  路  4Comments

m-ocejo picture m-ocejo  路  4Comments