dcat4 / ensembleTax

source R package
Other
6 stars 3 forks source link

bayestax2df: Error when setting custom ranks #3

Closed naurasd closed 1 year ago

naurasd commented 1 year ago

Hi,

according to the documentation for the bayestax2df function, I can set db = NULL and define customs ranks as a vector for ranks. However, when I do this for a PR2 v5.0.0 taxonomy table (9 taxonomy ranks), I get an error.

This is my code:

bayes.pr2.pretty <- bayestax2df(bayes.sample, db = NULL, ranks = c("Domain","Supergroup","Division","Subdivision","Clade_X","Clade_XX","Clade_XXX","Genus","Species"), boot = 70, rubric = rubric, return.conf = FALSE)

This is the error:

Error in if (db == "pr2") { : argument is of length zero

My workaround was to download the code of the bayestax2df function and change the ranks within the relevant part.

if (db == "pr2") { ranks <- c("Domain","Supergroup","Division","Subdivision","Clade_X","Clade_XX","Clade_XXX","Genus","Species") colnames(taxdf) <- ranks colnames(confdf) <- ranks

I know that your package is not yet compatible with PR2 v5.0.0, but this error has nothing to do with this incompatibility at this step, I think. Must be some other bug not recognizing custom ranks.

dcat4 commented 1 year ago

Thanks for pointing this out. I suspect updates to R were driving this.

I've implemented a fix. If you re-download ensembleTax from Github and do this: library(ensembleTax) data(bayes.sample) bayes.pr2.pretty <- bayestax2df(bayes.sample, db = NULL, ranks = c("Domain","Supergroup","Division","Subdivision","Clade_X","Clade_XX","Clade_XXX","Genus","Species"), boot = 70, rubric = rubric, return.conf = FALSE)

You should receive this error (which is expected given the structure of the ensembleTax sample data, which has only 8 ranks): Error in names(x) <- value : 'names' attribute [9] must be the same length as the vector [8]

If you remove one of the elements of your "ranks" vector to match the structure of the sample data like this: bayestax2df(bayes.sample, db = NULL, ranks = c("Domain","Supergroup","Division","Subdivision","Clade_X","Clade_XX","Genus","Species"), boot = 70, rubric = NULL, return.conf = FALSE) it should run successfully.

Please let me know if any problems persist (besides me being delinquent on updating to pr2 5.0!)

naurasd commented 1 year ago

Thanks for the quick reply, I appreciate it. If I don't use your example sample data, but my own sample data with 9 taxonomic ranks present, I would not need to drop a rank and can provide 9 ranks with the new fix?

dcat4 commented 1 year ago

That's correct. Closing this for now but please reopen if problems persist.