modified: src1/input.c
[GalaxyCodeBases.git] / makefiles / mpileup.mk
blob8b58fed70a814f61121727a5d42abc95fc41550a
1 OUTMAIN := mpileup
2 DATESTR := $(shell date +%Y%m%d%Z%H%M%S)
3 OUTP := $(OUTMAIN)_$(DATESTR)
4 OUT := $(OUTP).bcf
5 VCF := $(OUTP).vcf
6 SAMTOOLS := samtools
7 BCFTOOLS := bcftools
9 REF := /bak/seqdata/genomes/Felis_catus_80_masked/Felis_catus80_chr.fa
10 CMD := $(SAMTOOLS) mpileup -g -d 1000 -t AD,ADF,DP,DPR,DV,DP4,SP -f $(REF)
12 #BAMS := pti096_clean_aln_pe_rmdup.bam pti183_clean_aln_pe_rmdup.bam pti301_clean_aln_pe_rmdup.bam pti332_clean_aln_pe_rmdup.bam
13 BAMS := $(sort $(wildcard *.bam))
14 #CHRS := scaffold1000 scaffold979 scaffold982
15 RAWCHRS := $(sort $(shell $(SAMTOOLS) view -H $(firstword $(BAMS)) | sed -n 's/^@SQ\tSN:\([^\t]*\).*/\1/p'))
17 p+ = $(subst |,+,$1)
18 +p = $(subst +,|,$1)
20 CHRS := $(call p+,$(RAWCHRS))
22 BYCHR = $(addsuffix .bcf,$(addprefix bychr/_,$(CHRS)))
23 #BYCHRINX = $(addsuffix .csi,$(BYCHR))
24 BAIS = $(addsuffix .bai,$(BAMS))
25 #GATKBAIS = $(BAMS:.bam=.bai)
27 define newline
29 endef
31 NOOP :=
32 space = $(NOOP) $(NOOP)
34 .PHONY: all clean cleanall list
36 all: list $(OUT) bcfbychr.lst $(VCF)
37 $(BCFTOOLS) index $(VCF).gz &
38 $(BCFTOOLS) stats -F $(REF) -s - -d 0,1500,1 $(VCF).gz >$(VCF).stats
39 $(BCFTOOLS) norm -Df $(REF) -c e -m+both $(VCF).gz | $(BCFTOOLS) filter -sLowQual -e'%QUAL<10' | $(BCFTOOLS) filter -m+ -sDepthHigh -e'DP>650' | $(BCFTOOLS) filter -m+ -sDepthLow -e'DP<2' | $(BCFTOOLS) filter -m+ -sBadSites -e'%QUAL<10 && RPB<0.1' | tee >($(BCFTOOLS) view -Oz -o $(VCF).filtering.gz) | $(BCFTOOLS) view -f .,PASS -Oz -o $(VCF).filtered.gz
40 $(BCFTOOLS) index $(VCF).filtered.gz &
41 $(BCFTOOLS) index $(VCF).filtering.gz
43 list:
44 @echo -e '$(subst $(space),\n,$(BAMS))' >_bams.lst
45 @echo -e '$(subst $(space),\n,$(CHRS))' >_chrs.lst
46 @echo -e '\n$(subst $(space),\n,$(RAWCHRS))' >>_chrs.lst
47 @echo -e '$(subst $(space),\n,$(BYCHR))' >_bcfbychr.lst
49 bai: $(BAIS)
51 $(OUT): $(BYCHR) bcfbychr.lst
52 ulimit -n 2048
53 $(BCFTOOLS) concat -a -O b -f bcfbychr.lst -o $(OUT)
55 $(VCF): $(OUT)
56 $(BCFTOOLS) call -vmO z -f GQ,GP -o $(@).gz $<
58 bychr/:
59 mkdir bychr
61 bcfbychr.lst: $(BYCHR)
62 @echo dbg2 [$@] [$*] [$^] [$|]
63 echo -e '$(subst $(space),\n,$(BYCHR))' >bcfbychr.lst
65 %.bai: $*
66 $(SAMTOOLS) index $*
68 bychr/_%.bcf: $(BAMS) bai | bychr/
69 $(CMD) -r "$(call +p,$(*))" $(BAMS) >$@
70 $(BCFTOOLS) index $@
72 clean:
73 -rm -fr bychr
75 cleanall:
76 -rm -fr bychr
77 -rm bcfbychr.lst
78 -rm $(OUT)