r-如何从不同的文件中提取相同的数据

  • 本文关键字:提取 数据 文件 r qiime
  • 更新时间 :
  • 英文 :


为了从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:将其应用于每个文件

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)

相关内容

  • 没有找到相关文章

最新更新