-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile_combined_MSA
164 lines (147 loc) · 4.59 KB
/
Snakefile_combined_MSA
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
import os
# To run locally:
# snakemake --snakefile Snakefile_combined_MSA --keep-going --cores 4 --use-singularity --singularity-prefix ~/.singularity --singularity-args "--home ~"
# To visualise the pipeline
# snakemake --snakefile Snakefile_combined_MSA --dag | dot -Tsvg > pipeline_combined_MSA.svg
localrules: all, entrez
folder = os.path.abspath(config.get("folder", '..'))
data_dir = os.path.join(folder, 'data')
genbank_data = os.path.join(data_dir, 'genbank_20200811_org_Zika_virus_len_8000_14000.fa')
os.makedirs('logs', exist_ok=True)
rule all:
input:
os.path.join(data_dir, 'aln.fa'),
os.path.join(data_dir, 'metadata.combined.tab'),
rule entrez:
'''
Transforms dengue input file into fasta and metadata
'''
input:
data = genbank_data
output:
fa = temp(os.path.join(data_dir, 'sequences.gb.fasta')),
data = temp(os.path.join(data_dir, 'metadata.gb.tab')),
params:
mem = 2000,
name = 'metadata'
threads: 1
singularity: "docker://evolbioinfo/python-evol:v3.6"
shell:
"""
python3 py/gb_reader.py --input_fa {input.data} --output_fa {output.fa} --output_data {output.data}
"""
rule genome_detective:
'''
Manual step: detect serotype and genotype with with Genome Detective.
'''
input:
fa = os.path.join(data_dir, 'sequences.gb.fasta'),
output:
gd_data = os.path.join(data_dir, 'gd.csv'),
params:
mem = 1000,
name = 'genome_detective'
threads: 1
shell:
"""
echo "Manual step to be performed by Genome Detective."
"""
rule post_genome_detective:
'''
Puts together gb metadata and genotype data detected by Genome Detective
'''
input:
gd_data = os.path.join(data_dir, 'gd.csv'),
fa = os.path.join(data_dir, 'sequences.gb.fasta'),
data = os.path.join(data_dir, 'metadata.gb.tab')
output:
fa = os.path.join(data_dir, 'sequences.fa'),
data = os.path.join(data_dir, 'metadata.tab')
params:
mem = 2000,
name = 'gd_metadata'
threads: 1
singularity: "docker://evolbioinfo/python-evol:v3.6"
shell:
"""
python3 py/gd_reader.py --input_fa {input.fa} --output_fa {output.fa} --output_data {output.data} \
--input_data {input.data} --gd_data {input.gd_data}
"""
rule add_Vietnam:
'''
Adds metadata and sequences from Vietnam
'''
input:
fa = os.path.join(data_dir, 'sequences.fa'),
v_fa = os.path.join(data_dir, 'Vietnam.fa'),
data = os.path.join(data_dir, 'metadata.tab')
output:
fa = os.path.join(data_dir, 'sequences.combined.fa'),
data = os.path.join(data_dir, 'metadata.combined.tab')
params:
mem = 2000,
name = 'gd_metadata'
threads: 1
singularity: "docker://evolbioinfo/python-evol:v3.6"
shell:
"""
python3 py/add_Vietnam.py --input_fa {input.fa} --output_fa {output.fa} --output_data {output.data} \
--input_data {input.data} --input_Vietnam {input.v_fa}
"""
rule get_seq_ids:
'''
Extract sequence ids of interest.
'''
input:
tab = os.path.join(data_dir, 'metadata.combined.tab'),
output:
tab = os.path.join(data_dir, 'ids.txt')
params:
mem = 500,
name = 'ids',
qos = 'fast'
threads: 1
singularity: "docker://evolbioinfo/python-evol:v3.6"
shell:
"""
python3 py/get_seq_ids.py --input_data {input.tab} --output_data {output.tab}
"""
rule aln_against_reference:
'''
Align sequences against a reference.
'''
input:
fa = os.path.join(data_dir, 'sequences.combined.fa'),
ref = os.path.join(data_dir, 'ref', 'ZIKV.fa')
output:
aln = temp(os.path.join(data_dir, 'aln.ref.fa'))
params:
mem = 1000,
name = 'aln',
qos = 'fast'
threads: 12
singularity: "docker://evolbioinfo/mafft:v7.313"
shell:
"""
mafft --thread {threads} --memsave --retree 1 --maxiterate 0 --add {input.fa} \
--keeplength {input.ref} > {output.aln}
"""
rule remove_ref:
'''
Removes the reference from the alignment.
'''
input:
aln = os.path.join(data_dir, 'aln.ref.fa'),
ids = os.path.join(data_dir, 'ids.txt')
output:
aln = os.path.join(data_dir, 'aln.fa')
params:
mem = 1000,
name = 'rmref',
qos = 'fast',
threads: 1
singularity: "docker://evolbioinfo/goalign:v0.3.1"
shell:
"""
goalign subset -i {input.aln} -f {input.ids} -o {output.aln}
"""