<commit_before>REFS = data/references

print-%:
	@echo '$*=$($*)'


$(REFS)/silva.bact_archaea.% :
	wget -N -P $(REFS)/ http://www.mothur.org/w/images/b/be/Silva.nr_v123.tgz
	tar xvzf $(REFS)/Silva.nr_v123.tgz -C $(REFS)/;
	mothur "#get.lineage(fasta=$(REFS)/silva.nr_v123.align, taxonomy=$(REFS)/silva.nr_v123.tax, taxon=Bacteria-Archaea)";
	mv $(REFS)/silva.nr_v123.pick.align $(REFS)/silva.bact_archaea.align
	mv $(REFS)/silva.nr_v123.pick.tax $(REFS)/silva.bact_archaea.tax; \
	rm $(REFS)/README.Rmd $(REFS)/README.html
	rm $(REFS)/?ilva.nr_v123.*

$(REFS)/silva.bacteria.% : $(REFS)/silva.bact_archaea.align $(REFS)/silva.bact_archaea.tax
	mothur "#get.lineage(fasta=$(REFS)/silva.bact_archaea.align, taxonomy=$(REFS)/silva.bact_archaea.tax, taxon=Bacteria)";
	mv $(REFS)/silva.bact_archaea.pick.align $(REFS)/silva.bacteria.align
	mv $(REFS)/silva.bact_archaea.pick.tax $(REFS)/silva.bacteria.tax

$(REFS)/silva.v4.% : $(REFS)/silva.bacteria.align
	mothur "#pcr.seqs(fasta=$^, start=13862, end=23445, keepdots=F, processors=8);degap.seqs();unique.seqs()"
	cut -f 1 $(REFS)/silva.bacteria.pcr.ng.names > $(REFS)/silva.bacteria.pcr.ng.accnos
	mothur "#get.seqs(fasta=$(REFS)/silva.bacteria.pcr.align, accnos=$(REFS)/silva.bacteria.pcr.ng.accnos);screen.seqs(minlength=240, maxlength=275, maxambig=0, maxhomop=8, processors=8); filter.seqs(vertical=T)"
	mv $(REFS)/silva.bacteria.pcr.pick.good.filter.fasta $(REFS)/silva.v4.align
	grep "^>" $(REFS)/silva.v4.align | cut -c 2- > $(REFS)/silva.v4.accnos
	mothur "#get.seqs(taxonomy=$(REFS)/silva.bacteria.tax, accnos=$(REFS)/silva.v4.accnos)"
	mv data/references/silva.bacteria.pick.tax data/references/silva.v4.tax
	rm $(REFS)/silva.bacteria.pcr.*
	rm $(REFS)/silva.filter

$(REFS)/trainset14_032015.pds.% :
	mkdir -p $(REFS)/rdp
	wget -N -P $(REFS)/ http://www.mothur.org/w/images/8/88/Trainset14_032015.pds.tgz; \
	tar xvzf $(REFS)/Trainset14_032015.pds.tgz -C $(REFS)/rdp;\
	mv $(REFS)/rdp/trainset14_032015.pds/trainset14_032015.* $(REFS);\
	rm -rf $(REFS)/rdp $(REFS)/Trainset*


.SECONDEXPANSION:
data/%.fasta data/%.count_table data/%.taxonomy : code/$$(notdir $$*).batch code/$$(notdir $$*).R\
			$(REFS)/silva.v4.align\
			$(REFS)/trainset14_032015.pds.fasta\
			$(REFS)/trainset14_032015.pds.tax
	bash $<



SAMPLES = mice human soil sediment marine even staggered
FRACTIONS = 0_2 0_4 0_6 0_8 1_0
REPLICATE = 01 02 03 04 05 06 07 08 09 10
DATAPATH = $(foreach S,$(SAMPLES),$(foreach F,$(FRACTIONS), $(foreach R, $(REPLICATE), data/$S/$S.$F.$R)))
SUB_FASTA = $(foreach D,$(DATAPATH),$D.fasta)
SUB_TAX = $(foreach D,$(DATAPATH),$D.taxonomy)
SUB_COUNT = $(foreach D,$(DATAPATH),$D.count_table)
SUB_FILES = $(SUB_FASTA) $(SUB_TAX) $(SUB_COUNT)


