【问题标题】:Problems with the VEP snakemake wrapperVEP 蛇形包装器的问题
【发布时间】:2020-08-11 18:18:16
【问题描述】:

我在尝试为 snakemake 运行 VEP 包装器时遇到两个问题。

第一个是我想在calls中使用lambda wildcards,像这样:

calling_dir = os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"])
callings_locations = [calling_dir] * len_samples
callings_dict = dict(zip(sample_names, callings_locations))

def getVCFs(sample):
  return(list(os.path.join(callings_dict[sample],"{0}_sorted_dedupped_snp_varscan.vcf".format(sample,pair)) for pair in ['']))

rule variant_annotation:
    input:
        calls= lambda wildcards: getVCFs(wildcards.sample),
        cache="resources/vep/cache",
        plugins="resources/vep/plugins",
    output:
        calls="variants.annotated.vcf",
        stats="variants.html"
    params:
        plugins=["LoFtool"],
        extra="--everything"
    message: """--- Annotating Variants."""
    resources:
        mem = 30000,
        time = 120
    threads: 4
    wrapper:
        "0.64.0/bio/vep/annotate"

但是,我得到一个错误:

当我将 lambda wildcards 替换为 calls= expand('{CALLING_DIR}/{CALLING_TOOL}/{sample}_sorted_dedupped_snp_varscan.vcf', CALLING_DIR=dirs_dict["CALLING_DIR"], CALLING_TOOL=config["CALLING_TOOL"], sample=sample_names)([这不理想 - 请参阅此帖子的原因][1])时,它会给我关于 resources 文件夹的错误?

(snakemake) [moldach@cedar1 MTG353]$ snakemake -n -r
Building DAG of jobs...
MissingInputException in line 333 of /scratch/moldach/MADDOG/VCF-FILES/biostars439754/MTG353/Snakefile:
Missing input files for rule variant_annotation:
resources/vep/cache
resources/vep/plugins

我也 [从文档中对它如何知道应该指定哪个参考基因组(版本、_等)感到困惑][2]。

更新:

由于字数限制,我什至无法回复两位受访者,所以我将在此处继续问题

正如@jafors 提到的,两个包装器解决了cacheplugins 的问题 - 谢谢!

现在我从以下规则尝试运行 VEP 时遇到错误:

rule variant_annotation:
    input:
        calls= expand('{CALLING_DIR}/{CALLING_TOOL}/{sample}_sorted_dedupped_snp_varscan.vcf', CALLING_DIR=dirs_dict["CALLING_DIR"], CALLING_TOOL=config["CALLING_TOOL"], sample=sample_names),
        cache="resources/vep/cache",
        plugins="resources/vep/plugins",
    output:
        calls=expand('{ANNOT_DIR}/{ANNOT_TOOL}/{sample}.annotated.vcf', ANNOT_DIR=dirs_dict["ANNOT_DIR"], ANNOT_TOOL=config["ANNOT_TOOL"], sample=sample_names),
        stats=expand('{ANNOT_DIR}/{ANNOT_TOOL}/{sample}.html', ANNOT_DIR=dirs_dict["ANNOT_DIR"], ANNOT_TOOL=config["ANNOT_TOOL"], sample=sample_names)
    params:
        plugins=["LoFtool"],
        extra="--everything"
    message: """--- Annotating Variants."""
    resources:
        mem = 30000,
        time = 120
    threads: 4
    wrapper:
        "0.64.0/bio/vep/annotate"

这是我从日志中得到的错误:

Building DAG of jobs...
Using shell: /cvmfs/soft.computecanada.ca/nix/var/nix/profiles/16.09/bin/bash
Provided cores: 4
Rules claiming more threads will be scaled down.
Job counts:
        count   jobs
        1       variant_annotation
        1

[Wed Aug 12 20:22:49 2020]
Job 0: --- Annotating Variants.

