python - Snakemake - 尝试使用 global_wildcards 时出现问题(TypeError : expected str, 获取列表)

标签 python snakemake

我是 Snakemake 的新手,也不是 Python 专家,所以答案可能非常明显。我的工作流程中的所有内容在测试中都运行良好,直到我尝试使用 glob_wildcards将一个目录 (FASTQDIR) 中的所有 fastq.gz 文件转换为 fastqc 文件

样本列表中的样本名称没问题,但我有一个错误,指出需要一个字符串而不是一个列表(我假设这是我的样本列表),而且我真的不知道在哪里 在我的 Snakefile 中采取行动以纠正它。我知道这肯定与我使用 glob_wildcards 有关,但我不明白问题出在哪里。您知道我该如何解决它吗?

这是我的Snakefile代码:

FASTQDIR = "/fastq/files/directory/"
WDIR = "/my/working/directory/"
SAMPLES, = glob_wildcards(FASTQDIR + "{sample}.fastq.gz")

rule all:
    input:
        expand(WDIR + "Fastqc/{sample}_fastqc.html", sample=SAMPLES),
        expand(WDIR + "Fastqc/{sample}_fastqc.zip", sample=SAMPLES)

#Generates fastqc file for the sample fastq.gz file in the Fastqc directory
rule fastqc_generate_qc:
    input:
        expand(FASTQDIR + "{sample}.fastq.gz", sample=SAMPLES)
    output:
        expand(WDIR + "Fastqc/{sample}_fastqc.html", sample=SAMPLES),
        expand(WDIR + "Fastqc/{sample}_fastqc.zip", sample=SAMPLES)
    shell:
        "fastqc --outdir Fastqc/ {input}"

这是整个回溯:

Traceback (most recent call last):
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/__init__.py", line 420, in snakemake
    force_use_threads=use_threads)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/workflow.py", line 480, in execute
    success = scheduler.schedule()
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/scheduler.py", line 215, in schedule
    self.run(job)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/scheduler.py", line 229, in run
    error_callback=self._error)
  File "/home/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/executors.py", line 59, in run
    self._run(job)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/executors.py", line 120, in _run
    super()._run(job)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/executors.py", line 66, in _run
    self.printjob(job)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/executors.py", line 85, in printjob
    msg=job.message,
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/jobs.py", line 175, in message
    self.rule.message else None)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/jobs.py", line 542, in format_wildcards
    return format(string, **_variables)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/site-packages/snakemake/utils.py", line 259, in format
    return fmt.format(_pattern, *args, **variables)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/string.py", line 187, in format
    return self.vformat(format_string, args, kwargs)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/string.py", line 191, in vformat
    result, _ = self._vformat(format_string, args, kwargs, used_args, 2)
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/string.py", line 201, in _vformat
    self.parse(format_string):
  File "/home/miniconda3/envs/snakemake-tutorial/lib/python3.5/string.py", line 285, in parse
    return _string.formatter_parser(format_string)
TypeError: expected str, got list

预先感谢您的帮助

最佳答案

您没有在此处使用通配符。

您的规则 fastqc_generate_qc 将所有 fastq 文件作为输入,并在此处输出所有 fastqc 文件。
在snakemake 中要记住的一件事是:expand 生成一个文件列表。你不希望这里出现这样的情况:

rule fastqc_generate_qc:
    input:
        FASTQDIR + "{sample}.fastq.gz"
    output:
        WDIR + "Fastqc/{sample}_fastqc.html",
        WDIR + "Fastqc/{sample}_fastqc.zip"
    shell:
        "fastqc --outdir Fastqc/ {input}"

这里sample是一个通配符。您的规则将触发真实的文件名生成。然后,规则 fastqc_generate_qc 将使用通配符将该规则应用于规则 all 中要求的任何输出。

仅供引用,如果您想在扩展函数中使用通配符,则必须将括号括起来: expand("path/{{study}}/{sample},sample=SAMPLES)
这里,study 是通配符,sample 不是。 sample 值在展开函数的第二个参数中定义。

关于python - Snakemake - 尝试使用 global_wildcards 时出现问题(TypeError : expected str, 获取列表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60526646/

相关文章:

python - 反转元组和反转列表有什么区别?

python - TSP,算法陷入局部最小值

Python正则表达式提取浮点值

python - 始终在 Snakefile (snakemake) 中运行规则

snakemake - 如何跳过古代的中间规则?

python - 如何使多条线的颜色随渐变色对应的值变化?

python - 如何使用 PYTHON 遍历目录中的文件并将 INFO 插入 MySQL 数据库

if-statement - 根据 config.yaml 中的变量(非通配符)命名 Snakemake 中的输入/输出文件

windows - 为什么snakemake不执行shell命令

Snakemake:如果规则的输出文件已经生成了,会发生什么?