global_rules.snakefile 4.36 KB
Newer Older
1
2
3
4
5
rule prepare_report:
    input:
        *prepare_report_inputs(),
    output:
        *prepare_report_outputs(),
6
7
        config_multiqc = config["results_dir"] + "/config_multiqc.yaml",
        params_tab = config["results_dir"] + "/params_tab_mqc.csv"
8
    params:
mmassaviol's avatar
mmassaviol committed
9
        params_file = workflow.overwrite_configfile,
10
        results_dir = config["results_dir"]
11
12
13
    log:
        config["results_dir"]+"/logs/prepare_report_log.txt"
    run:
14
        # Specific scripts for each tool
15
16
        for script in prepare_report_scripts():
            shell("Rscript "+script+" {params.params_file} |& tee {log}")
17
        # Outputs files for Multiqc report
18
19
20
21
22
23
24
        outfile = config["results_dir"] + "/outputs_mqc.csv"
        head = """
# description: 'This is the list of the files generated by each step of the workflow'
# section_name: 'Workflow outputs'
"""
        with open(outfile,"w") as out:
            out.write(head)
25
26
            out.write("step\ttool\tfile\tdescription\n")#\tname
            for step in STEPS:
27
                tool = config[step["name"]]
28
29
                i=1
                for command in OUTPUTS[tool]:
mmassaviol's avatar
mmassaviol committed
30
                    if ("SeOrPe" not in config.keys() or (config["SeOrPe"] == "SE" and not("_PE" in command)) or (config["SeOrPe"] == "PE" and not("_SE" in command))):
31
                        outputs = OUTPUTS[tool][command]
32
                        for files in outputs:
33
34
                            name = files["file"] if 'file' in files.keys() else files["directory"]
                            path = config[command+"_output_dir"] + "/" + name #config["results_dir"] +"/"+
35
                            out.write(str(i)+"-"+step["title"]+"\t"+tool+"\t"+path+"\t"+files["description"]+"\n")#"\t"+files["name"]+
36
                            i+=1
37
38
        
        # Params list for Multiqc report
39
40
        params_list = "params_name\tdescription\tvalue\n"
        head = """# description: 'This is the list of the parameters for each rule'
41
42
43
44
45
# section_name: 'Workflow parameters'
"""
        for step in STEPS:
            tool = config[step["name"]]
            for key, value in config.items():    
mmassaviol's avatar
mmassaviol committed
46
                if (tool in key and tool != "null") or (key in ["results_dir","sample_dir","sample_suffix","SeOrPe"]) and ("SeOrPe" not in config.keys() or (config["SeOrPe"] == "SE" and not("_PE" in command)) or (config["SeOrPe"] == "PE" and not("_SE" in command))):
47
48
49
50
51
                    if (key in PARAMS_INFO.keys() and "label" in PARAMS_INFO[key].keys()):
                        description = PARAMS_INFO[key]["label"]
                    else:
                        description = ''
                    params_list += key + "\t'" + description + "'\t'" + str(value) + "'\n"
52
53
54
55

        with open(output.params_tab,"w") as out:
            out.write(head)
            out.write(params_list)
56

57
        # Config for Multiqc report
58
59
        shell("python3 /workflow/generate_multiqc_config.py {params.params_file} {output.config_multiqc}")

60
61
62
rule multiqc:
    input:
        multiqc_inputs(),
63
        config_multiqc = config["results_dir"] + "/config_multiqc.yaml"
64
65
66
67
68
69
70
    output:
        multiqc_dir = directory(config["results_dir"]+"/multiqc_data")
    params:
        output_dir = config["results_dir"]
    log:
        config["results_dir"]+'/logs/multiqc/multiqc_log.txt'
    shell:
71
        "multiqc --config {input.config_multiqc} -f {params.output_dir} "
72
73
74
75
76
        "-o {params.output_dir} |& tee {log}"

# Final Snakemake rule waiting for outputs of the final step choosen by user (default all steps)
rule all:
    input:
mmassaviol's avatar
mmassaviol committed
77
        workflow_outputs("all")
78
79
80
81
82
83
    output:
        Snakefile = config["results_dir"]+"/workflow/Snakefile",
        get_samples = config["results_dir"]+"/workflow/get_samples.py",
        scripts = directory(config["results_dir"]+"/workflow/scripts"),
        params = config["results_dir"]+"/workflow/params.yml"
    params:
mmassaviol's avatar
mmassaviol committed
84
        params_file = workflow.overwrite_configfile,
85
86
87
88
89
90
91
    shell:
        "cp /workflow/Snakefile {output.Snakefile} && "
        "cp /workflow/get_samples.py {output.get_samples} && "
        "cp -r /workflow/scripts {output.scripts} && "
        "cp {params.params_file} {output.params}"

onsuccess:
mmassaviol's avatar
mmassaviol committed
92
    print("Workflow finished with SUCCESS")
93
94
95
    shell("touch "+config["results_dir"]+"/logs/workflow_end.ok")

onerror:
mmassaviol's avatar
mmassaviol committed
96
    print("An ERROR occurred")
97
98
    shell("cat {log} > "+config["results_dir"]+"/logs/workflow_end.error")
    #shell("mail -s "an error occurred" youremail@provider.com < {log}")