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/
579 stars 188 forks source link

Subsetting specific samples from a phyloseq object #1564

Open LaFra7 opened 2 years ago

LaFra7 commented 2 years ago

Hi all, I am trying to do something that should be really easy, but I can't figure out how to do it.

I have my phyloseq object and I want to extract only few samples and with them I want to create another phyloseq object (because I want to make some plot with only these specific samples and it seems to me the only way to do it).

So I tried:

new_phy_obj <- prune_samples(sample_names(df_with_all_samples) == c("sampletosubset1", "sampletosubset2", "sampletosubset3"), df_with_all_samples)

But I got this message: Error in validObject(.Object) : invalid class “otu_table” object: OTU abundance data must have non-zero dimensions.

I also tried: samples_to_subset <- c("sampletosubset1", "sampletosubset2", "sampletosubset3") new_phy_obj <- prune_samples(samples_to_subset, df_with_all_samples)

And I tried many other ways, but I always get the same message.

Could somebody help me?

Thanks a lot,

ycl6 commented 2 years ago

Hi @LaFra7

Is your df_with_all_samples a phyloseq or a data.frame object? When you enter df_with_all_samples in R, what's the output in the console?