microbiome / mia

Microbiome analysis
https://microbiome.github.io/mia/
Artistic License 2.0
45 stars 25 forks source link

Error length.out in subsampleCounts() #560

Open imonteroo opened 1 month ago

imonteroo commented 1 month ago

I tried to rarefay a phyloseq object transformet to a SummarizedExperiment but obtained this Error.

ps.met.aar = subsampleCounts(makeTreeSEFromPhyloseq(ps.met.aa), min_size = mindeepth, name = "subsampled",replace = FALSE, seed = 123) Error en (function (x, length.out) : valor de 'length.out' no válido Además: Aviso: Subsampling/Rarefying may undermine downstream analyses and have unintended consequences. Therefore, make sure this normalization is appropriate for your data.

I obtained something similar with Something similar rarefy_even_depth() from phyloseq which use rarefaction_subsample() function inside.

Any idea

Thank you

antagomir commented 1 month ago

Could you provide code that does the transformations and rarification to generate this error? Most ideally a reproducible example with some demo data set from phyloseq package. This would be like 3-5 lines of code I expect(?) and it would help greatly with troubleshooting,

imonteroo commented 1 month ago

It is a phyloseq object created from humann3 pathabundance outputs. First I imported files using file3mecho package, then I transformed it to phyloseq and after that I merged both two phyloseq.

I created a shorter phyloseq that generate same error. I attached otu, taxa and metadata tables.

`

Expample of code used to create phyloseq object originally

Read humann3 output file

met.1 = humann2meco(feature_table = "pathabundance_relab_1.tsv",db = "MetaCyc", sample_table = "metadata_1.txt") otu = data.frame(met.1$otu_table) colnames(otu) = gsub("_Abundance", "", colnames(otu)) colnames(otu) = gsub("^X", "", colnames(otu)) met.1$otu_table = otu

met.2 = humann2meco(feature_table = "pathabundance_relab_2.tsv",db = "MetaCyc", sample_table = "metadata_2.txt") otu = data.frame(met.2$otu_table) colnames(otu) = gsub("_Abundance", "", colnames(otu)) colnames(otu) = gsub("^X", "", colnames(otu)) met.2$otu_table = otu

Transform to phyloseq

ps.met.1 = meco2phyloseq(met.1) ps.met.2 = meco2phyloseq(met.2)

Merge Phyloseq

ps.met.ra = merge_phyloseq(ps.met.1, ps.met.2)

This is the code to import test phyloseq parts

ot.short = read.delim2("ot.short.txt", row.names = 1, dec = ",") tt.short = read.delim2("tt.short.txt", row.names = 1, dec = ",") sd.short = read.delim2("sd.short.txt", row.names = 1, dec = ",")

Create phyloseq

ps.short = phyloseq(otu_table(as.matrix(ot.short), taxa_are_rows = T), tax_table(as.matrix(tt.short)), sample_data(sd.short))

Rarefy

mindeepth= min(sample_sums(ps.short)) mindeepth ps.met.aar = rarefy_even_depth(ps.short, rngseed=123, sample.size=mindeepth, replace=FALSE, trimOTUs = TRUE) set.seed(123)` was used to initialize repeatable random subsampling. Please record this for your records so others can reproduce. Tryset.seed(123); .Random.seedfor the full vector ... Error en rep_len(x["OTUi"], x["times"]): valor de 'length.out' no válido

ot.short.txt tt.short.txt sd.short.txt

antagomir commented 1 month ago

Hi @imonteroo there is a possible misunderstanding. This package (mia) is based on TreeSummarizedExperiment data container, which is an alternative to phyloseq. The correct place to troubleshoot problems with phyloseq functions is the phyloseq package itself (or other packages supporting that format).

From your original question "I tried to rarefay a phyloseq object transformet to a SummarizedExperiment" I understood that you would be operating with a (Tree)SE object. We can help to troubleshoot that, would this help?