Removing samples from phyloseq otu_table
1
0
Entering edit mode
3.6 years ago
zrf1 • 0

I am trying to remove samples from my otu_table in a phyloseq object ps . This is so I can match the samples in my sample_data (which does not have the samples stated below as I removed them due to NAs). I'm using this:

enter code hereto_remove <- c("Sample1", "Sample5", "Sample10", "Sample30")
# using z first to see if it works 
z <- prune_samples(ps@otu_table, !(sample_names() %in% to_remove))

but get this error:

# Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘prune_samples’ for signature ‘"otu_table", "logical"’

How do I go about removing samples from my otu_table?

phyloseq r R • 6.1k views
ADD COMMENT
2
Entering edit mode
3.6 years ago

Hi,

You're doing a couple of things wrong. First, prune_samples(samples, x) takes 2 positional arguments, samples and x:

  • samples: character of samples to keep or logical, where TRUE, is the samples that you want to keep;

  • x: phyloseq-class object.

Therefore, what you're doing wrong:

  1. you're giving the arguments in the wrong order, and unless you specific the parameters name, that will never work;

  2. you're giving a otu-class object and not a phyloseq class object. Here is important to give a phyloseq-class object, because when you remove samples, it is important to remove these samples not only from the otu table but also from metadata/sample data table - this can only work if you give the phyloseq-class object;

  3. sample_names() takes one argument, a phyloseq-class object, you did not give any, so does not work.

To fix and solve all these problems, try the following:

to_remove <- c("Sample1", "Sample5", "Sample10", "Sample30")

z <- prune_samples(!(sample_names(ps) %in% to_remove), ps)

This should work. Assuming that ps is your phyloseq-class object.

I hope this answers your question,

António

ADD COMMENT
0
Entering edit mode

My bad, didn't notice that i entered the arguments in the wrong order. Also should put in the phyloseq object for sample_names(). Thank you!

ADD REPLY

Login before adding your answer.

Traffic: 1705 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6