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/
582 stars 187 forks source link

loop for multiple Phyloseq object. #1646

Closed shashank-KU closed 1 year ago

shashank-KU commented 1 year ago

Hi all, I am trying to write a loop to do differential taxa analysis using "microbiomeMarker" package.

For example, I have multiple phyloseq objects-

AB1
AB2
AB3

and I am trying to write a loop, I am getting an error.

# Create a vector of inputs
inputs <- c("AB1", "AB2", "AB3")

# Loop over each input
for (input in inputs) {
  # Create the output object for the current input
  lef_out <- paste0("lef_out_", input)
  lef_out <- run_lefse(input, group = "Condition")

  # Create the subset object for the current input
  sub <- paste0("sub_", input)
  sub <- subset(marker_table(lef_out), marker_table(lef_out)$enrich_group == input)

  # Create the count object for the current input
  count <- paste0("count_", input)
  count <- nrow(sub)
}

Error: ps must be phyloseq object

But when I do it one by one, it works

lef_out_AB1 <- run_lefse(AB1, group = "New_Diet")
sub_AB1 <- subset(marker_table(lef_out_AB1), marker_table(lef_out_AB1)$enrich_group == "AB1")
count_AB1 <- nrow(sub_AB1)

I understand, that it is asking for a phyloseq object as an input, but in the loop how can I use phyloseq object? Any suggestions?

shashank-KU commented 1 year ago

Found the mistake.