Activating conda environment: /scratch/moldach/MADDOG/VCF-FILES/biostars439754/.snakemake/conda/f16fdb5f
Traceback (most recent call last):
  File "/scratch/moldach/MADDOG/VCF-FILES/biostars439754/.snakemake/scripts/tmpwx1u_776.wrapper.py", line 36, in <module>
    if snakemake.output.calls.endswith(".vcf.gz"):
AttributeError: 'Namedlist' object has no attribute 'endswith'
[Wed Aug 12 20:22:53 2020]
Error in rule variant_annotation:
    jobid: 0
    output: ANNOTATION/VEP/BC1217.annotated.vcf, ANNOTATION/VEP/470.annotated.vcf, ANNOTATION/VEP/MTG109.annotated.vcf, ANNOTATION/VEP/BC1217.html, ANNOTATION/VEP/470.html, ANNOTATION/VEP/MTG$
    conda-env: /scratch/moldach/MADDOG/VCF-FILES/biostars439754/.snakemake/conda/f16fdb5f

RuleException:
CalledProcessError in line 393 of /scratch/moldach/MADDOG/VCF-FILES/biostars439754/Snakefile:
Command 'source /home/moldach/miniconda3/bin/activate '/scratch/moldach/MADDOG/VCF-FILES/biostars439754/.snakemake/conda/f16fdb5f'; set -euo pipefail;  python /scratch/moldach/MADDOG/VCF-FILE$
  File "/scratch/moldach/MADDOG/VCF-FILES/biostars439754/Snakefile", line 393, in __rule_variant_annotation
  File "/cvmfs/soft.computecanada.ca/easybuild/software/2017/Core/python/3.8.0/lib/python3.8/concurrent/futures/thread.py", line 57, in run
Shutting down, this might take some time.
Exiting because a job execution failed. Look above for error message

明确

这是我在尝试包装器之前运行 VEP 的代码,所以我想保留类似的选项(例如离线,):

vep \
        -i {input.sample} \
        --species "caenorhabditis_elegans" \
        --format "vcf" \
        --everything \
        --cache_version 100 \
        --offline \
        --force_overwrite \
        --fasta {input.ref} \
        --gff {input.annot} \
        --tab \
        --variant_class \
        --regulatory \
        --show_ref_allele \
        --numbers \
        --symbol \
        --protein \
        -o {params.sample}

更新 2:

是的,使用expand() 是问题所在。我记得这就是为什么我喜欢使用lambdaos.path.join() 作为规则input/output 除了你在rule all 中提到的:

以下似乎解决了这个问题,尽管我遇到了一个新问题:

rule variant_annotation:
    input:
        calls= lambda wildcards: getVCFs(wildcards.sample),
        cache="resources/vep/cache",
        plugins="resources/vep/plugins",
    output:
        calls=os.path.join(dirs_dict["ANNOT_DIR"],config["ANNOT_TOOL"],"{sample}.annotated.vcf"),
        stats=os.path.join(dirs_dict["ANNOT_DIR"],config["ANNOT_TOOL"],"{sample}.html")

不知道为什么我会收到 unknown file type 错误 - 正如我所提到的,这是首先使用具有相同输入数据的完整命令进行测试的?

Activating conda environment: /scratch/moldach/MADDOG/VCF-FILES/biostars439754/.snakemake/conda/f16fdb5f
Failed to open VARIANT_CALLING/varscan/MTG109_sorted_dedupped_snp_varscan.vcf: unknown file type
Possible precedence issue with control flow operator at /scratch/moldach/MADDOG/VCF-FILES/biostars439754/.snakemake/conda/f16fdb5f/lib/site_perl/5.26.2/Bio/DB/IndexedBase.pm line 805.
Traceback (most recent call last):
  File "/scratch/moldach/MADDOG/VCF-FILES/biostars439754/.snakemake/scripts/tmpsh388k23.wrapper.py", line 44, in <module>
    "(bcftools view {snakemake.input.calls} | "
  File "/home/moldach/bin/snakemake/lib/python3.8/site-packages/snakemake/shell.py", line 156, in __new__
    raise sp.CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'set -euo pipefail;  (bcftools view VARIANT_CALLING/varscan/MTG109_sorted_dedupped_snp_varscan.vcf | vep --everything --fork 4 --format vcf --vcf --cach$
