KasperSkytte / ampvis2

Tools for visualising microbial community amplicon data
https://kasperskytte.github.io/ampvis2/
GNU General Public License v3.0
66 stars 23 forks source link

object error going into amp_ordinate #151

Closed emihoe closed 1 year ago

emihoe commented 1 year ago

Hello,

I had previously used ampvis2 to generate various ordination plots successfully, however, since the previous update the same code no longer works (I had gone back to increase the font size in the plots and changed nothing else).

I use version 2.7.34 AmpVis2 and Vegan v2.6-4.

The code below is what I successfully used previously to incorporate a phyloseq object into AmpVis2. `obj <- ps.species otutable <- data.frame(OTU = rownames(phyloseq::otu_table(obj)@.Data), phyloseq::otu_table(obj)@.Data, phyloseq::tax_table(obj)@.Data, check.names = FALSE )

Extract metadata from the phyloseq object:

metadata <- data.frame(phyloseq::sample_data(obj), check.names = FALSE ) metadata$SampleID <- rownames(metadata) metadata <- metadata %>% dplyr::select("SampleID", everything())

Load the data with amp_load:

my_ampvis2_object <- amp_load(otutable, metadata)`

Then when I use this object to generate my PCoA plot:

amp_ordinate(my_ampvis2_object, type = "pcoa", distmeasure = "bray", transform = "none", sample_color_by = "Leak", sample_shape_by = "Leak", sample_colorframe = TRUE, sample_point_size = 5,) + theme(legend.position = "right", legend.title = element_text(size = 20), legend.key.size = unit(1.5, "cm"), legend.key.width = unit(1.5,"cm"), text = element_text(size=50), plot.background = element_rect(fill = "white", color = NA))

I get the following error: Error in vegan::vegdist(data$abund, method = distmeasure) : missing values are not allowed with argument 'na.rm = FALSE'

When I use an alternative dataset i can confirm AmpVis2 package is working normally.

Can someone please suggest how I can correct my object going into AmpVis2 or as it passes to vegan (change na.rm from FALSE)? From what I can gather there is a missing value somewhere (not sure where it came from when it was working a few months ago and I've not touched it since then). I can't find a solution online anywhere so this is my last resort.

Thank you

KasperSkytte commented 1 year ago

Hi there

Could be changes to vegan or another package since last time, not necessarily ampvis2. Which version of ampvis2 and vegan were you using when you didn't get the error? Also if the code works fine with another dataset, then it's something specific for your data and I would need that to be able to debug

emihoe commented 1 year ago

Thanks so much for your quick reply, the believe the previous version of vegan I used when this worked was 2.6-2.

Sorry I'm not sure which element is best to share with you exactly so I have zipped the environment (RData file) that contains the phyloseq object (ps.species) made from metaphlan data import and the ampvis2 object (my_ampvis2_object) I made from the phyloseq object.

MGS_ampvis2_help.zip

Thank you very much

KasperSkytte commented 1 year ago

The issue was that you OTU's are species names. So resulted in a mismatch because prefixes like s__ are removed in the OTU column, but not in the rownames/identifiers, so NAs everywhere. Upgrade to the latest ampvis2 version or rename the OTUs and it should work.

emihoe commented 1 year ago

Thank you so much this solved my problem and I got my graphs back. I really appreciate your help, thank you again!!