我在snakemake中构建一个工作流,并希望将其中一个规则循环到两个不同的输入源。输入源可以是source1或source1+source2,根据输入的不同,输出目录也会有所不同。因为在同一条规则中这样做非常复杂,而且我不想创建完整规则的副本,所以我想创建两个输入/输出不同的规则,但是运行相同的命令。
有可能让这件事成功吗?我得到了正确的DAG解析,但是任务不能在集群(ERROR : bamcov_cmd not defined)上完成。下面是一个示例(这两条规则在结尾处使用相同的命令):
这是命令
def bamcov_cmd():
return( (deepTools_path+"bamCoverage " +
"-b {input.bam} " +
"-o {output} " +
"--binSize {params.bw_binsize} " +
"-p {threads} " +
"--normalizeTo1x {params.genome_size} " +
"{params.read_extension} " +
"&> {log}") )这是规矩
rule bamCoverage:
input:
bam = file1+"/{sample}.bam",
bai = file1+"/{sample}.bam.bai"
output:
"bamCoverage/{sample}.filter.bw"
params:
bw_binsize = bw_binsize,
genome_size = int(genome_size),
read_extension = "--extendReads"
log:
"bamCoverage/logs/bamCoverage.{sample}.log"
benchmark:
"bamCoverage/.benchmark/bamCoverage.{sample}.benchmark"
threads: 16
run:
bamcov_cmd()这是可选的rule2
rule bamCoverage2:
input:
bam = file2+"/{sample}.filter.bam",
bai = file2+"/{sample}.filter.bam.bai"
output:
"bamCoverage/{sample}.filter.bw"
params:
bw_binsize = bw_binsize,
genome_size = int(genome_size),
read_extension = "--extendReads"
log:
"bamCoverage/logs/bamCoverage.{sample}.log"
benchmark:
"bamCoverage/.benchmark/bamCoverage.{sample}.benchmark"
threads: 16
run:
bamcov_cmd()发布于 2017-07-21 22:13:23
在python中,您所要求的是可能的。这取决于文件中是否只有python代码,或者python和Snakemake。我会先回答这个问题,然后我会有一个后续的回应,因为我希望你以不同的方式设置它,这样你就不用这样做了。
只需Python:
from fileContainingMyBamCovCmdFunction import bamcov_cmd
rule bamCoverage:
...
run:
bamcov_cmd()在视觉上,看看我是如何在这个文件中这样做的,以引用对buildHeader和buildSample的访问。这些文件正在由一个Snakefile调用。对你来说也是一样的。buildFile/buildFile.py
编辑2017-07-23 -更新下面的代码段以反映用户评论
Snakemake和Python:
include: "fileContainingMyBamCovCmdFunction.suffix"
rule bamCoverage:
...
run:
shell(bamcov_cmd())编辑端
如果函数确实是特定于bamCoverage调用的,那么如果您愿意,可以将它放回规则中。这意味着它不在其他地方被调用,这可能是真的。使用“.”注释文件时要小心。表示法,我使用'_‘,因为我发现它更容易防止产生周期性依赖的方式。另外,如果您确实将这两条规则分开处理,则可能会出现歧义错误。如果可能的话,让规则生成唯一的输出是http://snakemake.readthedocs.io/en/latest/snakefiles/rules.html?highlight=ruleorder#handling-ambiguous-rules的最佳实践。
至于替代方案,可以考虑这样设置代码吗?
from subprocess import call
rule all:
input:
"path/to/file/mySample.bw"
#OR
#"path/to/file/mySample_filtered.bw"
bamCoverage:
input:
bam = file1+"/{sample}.bam",
bai = file1+"/{sample}.bam.bai"
output:
"bamCoverage/{sample}.bw"
params:
bw_binsize = bw_binsize,
genome_size = int(genome_size),
read_extension = "--extendReads"
log:
"bamCoverage/logs/bamCoverage.{sample}.log"
benchmark:
"bamCoverage/.benchmark/bamCoverage.{sample}.benchmark"
threads: 16
run:
callString= deepTools_path + "bamCoverage " \
+ "-b " + wilcards.input.bam \
+ "-o " + wilcards.output \
+ "--binSize " str(params.bw_binsize) \
+ "-p " + str({threads}) \
+ "--normalizeTo1x " + str(params.genome_size) \
+ " " + str(params.read_extension) \
+ "&> " + str(log)
call(callString, shell=True)
rule filterBam:
input:
"{pathFB}/{sample}.bam"
output:
"{pathFB}/{sample}_filtered.bam"
run:
callString="samtools view -bh -F 512 " + wildcards.input \
+ ' > ' + wildcards.output
call(callString, shell=True)有什么想法?
https://stackoverflow.com/questions/45245966
复制相似问题