繁体   English   中英

Snakemake:如何将每个调用列表中的一个整数用作脚本的输入?

[英]Snakemake: how to use one integer from list each call as input to script?

我正在尝试在 snakemake 中练习编写工作流程。

我的 Snakefile 的内容:

configfile: "config.yaml"

rule get_col:
  input:
   expand("data/{file}.csv",file=config["datname"])
  output:
   expand("output/{file}_col{param}.csv",file=config["datname"],param=config["cols"])
  params:
   col=config["cols"]
  script:
   "scripts/getCols.R"

config.yaml 的内容:

cols:
  [2,4]
datname:
  "GSE3790_expression_data"

我的 R 脚本:

getCols=function(input,output,col) {
  dat=read.csv(input)
  dat=dat[,col]
  write.csv(dat,output,row.names=F)
}

getCols(snakemake@input[[1]],snakemake@output[[1]],snakemake@params[['col']])

似乎两列都被同时调用。 我想要完成的是从每个输出文件的列表中调用一列。

由于第二个输出永远没有机会被创建(两列都用于创建第一个输出),snakemake 抛出一个错误:

Waiting at most 5 seconds for missing files.
MissingOutputException in line 3 of /Users/rebecca/Desktop/snakemake-tutorial/practice/Snakefile:
Job completed successfully, but some output files are missing.

在一个稍微不相关的注释中,我认为我可以将输入写为:'"data/{file}.csv"' 但是返回:

WildcardError in line 4 of /Users/rebecca/Desktop/snakemake-tutorial/practice/Snakefile:
Wildcards in input files cannot be determined from output files:
'file'

任何帮助将非常感激!

看起来您想为每个文件运行 Rscript 两次,对于col每个值运行一次。 在这种情况下,规则也需要被调用两次。 在我看来,这里使用expand也有点太多了。 expand用所有可能的值填充您的通配符并返回结果文件的列表。 因此,此规则的输出将是filescols之间的所有可能组合,这是简单脚本无法在一次运行中创建的。 这也是无法从输出中推断出file的原因 - 它在那里被扩展。

相反,尝试仅针对一个文件和列更轻松地编写规则,并在需要此输出作为输入的规则中扩展结果输出。 如果您生成了工作流的最终输出,请将其作为输入放入rule all以告诉工作流最终目标是什么。

rule all:
  input:
    expand("output/{file}_col{param}.csv",
    file=config["datname"], param=config["cols"])

rule get_col:
  input:
    "data/{file}.csv"
  output:
    "output/{file}_col{param}.csv"
  params:
    col=lambda wc: wc.param
  script:
    "scripts/getCols.R"

Snakemake 将从rule all (或任何其他规则以进一步使用输出)推断需要做什么,并相应地调用rule get_col

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM