generate_multiqc_config.py 4.17 KB
Newer Older
1
2
import re
import sys
mmassaviol's avatar
mmassaviol committed
3
from tools import read_yaml
4
5
6

config = read_yaml(sys.argv[1])

7
8
9
10
11
def files_or_dirs_to_ignore():
    # files
    res = "fn_ignore_files:\n"
    file_ignore = ["*.fa","*.fasta","*.fa.gz","*.fasta.gz","*.fq","*.fastq","*.fq.gz","*.fastq.gz","*.sam","*.bam","*.gtf","*.gtf.gz","*.vcf","*.vcf.gz"]
    for file in file_ignore:
mmassaviol's avatar
mmassaviol committed
12
        res += "  - '" + file + "'\n"
13
14
15
16
17

    res += "\n"
    res += "fn_ignore_dirs:\n"
    dirs_ignore = ["workflow"]
    for dir in dirs_ignore:
mmassaviol's avatar
mmassaviol committed
18
        res += "  - '" + dir + "'\n"
19
20
21
22
23

    res += "\n"

    return res

24
def module_order():
mmassaviol's avatar
mmassaviol committed
25
    res = ""
26
27
    for step in config["steps"]:
        tool = config["params"][step["name"]]
mmassaviol's avatar
mmassaviol committed
28
        print(tool)
29
30
31
32
33
34
35
36
        if (config["multiqc"][tool] != "custom"):
            res += "  - " + config["multiqc"][tool] + ":\n"
            res += "      name: " + step["title"] + " (" + tool + ")\n"
            res += "      anchor: " + step["name"] + "__" + config["multiqc"][tool] + "\n"
            res += "      path_filters:\n"
            for rule in config["outputs"][step["name"] + "__" + tool].keys():
                res += "        - '*" + config["params"][rule + "_output_dir"] + "/*'\n" # limit search to tool output dir
                res += "        - '*/logs/" + config["params"][rule + "_output_dir"] + "/*'\n" # and tool logs
mmassaviol's avatar
mmassaviol committed
37
38
    # dont put module order if empty
    if res != "" : res = "module_order:\n" + res
39
40
    return res

41
def report_section_order():
42
    res = "report_section_order:\n"
43
    res += "  Rule_graph:\n" 
44
    res += "    order: 990\n"
45
    res += "  params_tab:\n" 
mmassaviol's avatar
mmassaviol committed
46
    res += "    order: -960\n"
47
    res += "  outputs:\n" 
mmassaviol's avatar
mmassaviol committed
48
    res += "    order: -970\n"
mmassaviol's avatar
mmassaviol committed
49
    res += "  Tools_version:\n" 
mmassaviol's avatar
mmassaviol committed
50
    res += "    order: -980\n"
51
    res += "  Citations:\n" 
mmassaviol's avatar
mmassaviol committed
52
53
    res += "    order: -990\n"
    res += "  Run_Summary:\n" 
54
    res += "    order: -1000\n"
mmassaviol's avatar
mmassaviol committed
55
    cpt = 980
56
    for step in config["steps"]:
57
        tool = config["params"][step["name"]]
58
        if (config["multiqc"][tool] != "custom"):
59
            res += "  " + step["name"] + "__" + config["multiqc"][tool] + ":\n"
60
61
            res += "    " + "order: " + str(cpt) + "\n"
            cpt += -10
mmassaviol's avatar
mmassaviol committed
62
        for rule in config["outputs"][step["name"] + "__" + tool]:
mmassaviol's avatar
mmassaviol committed
63
            if ("SeOrPe" not in config.keys() or (config["params"]["SeOrPe"] == "SE" and not("_PE" in rule)) or (config["params"]["SeOrPe"] == "PE" and not("_SE" in rule))):
mmassaviol's avatar
mmassaviol committed
64
                for output in config["outputs"][step["name"] + "__" + tool][rule]:
65
                    if("file" in output.keys() and "mqc" in output["file"] and '{' not in output["file"]): # case of dynamic files ({wildcard}_mqc.png) to deal with
66
67
68
69
                        section = re.sub('\_mqc.*$', '', output["file"])
                        res += "  " + section + ":\n" 
                        res += "    " + "order: " + str(cpt) + "\n"
                        cpt += -10
70
71
72
73
74
75
76
77
78
79
80
81
                if step["name"] + "__" + tool in config["prepare_report_outputs"]:
                    if isinstance(config["prepare_report_outputs"][step["name"] + "__" + tool], list):
                        for output in config["prepare_report_outputs"][step["name"] + "__" + tool]:
                            section = re.sub('\_mqc.*$', '', output)
                            res += "  " + section + ":\n" 
                            res += "    " + "order: " + str(cpt) + "\n"
                            cpt += -10
                    else:
                        section = re.sub('\_mqc.*$', '', config["prepare_report_outputs"][step["name"] + "__" + tool])
                        res += "  " + step["name"] + "__" + section + ":\n" 
                        res += "    " + "order: " + str(cpt) + "\n"
                        cpt += -10
82
83
84
    return res

def main():
85
    res = "skip_generalstats: true\n\n"
khalid's avatar
khalid committed
86
87
88
89
90
    res += "report_comment: '" + config["params"]["memo"] +"'\n\n"
    res += "custom_logo: /workflow/mbb.png\n\n"
    res += "custom_logo_url: https://mbb.univ-montp2.fr\n\n"
    res += "custom_logo_title: MBB platform\n\n"

91
92
    res += module_order() + "\n\n"
    res += report_section_order() + "\n\n"
93
    res += files_or_dirs_to_ignore()
94
95
96
97
98
99
100

    with open(sys.argv[2],"w") as out:
        out.write(res)

if __name__ == "__main__":
    # execute only if run as a script
    main()