Snakefile 6.82 KB
Newer Older
van den Berg's avatar
van den Berg committed
1
from os import path
bow's avatar
bow committed
2

van den Berg's avatar
van den Berg committed
3
4
5
# We need the QC-seq output
include: "../qc-seq/Snakefile"

6
7
8
localrules: combine_plots, fusioncatcher_cp, intersect_fusions, plot_cp, plot_isect, plot_sf star_fusion_cp, subset_sf


9
10
containers = {
    "debian": "docker://debian:buster-slim",
van den Berg's avatar
van den Berg committed
11
    "fsnviz": "docker://quay.io/biocontainers/fsnviz:0.3.0--py_3",
12
    "fuma": "docker://quay.io/biocontainers/fuma:3.0.5--py27h24bf2e0_1",
13
    "fusioncatcher": "docker://quay.io/biocontainers/fusioncatcher:1.20--2",
van den Berg's avatar
van den Berg committed
14
    "star-fusion": "docker://quay.io/biocontainers/star-fusion:1.6.0--1",
van den Berg's avatar
van den Berg committed
15
    "hamlet-scripts": "docker://lumc/hamlet-scripts:0.2"
16
}
17

van den Berg's avatar
van den Berg committed
18
19
20
21
22
23
24
25
26
27
settings=config["settings"]

# Set the default settings
def set_default(key, value):
    """ Set default value for settings """
    if key not in settings:
        settings[key] = value

set_default("sf_subset_script", srcdir(path.join("scripts", "subset_sf.py")))
set_default("plot_combined_script", srcdir(path.join("scripts", "combine_svgs.py")))
bow's avatar
bow committed
28

van den Berg's avatar
van den Berg committed
29
30
rule all_fusion:
    input:
van den Berg's avatar
van den Berg committed
31
32
33
34
35
36
37
38
39
40
41
42
        star_predictions=expand("{sample}/fusion/star-fusion/star-fusion.fusion_predictions.tsv", sample=config["samples"]),
        star_final=expand("{sample}/fusion/{sample}.star-fusion", sample=config["samples"]),
        fusion_catcher=expand("{sample}/fusion/{sample}.fusioncatcher", sample=config["samples"]),
        fuma=expand("{sample}/fusion/{sample}.fuma", sample=config["samples"]),
        subset=expand("{sample}/fusion/{sample}.sf-isect", sample=config["samples"]),
        is_svg=expand("{sample}/fusion/{sample}.sf-isect-circos/fsnviz.svg", sample=config["samples"]),
        is_png=expand("{sample}/fusion/{sample}.sf-isect-circos/fsnviz.png", sample=config["samples"]),
        sf_svg=expand("{sample}/fusion/{sample}.star-fusion-circos/fsnviz.svg", sample=config["samples"]),
        sf_png=expand("{sample}/fusion/{sample}.star-fusion-circos/fsnviz.png", sample=config["samples"]),
        fc_svg=expand("{sample}/fusion/{sample}.fusioncatcher-circos/fsnviz.svg", sample=config["samples"]),
        fc_png=expand("{sample}/fusion/{sample}.fusioncatcher-circos/fsnviz.png", sample=config["samples"]),
        combined_svg=expand("{sample}/fusion/{sample}.fusions-combined.svg", sample=config["samples"]),
van den Berg's avatar
van den Berg committed
43

bow's avatar
bow committed
44
45
rule star_fusion:
    input:
van den Berg's avatar
van den Berg committed
46
47
48
        fq1="{sample}/{sample}-R1.fq.gz",
        fq2="{sample}/{sample}-R2.fq.gz",
        lib=settings["genome_star_fusion_lib"]
van den Berg's avatar
van den Berg committed
49
    params:
van den Berg's avatar
van den Berg committed
50
        folder="{sample}/fusion/star-fusion"
bow's avatar
bow committed
51
    output:
van den Berg's avatar
van den Berg committed
52
        txt="{sample}/fusion/star-fusion/star-fusion.fusion_predictions.tsv"
bow's avatar
bow committed
53
    threads: 8
54
    singularity: containers["star-fusion"]
bow's avatar
bow committed
55
    shell:
van den Berg's avatar
van den Berg committed
56
        "(rm -rf {params.folder}"
