lch14forever / microbiomeViz

Visualize microbiome data with black magic ggtree
68 stars 14 forks source link

Only works for phyloseq when the phyloseq object (e.g GlobalPattern) has taxa_are_row == TRUE #11

Open 2533245542 opened 6 years ago

2533245542 commented 6 years ago

I don't know why but phyloseq allows two kind of otu layout in a phyloseq object; one is taxa_are_row and the other one not. To access this information, one can use taxa_are_row(phyobj) to check.

What I found is microbiomeViz currently only supports the taxa_are_row == TRUE phyobj, but you can make adjustment if you have time. And here is one function I wrote to make that kind of adjustment.

edit_phyobj = function(phyobj){ # phyobj must be taxa_are_rows = TRUE for microbiomeviz to work
            if(!taxa_are_rows(phyobj)){
                otu = otu_table(phyobj)
                otu = t(otu)

                return(
                    phyloseq(
                        otu_table(otu,taxa_are_rows = TRUE),
                        tax_table(phyobj),
                        sample_data(phyobj)
                        )
                    )
            }
        }
lch14forever commented 6 years ago

Thanks for this. I will integrate this to the parser soon.

2533245542 commented 6 years ago

Actuall that last code does not work, I make some edits now

edit_phyobj = function(phyobj){ # phyobj must be taxa_are_rows = TRUE for microbiomeviz to work
            if(!taxa_are_rows(phyobj)){
                otu = otu_table(phyobj)
                otu = t(otu)
                return(
                  phyloseq(
                    otu_table(otu,taxa_are_rows = TRUE),
                    tax_table(phyobj),
                    sample_data(phyobj)
                  )
                )
            } else {
              return(phyobj)
            }
        }
lch14forever commented 6 years ago

Do you have some test data that I can try?