Open vmc5287 opened 3 years ago
@vmc5287 No problem running the code here, maybe you should check if your R and packages are up to date
I am using R version 4.0.3 and these packages:
other attached packages:
[1] tibble_3.1.0 dplyr_1.0.4 readxl_1.3.1 ggplot2_3.3.3 phyloseq_1.34.0
library("phyloseq")
library("ggplot2") # graphics
library("readxl") # necessary to import the data from Excel file
library("dplyr") # filter and reformat data frames
library("tibble") # Needed for converting column to row names
file <- "R_tutorials-master/data/CARBOM data.xlsx"
otu_mat <- read_excel(file, sheet = "OTU matrix")
tax_mat <- read_excel(file, sheet = "Taxonomy table")
samples_df <- read_excel(file, sheet = "Samples")
otu_mat <- otu_mat %>% tibble::column_to_rownames("otu")
tax_mat <- tax_mat %>% tibble::column_to_rownames("otu")
samples_df <- samples_df %>% tibble::column_to_rownames("sample")
otu_mat <- as.matrix(otu_mat)
tax_mat <- as.matrix(tax_mat)
OTU = otu_table(otu_mat, taxa_are_rows = TRUE)
TAX = tax_table(tax_mat)
samples = sample_data(samples_df)
carbom <- phyloseq(OTU, TAX, samples)
carbom
phyloseq-class experiment-level object
otu_table() OTU Table: [ 287 taxa and 55 samples ]
sample_data() Sample Data: [ 55 samples by 27 sample variables ]
tax_table() Taxonomy Table: [ 287 taxa by 7 taxonomic ranks ]
could it be the way my excel spreadsheet is formated?
Also how do I make sure my packages are up to date?
@vmc5287 It could be, you can download the example dataset from the URL you mentioned and compared to yours to check. I am using the said example file.
As to your 2nd question, after you load all necessary packages, run sessionInfo()
to check their version, then go to CRAN or Bioconductor depending on where they are hosted to check the latest version. If you are using an older version of R, I recommend updating to at least R 4.0.3 in order to use the latest packages.
otu_mat %>% tibble::column_to_rownames("otu") tax_mat <- tax_mat %>% tibble::column_to_rownames("otu") samples_df<- samples_df %>%tibble::column_to_rownames("sample") otu_mat <- as.matrix(otu_mat) tax_mat <- as.matrix(tax_mat) OTU = otu_table(otu_mat, taxa_are_rows = TRUE) I keep getting this after this code.... ..._Error in validObject(.Object) : invalid class “otutable” object: Non-numeric matrix provided as OTU table. Abundance is expected to be numeric..... cannot figure it out..... using this tutorial guide https://vaulot.github.io/tutorials/Phyloseq_tutorial.html#load-necessary-libraries