57
        " && STAR-Fusion --genome_lib_dir {input.lib}"
van den Berg's avatar
van den Berg committed
58
        "   --output_dir {params.folder}"
59
        "   --left_fq {input.fq1} --right_fq {input.fq2})"
bow's avatar
bow committed
60
61
62

rule star_fusion_cp:
    input:
van den Berg's avatar
van den Berg committed
63
        txt="{sample}/fusion/star-fusion/star-fusion.fusion_predictions.tsv",
bow's avatar
bow committed
64
    output:
van den Berg's avatar
van den Berg committed
65
        txt="{sample}/fusion/{sample}.star-fusion",
66
    singularity: containers["debian"]
bow's avatar
bow committed
67
68
    shell:
        "cp {input.txt} {output.txt}"
bow's avatar
bow committed
69

70
71
rule plot_sf:
    input:
van den Berg's avatar
van den Berg committed
72
        txt="{sample}/fusion/{sample}.star-fusion",
73
    output:
van den Berg's avatar
van den Berg committed
74
75
        svg="{sample}/fusion/{sample}.star-fusion-circos/fsnviz.svg",
        png="{sample}/fusion/{sample}.star-fusion-circos/fsnviz.png",
76
    singularity: containers["fsnviz"]
77
    shell:
bow's avatar
bow committed
78
79
        "PERL5LIB=\"\" fsnviz --out-dir `dirname {output.svg}` --png"
        " -k human.hg38 star-fusion {input.txt}"
80

bow's avatar
bow committed
81
82
rule plot_cp:
    input:
van den Berg's avatar
van den Berg committed
83
        svg="{sample}/fusion/{sample}.{ext}-circos/fsnviz.svg",
bow's avatar
bow committed
84
    output:
van den Berg's avatar
van den Berg committed
85
        svg="{sample}/fusion/{sample}.{ext}.svg",
van den Berg's avatar
van den Berg committed
86
87
    wildcard_constraints:
        ext="star-fusion|sf-isect|fusioncatcher",
88
    singularity: containers["debian"]
bow's avatar
bow committed
89
90
    shell:
        "cp {input.svg} {output.svg}"
bow's avatar
bow committed
91

van den Berg's avatar
van den Berg committed
92
93
rule fusioncatcher:
    input:
van den Berg's avatar
van den Berg committed
94
95
        fq1="{sample}/{sample}-R1.raw.fq.gz",
        fq2="{sample}/{sample}-R2.raw.fq.gz",
96
    params:
97
98
        data=settings["fusioncatcher_data"],
        max_junctions=1500000
van den Berg's avatar
van den Berg committed
99
    output:
van den Berg's avatar
van den Berg committed
100
        txt="{sample}/fusion/fusioncatcher/final-list_candidate-fusion-genes.txt"
van den Berg's avatar
van den Berg committed
101
    threads: 8
102
    singularity: containers["fusioncatcher"]
van den Berg's avatar
van den Berg committed
103
    shell:
104
        " dir=`dirname {output.txt}` "
105
        " && fusioncatcher.py --threads {threads} -i {input.fq1},{input.fq2} -o ${{dir}}"
106
        " --data {params.data} --limitSjdbInsertNsj {params.max_junctions} || test -f {output.txt}"
107

van den Berg's avatar
van den Berg committed
108
109
rule fusioncatcher_cp:
    input:
van den Berg's avatar
van den Berg committed
110
        txt="{sample}/fusion/fusioncatcher/final-list_candidate-fusion-genes.txt",
van den Berg's avatar
van den Berg committed
111
    output:
van den Berg's avatar
van den Berg committed
112
        txt="{sample}/fusion/{sample}.fusioncatcher",
113
    singularity: containers["debian"]
van den Berg's avatar
van den Berg committed
114
115
    shell:
        "cp {input.txt} {output.txt}"
bow's avatar
bow committed
116

van den Berg's avatar
van den Berg committed
117
118
rule plot_fc:
    input:
van den Berg's avatar
van den Berg committed
119
        txt="{sample}/fusion/{sample}.fusioncatcher",
van den Berg's avatar
van den Berg committed
120
    output:
