microbiome / microbiome

microbiome R package
Other
286 stars 54 forks source link

plot_core() error #179

Closed marwa38 closed 2 years ago

marwa38 commented 2 years ago

Hello .. Could you please let me know why I am getting this error running plot_core()? Error: id variables not found in data: ID I am using microbiome_1.14.0


# read/import non rarefied data
ps.prev <- readRDS("phyobjects/ps.prev.rds") 

# phyloseq-class experiment-level object
# otu_table()   OTU Table:         [ 1544 taxa and 36 samples ]
# sample_data() Sample Data:       [ 36 samples by 12 sample variables ]
# tax_table()   Taxonomy Table:    [ 1544 taxa by 7 taxonomic ranks ]
# phy_tree()    Phylogenetic Tree: [ 1544 tips and 1542 internal nodes ]
# refseq()      DNAStringSet:      [ 1544 reference sequences ]

# use print option to see the data saved as phyloseq object.
# Subset the data to keep only intestine samples [if needed] (to get rid of positive and negatives)
# my samples already have no pos and neg

# convert to relative abundance  
ps.ra <- microbiome::transform(ps.prev, "compositional")
# phyloseq-class experiment-level object
# otu_table()   OTU Table:         [ 1544 taxa and 36 samples ]
# sample_data() Sample Data:       [ 36 samples by 12 sample variables ]
# tax_table()   Taxonomy Table:    [ 1544 taxa by 7 taxonomic ranks ]
# phy_tree()    Phylogenetic Tree: [ 1544 tips and 1542 internal nodes ]
# refseq()      DNAStringSet:      [ 1544 reference sequences ]

ps.ra1 <- prune_taxa(taxa_sums(ps.ra) > 0, ps.ra)
# phyloseq-class experiment-level object
# otu_table()   OTU Table:         [ 776 taxa and 36 samples ]
# sample_data() Sample Data:       [ 36 samples by 12 sample variables ]
# tax_table()   Taxonomy Table:    [ 776 taxa by 7 taxonomic ranks ]
# phy_tree()    Phylogenetic Tree: [ 776 tips and 774 internal nodes ]
# refseq()      DNAStringSet:      [ 776 reference sequences ]

# Core with compositionals:
prevalences <- seq(.05, 1, .05)
detections <- 10^seq(log10(1e-3), log10(.2), length = 10)

# Also define gray color palette
gray <- gray(seq(0,1,length=5))
p.core <- plot_core(ps.ra1, 
                    plot.type = "heatmap", 
                    colours = gray,
                    prevalences = prevalences, 
                    detections = detections, 
                    min.prevalence = .5) +
  xlab("Detection Threshold (Relative Abundance (%))")
# Error: id variables not found in data: ID
print(p.core) 
# Error in print(p.core) : object 'p.core' not found

Thanks very much Marwa

antagomir commented 2 years ago

Not sure. Can you share the ps.ra1 object?

marwa38 commented 2 years ago

Thanks for your reply Leo @antagomir. Kindly find attached (zipped) ps.ra1.zip

I read it via after unzipping ps.ra1 <- readRDS("ps.ra1.rds")

antagomir commented 2 years ago

There was a bug that is now fixed. Can you reinstall with devtools::install_github("microbiome/microbiome"), then try again?

marwa38 commented 2 years ago

working fine, many thnaks not sure how to label this issue as a bug in case I need to?

antagomir commented 2 years ago

No need to label. Thansk!