Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OWLTools testing cleaning and updates around ECO #321

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 98 additions & 52 deletions OWLTools-Annotation/src/test/java/owltools/gaf/EcoToolsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ public static void beforeClass() throws Exception {
ParserWrapper pw = new ParserWrapper();

//NOTE: Yes, the GO here is unnecessary, but we're trying to also catch a certain behavior
// where auxilery ontologies are not caught. The best wat to do that here is to load ECO
// where auxilery ontologies are not caught. The best way to do that here is to load ECO
// second and then do the merge.
OWLOntology ont_main = pw.parse(getResourceIRIString("go_xp_predictor_test_subset.obo"));
OWLOntology ont_scnd = pw.parse(getResourceIRIString("eco.obo"));
OWLOntology ont_scnd = pw.parse(getResourceIRIString("eco.20211012.obo"));
g = new OWLGraphWrapper(ont_main);
g.addSupportOntology(ont_scnd);

// NOTE: This step is necessary or things will get ignored!
// (This cropped-up in the loader at one point.)
for (OWLOntology ont : g.getSupportOntologySet())
g.mergeOntology(ont);

OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
r = reasonerFactory.createReasoner(g.getSourceOntology());
g.setReasoner(r);
}

@AfterClass
public static void afterClass() throws Exception {
if (g != null) {
Expand All @@ -63,56 +63,102 @@ public static void afterClass() throws Exception {
@Test
public void testSimpleEco() throws OWLOntologyCreationException, IOException{

///
/// From: http://purl.obolibrary.org/obo/ECO_0000316
/// IGI should be: "experimental evidence used in manual assertion" in:
///
/// IGI
///
/// From: http://purl.obolibrary.org/obo/ECO_0000316
/// IGI should be: "experimental evidence used in manual assertion" in:
/// + evidence
/// + experimental evidence
/// + experimental phenotypic evidence
/// + genetic interaction evidence
/// - genetic interaction evidence used in manual assertion
///

// Create EcoTools instance.
EcoTools eco = new EcoTools(g, g.getReasoner(), true);

// Evidence type closure.
Set<OWLClass> ecoClasses = eco.getClassesForGoCode("IGI");

// Hopefully we're just getting one here.
assertEquals("Right now, one code (IGI) should go to one ECO term.", 1, ecoClasses.size());
OWLClass igi = ecoClasses.iterator().next();

IRI igiIRI = igi.getIRI();
assertEquals("http://purl.obolibrary.org/obo/ECO_0000316", igiIRI.toString());
String igiId = g.getIdentifier(igi);
assertEquals("ECO:0000316", igiId);

String igiLabel = g.getLabel(igi);
assertEquals("genetic interaction evidence used in manual assertion", igiLabel);

// Since we're reflexive, our six ancestors should be:
Set<String> foo = new HashSet<String>();
foo.add("evidence"); // ECO:0000000
foo.add("experimental evidence"); // ECO:0000006
foo.add("experimental phenotypic evidence"); // ECO:0000059
foo.add("genetic interaction evidence"); // ECO:0000011
foo.add(igiLabel); // ECO:0000316

/// + experimental evidence
/// + experimental phenotypic evidence
/// + genetic interaction evidence
/// - genetic interaction evidence used in manual assertion
///

// Create EcoTools instance.
EcoTools eco = new EcoTools(g, g.getReasoner(), true);

// Evidence type closure.
Set<OWLClass> ecoClasses = eco.getClassesForGoCode("IGI");

// Hopefully we're just getting one here.
assertEquals("Right now, one code (IGI) should go to one ECO term.", 1, ecoClasses.size());
OWLClass igi = ecoClasses.iterator().next();

IRI igiIRI = igi.getIRI();
assertEquals("http://purl.obolibrary.org/obo/ECO_0000316", igiIRI.toString());
String igiId = g.getIdentifier(igi);
assertEquals("ECO:0000316", igiId);

String igiLabel = g.getLabel(igi);
assertEquals("genetic interaction evidence used in manual assertion", igiLabel);

// Since we're reflexive, our ancestors should be:
Set<String> bar = new HashSet<String>();
bar.add("evidence");
bar.add("experimental evidence");
bar.add("experimental phenotypic evidence");
bar.add("experimental phenotypic evidence used in manual assertion");
bar.add("experimental evidence used in manual assertion");
bar.add("genetic interaction evidence");
bar.add(igiLabel);

// inferred by reasoner using cross products
foo.add("experimental evidence used in manual assertion"); // ECO:0000269

Set<OWLClass> ecoSuperClasses = eco.getAncestors(ecoClasses, true);

for( OWLClass ec : ecoSuperClasses ){
String ec_str_label = g.getLabel(ec);
assertTrue("Actual ancestor should have been in hash, not: " + ec_str_label,
foo.contains(ec_str_label));
}

assertEquals(6, ecoSuperClasses.size());
bar.add("evidence used in manual assertion");

Set<OWLClass> ecoSuperClasses = eco.getAncestors(ecoClasses, true);

for( OWLClass ec : ecoSuperClasses ){
String ec_str_label = g.getLabel(ec);
assertTrue("Actual ancestor should have been in hash, not: " + ec_str_label,
bar.contains(ec_str_label));
}

assertEquals(8, ecoSuperClasses.size());

///
/// IEA
///

Set<OWLClass> ecoIeaClasses = eco.getClassesForGoCode("IEA");

// Hopefully we're just getting one here?
assertEquals("Right now, one code (IEA) should go to one ECO term.", 1, ecoIeaClasses.size());


// OWLClass iea = ecoIeaClasses.iterator().next();

// IRI ieaIRI = iea.getIRI();
// assertEquals("http://purl.obolibrary.org/obo/ECO_0007669", ieaIRI.toString());
// String ieaId = g.getIdentifier(iea);
// assertEquals("ECO:0007669", ieaId);

// String ieaLabel = g.getLabel(iea);
// assertEquals("genetic interaction evidence used in manual assertion", ieaLabel);

// // Since we're reflexive, our ancestors should be:
// Set<String> foo = new HashSet<String>();
// foo.add("evidence");
// foo.add("experimental evidence");
// foo.add("experimental phenotypic evidence");
// foo.add("experimental phenotypic evidence used in manual assertion");
// foo.add("experimental evidence used in manual assertion");
// foo.add("genetic interaction evidence");
// foo.add(igiLabel); // ECO:0000316

// // inferred by reasoner using cross products
// foo.add("evidence used in manual assertion");

// Set<OWLClass> ecoIeaSuperClasses = eco.getAncestors(ecoClasses, true);

// for( OWLClass ec : ecoIeaSuperClasses ){
// String ec_str_label = g.getLabel(ec);
// assertTrue("Actual ancestor should have been in hash, not: " + ec_str_label,
// foo.contains(ec_str_label));
// }

// assertEquals(8, ecoIeaSuperClasses.size());

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,36 @@ public void basicTest() throws Exception {
ParserWrapper p = new ParserWrapper();
OWLGraphWrapper graph = p.parseToOWLGraph(EcoMapper.ECO_PURL);
EcoMapper mapper = EcoMapperFactory.createEcoMapper(graph);

assertFalse(mapper.isGoEvidenceCode(null));
assertFalse(mapper.isGoEvidenceCode("FOO"));

assertTrue(mapper.isGoEvidenceCode("IEA"));
assertTrue(mapper.isGoEvidenceCode("ND"));
assertTrue(mapper.isGoEvidenceCode("IPI"));

assertEquals(graph.getOWLClassByIdentifier("ECO:0000353"), mapper.getEcoClassForCode("IPI"));

assertEquals(2, mapper.getAllEcoClassesForCode("IGC").size());
}

@Test
public void checkMapping() throws Exception {
final OntologyMapperPair<TraversingEcoMapper> pair = EcoMapperFactory.createTraversingEcoMapper();
TraversingEcoMapper mapper = pair.getMapper();
OWLGraphWrapper g = pair.getGraph();

single(mapper, g, "0000269", "EXP");
single(mapper, g, "0000318", "IBA");
single(mapper, g, "0000319", "IBD");
single(mapper, g, "0000305", "IC");
single(mapper, g, "0000314", "IDA");

single(mapper, g, "0000270", "IEP");

single(mapper, g, "0000316", "IGI");
single(mapper, g, "0000320", "IKR"); // see also IMR
single(mapper, g, "0000315", "IMP");
single(mapper, g, "0000320", "IMR"); // yes, same as IKR, IMR is considered deprecated
single(mapper, g, "0000353", "IPI");
single(mapper, g, "0000321", "IRD");
single(mapper, g, "0000247", "ISA");
Expand All @@ -64,38 +63,36 @@ public void checkMapping() throws Exception {
single(mapper, g, "0000307", "ND");
single(mapper, g, "0000245", "RCA");
single(mapper, g, "0000304", "TAS");
multiple(mapper, g,
Arrays.asList("0000317", "0000354"),
"IGC",

multiple(mapper, g,
Arrays.asList("0000317", "0000354"),
"IGC",
Arrays.asList("GO_REF:0000025"));

multiple(mapper, g,
Arrays.asList("0000501", "0000256", "0000501", "0000501",
"0000265", "0000265", "0000501", "0000265",
"0000322", "0000323", "0000322", "0000323",
"0000265", "0000256", "0000363"),
"IEA",
Arrays.asList("GO_REF:0000002", "GO_REF:0000003", "GO_REF:0000004", "GO_REF:0000019",
"GO_REF:0000020", "GO_REF:0000023", "GO_REF:0000035", "GO_REF:0000037",
"GO_REF:0000038", "GO_REF:0000039", "GO_REF:0000040", "GO_REF:0000049",
"GO_REF:0000107", "GO_REF:0000108"));

multiple(mapper, g,
Arrays.asList("0000250", "0000255", "0000031", "0000031"),
"ISS",

multiple(mapper, g,
Arrays.asList("0007669", "0000256", "0007669", "0007669",
"0007669", "0000265", "0007669", "0007669",
"0007669", "0007669", "0000249", "0000363"),
"IEA",
Arrays.asList("GO_REF:0000002", "GO_REF:0000003", "GO_REF:0000004", "GO_REF:0000020",
"GO_REF:0000035", "GO_REF:0000041", "GO_REF:0000043", "GO_REF:0000116",
"GO_REF:0000044", "GO_REF:0000107", "GO_REF:0000108"));

multiple(mapper, g,
Arrays.asList("0000250", "0000255", "0000031", "0000031"),
"ISS",
Arrays.asList("GO_REF:0000011", "GO_REF:0000012", "GO_REF:0000027"));
}

private void single(TraversingEcoMapper mapper, OWLGraphWrapper ecoGraph, String eco, String go) {
final OWLClass cls = mapper.getEcoClassForCode(go);
assertEquals("http://purl.obolibrary.org/obo/ECO_"+eco, cls.getIRI().toString());
Set<OWLClass> codes = mapper.getAllEcoClassesForCode(go);
assertEquals(1, codes.size());
assertEquals(cls, codes.iterator().next());

checkEcoBranch(mapper, ecoGraph, cls);

}

private void checkEcoBranch(TraversingEcoMapper mapper, OWLGraphWrapper g, final OWLClass cls) {
Expand All @@ -105,24 +102,24 @@ private void checkEcoBranch(TraversingEcoMapper mapper, OWLGraphWrapper g, final
assertNotNull(e);
OWLClass a = g.getOWLClassByIdentifier("ECO:0000217");
assertNotNull(a);

Set<OWLClass> ancestors = mapper.getAncestors(cls, false);
String id = g.getIdentifier(cls);
assertTrue("The "+id+" class should be a descendant of ECO:0000000 ! evidence", ancestors.contains(e));
assertFalse("The "+id+" class may not be a descendant of ECO:0000217 ! assertion method", ancestors.contains(a));
}

private void multiple(TraversingEcoMapper mapper, OWLGraphWrapper ecoGraph, List<String> ecos, String go, List<String> refs) {
final OWLClass cls = mapper.getEcoClassForCode(go);
final String first = ecos.get(0);
assertEquals("http://purl.obolibrary.org/obo/ECO_"+first, cls.getIRI().toString());

assertEquals(refs.size() + 1, ecos.size());
checkEcoBranch(mapper, ecoGraph, cls);

Set<OWLClass> all = new HashSet<OWLClass>();
all.add(cls);

for (int i = 0; i < refs.size(); i++) {
String ref = refs.get(i);
String currentEco = ecos.get(i+1);
Expand All @@ -131,7 +128,7 @@ private void multiple(TraversingEcoMapper mapper, OWLGraphWrapper ecoGraph, List
all.add(refCls);
checkEcoBranch(mapper, ecoGraph, refCls);
}

Set<OWLClass> codes = mapper.getAllEcoClassesForCode(go);
assertEquals(all.size(), codes.size());
assertTrue(all.containsAll(codes));
Expand Down
Loading