0

为了从 qiime2 工件中提取频率表并将其写入 tsv 输出,您必须:

rel_freq_table <- read_qza("05.TaxonomyClassification/rel_freq/1_rel_freq_table.qza")
rel_freq_table <- data.frame(rel_freq_table$data)
rel_freq_table <-  setDT(rel_freq_table, keep.rownames = TRUE )
colnames(rel_freq_table)[1]<- c( "Feature.ID" )
write.table(rel_freq_table, file = "1_rel_freq_table.tsv", row.names = FALSE, dec = ",")

现在,我有七个 qiime2 工件

rel_freqs <- c("05.TaxonomyClassification/rel_freq/1_rel_freq_table.qza","05.TaxonomyClassification/rel_freq/2_rel_freq_table.qza",
           "05.TaxonomyClassification/rel_freq/3_rel_freq_table.qza","05.TaxonomyClassification/rel_freq/4_rel_freq_table.qza",
           "05.TaxonomyClassification/rel_freq/5_rel_freq_table.qza","05.TaxonomyClassification/rel_freq/6_rel_freq_table.qza",
           "05.TaxonomyClassification/rel_freq/7_rel_freq_table.qza")

我想自动化这个过程,所以我只需要运行一次命令。我试过循环和 lapply 但没有运气,有人知道吗?

4

1 回答 1

1

您可以编写一个函数并将其应用于每个文件lapply

read_qiime2_write_tsv <- function(filename) {
  rel_freq_table <- read_qza(filename)
  rel_freq_table <- data.frame(rel_freq_table$data)
  rel_freq_table <-  setDT(rel_freq_table, keep.rownames = TRUE )
  colnames(rel_freq_table)[1]<- c( "Feature.ID" )
  write.table(rel_freq_table, 
          file = paste0(tools::file_path_sans_ext(basename(filename)), '.tsv'), 
          row.names = FALSE, dec = ",")
}

lapply(rel_freqs, read_qiime2_write_tsv)
于 2021-04-16T08:36:08.860 回答