package owltools.gaf.owl;

import static org.junit.Assert.*;

import java.util.List;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyFormat;

import owltools.OWLToolsTestBasics;
import owltools.gaf.GafDocument;
import owltools.gaf.inference.FoldBasedPredictor;
import owltools.gaf.inference.Prediction;
import owltools.gaf.parser.GafObjectsBuilder;
import owltools.graph.OWLGraphWrapper;
import owltools.io.OWLPrettyPrinter;
import owltools.io.ParserWrapper;

public class FoldBasedPredictorTest extends OWLToolsTestBasics{

	private Logger LOG = Logger.getLogger(FoldBasedPredictorTest.class);
	
	@Test
	public void testConversion() throws Exception{
		ParserWrapper pw = new ParserWrapper();
		OWLOntology ont = pw.parse(getResourceIRIString("mgi-exttest-go-subset.obo"));
		OWLGraphWrapper g = new OWLGraphWrapper(ont);
		//g.addSupportOntology(pw.parse(getResourceIRIString("gorel.owl")));
		OWLPrettyPrinter owlpp = new OWLPrettyPrinter(g);

		GafObjectsBuilder builder = new GafObjectsBuilder();

		GafDocument gafdoc = builder.buildDocument(getResource("mgi-exttest.gaf"));
		//GafDocument gafdoc = builder.buildDocument(getResource("foo.gaf"));

		FoldBasedPredictor fbp = new FoldBasedPredictor(gafdoc, g, true);
		OWLClass ecp = (OWLClass) g.getOWLObjectByLabel("epithelial cell proliferation");
		for (OWLClassExpression ex : ecp.getEquivalentClasses(g.getSourceOntology())) {
			LOG.info("ECA="+ex);
			// expect:  ObjectIntersectionOf(<http://purl.obolibrary.org/obo/GO_0008283> ObjectSomeValuesFrom(<http://purl.obolibrary.org/obo/TEST_1234567> <http://purl.obolibrary.org/obo/CL_0000066>))
		}
		List<Prediction> preds = fbp.predict("MGI:TESTME");
		//Set<Prediction> preds = fbp.getAllPredictions();
		for (Prediction pred : preds) {
			LOG.info(pred);
		}
		assertEquals(1, preds.size());
		 preds = fbp.getAllPredictions();
		for (Prediction pred : preds) {
			LOG.info(pred.render(owlpp));
		}
		LOG.info("total preds: "+preds.size());
		/*
		OWLClass hcp = (OWLClass) 
		g.getOWLObjectByLabel("cell proliferation acts_on_population_of some hepatocyte");
		for (OWLClassExpression ex : hcp.getEquivalentClasses(g.getSourceOntology())) {
			LOG.info("EC for HCP ="+ex);
		}
		for(OWLClass sc : fbp.reasoner.getSuperClasses(hcp, false).getFlattened()) {
			LOG.info("SC ="+sc);
		}
		for(OWLClass ec : fbp.reasoner.getEquivalentClasses(hcp).getEntities()) {
			String label = g.getLabel(ec);
			LOG.info("hcp EQUIV_TO ="+ec+ " "+label);
		}
		*/
		
	}

}

@@ -51,17 +51,28 @@
 .Assert.
-*
+assertEquals
 ;%0A%0Aimpor
@@ -149,95 +149,8 @@
 st;%0A
-import org.semanticweb.owlapi.model.IRI;%0Aimport org.semanticweb.owlapi.model.OWLAxiom;%0A
 impo
@@ -290,134 +290,16 @@
 .OWL
-EquivalentClassesAxiom;%0Aimport org.semanticweb.owlapi.model.OWLOntology;%0Aimport org.semanticweb.owlapi.model.OWLOntologyFormat
+Ontology
 ;%0A%0Ai
@@ -1967,610 +1967,709 @@
 ;%0A%09%09
- preds = fbp.getAllPredictions();%0A%09%09for (Prediction pred : preds) %7B%0A%09%09%09LOG.info(pred.render(owlpp
+// GO:0050673 'epithelial cell proliferation'%0A%09%09assertEquals(%22GO:0050673%22, preds.get(0).getGeneAnnotation().getCls(
 ));%0A%09%09
-%7D
 %0A%09%09
-LOG.info(%22total preds: %22+preds.size());%0A%09%09/*%0A%09%09OWLClass hcp = (OWLClass) %0A%09%09g.getOWLObjectByLabel(%22cell proliferation acts_on_population_of some hepatocyte%22);%0A%09%09for (OWLClassExpression ex : hcp.getEquivalentClasses(g.getSourceOntology())) %7B%0A%09%09%09LOG.info(%22EC for HCP =%22+ex
+// TESTME2%0A%09%09preds = fbp.predict(%22MGI:TESTME2%22);%0A%09%09assertEquals(1, preds.size());%0A%09%09// GO:0050701 'interleukin-1 secretion'%0A%09%09assertEquals(%22GO:0050701%22, preds.get(0).getGeneAnnotation().getCls());%0A%09%09%0A%09%09// TESTME3%0A%09%09preds = fbp.predict(%22MGI:TESTME3%22);%0A%09%09assertEquals(1, preds.size());%0A%09%09// GO:0005623 'cell'%0A%09%09assertEquals(%22GO:0005623%22, preds.get(0).getGeneAnnotation().getCls()
 );%0A%09%09
-%7D
 %0A%09%09
-for(OWLClass sc : fbp.reasoner.getSuperClasses(hcp, false).getFlattened()) %7B%0A%09%09%09LOG.info(%22SC =%22+sc);%0A%09%09%7D%0A%09%09for(OWLClass ec : fbp.reasoner.getEquivalentClasses(hcp).getEntities()) %7B%0A%09%09%09String label = g.getLabel(ec
+// check that only the expected predictions are here%0A%09%09preds = fbp.getAllPredictions();%0A%09%09assertEquals(3, preds.size());%0A%09%09for (Prediction pred : preds) %7B%0A%09%09%09LOG.info(pred.render(owlpp)
 );%0A%09
+%09%7D%0A
 %09%09LO
@@ -2680,51 +2680,37 @@
 fo(%22
-hcp EQUIV_TO =%22+ec+ %22 %22+label);%0A%09%09%7D%0A%09%09*/%0A%09%09
+total preds: %22+preds.size());
 %0A%09%7D%0A

update test, see issue #132