[Thu Aug 13 09:02:22 2020]

更新 3:

bcftools view 正在从samtools mpileup/varscan pileup2snp 的输出中发出警告:

def getDeduppedBamsIndex(sample):
  return(list(os.path.join(aligns_dict[sample],"{0}.sorted.dedupped.bam.bai".format(sample,pair)) for pair in ['']))

rule mpilup:
    input:
    bam=lambda wildcards: getDeduppedBams(wildcards.sample),
        reference_genome=os.path.join(dirs_dict["REF_DIR"],config["REF_GENOME"])
    output:
    os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_{contig}.mpileup.gz"),
    log:
        os.path.join(dirs_dict["LOG_DIR"],config["CALLING_TOOL"],"{sample}_{contig}_samtools_mpileup.log")
    params:
        extra=lambda wc: "-r {}".format(wc.contig)
    resources:
    mem = 1000,
        time = 30
    wrapper:
    "0.65.0/bio/samtools/mpileup"

rule mpileup_to_vcf:
    input:
    os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_{contig}.mpileup.gz"),
    output:
    os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_{contig}.vcf")
    message:
    "Calling SNP with Varscan2"
    threads:
    2 # Keep threading value to one for unzipped mpileup input
          # Set it to two for zipped mipileup files
    log:
        os.path.join(dirs_dict["LOG_DIR"],config["CALLING_TOOL"],"varscan_{sample}_{contig}.log")
    resources:
    mem = 1000,
        time = 30
    wrapper:
    "0.65.0/bio/varscan/mpileup2snp"

rule vcf_merge:
    input:
    os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_I.vcf"),
        os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_II.vcf"),
        os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_III.vcf"),
        os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_IV.vcf"),
        os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_V.vcf"),
        os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_X.vcf"),
        os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}_MtDNA.vcf")
    output:
    os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"],"{sample}.vcf")
    log: os.path.join(dirs_dict["LOG_DIR"],config["CALLING_TOOL"],"{sample}_vcf-merge.log")
    resources:
    mem = 1000,
        time = 10
    threads: 1
    message: """--- Merge VarScan by Chromosome."""
    shell: """
    awk 'FNR==1 && NR!=1 {{ while (/^<header>/) getline; }} 1 {{print}} ' {input} > {output}
        """

calling_dir = os.path.join(dirs_dict["CALLING_DIR"],config["CALLING_TOOL"])
callings_locations = [calling_dir] * len_samples
callings_dict = dict(zip(sample_names, callings_locations))

def getVCFs(sample):
  return(list(os.path.join(callings_dict[sample],"{0}.vcf".format(sample,pair)) for pair in ['']))

rule annotate_variants:
    input:
    calls=lambda wildcards: getVCFs(wildcards.sample),
        cache="resources/vep/cache",
        plugins="resources/vep/plugins",
    output:
    calls="{sample}.annotated.vcf",
        stats="{sample}.html"
    params:
    # Pass a list of plugins to use, see https://www.ensembl.org/info/docs/tools/vep/script/vep_plugins.html
        # Plugin args can be added as well, e.g. via an entry "MyPlugin,1,FOO", see docs.
        plugins=["LoFtool"],
        extra="--everything"  # optional: extra arguments
    log:
        "logs/vep/{sample}.log"
    threads: 4
    resources:
    time=30,
        mem=5000
    wrapper:
    "0.65.0/bio/vep/annotate"

如果我在输出上运行bcftools view,我会收到错误:

