# User-defined parameters
# ASSEMBLY=abcDef1

.PHONY : init

db :
	#ln -s $(shell pwd) /gbdb/$(ASSEMBLY)
	ln -sf $(shell pwd) /gbdb/$(ASSEMBLY)
	hgsql -e "create database if not exists $(ASSEMBLY);" mysql
	hgsql $(ASSEMBLY) < $(KENT)/src/hg/lib/grp.sql
	hgLoadSqlTab -notOnServer $(ASSEMBLY) chromInfo $(KENT)/src/hg/lib/chromInfo.sql bed/chromInfo/chromInfo.tab
	hgGoldGapGl $(ASSEMBLY) $(ASSEMBLY).agp

init : $(ASSEMBLY).agp $(ASSEMBLY).2bit $(ASSEMBLY).check html bed/chromInfo/chromInfo.tab

bed/chromInfo/chromInfo.tab : chromInfo.txt
	mkdir -p $(dir $@)
	awk '{printf "%s\t%d\t/gbdb/$(ASSEMBLY)/$(ASSEMBLY).2bit\n", $$1, $$2}' $< > $@

chromInfo.txt : $(ASSEMBLY).2bit
	twoBitInfo $< stdout | sort -k2nr > $@

%.check : %.check.agp %.2bit
	checkAgpAndFa $^ > $@

%.check.agp : %.agp
	sort -k1,1 -k2n,2n $< > $@

html :
	mkdir -p $@

%.2bit : %.fasta
	faToTwoBit $< $@

%.agp : %.fasta
	hgFakeAgp -minContigGap=1 $< $@
