如何将字典输入读入snakemake。

huangapple go评论53阅读模式
英文:

How to read dictionary input into snakemake

问题

我有输入的fastq文件在文件夹里。我想在snakemake中访问它。有人可以建议我如何访问它吗?

这是我迄今为止尝试过的代码。

infile_loc = {"Sample1":["/home/joshua/snakemake_works/input/Sample1_R1.fq.gz","/home/joshua/snakemake_works/input/Sample1_R2.fq.gz"], "Sample2":["/home/joshua/snakemake_works/input/Sample2_R1.fq.gz","/home/joshua/snakemake_works/input/Sample2_R2.fq.gz"]}
    
SAMPLES=infile_loc.keys()
    
rule print_file_name:
    input:
        expand("{sample}", sample=SAMPLES)
    params:
        read1, read2 = lambda wildcards: infile_loc[wildcards.sample]
    script:
        """
        echo {params.read1}
        echo {params.read2}
        """

但我得到了以下错误。

在文件/home/joshua/snakemake_works/Snakefile的第9行中的NameError:
名称'read1'未定义
File "/home/joshua/snakemake_works/Snakefile", line 9, in <module>

有人可以指导我如何解决这个错误吗?

英文:

I have input fastq files inside dictionary. I want to access it inside snakemake. Could anyone please suggest me how I can access it?

Here is the code that I've tried so far.

infile_loc = {&quot;Sample1&quot;:[&quot;/home/joshua/snakemake_works/input/Sample1_R1.fq.gz&quot;,&quot;/home/joshua/snakemake_works/input/Sample1_R2.fq.gz&quot;], &quot;Sample2&quot;:[&quot;/home/joshua/snakemake_works/input/Sample2_R1.fq.gz&quot;,&quot;/home/joshua/snakemake_works/input/Sample2_R2.fq.gz&quot;]}

SAMPLES=infile_loc.keys()

rule print_file_name:
	input:
		expand(&quot;{sample}&quot;, sample=SAMPLES)
	params:
		read1, read2 = lambda wildcards: infile_loc[wildcards.sample]
	script:
		&quot;&quot;&quot;
		echo {params.read1}
		echo {params.read2}
		&quot;&quot;&quot;

But I'm getting the following error.

NameError in file /home/joshua/snakemake_works/Snakefile, line 9:
name &#39;read1&#39; is not defined
  File &quot;/home/joshua/snakemake_works/Snakefile&quot;, line 9, in &lt;module&gt;

Could anyone please guide me how I can resolve this error?

答案1

得分: 2

我认为问题在于您使用了 script 指令,而您应该改用 shell 指令。

rule print_file_name:
    input:
        expand("{sample}", sample=SAMPLES)
    params:
        read1, read2 = lambda wildcards: infile_loc[wildcards.sample]
    shell:  # <------- 将 script 改为 shell
        """
        echo {params.read1}
        echo {params.read2}
        """
英文:

I think the problem is that you use the script directive, and you should use the shell directive instead.

rule print_file_name:
    input:
        expand(&quot;{sample}&quot;, sample=SAMPLES)
    params:
        read1, read2 = lambda wildcards: infile_loc[wildcards.sample]
    shell:  # &lt;------- script changed to shell
        &quot;&quot;&quot;
        echo {params.read1}
        echo {params.read2}
        &quot;&quot;&quot;

huangapple
  • 本文由 发表于 2023年7月17日 18:04:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76703376.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定