-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
240 lines (195 loc) · 6.87 KB
/
Makefile
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
OS := $(shell uname)
ifeq ($(OS), Darwin)
# mainly for dev builds using homebrew things
EXTRA_LDFLAGS ?= -L$(shell brew --prefix [email protected])/lib
ARGP ?= $(shell brew --prefix argp-standalone)/lib/libargp.a
ARGP_INC ?= -I$(shell brew --prefix argp-standalone)/include
CFLAGS ?= -fpic -O3 ${ARGP_INC}
ZCAT = "gzcat"
else
ARGP ?=
ARGP_INC ?=
CFLAGS ?= -fpic -msse3 -O3 ${ARGP_INC}
ZCAT = "zcat"
endif
VALGRIND ?= valgrind
CC ?= gcc
STATIC_HTSLIB ?= htslib/libhts.a
EXTRA_CFLAGS ?=
EXTRA_LDFLAGS ?=
EXTRA_LIBS ?=
EXTRA_LIBS ?=
HTS_CONF_ARGS ?=
NOTHREADS ?=
PEPPER ?= 0
ifeq ($(NOTHREADS), 1)
CFLAGS += -DNOTHREADS
endif
# we can't do pedantic because min/max macros lead to:
# "ISO C forbids braced-groups within expressions [-Werror=pedantic]"
ifeq ($(shell $(CC) --version | grep clang | wc -l), 0)
WARNINGS = -Werror -Wall -Wextra -Wno-incompatible-pointer-types
else
WARNINGS = -Werror -Wall -Wextra -Wpedantic -Wno-language-extension-token -Wno-gnu-statement-expression -Wno-incompatible-function-pointer-types
endif
GRIND = $(VALGRIND) --error-exitcode=1 --tool=memcheck --leak-check=full --show-leak-kinds=all -s
# optionally run all tests under valgrind
ifeq ($(OS), 1)
PEPPER = $(RUN_VALGRIND)
else
PEPPER =
endif
.PHONY:
default: fastcat bamstats bamindex
.PHONY:
test: test_fastcat test_bamstats test_meta test_bamindex
.PHONY:
test_memory: mem_check_fastcat mem_check_bamstats mem_check_bamindex
.PHONY:
clean:
rm -rf fastcat bamstats bamindex src/fastcat/*.o src/bamstats/*.o src/bamindex/*.o src/*.o
.PHONY: clean_htslib
clean_htslib:
cd htslib && make clean
###
# build stages
htslib/libhts.a:
@echo Compiling $(@F)
cd htslib/ \
&& autoheader \
&& autoconf \
&& autoreconf --install \
&& CFLAGS="$(CFLAGS) $(EXTRA_CFLAGS)" ./configure $(HTS_CONF_ARGS) \
&& make -j 4
#TODO: for conda we could use zlib-ng from conda-forge
zlib-ng/zlib.h:
@echo Configuring zlib-ng
cd zlib-ng/ \
&& CFLAGS="$(CFLAGS) $(EXTRA_CFLAGS)" ./configure --zlib-compat \
zlib-ng/libz.a: zlib-ng/zlib.h
@echo Compiling $(@F)
cd zlib-ng/ \
&& make -j 4 libz.a
src/%.o: src/%.c zlib-ng/zlib.h
$(CC) -Isrc -Ihtslib -Izlib-ng -c -pthread $(WARNINGS) -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
$(CFLAGS) $(EXTRA_CFLAGS) $< -o $@
fastcat: src/fastcat/main.o src/fastcat/args.o src/fastcat/writer.o src/fastqcomments.o src/common.o src/stats.o src/kh_counter.o $(STATIC_HTSLIB) zlib-ng/libz.a
$(CC) -Isrc -Izlib-ng $(WARNINGS) -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
$(CFLAGS) $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS) \
$^ $(ARGP) \
-lm $(EXTRA_LIBS) \
-o $@
bamstats: src/bamstats/main.o src/bamstats/args.o src/bamstats/readstats.o src/bamstats/bamiter.o src/fastqcomments.o src/common.o src/regiter.o src/stats.o src/kh_counter.o $(STATIC_HTSLIB)
$(CC) -Isrc -Ihtslib $(WARNINGS) -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
$(CFLAGS) $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS) \
$^ $(ARGP) \
-lm -lz -llzma -lbz2 -lpthread -lcurl -lcrypto $(EXTRA_LIBS) \
-o $@
bamindex: src/bamindex/main.o src/bamindex/build_main.o src/bamindex/fetch_main.o src/bamindex/dump_main.o src/bamindex/index.o $(STATIC_HTSLIB)
$(CC) -Isrc -Ihtslib $(WARNINGS) -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
$(CFLAGS) $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS) \
$^ $(ARGP) \
-lm -lz -llzma -lbz2 -lpthread -lcurl -lcrypto $(EXTRA_LIBS) \
-o $@
test/rg_parse: test/rg_parse.o src/common.o
$(CC) -Isrc $(WARNINGS) -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
$(CFLAGS) $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS) \
$^ $(ARGP) \
-lm $(EXTRA_LIBS) \
-o $@
###
# fastcat tests
.PHONY:
test_fastcat: mem_check_fastcat mem_check_fastcat_demultiplex
.PHONY: mem_check_fastcat
mem_check_fastcat: fastcat
rm -rf fastcat-histograms
$(GRIND) ./fastcat test/data/*.fastq.gz > /dev/null
.PHONY: mem_check_fastcat_demultiplex
mem_check_fastcat_demultiplex: fastcat
rm -rf demultiplex
$(GRIND) ./fastcat test/data/*.fastq.gz --demultiplex demultiplex > /dev/null
###
# bamstats tests
.PHONY:
test_bamstats: test_bamstats_NM test_bamstats_polya mem_check_bamstats
.PHONY: test_bamstats_NM
test_bamstats_NM: bamstats
rm -rf test/test-tmp-bs-nm
mkdir test/test-tmp-bs-nm && \
cd test/test-tmp-bs-nm && \
$(PEPPER) ../../bamstats ../bamstats_badNM/test.sam 2> err || grep "appears to contain implausible alignment information" err && rm -rf bamstats-histograms-bs-nm && \
rm -rf bamstats-histograms && \
$(PEPPER) ../../bamstats ../bamstats_zeroNM/test.sam
rm -r test/test-tmp-bs-nm
.PHONY: test_bamstats_polya
test_bamstats_polya: bamstats
rm -rf test/test-tmp-bs-pa
mkdir test/test-tmp-bs-pa && \
cd test/test-tmp-bs-pa && \
$(PEPPER) ../../bamstats ../bamstats/RCS-100A.bam --poly_a > /dev/null && \
diff bamstats-histograms/polya.hist ../bamstats/RCS-100A.bam.polya.hist
rm -r test/test-tmp-bs-pa
.PHONY:
mem_check_bamstats: bamstats
@echo "Memcheck bamstats with good data"
rm -rf bamstats-histograms
$(GRIND) ./bamstats test/parse_rg/[email protected] > /dev/null
@echo "Memcheck bamstats with bad data"
@echo ""
rm -rf bamstats-histograms
$(GRIND) ./bamstats test/parse_rg/bad-ones.bam > /dev/null
@echo ""
@echo "Memcheck bamstats with qcfails"
rm -rf bamstats-histograms
$(GRIND) ./bamstats test/bamstats/400ecoli-with-qcfail.bam > /dev/null
@echo ""
@echo "Memcheck bamstats duplex"
rm -rf bamstats-histograms
$(GRIND) ./bamstats test/bamstats/310dx.bam
###
# meta data tests (both fastcat and bamstats)
.PHONY:
test_meta: test_meta_fastcat test_meta_bamstats
.PHONY: regression_test_parse_rd_fastq
test_meta_fastcat: fastcat
rm -rf test/test-tmp-meta-fastq
mkdir test/test-tmp-meta-fastq && \
cd test/test-tmp-meta-fastq && \
set -e; \
for i in ../parse_rd/*.fastq; do \
echo $$i; \
$(PEPPER) ../../fastcat $$i --histograms hist -i rd > /dev/null; \
diff rd $$i.runids || exit 1; \
rm -rf hist rg; \
done;
rm -r test/test-tmp-meta-fastq
.PHONY: regression_test_parse_rg_bam
test_meta_bamstats: bamstats
rm -rf test/test-tmp-meta-bam
mkdir test/test-tmp-meta-bam && \
cd test/test-tmp-meta-bam && \
set -e; \
for i in ../parse_rg/*.bam; do \
$(PEPPER) ../../bamstats $$i --histograms hist -l rg \
> /dev/null; \
diff rg $$i.callers || exit 1; \
rm -rf hist rg; \
done;
rm -r test/test-tmp-meta-bam
.PHONY: regression_test_rg_parsing
regression_test_rg_parsing: test/rg_parse
$(PEPPER) ./test/rg_parse
###
# bamindex tests
.PHONY:
test_bamindex: mem_check_bamindex-build mem_check_bamindex-dump mem_check_bamindex-fetch
.PHONY: mem_check_bamindex-build
mem_check_bamindex-build: bamindex
$(GRIND) ./bamindex build test/bamindex/400.bam
.PHONY: mem_check_bamindex-dump
mem_check_bamindex-dump: bamindex mem_check_bamindex-build
$(GRIND) ./bamindex dump test/bamindex/400.bam.bci > /dev/null
.PHONY: mem_check_bamindex-fetch
mem_check_bamindex-fetch: bamindex mem_check_bamindex-build
$(GRIND) ./bamindex fetch test/bamindex/400.bam --chunk 5 > /dev/null