joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
582 stars 187 forks source link

Error in access(object, "sam_data", errorIfNULL) : sam_data slot is empty. #1620

Open B-1991-ing opened 2 years ago

B-1991-ing commented 2 years ago

Dear phyloseq support team,

I got the error when using the phyloseq software. Could you help me have a look?

Error: Error in access(object, "sam_data", errorIfNULL) : sam_data slot is empty.

My code: metadata = read.delim("metadata.tsv",row.names = 1) dat = read.delim("matrix_ggclusternet.tsv",row.names = 1) ps = phyloseq(sample_data(as.matrix(metadata)), otu_table(as.matrix(dat),taxa_are_rows = TRUE) )

metadata and matrix_ggclusternet file: matrix_ggclusternet.txt metadata.txt

Best,

Bing

ycl6 commented 2 years ago

Hi @B-1991-ing I tried downloading both files, but they are not text files.

B-1991-ing commented 2 years ago

Thank you very much for your reply, I-Hsuan Lin. I can't upload the tsv, so I changed them into the text files.

I can send to you in email using my email - bisong@env.dtu.dk.

Best,

Bing

B-1991-ing commented 2 years ago

Could you give me your email address?

B-1991-ing commented 2 years ago

I am using the rstudio1.3.1073 and R.4.0.0, phyloseq 1.34.0, and all other added packages as shown below.

library(tidyfst) library(phyloseq) #packageVersion("phyloseq") library(igraph) library(network) library(sna) library(ggrepel) library(psych) library(reshape2) library(ggplot2) library(ggpubr) library(RColorBrewer) library(data.table) library(ggClusterNet) library(tidyverse) library(Biostrings) library(ggnewscale)

ycl6 commented 2 years ago

Hi @B-1991-ing

Unlike otu_table and tax_table, sample_data requires an object of data.frame class when it is used to create a phyloseq object. Also, your dat has samples in rows and taxa in columns, therefore we need to change taxa_are_rows to FALSE.

So, the code should be like this:

library(phyloseq)

metadata = read.delim("metadata.tsv", row.names = 1)
dat = read.delim("matrix_ggclusternet.tsv", row.names = 1)
ps = phyloseq(sample_data(metadata), 
              otu_table(as.matrix(dat), taxa_are_rows = FALSE))
> ps
phyloseq-class experiment-level object
otu_table()   OTU Table:         [ 1735 taxa and 117 samples ]
sample_data() Sample Data:       [ 117 samples by 1 sample variables ]
B-1991-ing commented 2 years ago

Hi I-Hsuan,

Thank you very much for your reply.

Have a nice evening.

Best,

Bing

B-1991-ing commented 2 years ago

But, one more question,

For my metadata and dat, I have 136 rows. Why it showed 117 samples?

ycl6 commented 2 years ago

Hi @B-1991-ing Seems like some sample names do not match in dat and metadata. One is using "BGO" and the other is "BG".

> table(rownames(dat) %in% sample_names(ps))

FALSE  TRUE 
   19   117 

> rownames(dat)[!rownames(dat) %in% sample_names(ps)]
 [1] "BGO21C1"  "BGO21C2"  "BGO21C3"  "BGO21C4"  "BGO21C5"  "BGO21C6"  "BGO21C7"  "BGO21C8" 
 [9] "BGO21C9"  "BGO21C10" "BGO21C11" "BGO21C12" "BGO21C13" "BGO21C14" "BGO21C15" "BGO21C16"
[17] "BGO21C17" "BGO21C18" "BGO21C19"

> rownames(metadata)[metadata$group == "BG"]
 [1] "BG21C1"  "BG21C2"  "BG21C3"  "BG21C4"  "BG21C5"  "BG21C6"  "BG21C7"  "BG21C8"  "BG21C9" 
[10] "BG21C10" "BG21C11" "BG21C12" "BG21C13" "BG21C14" "BG21C15" "BG21C16" "BG21C17" "BG21C18"
[19] "BG21C19"
B-1991-ing commented 2 years ago

Thank you very much for your reply, I-Hsuan,

I didn't checked the sample ids very well.

Best,

Bing