GO=../../../ontology/editors/gene_ontology_write.obo

ALL_OBO =  taxon_go_triggers.obo  taxon_union_terms.obo  $(GO)  ../../../scratch/xps/biological_process_xp_cellular_component.obo  ../../../scratch/xps/relations_process_xp.obo
INC_ALL_OBO = $(patsubst %, -i %,$(ALL_OBO))

all: taxon_union_materialized.obo

cvs_update:
	cd ../../.. && cvs update ; echo updated

cycle: cvs_update
	cvs add report-*.txt ; cvs commit -m autocommit

all_reports:
	ls gene-associations/gene_association.*.gz | grep -v pdb | perl -ne '/gene_association.(\S+).gz/;print `make report-$$1.txt`'

gene-associations:
	ln -s ../../../gene-associations

taxon_union_inferred-ontol_db.pro: taxon_union_terms.obo
	blip-findall -i $< -r taxslim -consult materialize_union.pro "new_subclass(X,Y)" -select "ontol_db:subclass(X,Y);class(X)" -write_prolog > $@

taxon_union_materialized.obo: taxon_union_inferred-ontol_db.pro taxon_union_terms.obo
	blip -i $< -i taxon_union_terms.obo io-convert -to obo -o $@

problem_assertions.txt:
	blip-findall -r taxunionm  -r go -r taxslim -r gotax -u examples/taxon_restrictions problem_assertions/7 -label -no_pred > $@

#taxon_union_materialized.obo: taxon_union_terms.obo
#	blip -i taxon_union_terms.obo io-convert -to obo -u ontol_entailment_union -o $@


go-taxon-merged.obo:
	obo-cat.pl $(ALL_OBO) ncbi_taxon_slim.obo > $@

#violations.txt: go2taxon.pro
#	blip -r go -r taxonomy -i $< -u query_go_taxon findall -label violation/2 > $@.tmp && mv $@.tmp $@

taxon_violations.txt:
	go-gaf-inference.pl --validate $(INC_ALL_OBO) -i $(HOME)/obo-util/obo-all/ncbi_taxonomy/ncbi_taxonomy.obo ../../gene-associations/gene_association.*.gz > $@.tmp && mv $@.tmp $@

report-%.txt: gene-associations/gene_association.%.gz taxon_go_triggers.obo taxon_union_materialized.obo $(GO)
	gzip -dc $< | blip sed -u ontol_db -table_pred user:only_in_taxon/2 -table_pred user:never_in_taxon/2 -r go -i taxon_union_materialized.obo -i taxon_go_triggers.obo -r taxonomy -i tax_logic.pro -rulefile invalid_taxon_gafrule.pro - > $@.tmp && mv $@.tmp $@