# Override this in Jenkins

OBO=http://purl.obolibrary.org/obo

all: gene_ontology_write.owl

%.owl: %.obo
	owltools --use-catalog $< -o $@

t:
	echo $(SVN)

# ----------------------------------------
# ADDING INFERENCES
# ----------------------------------------
# see: https://github.com/geneontology/go-ontology/issues/12315
# go inferences now go into a separate file.
# this is imported during an OE session (see oboedit.catalog)

# first strip the go_inferences import; we need to do this
# because we cannot create a new ontology with the same name
gene_ontology_write_noinf.obo: gene_ontology_write.obo
	grep -v '^import: http://purl.obolibrary.org/obo/go/extensions/go_inferences.owl' $< > $@.tmp && mv $@.tmp $@

# use robot to place inferences in a new file.
# TBD: should relaxed axioms go here?
go_inferences.owl: gene_ontology_write_noinf.obo
	robot reason -i $< -r ELK -n true -a true -x true annotate -R -O $(OBO)/go/extensions/go_inferences.owl -o $@.tmp.owl && mv $@.tmp.owl $@

# translation to obo.
# note that in order to get obo "!" comments into the file (to enhance readability), we must:
# (a) import the go ontology that contains the labels (b) save (c) strip out the import directive
go_inferences.obo: go_inferences.owl
	owltools $< --use-catalog gene_ontology_write.obo --add-imports-from-supports -o -f obo $@.tmp && grep -v ^import: $@.tmp > $@
#	owltools $< --use-catalog gene_ontology_write.obo -o -f obo $@

new_validated.obo: gene_ontology_write_noinf.obo
	robot reason -i $< -r elk -a true -s true -o $@.tmp.obo && grep -v ^owl-axioms: $@.tmp.obo > $@

SVN=SVN_SSH='$(SVNCL)' svn
#t2:
#	echo $(SVN)
go_inferences.diff: go_inferences.obo
	$(SVN) log gene_ontology_write.obo | head -4 > $@
	echo >> $@
	echo "changes in entailments" >> $@
	echo >> $@
	$(SVN) diff go_inferences.obo >> $@
.PRECIOUS: go_inferences.diff

go_inferences_difflog.txt: go_inferences.diff
	cat $< $@ > $@.tmp && mv $@.tmp $@

# ----------------------------------------
# EXPERIMENTAL/OBSOLETE BELOW
# ----------------------------------------

etines.tsv:
	wget --no-check-certificate https://raw.githubusercontent.com/geneontology/go-ontology/master/refactoring_inference_pipeline/etines.tsv

go_uber.obo: gene_ontology_write.obo uberon-ecas-to-add.obo
	(echo import: http://purl.obolibrary.org/obo/go/extensions/uberon_import.owl && obo-merge-tags.pl -t intersection_of $< uberon-ecas-to-add.obo) > $@


# NEW! NEW! NEW! NEW! NEW! NEW! NEW! NEW! 
# ----------------------------------------
# EXPERIMENTAL/OBSOLETE BELOW
# ----------------------------------------
# NEW! NEW! NEW! NEW! NEW! NEW! NEW! NEW! 

SRC=gene_ontology_write.obo

sync-from-git:
	curl -L https://raw.githubusercontent.com/geneontology/go-ontology/master/src/ontology/go-edit.obo | perl -npe 's@http://purl.obolibrary.org/obo/go/imports/@http://purl.obolibrary.org/obo/go/extensions/@' > $(SRC).tmp && mv $(SRC).tmp $(SRC)