Snakemake无法读取R中的完整文件吗?

在执行量化(kallisto / salmon)之后,我正在使用一些快速的R脚本来绑定文件。 问题是,我得到一个R错误,说我的输入文件长度不一样,所以cbind()无法工作。
显然不是这种情况,它们全都是16887行(用bash wc检查),并且在R上运行完全正常而没有蛇行。

还值得一提的是,我确实获得了一个随机样本(〜1至4)的输出。

这是R代码:

sample <- read.table(snakemake@input[[1]],sep = "\t",header = TRUE)
if (!file.exists(snakemake@params[[1]])) {
  merge <- data.frame(sample)
} else {
  merge1 <- read.table(snakemake@params[[1]],header = TRUE)
  merge <- cbind(merge1,sample[,2,drop=F])
}
write.table(merge,snakemake@params[[1]],quote = F,row.names = F)
file.create(snakemake@output[[1]])

还有snakemake规则:

rule merge_quantif:
        input:
            QUANTIF+"/{sample}/quantif.txt"
        output:
            QUANTIF+"/{sample}/merge.done"
        params:
            QUANTIF+"/all_sample_quantified.txt"
        script:
            "Tools/merge_quantif.R"

我的文件是这样的:

Gene    R1
A1BG    0.287571
A1CF    0
A2M 0.198756
A2ML1   0
A2MP1   0
A3GALT2 0
A4GALT  3.098108

输出应该是这样,但要包含所有17个样本

Gene    R4  R8  R15 R13
A1BG    0.337515    0.284943    0.488654    0.587114
A1CF    0   0   0   0
A2M 0   0   0.105159    0.009539

如果有人有想法解决这个问题,将不胜感激。

------------编辑 修改后的R代码以配合使用:

sample <- snakemake@input

merge <- read.table(sample[[1]],header = T)
for (i in 2:length(sample)) {
  x <- read.table(sample[[i]],header = T)
  merge <- merge(merge,x,by="Gene")
}

write.table(merge,snakemake@output[[1]],row.names = F)
mmrldb 回答:Snakemake无法读取R中的完整文件吗?

我认为问题在于规则merge_quantif对于每个样本都可能并行执行17次。但是,每次运行merge_quantif都会写入相同的输出文件(QUANTIF+"/all_sample_quantified.txt"),因为在R脚本中您有write.table(merge,snakemake@params[[1]],...)。我怀疑这会导致问题,或者至少不是理想的设置。我怀疑您想要的是这样的东西:

rule merge_quantif:
        input:
            expand(QUANTIF+"/{sample}/quantif.txt",sample= list_of_samples)
        output:
            QUANTIF+"/all_sample_quantified.txt"
        script:
            "Tools/merge_quantif.R"

Tools/merge_quantif.R逐一读取输入文件列表,将其合并,最后将合并的文件写入QUANTIF+"/all_sample_quantified.txt"

本文链接:https://www.f2er.com/2393976.html

大家都在问