$ bcftools view variant_calling/varscan/MTG324.vcf 
Failed to read from variant_calling/varscan/MTG324.vcf: unknown file type

【问题讨论】:

    标签: wrapper snakemake vcf-variant-call-format


    【解决方案1】:
    1. 关于使用扩展与通配符,这根本不重要。 biostar 的帖子只是建议如何保持可读性。在蛇形/程序化方面,您如何定义输入并不重要,只要它是正确的。

    2. 有关资源的抱怨是您在规则variant_annotation 的输入中定义resources/vep/cacheresources/vep/plugins 是能够运行variant_annotation 的必要输入。有了这个错误,snakemake 有效地告诉您这些文件不存在,因此它无法为您运行规则。

    3. 当我查看文档中的代码时,似乎缓存目录作为输入应该定义您使用的基因组:

    entrypath = get_only_child_dir(get_only_child_dir(Path(cache)))
    species = entrypath.parent.name
    release, build = entrypath.name.split("_")
    

    【讨论】:

      【解决方案2】:

      除了 Maarten 所说的(resources/vep/cacheresources/vep/plugins 只是所需输入的示例路径,它还定义了您要使用的基因组和版本),您可以使用另外两个轻松获取缓存和插件目录在你的 Snakefile 中使用这些包装器的简单规则:

      编辑

      很高兴这解决了您的第一个问题。 第二个错误似乎来自输出中的expand。 我是否正确理解您想要一一注释所有 vcfs?所以输入是{sample}.vcf,输出是{sample}.annotated.vcf

      如果是这种情况,您可能不想在此规则中使用expand

      我也不确定,为什么您需要在这里将 {ANNOT_DIR}{ANNOT_TOOL} 用作通配符。我想如果您使用 VEP,ANNOT_TOOL 将始终为 VEPANNOT_DIR 将始终为 ANNOTATION? 然后,您可以直接在输出中将它们写为ANNOTATION/VEP/{sample}.annotated.vcf

      {CALLING_DIR} 也是一样,我想这将始终是同一个目录,对吧?我知道如果您在样本上使用多个调用者,{CALLING_TOOL} 可能有多个值。

      如果我仍然步入正轨,您可以在使用 VEP 时扩展两个通配符,{sample}{CALLING_TOOL}

      随便写

      input:
          calls: 'CALLDIR/{CALLING_TOOL}/{sample}_sorted_dedupped_snp_varscan.vcf',
          cache="resources/vep/cache",
          plugins="resources/vep/plugins"
      output:
          calls='ANNOTATION/VEP/{CALLING_TOOL}/{sample}.annotated.vcf',
          stats='ANNOTATION/VEP/{CALLING_TOOL}/{sample}.html'
      

      expand 属于您的规则 all 或任何其他同时使用所有带注释的 vcfs 的目标规则,……。像这样:

      rule all:
          input: expand('ANNOTATION/VEP/{CALLING_TOOL}/{sample}.annotated.vcf', CALLING_TOOL=config["CALLING_TOOL"], sample=sample_names)
      

      然后,variant_annotation 规则将运行您在规则 all 中扩展的所有示例。

      我希望我正确地理解了你的想法,这会有所帮助。

      EDIT2

      好的,看来我们快完成了。你得到的错误是由bcftools view 抛出的 - 它表明 vcf 可能有问题。

      您是否尝试在 Snakefile 之外使用您的 vcf 使用 bcftools view?如果在此规则期间出现问题,或者 vcf 是否已经存在某种问题,这会给我们一个想法。

      【讨论】:

      • 非常感谢您对这两个包装器@jafors 的建议。这为我解决了问题 #1
      • 第二个建议,在规则 input/output 中不使用 expand() 解决了问题 #2。我觉得这个unknown file type可能是最后一期了!
      猜你喜欢
      • 2020-04-16
      • 1970-01-01
      • 2012-09-27
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-21
      • 2022-06-13
      相关资源
      最近更新 更多