-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
198 lines (181 loc) · 4.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
CONDAENV='envs'
contigs_db="genomes/anvio/all_contigs.db"
bam_file="genomes/alignments/{sample}.bam"
SAMPLES = glob_wildcards(bam_file).sample
localrules: anvio
rule anvio:
input:
"genomes/anvio/imported_clusters",
"genomes/anvio/profiles/merged/PROFILE.db",
contigs_db
localrules: get_contigs
rule get_contigs:
input:
fasta_dir = "genomes/genomes"
output:
fasta=temp("genomes/anvio/all_contigs.fasta")
shell:
"cat {input}/*.fasta > {output}"
rule anvi_gen_contigs_database:
input:
rules.get_contigs.output
output:
contigs_db
params:
name='All genomes',
threads:
1
resources:
mem=20
conda:
"%s/anvio.yaml" % CONDAENV
log:
"logs/genomes/anvio/anvi_gen_contigs_database.log"
shell:
"""
anvi-gen-contigs-database -f {input} -o {output} -n '{params.name}' \
--skip-gene-calling \
--skip-mindful-splitting --split-length -1 |& tee {log}
"""
# rule anvi_run_hmms:
# input:
# contigs_db
# output:
# touch("anvio/runned_hmm")
# params:
# profile='mono-shared',
# time=10*60
# benchmark:
# "logs/benchmark/anvi_run_hmms.txt"
# threads:
# 8
# resources:
# mem=20
# conda:
# "%s/anvio.yaml" % CONDAENV
# log:
# "logs/genomes/anvio/anvi_run_hmms.log"
# shell:
# """
# anvi-run-hmms -c {input} -T {threads} |& tee {log}
# """
#
#
# rule anvi_run_ncbi_cogs:
# input:
# contigs_db
# output:
# touch("anvio/runned_cogs")
# threads:
# 8
# resources:
# mem=20
# conda:
# "../envs/anvio.yaml"
# log:
# "logs/anvi_run_ncbi_cogs.log"
# shell:
# """
# anvi-run-ncbi-cogs -c {input} -T {threads} |& tee {log}
# """
localrules: create_bam_index
rule create_bam_index:
input:
"{file}.bam"
output:
"{file}.bam.bai"
conda:
"%s/samtools.yaml" %CONDAENV
threads:
1
resources:
mem=1
shell:
"samtools index {input}"
rule anvi_profile:
input:
db=contigs_db,
bam=bam_file,
bai=bam_file+".bai"
output:
"genomes/anvio/profiles/{sample}/PROFILE.db"
params:
outdir=lambda wc, output: os.path.dirname(output[0]),
threads:
4
resources:
mem=250
conda:
"%s/anvio.yaml" %CONDAENV
log:
"logs/genomes/anvio/profile_{sample}.log"
shell:
"""
rm -rf {params.outdir} |& tee {log} # outdir shouldn't exist before
anvi-profile -i {input.bam} -c {input.db} -T {threads} \
--output-dir {params.outdir} -S {wildcards.sample} \
--skip-SNV-profiling |& tee {log}
"""
rule anvi_merge:
input:
db=contigs_db,
profiles= expand(rules.anvi_profile.output,sample=SAMPLES)
output:
"genomes/anvio/profiles/merged/PROFILE.db"
params:
outdir=lambda wc, output: os.path.dirname(output[0]),
threads:
1
conda:
"%s/anvio.yaml" %CONDAENV
log:
"logs/genomes/anvio/merge_profile.log"
shell:
"""
anvi-merge {input.profiles} \
-o {params.outdir} \
-c {input.db} \
--skip-concoct-binning \
--overwrite-output-destinations |& tee {log}
"""
rule anvi_import_binning_results:
input:
db=contigs_db,
profiles= rules.anvi_merge.output,
binning_results = "genomes/clustering/contig2genome.tsv"
output:
touch("genomes/anvio/imported_clusters")
params:
name= "genomes"
threads:
1
conda:
"%s/anvio.yaml" % CONDAENV
log:
"logs/genomes/anvio/import_bins.log"
shell:
"""
anvi-import-collection {input.binning_results} \
-C {params.name} \
-c {input.db} \
-p {input.profiles} \
--contigs-mode \
|& tee {log}
"""
rule interactive:
input:
profiles="genomes/anvio/profiles/merged/PROFILE.db",
contigs=contigs_db
# output:
#"genomes/anvio/anvio_plot.svg"
conda:
"%s/anvio.yaml" %CONDAENV
params:
name='genomes'
threads:
1
shell:
"anvi-interactive -p {input.profiles} "
" -c {input.contigs} "
# " --export-svg {output} "
" --collection-name {params.name} "