I have installed the local docker galaxy on my own PC, the galaxy work correctly. But now I am trying to install my own R script on it, I prepared the R script file, xml file, and also modified the tool_config.xml, now I can see my tool, and choose the correct three input files: OTU/ASV table, classifier table, sample data table. My R script will convert them into the phyloseq format file as output. However, the error occurred as follows:
Here are my Rscript file and xml:
#!/usr/bin/env Rscript
library(phyloseq)
library(tidyverse)
--------------------------
从Galaxy命令行参数获取输入输出路径
--------------------------
args ← commandArgs(trailingOnly = TRUE)
输入文件路径(Galaxy自动注入)
otu_path ← args[1] # 例如:${otu_table}
taxonomy_path ← args[2] # 例如:${taxonomy_table}
metadata_path ← args[3] # 例如:${metadata}
output_rds ← args[4] # 例如:${output_rds}
--------------------------
数据读取与预处理
--------------------------
读取OTU表(行为OTU,列为样本)
otu_mat ← as.matrix(read.table(
file = otu_path,
sep = “\t”,
header = TRUE,
row.names = 1,
check.names = FALSE
))
读取分类表(自动处理分号分隔的层级)
taxonomy_df ← read.table(
file = taxonomy_path,
sep = “\t”,
header = TRUE,
row.names = 1,
stringsAsFactors = FALSE
)
读取样本元数据(兼容#开头的注释行)
metadata_df ← read.table(
file = metadata_path,
sep = “\t”,
header = TRUE,
row.names = 1,
comment.char = “#” # 忽略#开头的注释行
)
--------------------------
数据验证(含错误终止)
--------------------------
检查OTU表列名与元数据行名匹配
if(!all(colnames(otu_mat) %in% rownames(metadata_df))) {
missing_samples ← setdiff(colnames(otu_mat), rownames(metadata_df))
stop(paste(“以下样本在元数据中缺失:”, paste(missing_samples, collapse = ", ")))
}
检查OTU表行名与分类表匹配
if(!all(rownames(otu_mat) %in% rownames(taxonomy_df))) {
missing_otus ← setdiff(rownames(otu_mat), rownames(taxonomy_df))
stop(paste(“以下OTU在分类表中缺失:”, paste(missing_otus, collapse = ", ")))
}
--------------------------
构建phyloseq对象
--------------------------
physeq ← phyloseq(
otu_table(otu_mat, taxa_are_rows = TRUE),
tax_table(as.matrix(taxonomy_df)),
sample_data(metadata_df)
)
--------------------------
输出结果(适配Galaxy)
--------------------------
保存RDS文件(主输出)
saveRDS(physeq, file = output_rds)
生成人类可读的摘要报告
sink(“phyloseq_summary.txt”) # Galaxy可捕获的标准输出
cat(“=== Phyloseq对象构建成功 ===\n”)
cat(sprintf(“样本数量: %d\n”, nsamples(physeq)))
cat(sprintf(“OTU数量: %d\n”, ntaxa(physeq)))
cat(“\n分类层级结构:\n”)
print(colnames(tax_table(physeq)))
cat(“\n前3个样本的元数据:\n”)
print(head(sample_data(physeq), 3))
sink()
I also tried to install the package “phyloseq” through the docker terminal, but the R version is 4.1.3, the phyloseq can not be installed. But if I am trying to update the R version, failed again.