-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
540 lines (488 loc) · 15.5 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
import pandas as pd
from Bio import AlignIO
from pytools.persistent_dict import PersistentDict
### Required output files ###
rule all:
input:
"apr_evolution/sarcopterygii_phylogeny_suppl.treefile",
# "ancestral_reconstruction/ancestral_sequences.faa",
"viz/panels/aprs_conservation.svg",
"viz/panels/aprs_entropy.svg",
"viz/panels/natural_selection_regimes.svg",
"viz/panels/evolutionary_rate_profile.svg",
"viz/panels/aprs_flexibility.svg",
"viz/panels/aprs_flexibility_profiles.svg",
"viz/panels/aprs_impact.svg"
# "mutatex/mutations/apoa1_model0_checked_Repair/LA14/WT_apoa1_model0_checked_Repair_2_4.pd"
### APRs evolution ###
# Get apoa1 protein ortholog sequences from ensembl
rule get_protein_sequences:
input:
output:
"apr_evolution/ensembl_sequences.faa"
shell:
"src/get_ensembl_sequences.py protein {output}"
# Get apoa1 nucleotide ortholog sequences from ensembl
rule get_nucleotide_sequences:
input:
output:
"apr_evolution/ensembl_sequences.fna"
shell:
"src/get_ensembl_sequences.py nucleotide {output}"
# Retain only sequences belonging to sarcopterygii species
rule filter_sarcopterygii_sequences:
input:
"apr_evolution/ensembl_sequences.faa"
output:
"apr_evolution/raw_sarcopterygii_sequences.faa"
shell:
"src/filter_sarcopterygii_sequences.py {input} {output}"
# Remove sequences too short or without start codon
rule filter_low_quality_sequences:
input:
"apr_evolution/raw_sarcopterygii_sequences.faa"
output:
"apr_evolution/sarcopterygii_sequences.faa"
shell:
"src/filter_bad_quality_sequences.py {input} {output}"
# Align protein sequences with MAFFT
rule mafft_protein_alignment:
input:
"apr_evolution/sarcopterygii_sequences.faa"
output:
"apr_evolution/sarcopterygii_mafft.faa"
shell:
"""
mafft --maxiterate 1000 --localpair \
{input} >> {output}
"""
# Infer a protein phylogeny from the sarcopterygii alignment
rule infer_phylogeny:
input:
"apr_evolution/sarcopterygii_mafft.faa"
params:
"apr_evolution/sarcopterygii_phylogeny"
output:
"apr_evolution/sarcopterygii_phylogeny.treefile",
"apr_evolution/sarcopterygii_phylogeny.state"
shell:
"""
iqtree -s {input} --prefix {params} \
--ufboot 1000 --alrt 1000 -nt 4 --ancestral \
-o Xenopus_tropicalis_ENSXETP00000008146,Leptobrachium_leishanense_ENSLLEP00000049402
"""
# Align protein sequences with ClustalO
rule clustalo_protein_alignment:
input:
"apr_evolution/sarcopterygii_sequences.faa"
output:
"apr_evolution/sarcopterygii_clustalo.faa"
shell:
"""
clustalo -i {input} -o {output}
"""
# Prepare a supplementary phylogeny based on the ClustalO alignment
rule infer_supplementary_phylogeny:
input:
"apr_evolution/sarcopterygii_clustalo.faa"
params:
"apr_evolution/sarcopterygii_phylogeny_suppl"
output:
"apr_evolution/sarcopterygii_phylogeny_suppl.treefile",
shell:
"""
iqtree -s {input} --prefix {params} \
--ufboot 1000 --alrt 1000 -nt 4 \
-o Xenopus_tropicalis_ENSXETP00000008146,Leptobrachium_leishanense_ENSLLEP00000049402
"""
# Retain only coding sequences matching the sequences present in the protein dataset
rule filter_cds_ensembl:
input:
"apr_evolution/ensembl_sequences.fna",
"apr_evolution/sarcopterygii_mafft.faa"
output:
"apr_evolution/sarcopterygii_sequences.fna"
shell:
"src/filter_nucleotide_sequences.py {input} > {output}"
# Align nucleotide sequences with PAL2NAL
rule pal2nal_alignment:
input:
"apr_evolution/sarcopterygii_mafft.faa",
"apr_evolution/sarcopterygii_sequences.fna"
output:
"apr_evolution/sarcopterygii_mafft.fna"
shell:
"""
pal2nal.pl {input} -output fasta > {output}
"""
# Trim out highly gapped positions
#rule trim_nucleotide_alignment:
# input:
# "apr_evolution/sarcopterygii_mafft.fna"
# output:
# "apr_evolution/sarcopterygii_mafft_trimmed.fna"
# shell:
# "trimal -in {input} -out {output} -gt 0.05"
# Run FEL analysis
rule fel_analysis:
input:
"apr_evolution/sarcopterygii_mafft.fna",
"apr_evolution/sarcopterygii_phylogeny.treefile"
output:
"apr_evolution/sarcopterygii_fel.json"
shell:
"hyphy fel --alignment {input[0]} --tree {input[1]} --output {output}"
# Run FUBAR analysis
rule fubar_analysis:
input:
"apr_evolution/sarcopterygii_mafft.fna",
"apr_evolution/sarcopterygii_phylogeny.treefile"
output:
"apr_evolution/sarcopterygii_fubar.json"
shell:
"""
hyphy fubar --alignment {input[0]} --tree {input[1]} && \
mv apr_evolution/sarcopterygii_mafft.fna.FUBAR.json {output} && \
rm apr_evolution/sarcopterygii_mafft.fna.FUBAR.cache
"""
# Remove treefile node label for MEME
rule fix_treefile_meme:
input:
"apr_evolution/sarcopterygii_phylogeny.treefile"
output:
"apr_evolution/sarcopterygii_phylogeny_meme.treefile"
shell:
"""
sed -E 's/Node[0-9]*\///g' {input} > {output}
"""
# Run MEME analysis
rule meme_analysis:
input:
"apr_evolution/sarcopterygii_mafft.fna",
"apr_evolution/sarcopterygii_phylogeny_meme.treefile"
output:
"apr_evolution/sarcopterygii_meme.json"
shell:
"""
hyphy meme --alignment {input[0]} --tree {input[1]} --outfile {output} &&\
mv apr_evolution/sarcopterygii_mafft.fna.MEME.json {output}
"""
# Parse FEL JSON results into CSV files
rule parse_fel:
input:
"apr_evolution/sarcopterygii_fel.json",
"apr_evolution/sarcopterygii_mafft.faa"
params:
"Homo_sapiens_ENSP00000364472"
output:
"apr_evolution/sarcopterygii_fel.csv"
shell:
"""
./src/parse_hyphy_fel.py {input} {params}
"""
# Parse FUBAR JSON results into CSV files
rule parse_fubar:
input:
"apr_evolution/sarcopterygii_fubar.json",
"apr_evolution/sarcopterygii_mafft.faa"
params:
"Homo_sapiens_ENSP00000364472"
output:
"apr_evolution/sarcopterygii_fubar.csv"
shell:
"""
./src/parse_hyphy_fubar.py {input} {params}
"""
# Parse MEME JSON results into CSV files
rule parse_meme:
input:
"apr_evolution/sarcopterygii_meme.json",
"apr_evolution/sarcopterygii_mafft.faa"
params:
"Homo_sapiens_ENSP00000364472"
output:
"apr_evolution/sarcopterygii_meme.csv"
shell:
"""
./src/parse_hyphy_meme.py {input} {params}
"""
# Aggregate HyPhy results
rule aggregate_hyphy_results:
input:
"apr_evolution/sarcopterygii_fel.csv",
"apr_evolution/sarcopterygii_fubar.csv",
"apr_evolution/sarcopterygii_meme.csv"
output:
"apr_evolution/hyphy_results.csv"
run :
# Read all inputs as Pandas DataFrames
df_fel = pd.read_csv(input[0])
df_fubar = pd.read_csv(input[1])
df_meme = pd.read_csv(input[2])
# Save columns with the selection regime data
dic = { "FEL": df_fel["Selection_type"],
"FUBAR": df_fubar["Selection_type"],
"MEME": df_meme["Episodic Selection"]}
# Save data to output file
df = pd.DataFrame(dic)
df.to_csv(output[0], index=False, header=True)
### APR aggregation prediction ###
# Predict aggregation propensity with Tango
rule run_tango_predictions:
input:
"apr_evolution/sarcopterygii_sequences.faa"
output:
"apr_evolution/aprs_aggregation_scores.csv"
shell:
"""
./src/run_tango.py {input} 12 20 {config[tango]} APR1 >> {output}
./src/run_tango.py {input} 51 59 {config[tango]} APR2 >> {output}
./src/run_tango.py {input} 65 73 {config[tango]} APR3 >> {output}
./src/run_tango.py {input} 225 233 {config[tango]} APR4 >> {output}
rm nt=N.txt
"""
### Calculate sequence entropy ###
rule calc_shannon_entropy:
input:
"apr_evolution/sarcopterygii_mafft.faa"
output:
"apr_evolution/aprs_entropy.csv"
shell:
"src/calc_shannon_entropy.py {input} >> {output}"
### Flexibility evolution ###
# Reconstruct ancestral sequences from IQ-Tree states file
#rule reconstruct_ancestral_sequences:
# input:
# "apr_evolution/sarcopterygii_phylogeny.state",
# "apr_evolution/sarcopterygii_phylogeny.treefile",
# "apr_evolution/sarcopterygii_mafft.faa"
# output:
# "ancestral_reconstruction/ancestral_sequences.faa"
# shell:
# """
# src/get_ancestral_sequence.py {input} >> {output} &&
# mv *.svg ancestral_reconstruction/
# """
# Extant species used for structural comparisons
EXTANTS = ["Homo_sapiens_ENSP00000364472",
"Mus_musculus_ENSMUSP00000034588",
"Canis_lupus_familiaris_ENSCAFP00000019630",
"Bos_taurus_ENSBTAP00000002914",
"Gallus_gallus_ENSGALP00000011510",
"Crocodylus_porosus_ENSCPRP00005000967",
"Chelonoidis_abingdonii_ENSCABP00000011720",
"Xenopus_tropicalis_ENSXETP00000008146"]
# Ancestral nodes used for structural comparisons
#NODES = ["Node2", "Node3", "Node4", "Node5",
# "Node6", "Node7", "Node54", "Node55",
# "Node58", "Node59", "Node68", "Node69"]
# Set target sequences
TARGETS = EXTANTS
# Extract target sequences to be structurally modelled
rule extract_extant_sequences:
input:
"apr_evolution/sarcopterygii_sequences.faa"
params:
extants=expand("{extants}", extants=EXTANTS)
output:
"structural_modelling/target_sequences.faa"
run:
for extant in params.extants:
shell("grep -A 1 {extant} {input} >> {output}")
# Merge ancestral and extant sequences
#rule merge_sequences:
# input:
# "ancestral_reconstruction/ancestral_sequences.faa",
# "ancestral_reconstruction/extant_sequences.faa"
# output:
# "ancestral_reconstruction/target_sequences.faa"
# shell:
# "cat {input} > {output}"
# Align protein sequences with MAFFT
rule mafft2_protein_alignment:
input:
"structural_modelling/target_sequences.faa"
output:
"structural_modelling/alignment.faa"
shell:
"""
mafft --maxiterate 1000 --localpair \
{input} >> {output}
"""
# Trim signal peptide from alignment
rule trim_signal_peptide:
input:
"structural_modelling/alignment.faa"
output:
"structural_modelling/alignment_trimmed.faa"
run:
align = AlignIO.read(input[0], "fasta")
align_trimmed = align[:, 48:]
with open (output[0], "w") as fh:
for seq in align_trimmed:
fh.write(f">{seq.id}\n{seq.seq}\n")
# Create protein models with Modeller
rule protein_modelling:
input:
"structural_modelling/alignment_trimmed.faa",
"apoa1.pdb",
params:
"Homo_sapiens_ENSP00000364472"
output:
expand("structural_modelling/{target}_best_model.pdb", target=TARGETS)
shell:
"""
./src/run_modeller.py {input[0]} {params} {input[1]} &&\
rm template.pdb *.B* *.D* *.V* *.ini *.rsr *.sch &&\
mv *best_model.pdb *.pir structural_modelling/
"""
# Model refinement (energy minimization)
rule model_refinement:
input:
"structural_modelling/{target}_best_model.pdb",
output:
"structural_modelling/{target}_best_model_relaxed.pdb"
shell:
"""
./src/pyrosetta_fastrelax.py {input}
"""
# Compute MSF for each model
rule compute_msf:
input:
"structural_modelling/{target}_best_model_relaxed.pdb",
output:
"structural_modelling/{target}_best_model_relaxed.msf"
shell:
"""
./src/calc_gnm.py {input}
"""
# Compute WCN for each model
rule compute_wcn:
input:
"structural_modelling/{target}_best_model_relaxed.pdb",
output:
"structural_modelling/{target}_best_model_relaxed.wcn"
shell:
"""
python ./src/calc_wcn.py {input}
"""
# Aggregate MSF values
rule aggregate_msf:
input:
expand("structural_modelling/{target}_best_model_relaxed.msf", target=TARGETS)
output:
"structural_modelling/msf.csv"
shell:
"paste {input} > {output}"
# Aggregate WCN values
rule aggregate_wcn:
input:
expand("structural_modelling/{target}_best_model_relaxed.wcn", target=TARGETS)
output:
"structural_modelling/wcn.csv"
shell:
"paste {input} > {output}"
### MutateX in-silico mutagenesis ###
# Create MutateX configuration files
rule prepare_mutatex_templates:
input:
"apoa1.pdb"
output:
"mutatex_mutagenesis/mutate_runfile_template.txt",
"mutatex_mutagenesis/repair_runfile_template.txt"
run:
with open(output[0], "w") as fh:
fh.write("""command=BuildModel
pdb=$PDBS$
mutant-file=individual_list.txt
water=-CRYSTAL
numberOfRuns=$NRUNS$
complexWithDNA=true
""")
with open(output[1], "w") as fh:
fh.write("""command=RepairPDB
pdb=$PDBS$
temperature=298
water=-CRYSTAL
complexWithDNA=true
""")
# MutateX Mutagenesis
rule mutatex_mutagenesis:
input:
"apoa1.pdb",
"mutatex_mutagenesis/mutate_runfile_template.txt",
"mutatex_mutagenesis/repair_runfile_template.txt"
params:
"mutatex_mutagenesis",
"/home/tmasson/foldx/foldx"
output:
"mutatex/mutations/apoa1_model0_checked_Repair/LA14/WT_apoa1_model0_checked_Repair_2_4.pd"
shell:
"""
cp {input[0]} {params[0]}/
cd {params[0]}
mutatex -f suite5 -x {params[1]} --np 4 {input[0]}
"""
### Plots generation ###
# APRs evolution plotting
rule plot_aprs_evolution:
input:
"apr_evolution/aprs_aggregation_scores.csv",
"apr_evolution/aprs_entropy.csv",
"apr_evolution/sarcopterygii_mafft.faa"
output:
"viz/panels/aprs_entropy.svg",
"viz/panels/aprs_conservation.svg"
params:
"aprs_entropy.svg",
"aprs_conservation.svg"
shell:
"""
./viz/src/plot_apr_evolution.py {input} &&\
mv {params} viz/panels/
"""
# HyPhy selection regimes plotting
rule plot_hyphy_evolution:
input:
"apr_evolution/hyphy_results.csv",
"apr_evolution/sarcopterygii_fel.csv"
output:
"viz/panels/evolutionary_rate_profile.svg",
"viz/panels/natural_selection_regimes.svg"
params:
"evolutionary_rate_profile.svg",
"natural_selection_regimes.svg"
shell:
"""
./viz/src/plot_hyphy_selection.py {input} &&\
mv {params} viz/panels/
"""
# MSF and WCN plotting
rule plot_aprs_msf_wcn:
input:
"structural_modelling/msf.csv",
"structural_modelling/wcn.csv"
output:
"viz/panels/aprs_flexibility.svg",
"viz/panels/aprs_flexibility_profiles.svg"
params:
"aprs_flexibility.svg",
"aprs_flexibility_profiles.svg"
shell:
"""
./viz/src/plot_msf_wcn.py {input} &&\
mv {params} viz/panels/
"""
# APR ΔΔG average values plotting
rule plot_aprs_impact:
input:
"in-silico_mutagenesis/foldx_dataset.csv"
output:
"viz/panels/aprs_impact.svg"
params:
"aprs_impact.svg"
shell:
"""
./viz/src/plot_apr_impact.py {input} &&\
mv {params} viz/panels/
"""