4 ALNARG
:=aln
-l
17 -q
10
9 INF
:= $(patsubst %_1.fastq.gz
,%,$(foreach ONEINPUTPATH
,$(INPUTPATH
),$(wildcard $(ONEINPUTPATH
)/*_1.fastq.gz
)))
11 OUTF
:= $(addprefix $(OUTPUTPREFIX
)/,$(INF
))
12 SAI1
:= $(addsuffix _1.sai
,$(OUTF
))
13 SAI2
:= $(addsuffix _2.sai
,$(OUTF
))
14 SAMS
:= $(addsuffix .sam.gz
,$(OUTF
))
15 BAMS
:= $(addsuffix .bam
,$(OUTF
))
16 BAMSORT
:= $(addsuffix .
sort.bam
,$(OUTF
))
17 BAMRMDUP
:= $(addsuffix .rmdup.bam
,$(OUTF
))
19 PATHS
:= $(addprefix $(OUTPUTPREFIX
)/,$(MDAPATH
) $(MLBACPATH
))
21 NUMPROC
:= $(shell grep
-c ^processor
/proc
/cpuinfo
)
22 SAMCOUNT
:= $(words $(SAI1
))
23 SAITHREADS
:= $(shell echo
1.5*$(NUMPROC
)/$(SAMCOUNT
) |bc
)
24 ifneq ($(SAITHREADS
),)
25 ifneq ($(SAITHREADS
),0)
26 ifneq ($(SAITHREADS
),1)
27 ALNARG
+= -t
$(SAITHREADS
)
31 FREEMEM
:= $(shell free
-m|grep
-e
'-/+ buffers/cache'|awk
'{print $$NF}')
32 SAMMEM
:= $(shell echo
0.8*$(FREEMEM
)/$(SAMCOUNT
)/$(SAITHREADS
) |bc
)
34 NEEDED_COMMANDS
:= bc bwa samtools grep mkdir free gzip
37 @echo
"[$(OUTF)]" "[$(INF)]" "[$@]" "[$(SAMMEM) $(FREEMEM)]"
38 date
> $(OUTPUTPREFIX
)/_alldone.log
41 @for thecmd in
$(NEEDED_COMMANDS
); do \
42 if
! command
-v
"$${thecmd%% *}" >/dev
/null
2>&1; then \
44 echo
"[x]'$${thecmd%% *}' not found."; \
47 if
[ "$${checkok}" == "0" ]; then \
48 echo
"[!]Please install missing cmd(s) above."; \
55 $(OUTF
): $(PATHS
) $(BAMRMDUP
)
56 $(eval IN
:= $(patsubst $(OUTPUTPREFIX
)/%,%,$@
))
57 echo
"$@" "$<" "$(IN)"
60 $(SAI1
) $(SAI2
): |
$(PATHS
)
61 $(eval IN
:= $(patsubst $(OUTPUTPREFIX
)/%,%,$(@
:%.sai
=%)))
62 bwa
$(ALNARG
) $(REF
) $(IN
).fastq.gz
>$@
2>$@.log
&& \
66 $(SAMS
): $(SAI1
) $(SAI2
)
67 $(eval IN
:= $(@
:%.sam.gz
=%))
68 $(eval FQ
:= $(patsubst $(OUTPUTPREFIX
)/%,%,$(IN
)))
69 bwa
$(SAMPEARG
) $(REF
) $(IN
)_1.sai
$(IN
)_2.sai
$(FQ
)_1.fastq.gz
$(FQ
)_2.fastq.gz
2>$(IN
).sam.log |gzip
-9c
>$@
&& \
70 date
>>$(IN
).sam.log
&& \
71 echo done.
>>$(IN
).sam.log
74 samtools view
-bS
$< >$@
2>$@.log
&& \
76 echo
"done (sam.gz to bam)">>$@.log
79 if
[ "$(SAMMEM)" -gt
"768" ]; then \
80 SAMSORTMEM
="-@ $(SAITHREADS) -m $(SAMMEM)M";\
84 samtools
$(SAMSORTARG
) $$SAMSORTMEM $< $(@
:%.bam
=%) >>$<.log
&& \
86 echo
"done (bam sort)">>$<.log
88 $(BAMRMDUP
): $(BAMSORT
)
89 $(eval LOG
:= $(@
:%.rmdup.bam
=%.bam.log
))
90 samtools rmdup
$< $@
>>$(LOG
) && \
92 echo
"done (bam rmdup)">>$(LOG
)
95 @if
[ "$(NUMPROC)" -gt
"$(SAMCOUNT)" ]; then \
96 JOBCNT
="$(SAMCOUNT)";\
98 echo
-e
"Usage: make -j $(SAMCOUNT) |tee make.log\n\n$(NUMPROC) core(s) & $(FREEMEM) mb free memory found now.\nBWA will run sai with [$(ALNARG)] for your $(SAMCOUNT) bam file(s)."
99 @if
[ "$(SAMMEM)" -gt
"768" ]; then \
100 echo
-e
"SAMTOOLS will sort with [-@ $(SAITHREADS) -m $(SAMMEM)M], if free memory remains same when you type make."; \
106 .PHONY
: help
clean check