0
votes

I am relatively new to phyloseq and I struggle to obtain a relative abundance otu-table acceptable for input to siamcat R code for meta-analysis.

# this works: from qza to phyloseq object
ps<-qza_to_phyloseq(
  features="all-table.qza",
  tree="rooted-tree.qza",
  taxonomy = "all-taxonomy.qza",
  metadata = "metafinal.tsv"
)

# import metadata
metadata <- read_tsv("metafinal.tsv")

# 30 overlap of the metadata-sample_id with ps, 115 only in metadata
gplots::venn(list(metadata=metadata$sample_id, features=sample_names(ps))

# works: from phyloseq object to relative abundance otu table
table(tax_table(ps)[, "Phylum"])
ps_rel_abund <- transform_sample_counts(ps, function(x){x / sum(x)})
ps_phylum_rel <- tax_glom(ps_rel_abund, "Phylum")
taxa_names(ps_phylum_rel) <- tax_table(ps_phylum_rel)[, "Phylum"]
rel_table <- as(otu_table(ps_phylum_rel), "matrix")

# column names and sample_id are 100% the same
colnames(rel_table)
metadata$sample_id

# 100% overlap:
gplots::venn(list(metadata=metadata$sample_id, featuretable=colnames(rel_table)))

# check that metadata and feature agree
stopifnot(all(colnames(rel_table) == metadata$sample_id))

and here I get an error message: all(colnames(rel_table) == metadata$sample_id) is not TRUE and the following siamcat code is not working at all.

my metadata[1:5, 1:5]: sample_id absolute_filepath study experiment_acce… study_title

1 SRR8547628 $PWD/Chen_2020_da… Chen… SRX5349649 Dissection of c… 2 SRR8547629 $PWD/Chen_2020_da… Chen… SRX5349648 Dissection of c… 3 SRR8547630 $PWD/Chen_2020_da… Chen… SRX5349647 Dissection of c… 4 SRR8547631 $PWD/Chen_2020_da… Chen… SRX5349646 Dissection of c… 5 SRR8547632 $PWD/Chen_2020_da… Chen… SRX5349645 Dissection of c…

my rel-table[1:5, 1:5]: SRR5092146 SRR5092147 SRR5092148 SRR5092149 Phragmoplastophyta 0 0.0000000 0.00000000 0.000000000 Vertebrata 0 0.0000000 0.00000000 0.000000000 Apicomplexa 0 0.0000000 0.00000000 0.000000000 Ascomycota 0 0.0000000 0.00000000 0.000000000 Campilobacterota 0 0.2465222 0.01166882 0.004337051 SRR5092150 Phragmoplastophyta 0.00000000 Vertebrata 0.00000000 Apicomplexa 0.00000000 Ascomycota 0.00000000 Campilobacterota 0.02106281

nrow(metadata)= 154 ncol(rel_table)= 154

Please, why is it not working? I tried for weeks now and I can't make the code run properly ...

Thank you for your time and help.

1

1 Answers

0
votes

If I understand your question correctly, you are wondering, why you have perfect overlap between sample IDs in your metadata and in your feature table, but why

stopifnot(all(colnames(rel_table) == metadata$sample_id))

returns FALSE.

I think it is because your samples seem to be in a different order. The first five samples in your metadata are:

SRR8547628
SRR8547629
SRR8547630
SRR8547631
SRR8547632

and the first five samples in your feature table are:

SRR5092146
SRR5092147
SRR5092148
SRR5092149
SRR5092150

Try

stopifnot(all(colnames(rel_table) %in% metadata$sample_id))