.SECONDEXPANSION:
$(SUB_FILES) : code/subsample.R $$(basename $$(basename $$(basename $$@))).fasta $$(basename $$(basename $$(basename $$@))).taxonomy $$(basename $$(basename $$(basename $$@))).count_table
	@echo $^
	$(eval SAMPLE=$(basename $(basename $(basename $(notdir $@)))))
	$(eval REP=$(subst .,,$(suffix $(basename $@))))
	$(eval FRAC=$(subst .,,$(suffix $(basename $(basename $@)))))
	@echo $(FRAC)
	@echo $(REP)
	R -e "source('code/subsample.R'); subsample('$(SAMPLE)', '$(FRAC)', '$(REP)')"

SUB_SM_DIST = $(subst fasta,sm.dist,$(SUB_FASTA))
$(SUB_SM_DIST) : $$(subst sm.dist,fasta,$$@)
	$(eval STATS=$(subst dist,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#dist.seqs(fasta=$^, cutoff=0.03, processors=8)"
	$(eval FULL_NAME=$(subst sm.dist,dist,$@))
	mv $(FULL_NAME) $@

SUB_LG_DIST = $(subst fasta,lg.dist,$(SUB_FASTA))
$(SUB_LG_DIST) : $$(subst lg.dist,fasta,$$@)
	$(eval STATS=$(subst dist,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#dist.seqs(fasta=$^, cutoff=0.15, processors=8)"
	$(eval FULL_NAME=$(subst lg.dist,dist,$@))
	mv $(FULL_NAME) $@




NN_LIST = $(subst sm.dist,nn.list,$(SUB_SM_DIST))
FN_LIST = $(subst sm.dist,fn.list,$(SUB_SM_DIST))
AN_LIST = $(subst lg.dist,an.list,$(SUB_LG_DIST))
VAGC_LIST = $(subst sm.dist,vagc.list,$(SUB_SM_DIST))
VDGC_LIST = $(subst sm.dist,vdgc.list,$(SUB_SM_DIST))
MCC_LIST = $(subst sm.dist,mcc.list,$(SUB_SM_DIST))
F1SCORE_LIST = $(subst sm.dist,f1score.list,$(SUB_SM_DIST))
ACCURACY_LIST = $(subst sm.dist,accuracy.list,$(SUB_SM_DIST))

AN_SPLIT5_1_LIST = $(subst fasta,an_split5_1.list,$(SUB_FASTA))
AN_SPLIT5_8_LIST = $(subst fasta,an_split5_8.list,$(SUB_FASTA))
MCC_SPLIT5_1_LIST = $(subst fasta,mcc_split5_1.list,$(SUB_FASTA))
MCC_SPLIT5_8_LIST = $(subst fasta,mcc_split5_8.list,$(SUB_FASTA))
VDGC_SPLIT5_1_LIST = $(subst fasta,vdgc_split5_1.list,$(SUB_FASTA))
VDGC_SPLIT5_8_LIST = $(subst fasta,vdgc_split5_8.list,$(SUB_FASTA))

UAGC_LIST = $(subst fasta,uagc.list,$(SUB_FASTA))
UDGC_LIST = $(subst fasta,udgc.list,$(SUB_FASTA))
OTUCLUST_LIST = $(subst fasta,otuclust.list,$(SUB_FASTA))
SUMACLUST_LIST = $(subst fasta,sumaclust.list,$(SUB_FASTA))
SWARM_LIST = $(subst fasta,swarm.list,$(SUB_FASTA))

LIST = $(FN_LIST) $(AN_LIST) $(VAGC_LIST) $(VDGC_LIST) $(MCC_LIST) $(F1SCORE_LIST) $(ACCURACY_LIST)\
	$(AN_SPLIT5_1_LIST) $(AN_SPLIT5_8_LIST) $(MCC_SPLIT5_1_LIST) $(MCC_SPLIT5_8_LIST) $(SWARM_LIST)\
	$(VDGC_SPLIT5_1_LIST) $(VDGC_SPLIT5_8_LIST) $(UAGC_LIST) $(UDGC_LIST) $(OTUCLUST_LIST) $(SUMACLUST_LIST)

LIST_% : 
	$(eval FILES=$(filter data/$*/%,$(LIST)))
	@echo '$(FILES)'


.SECONDEXPANSION:
$(NN_LIST) : $$(subst .nn.list,.sm.dist, $$@) $$(subst nn.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=nearest)" > /dev/null
	$(eval TEMP=$(subst nn.list,sm.nn.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(FN_LIST) : $$(subst .fn.list,.sm.dist, $$@) $$(subst fn.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=furthest)" > /dev/null
	$(eval TEMP=$(subst fn.list,sm.fn.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(AN_LIST) : $$(subst .an.list,.lg.dist, $$@) $$(subst an.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=average)" > /dev/null
	$(eval TEMP=$(subst an.list,lg.an.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(VAGC_LIST) : $$(subst vagc.list,fasta, $$@) $$(subst vagc.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(fasta=$(FASTA), count=$(COUNT), method=agc, cutoff=0.03)" > /dev/null
	$(eval TEMP=$(subst vagc.list,agc.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(VDGC_LIST) : $$(subst vdgc.list,fasta, $$@) $$(subst vdgc.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(fasta=$(FASTA), count=$(COUNT), method=dgc, cutoff=0.03)" > /dev/null
	$(eval TEMP=$(subst vdgc.list,dgc.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(MCC_LIST) : $$(subst .mcc.list,.sm.dist, $$@) $$(subst mcc.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=opti, metric=mcc, cutoff=0.03)" > /dev/null
	$(eval TEMP=$(subst mcc.list,sm.opti_mcc.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst mcc.list,sm.opti_mcc.sensspec,$@))
	$(eval TEMP2=$(subst mcc.list,mcc.sensspec,$@))
	mv $(TEMP1) $(TEMP2)

.SECONDEXPANSION:
$(F1SCORE_LIST) : $$(subst .f1score.list,.sm.dist, $$@) $$(subst f1score.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=opti, metric=f1score, cutoff=0.03)" > /dev/null
	$(eval TEMP=$(subst f1score.list,sm.opti_f1score.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst f1score.list,sm.opti_f1score.sensspec,$@))
	$(eval TEMP2=$(subst f1score.list,f1score.sensspec,$@))
	mv $(TEMP1) $(TEMP2)

.SECONDEXPANSION:
$(ACCURACY_LIST) : $$(subst .accuracy.list,.sm.dist, $$@) $$(subst accuracy.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=opti, metric=accuracy, cutoff=0.03)" > /dev/null
	$(eval TEMP=$(subst accuracy.list,sm.opti_accuracy.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst accuracy.list,sm.opti_accuracy.sensspec,$@))
	$(eval TEMP2=$(subst accuracy.list,accuracy.sensspec,$@))
	mv $(TEMP1) $(TEMP2)




.SECONDEXPANSION:
$(AN_SPLIT5_1_LIST) : $$(subst an_split5_1.list,fasta, $$@) $$(subst an_split5_1.list,taxonomy, $$@) $$(subst an_split5_1.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), count=$(COUNT), taxonomy=$(TAXONOMY), taxlevel=5, processors=1, cutoff=0.15)" > /dev/null
	$(eval TEMP=$(subst an_split5_1.list,an.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(AN_SPLIT5_8_LIST) : $$(subst an_split5_8.list,fasta, $$@) $$(subst an_split5_8.list,taxonomy, $$@) $$(subst an_split5_8.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), count=$(COUNT), taxonomy=$(TAXONOMY), taxlevel=5, processors=8, cutoff=0.15)" > /dev/null
	$(eval TEMP=$(subst an_split5_8.list,an.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(MCC_SPLIT5_1_LIST) : $$(subst mcc_split5_1.list,fasta, $$@)  $$(subst mcc_split5_1.list,taxonomy, $$@) $$(subst mcc_split5_1.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), taxonomy=$(TAXONOMY), count=$(COUNT), method=opti, metric=mcc, taxlevel=5, cutoff=0.03, processors=1)" > /dev/null
	$(eval TEMP=$(subst mcc_split5_1.list,opti_mcc.unique_list.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst mcc_split5_1.list,opti_mcc.unique_list.sensspec,$@))
	$(eval TEMP2=$(subst mcc_split5_1.list,mcc_split5_1.sensspec,$@))
	mv $(TEMP1) $(TEMP2)

.SECONDEXPANSION:
$(MCC_SPLIT5_8_LIST) : $$(subst mcc_split5_8.list,fasta, $$@)  $$(subst mcc_split5_8.list,taxonomy, $$@) $$(subst mcc_split5_8.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), taxonomy=$(TAXONOMY), count=$(COUNT), method=opti, metric=mcc, taxlevel=5, cutoff=0.03, processors=8)" > /dev/null
	$(eval TEMP=$(subst mcc_split5_8.list,opti_mcc.unique_list.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst mcc_split5_8.list,opti_mcc.unique_list.sensspec,$@))
	$(eval TEMP2=$(subst mcc_split5_8.list,mcc_split5_8.sensspec,$@))
	mv $(TEMP1) $(TEMP2)

.SECONDEXPANSION:
$(VDGC_SPLIT5_1_LIST) : $$(subst vdgc_split5_1.list,fasta, $$@)  $$(subst vdgc_split5_1.list,taxonomy, $$@) $$(subst vdgc_split5_1.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), taxonomy=$(TAXONOMY), count=$(COUNT), method=dgc, taxlevel=5, processors=1, cutoff=0.03)" > /dev/null
	$(eval TEMP=$(subst vdgc_split5_1.list,dgc.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(VDGC_SPLIT5_8_LIST) : $$(subst vdgc_split5_8.list,fasta, $$@)  $$(subst vdgc_split5_8.list,taxonomy, $$@) $$(subst vdgc_split5_8.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), taxonomy=$(TAXONOMY), count=$(COUNT), method=dgc, taxlevel=5, processors=8, cutoff=0.03)" > /dev/null
	$(eval TEMP=$(subst vdgc_split5_8.list,dgc.unique_list.list,$@))
	mv $(TEMP) $@



.SECONDEXPANSION:
$(UDGC_LIST) : $$(subst .udgc.list,.fasta, $$@) $$(subst .udgc.list,.count_table, $$@) code/run_udgc.sh code/uc_to_list.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) code/run_udgc.sh $(FASTA) $(COUNT)

.SECONDEXPANSION:
$(UAGC_LIST) : $$(subst .uagc.list,.fasta, $$@) $$(subst .uagc.list,.count_table, $$@) code/run_uagc.sh code/uc_to_list.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) code/run_uagc.sh $(FASTA) $(COUNT)

.SECONDEXPANSION:
$(OTUCLUST_LIST) : $$(subst .otuclust.list,.fasta, $$@) $$(subst .otuclust.list,.count_table, $$@) code/run_otuclust.sh code/run_otuclust.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) ./code/run_otuclust.sh $(FASTA) $(COUNT)

.SECONDEXPANSION:
$(SUMACLUST_LIST) : $$(subst .sumaclust.list,.fasta, $$@) $$(subst .sumaclust.list,.count_table, $$@) code/run_sumaclust.sh code/run_sumaclust.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) ./code/run_sumaclust.sh $(FASTA) $(COUNT)


$(SWARM_LIST) : $$(subst swarm.list,fasta, $$@) $$(subst swarm.list,count_table, $$@) code/run_swarm.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) R -e 'source("code/run_swarm.R"); get_mothur_list("$(FASTA)", "$(COUNT)")'
<commit_msg>Stop redirecting output to /dev/null<commit_after>REFS = data/references

print-%:
	@echo '$*=$($*)'


$(REFS)/silva.bact_archaea.% :
	wget -N -P $(REFS)/ http://www.mothur.org/w/images/b/be/Silva.nr_v123.tgz
	tar xvzf $(REFS)/Silva.nr_v123.tgz -C $(REFS)/;
	mothur "#get.lineage(fasta=$(REFS)/silva.nr_v123.align, taxonomy=$(REFS)/silva.nr_v123.tax, taxon=Bacteria-Archaea)";
	mv $(REFS)/silva.nr_v123.pick.align $(REFS)/silva.bact_archaea.align
	mv $(REFS)/silva.nr_v123.pick.tax $(REFS)/silva.bact_archaea.tax; \
	rm $(REFS)/README.Rmd $(REFS)/README.html
	rm $(REFS)/?ilva.nr_v123.*

$(REFS)/silva.bacteria.% : $(REFS)/silva.bact_archaea.align $(REFS)/silva.bact_archaea.tax
	mothur "#get.lineage(fasta=$(REFS)/silva.bact_archaea.align, taxonomy=$(REFS)/silva.bact_archaea.tax, taxon=Bacteria)";
	mv $(REFS)/silva.bact_archaea.pick.align $(REFS)/silva.bacteria.align
	mv $(REFS)/silva.bact_archaea.pick.tax $(REFS)/silva.bacteria.tax

$(REFS)/silva.v4.% : $(REFS)/silva.bacteria.align
	mothur "#pcr.seqs(fasta=$^, start=13862, end=23445, keepdots=F, processors=8);degap.seqs();unique.seqs()"
	cut -f 1 $(REFS)/silva.bacteria.pcr.ng.names > $(REFS)/silva.bacteria.pcr.ng.accnos
	mothur "#get.seqs(fasta=$(REFS)/silva.bacteria.pcr.align, accnos=$(REFS)/silva.bacteria.pcr.ng.accnos);screen.seqs(minlength=240, maxlength=275, maxambig=0, maxhomop=8, processors=8); filter.seqs(vertical=T)"
	mv $(REFS)/silva.bacteria.pcr.pick.good.filter.fasta $(REFS)/silva.v4.align
	grep "^>" $(REFS)/silva.v4.align | cut -c 2- > $(REFS)/silva.v4.accnos
	mothur "#get.seqs(taxonomy=$(REFS)/silva.bacteria.tax, accnos=$(REFS)/silva.v4.accnos)"
	mv data/references/silva.bacteria.pick.tax data/references/silva.v4.tax
	rm $(REFS)/silva.bacteria.pcr.*
	rm $(REFS)/silva.filter

$(REFS)/trainset14_032015.pds.% :
	mkdir -p $(REFS)/rdp
	wget -N -P $(REFS)/ http://www.mothur.org/w/images/8/88/Trainset14_032015.pds.tgz; \
	tar xvzf $(REFS)/Trainset14_032015.pds.tgz -C $(REFS)/rdp;\
	mv $(REFS)/rdp/trainset14_032015.pds/trainset14_032015.* $(REFS);\
	rm -rf $(REFS)/rdp $(REFS)/Trainset*


.SECONDEXPANSION:
data/%.fasta data/%.count_table data/%.taxonomy : code/$$(notdir $$*).batch code/$$(notdir $$*).R\
			$(REFS)/silva.v4.align\
			$(REFS)/trainset14_032015.pds.fasta\
			$(REFS)/trainset14_032015.pds.tax
	bash $<



SAMPLES = mice human soil sediment marine even staggered
FRACTIONS = 0_2 0_4 0_6 0_8 1_0
REPLICATE = 01 02 03 04 05 06 07 08 09 10
DATAPATH = $(foreach S,$(SAMPLES),$(foreach F,$(FRACTIONS), $(foreach R, $(REPLICATE), data/$S/$S.$F.$R)))
SUB_FASTA = $(foreach D,$(DATAPATH),$D.fasta)
SUB_TAX = $(foreach D,$(DATAPATH),$D.taxonomy)
SUB_COUNT = $(foreach D,$(DATAPATH),$D.count_table)
SUB_FILES = $(SUB_FASTA) $(SUB_TAX) $(SUB_COUNT)


.SECONDEXPANSION:
$(SUB_FILES) : code/subsample.R $$(basename $$(basename $$(basename $$@))).fasta $$(basename $$(basename $$(basename $$@))).taxonomy $$(basename $$(basename $$(basename $$@))).count_table
	@echo $^
	$(eval SAMPLE=$(basename $(basename $(basename $(notdir $@)))))
	$(eval REP=$(subst .,,$(suffix $(basename $@))))
	$(eval FRAC=$(subst .,,$(suffix $(basename $(basename $@)))))
	@echo $(FRAC)
	@echo $(REP)
	R -e "source('code/subsample.R'); subsample('$(SAMPLE)', '$(FRAC)', '$(REP)')"

SUB_SM_DIST = $(subst fasta,sm.dist,$(SUB_FASTA))
$(SUB_SM_DIST) : $$(subst sm.dist,fasta,$$@)
	$(eval STATS=$(subst dist,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#dist.seqs(fasta=$^, cutoff=0.03, processors=8)"
	$(eval FULL_NAME=$(subst sm.dist,dist,$@))
	mv $(FULL_NAME) $@

SUB_LG_DIST = $(subst fasta,lg.dist,$(SUB_FASTA))
$(SUB_LG_DIST) : $$(subst lg.dist,fasta,$$@)
	$(eval STATS=$(subst dist,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#dist.seqs(fasta=$^, cutoff=0.15, processors=8)"
	$(eval FULL_NAME=$(subst lg.dist,dist,$@))
	mv $(FULL_NAME) $@




NN_LIST = $(subst sm.dist,nn.list,$(SUB_SM_DIST))
FN_LIST = $(subst sm.dist,fn.list,$(SUB_SM_DIST))
AN_LIST = $(subst lg.dist,an.list,$(SUB_LG_DIST))
VAGC_LIST = $(subst sm.dist,vagc.list,$(SUB_SM_DIST))
VDGC_LIST = $(subst sm.dist,vdgc.list,$(SUB_SM_DIST))
MCC_LIST = $(subst sm.dist,mcc.list,$(SUB_SM_DIST))
F1SCORE_LIST = $(subst sm.dist,f1score.list,$(SUB_SM_DIST))
ACCURACY_LIST = $(subst sm.dist,accuracy.list,$(SUB_SM_DIST))

AN_SPLIT5_1_LIST = $(subst fasta,an_split5_1.list,$(SUB_FASTA))
AN_SPLIT5_8_LIST = $(subst fasta,an_split5_8.list,$(SUB_FASTA))
MCC_SPLIT5_1_LIST = $(subst fasta,mcc_split5_1.list,$(SUB_FASTA))
MCC_SPLIT5_8_LIST = $(subst fasta,mcc_split5_8.list,$(SUB_FASTA))
VDGC_SPLIT5_1_LIST = $(subst fasta,vdgc_split5_1.list,$(SUB_FASTA))
VDGC_SPLIT5_8_LIST = $(subst fasta,vdgc_split5_8.list,$(SUB_FASTA))

UAGC_LIST = $(subst fasta,uagc.list,$(SUB_FASTA))
UDGC_LIST = $(subst fasta,udgc.list,$(SUB_FASTA))
OTUCLUST_LIST = $(subst fasta,otuclust.list,$(SUB_FASTA))
SUMACLUST_LIST = $(subst fasta,sumaclust.list,$(SUB_FASTA))
SWARM_LIST = $(subst fasta,swarm.list,$(SUB_FASTA))

LIST = $(FN_LIST) $(AN_LIST) $(VAGC_LIST) $(VDGC_LIST) $(MCC_LIST) $(F1SCORE_LIST) $(ACCURACY_LIST)\
	$(AN_SPLIT5_1_LIST) $(AN_SPLIT5_8_LIST) $(MCC_SPLIT5_1_LIST) $(MCC_SPLIT5_8_LIST) $(SWARM_LIST)\
	$(VDGC_SPLIT5_1_LIST) $(VDGC_SPLIT5_8_LIST) $(UAGC_LIST) $(UDGC_LIST) $(OTUCLUST_LIST) $(SUMACLUST_LIST)

LIST_% :
	$(eval FILES=$(filter data/$*/%,$(LIST)))
	@echo '$(FILES)'


.SECONDEXPANSION:
$(NN_LIST) : $$(subst .nn.list,.sm.dist, $$@) $$(subst nn.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=nearest)"
	$(eval TEMP=$(subst nn.list,sm.nn.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(FN_LIST) : $$(subst .fn.list,.sm.dist, $$@) $$(subst fn.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=furthest)"
	$(eval TEMP=$(subst fn.list,sm.fn.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(AN_LIST) : $$(subst .an.list,.lg.dist, $$@) $$(subst an.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=average)"
	$(eval TEMP=$(subst an.list,lg.an.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(VAGC_LIST) : $$(subst vagc.list,fasta, $$@) $$(subst vagc.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(fasta=$(FASTA), count=$(COUNT), method=agc, cutoff=0.03)"
	$(eval TEMP=$(subst vagc.list,agc.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(VDGC_LIST) : $$(subst vdgc.list,fasta, $$@) $$(subst vdgc.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(fasta=$(FASTA), count=$(COUNT), method=dgc, cutoff=0.03)"
	$(eval TEMP=$(subst vdgc.list,dgc.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(MCC_LIST) : $$(subst .mcc.list,.sm.dist, $$@) $$(subst mcc.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=opti, metric=mcc, cutoff=0.03)"
	$(eval TEMP=$(subst mcc.list,sm.opti_mcc.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst mcc.list,sm.opti_mcc.sensspec,$@))
	$(eval TEMP2=$(subst mcc.list,mcc.sensspec,$@))
	mv $(TEMP1) $(TEMP2)

.SECONDEXPANSION:
$(F1SCORE_LIST) : $$(subst .f1score.list,.sm.dist, $$@) $$(subst f1score.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=opti, metric=f1score, cutoff=0.03)"
	$(eval TEMP=$(subst f1score.list,sm.opti_f1score.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst f1score.list,sm.opti_f1score.sensspec,$@))
	$(eval TEMP2=$(subst f1score.list,f1score.sensspec,$@))
	mv $(TEMP1) $(TEMP2)

.SECONDEXPANSION:
$(ACCURACY_LIST) : $$(subst .accuracy.list,.sm.dist, $$@) $$(subst accuracy.list,count_table, $$@)
	$(eval DIST=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster(column=$(DIST), count=$(COUNT), method=opti, metric=accuracy, cutoff=0.03)"
	$(eval TEMP=$(subst accuracy.list,sm.opti_accuracy.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst accuracy.list,sm.opti_accuracy.sensspec,$@))
	$(eval TEMP2=$(subst accuracy.list,accuracy.sensspec,$@))
	mv $(TEMP1) $(TEMP2)




.SECONDEXPANSION:
$(AN_SPLIT5_1_LIST) : $$(subst an_split5_1.list,fasta, $$@) $$(subst an_split5_1.list,taxonomy, $$@) $$(subst an_split5_1.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), count=$(COUNT), taxonomy=$(TAXONOMY), taxlevel=5, processors=1, cutoff=0.15)"
	$(eval TEMP=$(subst an_split5_1.list,an.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(AN_SPLIT5_8_LIST) : $$(subst an_split5_8.list,fasta, $$@) $$(subst an_split5_8.list,taxonomy, $$@) $$(subst an_split5_8.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), count=$(COUNT), taxonomy=$(TAXONOMY), taxlevel=5, processors=8, cutoff=0.15)"
	$(eval TEMP=$(subst an_split5_8.list,an.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(MCC_SPLIT5_1_LIST) : $$(subst mcc_split5_1.list,fasta, $$@)  $$(subst mcc_split5_1.list,taxonomy, $$@) $$(subst mcc_split5_1.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), taxonomy=$(TAXONOMY), count=$(COUNT), method=opti, metric=mcc, taxlevel=5, cutoff=0.03, processors=1)"
	$(eval TEMP=$(subst mcc_split5_1.list,opti_mcc.unique_list.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst mcc_split5_1.list,opti_mcc.unique_list.sensspec,$@))
	$(eval TEMP2=$(subst mcc_split5_1.list,mcc_split5_1.sensspec,$@))
	mv $(TEMP1) $(TEMP2)

.SECONDEXPANSION:
$(MCC_SPLIT5_8_LIST) : $$(subst mcc_split5_8.list,fasta, $$@)  $$(subst mcc_split5_8.list,taxonomy, $$@) $$(subst mcc_split5_8.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), taxonomy=$(TAXONOMY), count=$(COUNT), method=opti, metric=mcc, taxlevel=5, cutoff=0.03, processors=8)"
	$(eval TEMP=$(subst mcc_split5_8.list,opti_mcc.unique_list.list,$@))
	mv $(TEMP) $@
	$(eval TEMP1=$(subst mcc_split5_8.list,opti_mcc.unique_list.sensspec,$@))
	$(eval TEMP2=$(subst mcc_split5_8.list,mcc_split5_8.sensspec,$@))
	mv $(TEMP1) $(TEMP2)

.SECONDEXPANSION:
$(VDGC_SPLIT5_1_LIST) : $$(subst vdgc_split5_1.list,fasta, $$@)  $$(subst vdgc_split5_1.list,taxonomy, $$@) $$(subst vdgc_split5_1.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), taxonomy=$(TAXONOMY), count=$(COUNT), method=dgc, taxlevel=5, processors=1, cutoff=0.03)"
	$(eval TEMP=$(subst vdgc_split5_1.list,dgc.unique_list.list,$@))
	mv $(TEMP) $@

.SECONDEXPANSION:
$(VDGC_SPLIT5_8_LIST) : $$(subst vdgc_split5_8.list,fasta, $$@)  $$(subst vdgc_split5_8.list,taxonomy, $$@) $$(subst vdgc_split5_8.list,count_table, $$@)
	$(eval FASTA=$(word 1,$^))
	$(eval TAXONOMY=$(word 2,$^))
	$(eval COUNT=$(word 3,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) mothur "#cluster.split(fasta=$(FASTA), taxonomy=$(TAXONOMY), count=$(COUNT), method=dgc, taxlevel=5, processors=8, cutoff=0.03)"
	$(eval TEMP=$(subst vdgc_split5_8.list,dgc.unique_list.list,$@))
	mv $(TEMP) $@



.SECONDEXPANSION:
$(UDGC_LIST) : $$(subst .udgc.list,.fasta, $$@) $$(subst .udgc.list,.count_table, $$@) code/run_udgc.sh code/uc_to_list.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) code/run_udgc.sh $(FASTA) $(COUNT)

.SECONDEXPANSION:
$(UAGC_LIST) : $$(subst .uagc.list,.fasta, $$@) $$(subst .uagc.list,.count_table, $$@) code/run_uagc.sh code/uc_to_list.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) code/run_uagc.sh $(FASTA) $(COUNT)

.SECONDEXPANSION:
$(OTUCLUST_LIST) : $$(subst .otuclust.list,.fasta, $$@) $$(subst .otuclust.list,.count_table, $$@) code/run_otuclust.sh code/run_otuclust.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) ./code/run_otuclust.sh $(FASTA) $(COUNT)

.SECONDEXPANSION:
$(SUMACLUST_LIST) : $$(subst .sumaclust.list,.fasta, $$@) $$(subst .sumaclust.list,.count_table, $$@) code/run_sumaclust.sh code/run_sumaclust.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) ./code/run_sumaclust.sh $(FASTA) $(COUNT)


$(SWARM_LIST) : $$(subst swarm.list,fasta, $$@) $$(subst swarm.list,count_table, $$@) code/run_swarm.R
	$(eval FASTA=$(word 1,$^))
	$(eval COUNT=$(word 2,$^))
	$(eval STATS=$(subst list,stats, $@))
	/usr/bin/time -o $(STATS) R -e 'source("code/run_swarm.R"); get_mothur_list("$(FASTA)", "$(COUNT)")'
{'fraction_non_alphanumeric': 0.24371777769766018, 'fraction_numerical': 0.027183905973969788, 'mean_word_length': 6.24418908331157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1574390', 'n_tokens_mistral': 13127, 'n_tokens_neox': 12239, 'n_words': 1870}