Open phorve opened 4 years ago
Hi phorve
Probably you found a solution by now, however, I have a somewhat similar issue, but for different reasons.
In my case, I have 4 replicates (which are 1 sample each in my phyloseq object) and I want to merge them, but only taking OTUs that are present in at least 2 of the 4 replicates. With intersect and uncion, I manage to get the taxa_names of these OTUs, and I can subset samples in a loop, but I don't know how to reassemble these cropped samples into a new object. :/
What I did find is that you can create a 'for' loop and store the phyloseq object in a list.
for (i in 1:length(samples)) {
site_i <- subset_samples(phylo, sample == sample[i]) ....
Top25 <- prune_taxa(top25, site_i)
pruned_data[[i]] <- Top25 }
However, unlike with normal lists, where you could simply use rbind to unlist this object, it does not work with phyloseq objects. I tried to write a loop for merging the objects, like the following:
for (i in 1:length(samples)) {
p_new <- phyloseq(pruned_data[[i]], pruned_data[[i+1]])
pruned_data[[i+1]] <- p_new }
However, it tells me that the tree cannot be merged, because of course, individual samples do not contain all tips... I really don't know how to work around. I think about dropping the phyloseq framework and work with normal tables instead... ?! I'd be glad to hear about your ideas.
@phorve, subset_samples()
and subset_taxa()
use non-standard evaluation (see issue #752), which means you should only use it for interactive (i.e. not in loop) use. My solution to that is to first generate a logical vector based on whatever critieria you have, in this case, we are subsetting by SampleName. There is probably a much better way than
names <- sample_names(ps)
for (name in names){
single_sample <- prune_samples(name, ps, ) # This is your single sample
# Here you can do the top 25 ASV code, but avoid using subset_taxa()
# Replace it with prune_taxa()
}
Hi all,
I am hoping to create a compositional barplot for each individual sample in a study. I have my data in a phyloseq, and I was able to create the compositional barplot for the top25 taxa across all samples using the code below:
view_final_vst is my normalized phyloseq object.
However, this just finds the top 25 taxa in the phyloseq object that I created. I was hoping to be able to make a loop that will run through each sample name in the phyloseq object and create an individual phyloseq object for each sample, then plot that phyloseq using the code above. However, I have been having difficulty figuring out how this loop would work, especially with phyloseq.
I did some searching through the previous issues and found a way to view the top 25 in each sample ( #847 ), but this does not allow me (at least as to my knowledge) to convert into a phyloseq object with abundance data.
I would really appreciate any help in trying pt put this loop together. I would also imagine that this could be helpful for individuals in the future that want to find the top however many taxa in individual samples.
Thanks in advance for any help!