YuLab-SMU / MicrobiotaProcess

:microbe: A comprehensive R package for deep mining microbiome
https://www.sciencedirect.com/science/article/pii/S2666675823000164
182 stars 37 forks source link

Error in seq_len(ncol(taxdf)) : argument must be coercible to non-negative integer #13

Closed tiramisutes closed 4 years ago

tiramisutes commented 4 years ago

Hi, I want to get an abundance of specific levels of the class using get_taxadf(obj=ps_qiime2, taxlevel=2). But I get this error:

Error in seq_len(ncol(taxdf)) : argument must be coercible to non-negative integer

And there is the same error when using diff_analysis function:

diff_analysis(obj=ps_qiime2, class="type",
                         mlfun="lda",
                         filtermod="fdr",
                         firstcomfun = "kruskal.test",
                         firstalpha=0.05,
                         strictmod=TRUE,
                         secondcomfun = "wilcox.test",
                         subclmin=3,
                         subclwilc=TRUE,
                         secondalpha=0.01,
                         lda=3)

The object ps_qiime2 is creat through import_qiime2. Thanks!

xiangpin commented 4 years ago

Sorry, your information is too simple, I can not get the details. Would you please to send the ps_qiime2 object to me by email. You can use saveRDS(ps_qiime2, file="ps_qiime2.obj") to save it. Or you can use the following codes to show the taxanomy table to me.

library(phyloseq)
head(tax_table(ps_qiime2))
tiramisutes commented 4 years ago

Hi, The follows is the output of tax_table.

> library(phyloseq)
> head(tax_table(ps_qiime2))
Taxonomy Table:     [6 taxa by 8 taxonomic ranks]:
                                 Kingdom    Phylum            Class                 Order                Family                Genus Species
84d63a19a6f9811c726003c41c25a792 "Bacteria" "Verrucomicrobia" "Verrucomicrobiae"    "Verrucomicrobiales" "Verrucomicrobiaceae" NA    NA     
9256dde7d3b6e40233db5e9da7ad3aee "Bacteria" "Verrucomicrobia" "Verrucomicrobiae"    "Verrucomicrobiales" "Verrucomicrobiaceae" NA    NA     
b87024d901b27a4b32736eb4770c1939 "Bacteria" "Verrucomicrobia" "Verrucomicrobiae"    "Verrucomicrobiales" "Verrucomicrobiaceae" NA    NA     
e23a44a941131b0be9cc4f70dc8c60b3 "Bacteria" "Verrucomicrobia" "Verrucomicrobiae"    "Verrucomicrobiales" "Verrucomicrobiaceae" NA    NA     
44c9f59231dd703269388032da1d5a98 "Bacteria" "Proteobacteria"  "Gammaproteobacteria" "Enterobacteriales"  "Enterobacteriaceae"  NA    NA     
0dc52a30ea6b84b5bade843b94ad975a "Bacteria" "Verrucomicrobia" "Verrucomicrobiae"    "Verrucomicrobiales" "Verrucomicrobiaceae" NA    NA     
                                 Rank1
84d63a19a6f9811c726003c41c25a792 NA   
9256dde7d3b6e40233db5e9da7ad3aee NA   
b87024d901b27a4b32736eb4770c1939 NA   
e23a44a941131b0be9cc4f70dc8c60b3 NA   
44c9f59231dd703269388032da1d5a98 NA   
0dc52a30ea6b84b5bade843b94ad975a NA  

And the object file (ps_qiime2.zip) save using saveRDS(ps_qiime2, file="ps_qiime2.obj").

xiangpin commented 4 years ago

It might be that some first rank level (Kingdom) is NA in the taxanomy table. I will fix it as soon as possible. And you can use the following codes to solve it.

library(MicrobiotaProcess)
library(phyloseq)
set.seed(1024)
ps_qiime2 <- readRDS("./ps_qiime2.obj")
ps_qiime2
taxtab <- data.frame(tax_table(ps_qiime2))
taxtab[is.na(taxtab[,1]),1] <- "Unknown"
ps_qiime2@tax_table <- tax_table(as.matrix(taxtab))
phytab <- get_taxadf(ps_qiime2, taxlevel=2)
phytab
# convet to data.frame
ptab <- data.frame(otu_table(phytab), check.names=FALSE)
tiramisutes commented 4 years ago

Yes, there is some feature id annotated as Unassigned. Maybe it changes as NA when import using import_qiime2. image

Now, It's working after follows your suggestion. Thanks.