cmmr / rbiom

Interact with Biological Observation Matrix files.
https://cmmr.github.io/rbiom/
Other
12 stars 0 forks source link

cannot import phyloseq object #14

Closed jayelldubya closed 9 months ago

jayelldubya commented 9 months ago

Hi there,

I'm trying to import my data from a phyloseq object, but am running into problems using the 'as_rbiom', in that it does not appear to work with a phyloseq object. I receive the error:

mybiom = as_rbiom(phyloseqObject)
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'object' in selecting a method for function 'otu_table': object 'phy' not found

Everything is installed properly as I was able to replicate your vignette, and further, I am able to extract the OTU table as a matrix from the same phyloseq object that does not produce any errors or warnings. E.g.

otu = as.matrix(otu_table(phyloseqObject))
mybiom2 = as_rbiom(otu)

Apologies if I somehow missed this, but I looked through your tutorial on github as well as the R documentation and was not able to find information that could help me troubleshoot this. Thanks in advance

dansmith01 commented 9 months ago

Thanks for pointing that out! I see where the bug is and will push a fix shortly. Until then, this function will do the trick:

phy2biom <- function (phy) {

  rbiom$new(
    counts    = phy %>% phyloseq::otu_table() %>% slam::as.simple_triplet_matrix(), 
    metadata  = phy %>% phyloseq::sample_data(errorIfNULL = FALSE) %>% data.frame(), 
    taxonomy  = phy %>% phyloseq::tax_table(errorIfNULL = FALSE) %>% data.frame(), 
    sequences = phy %>% phyloseq::refseq(errorIfNULL = FALSE) %>% as.vector(), 
    tree      = phy %>% phyloseq::phy_tree(errorIfNULL = FALSE), 
    id        = "Imported PhyloSeq Data" )
}
jayelldubya commented 9 months ago

Thank you so much for your prompt reply! I tried using the above function but am still running into issues. I ran the following:

phy2biom <- function (phy) {

  rbiom$new(
    counts    = phy %>% phyloseq::otu_table() %>% slam::as.simple_triplet_matrix(), 
    metadata  = phy %>% phyloseq::sample_data(errorIfNULL = FALSE) %>% data.frame(), 
    taxonomy  = phy %>% phyloseq::tax_table(errorIfNULL = FALSE) %>% data.frame(), 
    sequences = phy %>% phyloseq::refseq(errorIfNULL = FALSE) %>% as.vector(), 
    tree      = phy %>% phyloseq::phy_tree(errorIfNULL = FALSE), 
    id        = "Imported PhyloSeq Data" )
}

The above resulted in no warnings, but when I tried the below I received an error "Error in phy2biom(CombPhyNumFiltered) : object 'rbiom' not found"

test = phy2biom(phyloseqObject)

Did I misunderstand how to use the function you provided? I tried a few other iterations as well but did not have any success.

dansmith01 commented 9 months ago

Oh, oops.. forgot that was a private object. I just pushed the fix to this repo, along with lots of other improvements. as_rbiom() should work as expected now in version 2.0.0.9114.

jayelldubya commented 9 months ago

It's working now! A huge thanks again for your help :)