van den Berg's avatar
van den Berg committed
121
122
        svg="{sample}/fusion/{sample}.fusioncatcher-circos/fsnviz.svg",
        png="{sample}/fusion/{sample}.fusioncatcher-circos/fsnviz.png",
123
    singularity: containers["fsnviz"]
van den Berg's avatar
van den Berg committed
124
125
126
    shell:
        "PERL5LIB=\"\" fsnviz --out-dir `dirname {output.svg}` --png"
        " -k human.hg38 fusioncatcher {input.txt}"
bow's avatar
bow committed
127

van den Berg's avatar
van den Berg committed
128
129
rule intersect_fusions:
    input:
van den Berg's avatar
van den Berg committed
130
131
132
        sf="{sample}/fusion/{sample}.star-fusion",
        fc="{sample}/fusion/{sample}.fusioncatcher",
        bed=settings["transcripts_bed"],
van den Berg's avatar
van den Berg committed
133
    output:
van den Berg's avatar
van den Berg committed
134
        txt="{sample}/fusion/{sample}.fuma",
135
    singularity: containers["fuma"]
van den Berg's avatar
van den Berg committed
136
137
138
139
140
141
    shell:
        "fuma -a hg38:{input.bed} -s"
        " fc-{wildcards.sample}:fusion-catcher_final:{input.fc}"
        " sf-{wildcards.sample}:star-fusion_final:{input.sf}"
        " -l \"fc-{wildcards.sample}:hg38\" \"sf-{wildcards.sample}:hg38\""
        " -f extensive -o -"
142
        " | grep -vE \"FuMa::\""
van den Berg's avatar
van den Berg committed
143
144
145
146
        " > {output.txt}"

rule subset_sf:
    input:
van den Berg's avatar
van den Berg committed
147
148
149
        sf="{sample}/fusion/{sample}.star-fusion",
        isect="{sample}/fusion/{sample}.fuma",
        subset_script=settings["sf_subset_script"],
van den Berg's avatar
van den Berg committed
150
    output:
van den Berg's avatar
van den Berg committed
151
        sf="{sample}/fusion/{sample}.sf-isect",
van den Berg's avatar
van den Berg committed
152
    singularity: containers["hamlet-scripts"]
van den Berg's avatar
van den Berg committed
153
    shell:
van den Berg's avatar
van den Berg committed
154
        "python3 {input.subset_script} {input.isect} {input.sf} > {output.sf} || rm -f {output.sf}"
bow's avatar
bow committed
155

van den Berg's avatar
van den Berg committed
156
157
rule plot_isect:
    input:
van den Berg's avatar
van den Berg committed
158
        txt="{sample}/fusion/{sample}.sf-isect",
van den Berg's avatar
van den Berg committed
159
    output:
van den Berg's avatar
van den Berg committed
160
161
        svg="{sample}/fusion/{sample}.sf-isect-circos/fsnviz.svg",
        png="{sample}/fusion/{sample}.sf-isect-circos/fsnviz.png",
162
    singularity: containers["fsnviz"]
van den Berg's avatar
van den Berg committed
163
164
165
    shell:
        "PERL5LIB=\"\" fsnviz --out-dir `dirname {output.svg}` --png"
        " -k human.hg38 star-fusion {input.txt}"
bow's avatar
bow committed
166

van den Berg's avatar
van den Berg committed
167
168
rule combine_plots:
    input:
van den Berg's avatar
van den Berg committed
169
170
171
172
        sf="{sample}/fusion/{sample}.star-fusion.svg",
        fc="{sample}/fusion/{sample}.fusioncatcher.svg",
        isect="{sample}/fusion/{sample}.sf-isect.svg",
        combine_script=settings["plot_combined_script"]
van den Berg's avatar
van den Berg committed
173
    output:
van den Berg's avatar
van den Berg committed
174
        svg="{sample}/fusion/{sample}.fusions-combined.svg",
van den Berg's avatar
van den Berg committed
175
    singularity: containers["hamlet-scripts"]
van den Berg's avatar
van den Berg committed
176
    shell:
van den Berg's avatar
van den Berg committed
177
        "python3 {input.combine_script}"
van den Berg's avatar
van den Berg committed
178
179
        " 'STAR-Fusion':{input.sf} 'FusionCatcher':{input.fc}"
        " 'Intersection':{input.isect} {output.svg}"