首页 > 解决方案 > 如何使用输出目录来聚合文件(并接收更多信息错误消息)?

问题描述

我试图解决的总体问题是一种在我正在构建的 QC 管道的每个步骤中计算每个文件中存在的读取次数的方法。我有一个过去使用过的 shell 脚本,它接收一个目录并输出每个文件的读取次数。由于我希望使用目录作为输入,因此我尝试遵循 Rasmus 在这篇文章中列出的格式:

https://bitbucket.org/snakemake/snakemake/issues/961/rule-with-folder-as-input-and-output

以下是管道中较早创建的一些示例输入:

$ ls -1 cut_reads/
97_R1_cut.fastq.gz
97_R2_cut.fastq.gz
98_R1_cut.fastq.gz
98_R2_cut.fastq.gz
99_R1_cut.fastq.gz
99_R2_cut.fastq.gz

还有一个简化的 Snakefile,首先通过在新目录中创建符号链接来聚合所有读取,然后使用该目录作为读取计数 shell 脚本的输入:

import os

configfile: "config.yaml"

rule all:
    input:
        "read_counts/read_counts.txt"

rule agg_count:
    input:
        cut_reads = expand("cut_reads/{sample}_{rdir}_cut.fastq.gz", rdir=["R1", "R2"], sample=config["forward_reads"])
    output:
        cut_dir = directory("read_counts/cut_reads")
    run:
        os.makedir(output.cut_dir)
        for read in input.cut_reads:
            abspath = os.path.abspath(read)       
            shell("ln -s {abspath} {output.cut_dir}")

 rule count_reads:
    input:
        cut_reads = "read_counts/cut_reads"
    output:
        "read_counts/read_counts.txt"
    shell:
        '''
        readcounts.sh {input.cut_reads} >> {output}
        '''

在试运行中一切都很好,但是当我尝试实际执行它时,我收到一条相当神秘的错误消息:

Building DAG of jobs...
Using shell: /bin/bash
Provided cores: 1
Rules claiming more threads will be scaled down.
Job counts:
    count   jobs
    1   agg_count
    1   all
    1   count_reads
    3

[Tue Jun 18 11:31:22 2019]
rule agg_count:
    input: cut_reads/99_R1_cut.fastq.gz, cut_reads/98_R1_cut.fastq.gz, cut_reads/97_R1_cut.fastq.gz, cut_reads/99_R2_cut.fastq.gz, cut_reads/98_R2_cut.fastq.gz, cut_reads/97_R2_cut.fastq.gz
output: read_counts/cut_reads
    jobid: 2

 Job counts:
    count   jobs
    1   agg_count
    1
[Tue Jun 18 11:31:22 2019]
Error in rule agg_count:
    jobid: 0
    output: read_counts/cut_reads

Exiting because a job execution failed. Look above for error message
Shutting down, this might take some time.
Exiting because a job execution failed. Look above for error message
Complete log: /home/douglas/snakemake/scrap_directory/.snakemake/log/2019-06-18T113122.202962.snakemake.log

read_counts/已创建,但里面没有cut_reads/目录。完整日志中不存在其他错误消息。任何人都知道出了什么问题或如何接收更具描述性的错误消息?

我也(显然)对snakemake相当陌生,所以可能有更好的方法来完成整个过程。任何帮助深表感谢!

标签: snakemake

解决方案


......这是一个错字。典型的。os.makedir(output.cut_dir)应该是os.makedirs(output.cut_dir)。我仍然很好奇为什么当您尝试运行时,snakemake 不显示 AttributeError python throws:

AttributeError: module 'os' has no attribute 'makedir'

是否在某个地方存储或可以访问以防止将来出现问题?


推荐阅读