-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
200 lines (174 loc) · 7.09 KB
/
Snakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# Loading config file
configfile: "config.yaml"
# Functions to get output and some parameters
def get_contrast(wildcards):
return config["contrasts"][wildcards.contrast]
def get_pca_output(wildcards):
pca_output = []
if config["dge_method"] == "deseq2":
pca_output = rules.pca_deseq2.output
if config["dge_method"] == "limma":
pca_output = rules.pca_limma.output
return pca_output
def get_deseq2_output(wildcards):
deseq2_output = []
if config["onlypca"] == False:
if config["dge_method"] == "deseq2":
deseq2_output = expand(rules.dge_deseq2.output, contrast = config["contrasts"])
return deseq2_output
def get_limma_output(wildcards):
limma_output = []
if config["onlypca"] == False:
if config["dge_method"] == "limma":
limma_output = expand(rules.dge_limma.output, contrast = config["contrasts"])
return limma_output
def get_ora_output(wildcards):
ora_output = []
if config["onlypca"] == False:
if config["pathway_method"] == "both" or config["pathway_method"] == "gprofiler":
ora_output = expand(rules.ora.output, contrast = config["contrasts"])
return ora_output
def get_fgsea_output(wildcards):
fgsea_output = []
if config["onlypca"] == False:
if config["pathway_method"] == "both" or config["pathway_method"] == "fgsea":
fgsea_output = expand(rules.fgsea.output, contrast = config["contrasts"])
return fgsea_output
# Rules to include
"""# Including rules
include: "rules/common.smk"
include: "rules/trim.smk"
include: "rules/map.smk"
include: "rules/quant.smk"
# Setting targets
rule all:
input:
expand(config['path']['map']+"/{FLI}.Aligned.sortedByCoord.out.bam",FLI=FLI),
expand(config['path']['quant']+"/{FLI}.genes.results",FLI=FLI),
expand(config['path']['quant']+"/{FLI}.isoforms.results",FLI=FLI),
config['project']+".isoforms.tsv",
config['project']+".genes.tsv"""
# Target rule
rule all:
input:
get_pca_output,
get_deseq2_output,
get_limma_output,
get_ora_output,
get_fgsea_output
# Other rules (to be put in other files)
if config["gmt"] is not None:
rule fgsea:
input:
deg_results = config["path"]["dge"]+"/{contrast}/{contrast}_deg_results.txt",
gmt = config["gmt"],
output:
fgsea_pdf = config["path"]["dge"]+"/{contrast}/{contrast}_fgsea.pdf",
fgsea_main_pathways_pdf = config["path"]["dge"]+"/{contrast}/{contrast}_fgsea_main_pathways.pdf",
fgsea = config["path"]["dge"]+"/{contrast}/{contrast}_fgsea.tsv"
script:
"scripts/fgsea.R"
if config["gmt"] is None:
from datetime import datetime
current_date = datetime.now().strftime("%Y_%m_%d")
rule get_reactome_pathways:
output:
reactome = temp(config["path"]["dge"]+"/ensemble2reactome.txt")
shell:
"echo 'Downloading patwhays from reactome, it may take a while' &&"
"GMT_URL=https://reactome.org/download/current/Ensembl2Reactome_All_Levels.txt &&"
"wget $GMT_URL -O {output} && unset $GMT_URL"
rule make_gmt:
input:
reactome = config["path"]["dge"]+"/ensemble2reactome.txt"
output:
gmt = config["path"]["dge"]+f"/ensemble2reactome_{current_date}.gmt"
script:
"scripts/create_gmt.py"
rule fgsea:
input:
deg_results = config["path"]["dge"]+"/{contrast}/{contrast}_deg_results.txt",
gmt = config["path"]["dge"]+f"/ensemble2reactome_{current_date}.gmt"
output:
fgsea_pdf = config["path"]["dge"]+"/{contrast}/{contrast}_fgsea.pdf",
fgsea_main_pathways_pdf = config["path"]["dge"]+"/{contrast}/{contrast}_main_patwhays_fgsea.pdf",
fgsea = config["path"]["dge"]+"/{contrast}/{contrast}_fgsea.tsv"
script:
"scripts/fgsea.R"
rule ora:
input:
deg_list = config["path"]["dge"]+"/{contrast}/{contrast}_deg_list.txt"
output:
ora = config["path"]["dge"]+"/{contrast}/{contrast}_ora.table"
script:
"scripts/gprofiler.R"
# Selecting the DEGs.
if config["dge_method"] == "deseq2":
rule select_deg_deseq2:
input:
deg_results = config["path"]["dge"]+"/{contrast}/{contrast}_deg_results.txt"
output:
deg_list = temp(config["path"]["dge"]+"/{contrast}/{contrast}_deg_list.txt"),
shell:
"cat {input} | awk '{{if($NF < 0.05 && sqrt($4^2) > log(1.5)/log(2))"
" print $1}}' > {output}"
if config["dge_method"] == "limma":
rule select_deg_limma:
input:
deg_results = config["path"]["dge"]+"/{contrast}/{contrast}_deg_results.txt"
output:
deg_list = temp(config["path"]["dge"]+"/{contrast}/{contrast}_deg_list.txt"),
shell:
"cat {input} | awk '{{if($6 < 0.05 && sqrt($2^2) > log(1.5)/log(2))"
" print $1}}' > {output}"
# Running the PCA
if config["dge_method"] == "deseq2":
rule pca_deseq2:
input:
counts = config["counts"],
info = config["info"]
output:
pcas = config["path"]["dge"]+"/PCA.pdf",
sampletosample = config["path"]["dge"]+"/sampletosample_heatmap.pdf",
rlog = config["path"]["dge"]+"/rlogMat.txt",
pc_contribution = config["path"]["dge"]+"/pc_contribution.txt",
dds = temp(config["path"]["dge"]+"/dds"),
norm_counts = config["path"]["dge"]+"/norm_counts.txt"
script:
"scripts/PCA_deseq2.R"
rule dge_deseq2:
input:
dds = config["path"]["dge"]+"/dds",
rlogmat = config["path"]["dge"]+"/rlogMat.txt",
output:
stats = config["path"]["dge"]+"/{contrast}/{contrast}_stats.txt",
deg_results = config["path"]["dge"]+"/{contrast}/{contrast}_deg_results.txt",
topDEgenes_heatmap = config["path"]["dge"]+"/{contrast}/{contrast}_top50DEgenes_heatmap.pdf",
heatmap_custom = config["path"]["dge"]+"/{contrast}/{contrast}_topgenes_heatmap.tiff",
params:
contrast = get_contrast,
script:
"scripts/deseq2.R"
if config["dge_method"] == "limma":
rule pca_limma:
input:
counts = config["counts"],
info = config["info"]
output:
sampletosample = config["path"]["dge"]+"/sampletosample_heatmap.pdf",
pcas = config["path"]["dge"]+"/PCA.pdf",
pc_contribution = config["path"]["dge"]+"/pc_contribution.txt",
dge = config["path"]["dge"]+"/dge"
script:
"scripts/PCA_limma.R"
rule dge_limma:
input:
dge = config["path"]["dge"]+"/dge"
output:
expand(config["path"]["dge"]+"/{contrast}/{contrast}_deg_results.txt",
contrast = config["contrasts"]),
expand(config["path"]["dge"]+"/{contrast}/{contrast}_heatmap.pdf",
contrast = config["contrasts"]),
logcpm = config["path"]["dge"]+"/logCPM.txt"
script:
"scripts/limma_voom.R"