-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
197 lines (171 loc) · 5.52 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
# TOP LEVEL RULES
# * make_collections (default rule) - makes all the link collections etc
# * databases - builds the downsampled databases
# * print_gbsketch - print out the directsketch command to make missing euks
EUK_SKETCHES = '/group/ctbrowngrp5/2025-genbank-eukaryotes/*.sig.zip'
DATABASE_SCALED = 10_000
DATABASE_KSIZES = [21, 31, 51]
# map various names to NCBI taxonomic ID
NAMES_TO_TAX_ID = {
'eukaryotes': 2759,
'metazoa': 33208,
'plants': 33090,
'fungi': 4751,
'bilateria': 33213,
'vertebrates': 7742,
}
ADD_OTHER = [
'collections/bilateria-minus-vertebrates.links.csv',
'collections/metazoa-minus-bilateria.links.csv',
'collections/eukaryotes-other.links.csv',
]
DATABASE_NAMES = [
'fungi',
'eukaryotes-other',
'metazoa-minus-bilateria',
'bilateria-minus-vertebrates',
'plants',
'vertebrates',
]
rule make_collections:
input:
expand("collections/{NAME}.links.csv", NAME=set(NAMES_TO_TAX_ID)),
expand("collections/{NAME}.links.csv", NAME=DATABASE_NAMES),
ADD_OTHER,
'databases/eukaryotes.lineages.csv',
'collections/upsetplot.png',
"collections/eukaryotes-missing.links.csv"
rule databases:
input:
expand("databases/{db}.k51.sig.zip", db=DATABASE_NAMES),
# just print out the gbsketch rule, rather than running it - it's easier
# to run it outside of snakemake
rule print_gbsketch:
input:
"collections/eukaryotes-missing.links.csv",
params:
sigs="eukaryotes-missing.sig.zip",
check_fail="eukaryotes-missing.gbsketch-check-fail.txt",
fail="eukaryotes-missing.gbsketch-fail.txt",
shell: """
echo /usr/bin/time -v sourmash scripts gbsketch {input} \
-n 9 -r 10 -p k=21,k=31,k=51,dna \
--failed {params.fail} --checksum-fail {params.check_fail} \
-o {params.sigs} -c {threads} --batch 50
"""
rule make_combined_manifest:
output:
"collections/eukaryotes.mf.csv"
shell: """
rm -f {output}
sourmash sig collect -F csv {EUK_SKETCHES} -o {output} --abspath
sourmash sig summarize {output}
"""
rule check_combined_manifest:
input:
mf="collections/eukaryotes.mf.csv",
links="collections/eukaryotes.links.csv",
output:
missing="collections/eukaryotes-missing.links.csv",
shell: """
scripts/compare-sigs-and-links.py --sigs {input.mf} --links {input.links} \
--save-missing {output.missing}
"""
rule downsample:
input:
expand("databases/{NAME}.k51.s100_000.sig.zip", NAME=DATABASE_NAMES),
rule merge:
input:
expand("databases/{NAME}-merged.k51.s100_000.sig.zip", NAME=DATABASE_NAMES),
rule upset_plot:
input:
expand("collections/{NAME}.links.csv", NAME=set(NAMES_TO_TAX_ID)),
ADD_OTHER,
output:
'collections/upsetplot.png',
shell: """
scripts/make-upset.py {input} -o {output}
"""
rule get_tax:
output:
"collections/{NAME}.dataset-reports.pickle"
params:
tax_id = lambda w: { **NAMES_TO_TAX_ID }.get(w.NAME)
shell: """
scripts/1-get-by-tax.py --taxons {params.tax_id} -o {output}
"""
rule parse_links:
input:
datasets="collections/{NAME}.dataset-reports.pickle",
output:
"collections/{NAME}.links.csv",
shell: """
scripts/2-output-directsketch-csv.py {input} -o {output}
"""
rule lineages_csv:
input:
"collections/{NAME}.links.csv",
output:
"databases/{NAME}.lineages.csv",
shell: """
scripts/taxid-to-lineages.taxonkit.py {input} -o {output}
"""
### specific subsets/groups
rule make_invertebrates_csv:
priority: 10
input:
sub_from='collections/bilateria.links.csv',
sub='collections/vertebrates.links.csv',
output:
'collections/bilateria-minus-vertebrates.links.csv',
shell: """
./scripts/subtract-links.py -1 {input.sub_from} \
-2 {input.sub} -o {output}
"""
rule make_metazoa_sub_bilateria_csv:
priority: 10
input:
sub_from='collections/metazoa.links.csv',
sub='collections/bilateria.links.csv',
output:
'collections/metazoa-minus-bilateria.links.csv',
shell: """
./scripts/subtract-links.py -1 {input.sub_from} \
-2 {input.sub} -o {output}
"""
rule eukaryotes_other_csv:
priority: 10
input:
sub_from='collections/eukaryotes.links.csv',
sub=['collections/metazoa.links.csv',
'collections/plants.links.csv',
'collections/fungi.links.csv',
]
output:
'collections/eukaryotes-other.links.csv',
shell: """
./scripts/subtract-links.py -1 {input.sub_from} \
-2 {input.sub} -o {output}
"""
ruleorder: make_invertebrates_csv > make_metazoa_sub_bilateria_csv > eukaryotes_other_csv > parse_links
# @CTB database preparation rules
rule downsample_sig:
input:
mf="collections/eukaryotes.mf.csv",
pl="collections/{NAME}.links.csv",
output:
"databases/{NAME}.k{KSIZE}.sig.zip",
shell: """
sourmash sig downsample -k {wildcards.KSIZE} --scaled {DATABASE_SCALED} \
--picklist {input.pl}:accession:ident \
{input.mf} -o {output}
"""
rule merge_sig:
input:
"downsampled/{NAME}.k51.s100_100.sig.zip",
output:
"merged/{NAME}-merged.k51.s100_100.sig.zip",
shell: """
sourmash sig merge -k 51 -s 100_000 {input} -o {output} \
--set-name {wildcards.NAME}-merged
"""