-
Notifications
You must be signed in to change notification settings - Fork 3
/
aq-qiime-base
245 lines (227 loc) · 11.1 KB
/
aq-qiime-base
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
#!/usr/bin/make -f
# Basic rules for doing QIIME analysis. It assumes you have a mapping.txt file with all your sequences and that your sequences are named in QIIME's ${SampleID::int}_${UID::int} format. AXIOME does this for you. ;-)
ifeq ($(PIPELINE),QIIME)
#Defaults for QIIME, as a fallback
OTU_PICKING_METHOD ?= cdhit
PHYLO_METHOD ?= fasttree
CLUSTER_IDENT ?= 0.97
ALIGN_METHOD ?= pynast
ifeq ($(QIIME_GREATER_THAN_1_5),TRUE)
ifdef MIN_SEQ_IN_OTU
MIN_SEQ_IN_OTU := -n $(MIN_SEQ_IN_OTU)
endif
ifdef MAX_SEQ_IN_OTU
MAX_SEQ_IN_OTU := -x $(MAX_SEQ_IN_OTU)
endif
ifdef MIN_SAMPLES_IN_OTU
MIN_SAMPLES_IN_OTU := -s $(MIN_SAMPLES_IN_OTU)
endif
ifdef MAX_SAMPLES_IN_OTU
MAX_SAMPLES_IN_OTU := -y $(MAX_SAMPLES_IN_OTU)
endif
else
ifdef MIN_SEQ_IN_OTU
MIN_SEQ_IN_OTU := -c $(MIN_SEQ_IN_OTU)
endif
ifdef MIN_SAMPLES_IN_OTU
MIN_SAMPLES_IN_OTU := -s $(MIN_SAMPLES_IN_OTU)
endif
endif
# Build basic data from sequences, OTU picking step
ifeq ($(OTU_PICKING_METHOD),raw-uclust)
sorted.fasta: seq.fasta
@echo Sorting sequences...
$(V)uclust --mergesort $< --output $@
seq.uc: sorted.fasta
@echo Picking OTUs using uclust without QIIME...
$(V)uclust --id $(CLUSTER_IDENT) --input sorted.fasta --uc seq.uc
picked_otus/seq_otus.txt: seq.uc
@test -d picked_otus || mkdir -p picked_otus
@awk '$$1 == "S" { a[$$2] = "\t" $$9; if ($$2 > m) { m = $$2; } } $$1 == "H" { a[$$2] = (a[$$2] "\t" $$9); } END { for (i = 0; i < m; i++) { print i a[i]; }}' $< > $@
else
ifeq ($(OTU_PICKING_METHOD),raw-cdhit)
picked_otus/cd-hit-out.clstr: seq.fasta
@echo Generating cluster file using cdhit...
@echo Please note: If using cdhit version 3.1 or lower, you will need to run the cd-hit-est command without the -M and -T parameters, and rerun make
@test -d picked_otus || mkdir -p picked_otus
ifdef MULTICORE
cd-hit-est -i seq.fasta -o picked_otus/cd-hit-out -c $(CLUSTER_IDENT) -B 1 -M 0 -T $(NUM_CORES) > picked_otus/cd-hit.output 2>&1
else
cd-hit-est -i seq.fasta -o picked_otus/cd-hit-out -c $(CLUSTER_IDENT) -B 1 -M 0 > picked_otus/cd-hit.output 2>&1
endif
picked_otus/seq_otus.txt: picked_otus/cd-hit-out.clstr
@echo Converting cdhit cluster file to proper format...
@awk '{ ORS="" } { if (/>Cluster/) { if ( NR != 1 ) { print "\n"; } print $$2; } else { print "\t"; gsub(/\.\.\./,""); print substr($$3,2); }}' $< > $@
else
picked_otus/seq_otus.txt: seq.fasta
@test ! -d picked_otus || rm -r picked_otus
ifeq ($(OTU_PICKING_METHOD),uclust_ref)
ifdef MULTICORE
@echo Picking OTUs using QIIME and uclust_ref using $(NUM_CORES) cores...
$(V)$(QIIME_PREFIX)parallel_pick_otus_uclust_ref.py -i seq.fasta -s $(CLUSTER_IDENT) -o picked_otus -r $(OTU_REFSEQS) -O $(NUM_CORES) $(OTU_FLAGS)
else
@echo Picking OTUs using QIIME and uclust_ref...
$(V)$(QIIME_PREFIX)pick_otus.py -i seq.fasta -s $(CLUSTER_IDENT) -m uclust_ref -o picked_otus -r $(OTU_REFSEQS) $(OTU_FLAGS)
endif
else
ifeq ($(OTU_PICKING_METHOD),usearch_ref)
@echo Picking OTUs using QIIME and usearch_ref...
$(V)$(QIIME_PREFIX)pick_otus.py -i seq.fasta -s $(CLUSTER_IDENT) -m usearch_ref -o picked_otus -r $(OTU_REFSEQS) $(OTU_FLAGS)
else
ifeq ($(OTU_PICKING_METHOD),blast)
ifdef OTU_REFSEQS
ifdef MULTICORE
@echo Picking OTUs using QIIME, BLAST and reference sequences with $(NUM_CORES) cores...
$(V)$(QIIME_PREFIX)parallel_pick_otus_blast.py -i seq.fasta -s $(CLUSTER_IDENT) -o picked_otus -r $(OTU_REFSEQS) -O $(NUM_CORES) $(OTU_FLAGS)
else
@echo Picking OTUs using QIIME, BLAST and reference sequences...
$(V)$(QIIME_PREFIX)pick_otus.py -i seq.fasta -s $(CLUSTER_IDENT) -m blast -o picked_otus -r $(OTU_REFSEQS) $(OTU_FLAGS)
endif
endif
ifdef OTU_BLASTDB
ifdef MULTICORE
@echo Picking OTUs using QIIME, BLAST and a BLAST database with $(NUM_CORES) cores...
$(V)$(QIIME_PREFIX)parallel_pick_otus_blast.py -i seq.fasta -s $(CLUSTER_IDENT) -o picked_otus -b $(OTU_BLASTDB) -O $(NUM_CORES) $(OTU_FLAGS)
else
@echo Picking OTUs using QIIME, BLAST and a BLAST database...
$(V)$(QIIME_PREFIX)pick_otus.py -i seq.fasta -s $(CLUSTER_IDENT) -m blast -o picked_otus -b $(OTU_BLASTDB) $(OTU_FLAGS)
endif
endif
else
ifeq ($(OTU_PICKING_METHOD),usearch)
ifndef OTU_CHIMERA_REFSEQS
@echo Picking OTUs using QIIME and usearch with de novo chimera detection...
$(V)$(QIIME_PREFIX)pick_otus.py -m usearch --word_length 64 -o picked_otus -i seq.fasta -x $(OTU_FLAGS)
else
@echo Picking OTUs using QIIME and usearch with reference chimera detection...
$(V)$(QIIME_PREFIX)pick_otus.py -m usearch --word_length 64 -o picked_otus -i seq.fasta -f $(OTU_CHIMERA_REFSEQS) $(OTU_FLAGS)
endif
else
@echo Picking OTUs using QIIME and $(OTU_PICKING_METHOD)...
$(V)$(QIIME_PREFIX)pick_otus.py -i seq.fasta -s $(CLUSTER_IDENT) -m $(OTU_PICKING_METHOD) -o picked_otus $(OTU_FLAGS)
endif
endif
endif
endif
endif
endif
seq.fasta_rep_set.fasta: picked_otus/seq_otus.txt seq.fasta
@echo Picking representative set...
$(V)aq-mkrepset seq.fasta picked_otus/seq_otus.txt > seq.fasta_rep_set.fasta
ifeq ($(ALIGN_METHOD),infernal)
aligned/seq.fasta_rep_set_aligned.fasta: seq.fasta_rep_set.fasta
@echo Aligning representative sequences with infernal...
@test ! -d aligned || rm -r aligned
$(V)$(QIIME_PREFIX)align_seqs.py -o aligned -m infernal -t $$INFERNAL_MODEL -i seq.fasta_rep_set.fasta
else
ifdef MULTICOREBROKEN
aligned/seq.fasta_rep_set_aligned.fasta: seq.fasta_rep_set.fasta
@echo Aligning representative sequences with multicore pynast using $(NUM_CORES) cores...
@test ! -d aligned || rm -r aligned
$(V)$(QIIME_PREFIX)parallel_align_seqs_pynast.py -i seq.fasta_rep_set.fasta -o aligned -O $(NUM_CORES)
else
aligned/seq.fasta_rep_set_aligned.fasta: seq.fasta_rep_set.fasta
@echo Aligning representative sequences with $(ALIGN_METHOD)...
@test ! -d aligned || rm -r aligned
$(V)$(QIIME_PREFIX)align_seqs.py -o aligned -m $(ALIGN_METHOD) -i seq.fasta_rep_set.fasta
endif
endif
assigned_taxonomy/seq.fasta_rep_set_tax_assignments.txt: seq.fasta_rep_set.fasta
@echo Assigning taxonomy...
@test ! -d assigned_taxonomy || rm -r assigned_taxonomy
ifeq ($(CLASSIFICATION_METHOD),rdp)
ifdef MULTICORE
$(V)$(QIIME_PREFIX)parallel_assign_taxonomy_rdp.py -i seq.fasta_rep_set.fasta -o assigned_taxonomy -O $(NUM_CORES) $(RDP_CLASSIFIER_FLAGS)
else
$(V)$(QIIME_PREFIX)assign_taxonomy.py -m rdp -i seq.fasta_rep_set.fasta -o assigned_taxonomy $(RDP_CLASSIFIER_FLAGS)
endif
else
ifeq ($(CLASSIFICATION_METHOD),blast)
ifdef MULTICORE
#Multicore assign taxonomy appears to be broken (uses wrong relative filepath after a cd command in the jobs command file)
$(V)$(QIIME_PREFIX)parallel_assign_taxonomy_blast.py -i seq.fasta_rep_set.fasta -o assigned_taxonomy -O $(NUM_CORES) $(BLAST_CLASSIFIER_FLAGS)
else
$(V)$(QIIME_PREFIX)assign_taxonomy.py -m blast -i seq.fasta_rep_set.fasta -o assigned_taxonomy $(BLAST_CLASSIFIER_FLAGS)
endif
else
ifeq ($(CLASSIFICATION_METHOD),rtax)
ifndef RTAX_CLASSIFIER_FLAGS
$(error Error: You must use the rtax plugin to configure the rtax classifier. Please see axiome manual page.)
else
$(V)$(QIIME_PREFIX)assign_taxonomy.py -m rtax -i seq.fasta_rep_set.fasta -o assign_taxonomy $(RTAX_CLASSIFIER_FLAGS)
endif
endif
endif
endif
seq.fasta_rep_set_aligned_pfiltered.fasta: aligned/seq.fasta_rep_set_aligned.fasta
@echo Filtering alignment...
$(V)$(QIIME_PREFIX)filter_alignment.py -i aligned/seq.fasta_rep_set_aligned.fasta -s
ifeq ($(PHYLO_METHOD),raw-fasttree)
seq.fasta_rep_set_aligned_pfiltered.tre: seq.fasta_rep_set_aligned_pfiltered.fasta
@echo Building tree with a RAW FastTree call...
$(V)$(QIIME_PREFIX)FastTree -nt < seq.fasta_rep_set_aligned_pfiltered.fasta > seq.fasta_rep_set_aligned_pfiltered.tre
else
ifeq ($(PHYLO_METHOD),raw-fasttreemp)
seq.fasta_rep_set_aligned_pfiltered.tre: seq.fasta_rep_set_aligned_pfiltered.fasta
@echo Building tree with a RAW FastTreeMP call \(utilizes all available processors\)...
$(V)$(QIIME_PREFIX)FastTreeMP -nt < seq.fasta_rep_set_aligned_pfiltered.fasta > seq.fasta_rep_set_aligned_pfiltered.tre
else
seq.fasta_rep_set_aligned_pfiltered.tre: seq.fasta_rep_set_aligned_pfiltered.fasta
@echo Building tree with $(PHYLO_METHOD)...
$(V)$(QIIME_PREFIX)make_phylogeny.py -i seq.fasta_rep_set_aligned_pfiltered.fasta -t $(PHYLO_METHOD)
endif
endif
exclude_otus.list: $(TAXA_EXCLUDE_FILE) $(CHIMERA_EXCLUDE_FILE)
@echo Creating taxa exclusion list...
ifdef TAXA_EXCLUDE_FILE
$(V)awk 'BEGIN { FS=" "; print "#Taxa Exclusion List Generated by AXIOME" > "exclude_otus.list"; } { if ($(TAXA_EXCLUDE_STR)) { print $$1 > "exclude_otus.list"; } }' $(TAXA_EXCLUDE_FILE)
endif
ifdef CHIMERA_EXCLUDE_FILE
$(V)awk 'BEGIN { FS="\t"; print "#CHIMERAS"; } { if ($$18=="Y") { split($$2, label, " "); print label[1]; } }' $(CHIMERA_EXCLUDE_FILE) >> exclude_otus.list
endif
otu_table.txt: picked_otus/seq_otus.txt assigned_taxonomy/seq.fasta_rep_set_tax_assignments.txt $(OTU_EXCLUDE_FILE)
@echo Making OTU table...
$(V)$(QIIME_PREFIX)make_otu_table.py -i picked_otus/seq_otus.txt -t assigned_taxonomy/seq.fasta_rep_set_tax_assignments.txt -o otu_table.txt $(OTU_EXCLUDE)
ifdef FILTEROTUTABLE
@echo Filtering OTU table...
ifeq ($(QIIME_GREATER_THAN_1_5),TRUE)
$(V)$(QIIME_PREFIX)filter_otus_from_otu_table.py -i otu_table.txt $(MIN_SEQ_IN_OTU) $(MAX_SEQ_IN_OTU) $(MIN_SAMPLES_IN_OTU) $(MAX_SAMPLES_IN_OTU) -o otu_table_filtered.txt
else
$(V)$(QIIME_PREFIX)filter_otu_table.py -i otu_table.txt -c $(MIN_SEQ_IN_OTU) -s $(MIN_SAMPLES_IN_OTU) -o otu_table_filtered.txt
endif
$(V)mv otu_table_filtered.txt otu_table.txt
endif
ifeq ($(QIIME_1_8),TRUE)
otu_table%.tab: otu_table%.txt
@echo Creating legacy OTU table...
@if [ -f $< ]; then rm -rf $<; fi
$(V)$(QIIME_PREFIX)biom convert -b -i $< -o $@ --header-key=taxonomy --output-metadata-id=Consensus\ Lineage
else
otu_table%.tab: otu_table%.txt
@echo Creating legacy OTU table...
$(V)$(QIIME_PREFIX)convert_biom.py -b -i $< -o $@ --header-key=taxonomy --output-metadata-id=Consensus\ Lineage
endif
# Produce a rank-abundance plot
ifeq ($(QIIME_GREATER_THAN_1_6),TRUE)
rank_abundance/rank_abundance.pdf: otu_table.txt otu_table.tab
@echo Plotting rank-abundance curves...
@test ! -d rank_abundance || rm -r rank_abundance
$(V)$(QIIME_PREFIX)plot_rank_abundance_graph.py -i otu_table.txt -s "$$(awk -F "\t" 'NR == 2 { printf("%s", $$2); for (i = 3; i < NF; i++) { printf(",%s", $$i); } printf("\n"); exit; }' otu_table.tab)" -o rank_abundance
mkdir rank_abundance
mv rank_abundance.pdf rank_abundance/rank_abundance.pdf
else
ifeq ($(QIIME_GREATER_THAN_1_5),TRUE)
rank_abundance/rank_abundance.pdf: otu_table.txt otu_table.tab
@echo Plotting rank-abundance curves...
@test ! -d rank_abundance || rm -r rank_abundance
$(V)$(QIIME_PREFIX)plot_rank_abundance_graph.py -i otu_table.txt -s "$$(awk -F "\t" 'NR == 2 { printf("%s", $$2); for (i = 3; i < NF; i++) { printf(",%s", $$i); } printf("\n"); exit; }' otu_table.tab)" -o rank_abundance
mv rank_abundance/rank_abundance_cols*.pdf rank_abundance/rank_abundance.pdf
else
rank_abundance/rank_abundance.pdf: otu_table.txt
@echo Plotting rank-abundance curves...
@test ! -d rank_abundance || rm -r rank_abundance
$(V)$(QIIME_PREFIX)plot_rank_abundance_graph.py -i otu_table.txt -s "$$(awk -F "\t" 'NR == 2 { printf("%s", $$2); for (i = 3; i < NF; i++) { printf(",%s", $$i); } printf("\n"); exit; }' otu_table.txt)" -o rank_abundance
mv rank_abundance/rank_abundance_cols*.pdf rank_abundance/rank_abundance.pdf
endif
endif
endif