Snakemake删除配置值中的下划线?

2024-10-02 04:30:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将名为samples的--config参数传递给snakemake函数。似乎不管我怎么传递,所有的下划线都被删除了?有什么建议吗,还是我做错了什么

snakemake -s snakefile.py all --configfile /share/biocore/keith/dennislab/snakemake/templates/tagseq.json --config samples=60_3_6,

snakemake -s snakefile.py all --configfile /share/biocore/keith/dennislab/snakemake/templates/tagseq.json --config samples="60_3_6"

snakemake -s snakefile.py all --configfile /share/biocore/keith/dennislab/snakemake/templates/tagseq.json --config samples='60_3_6'


所有这些都会为snakefile中的配置字典生成这样的结果(注意最后的samples参数)

{'__default__': OrderedDict([('__comment1', 'running_locally=[True,False] ~ type=[PE,SE,tagseq]'), ('running_locally', 'False'), ('type', 'tagseq'), ('__comment2', 'Path to the file containing a column of sample names'), ('samples_file', '/share/biocore/keith/dennislab/rhesus_tagseq/samples.txt')]), 'project': OrderedDict([('basename', '/share/biocore/keith/dennislab'), ('id', 'PE'), ('fastqs', 'rhesus_tagseq'), ('human_rrna_ref', '/share/biocore/keith/workshop/rnaseq_examples/References/human_rrna.fasta'), ('star_ref', '/share/biocore/keith/dennislab/star.overlap100.gencode')]), 'hts_star': OrderedDict([('__comment', 'This is for running one sample for htspreproc > star'), ('job-name', 'hts_star_'), ('n', 1), ('ntasks', 9), ('partition', 'production'), ('time', '120'), ('mem', '32000'), ('__comment2', 'The name of the sample and analysis type will be inserted before .out and .err'), ('output', 'slurm_out/hts_star_.out'), ('error', 'slurm_out/hts_star_.err'), ('mail-type', 'NONE'), ('mail-user', 'kgmitchell@ucdavis.edu')]), 'samples': (6036,)}


Tags: pyconfigsharetypealloutstarsamples
2条回答

Snakemake将 config键/值对的值作为输入传递给this list中的每个函数,依次计算该值:

parsers = [int, float, eval, str]

在Python[u]nderscores are ignored for determining the numeric value of the literal中计算数字文本时

因此,60_3_6作为整数计算,因为intstr之前被尝试:

>>> for p in parsers:
...     print(p('60_3_6'))
... 
6036
6036.0
6036
60_3_6

(在问题的第一个示例中,60_3_6,作为值传递;在本例中,eval返回一个元组,其中包含6036作为其唯一元素,如配置值转储中所示

要解决这个问题,您需要传递一个值,该值只能由str成功处理

另一个可能的解决方法是传递

lambda : '60_3_6'

由于snakemake将使用callable instead of the result of processing parsers但是我不知道如何从配置文件或命令行执行此操作,因此我认为您需要直接从python代码调用snakemake的main函数(可能创建包装脚本?)

这种“双重引用”似乎奏效了:

snakemake  config samples='"10_13"'

它也适用于多个示例:

snakemake  config samples='"10_13", "foo", "19_19"'

虚拟蛇形文件:

samples= config['samples']

rule all:
    input:
        expand('{sample}.txt', sample= samples),

rule one:
    output:
        '{sample}.txt',
    shell:
        r"""
        touch {output}
        """

相关问题 更多 >

    热门问题