我在执行量化(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]], sep = "\t", header = TRUE)
merge <- cbind(merge1, sample[,2, drop=F])
}
write.table(merge, snakemake@params[[1]], sep = "\t", 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]], sep = "\t", header = T)
for (i in 2:length(sample)) {
x <- read.table(sample[[i]], sep = "\t", header = T)
merge <- merge(merge, x, by="Gene")
}
write.table(merge, snakemake@output[[1]], sep = "\t", quote = F, row.names = F)
我认为问题是可能对每个样本并行执行规则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"