Skip to content

Commit

Permalink
attempt to clean up older eco-related tests; updating resources for e…
Browse files Browse the repository at this point in the history
…co tests; add some testing for IEAs; attempting clarifying work on work on geneontology/pipeline#251
  • Loading branch information
kltm committed Oct 12, 2021
1 parent 9faa4f4 commit 7557c2b
Show file tree
Hide file tree
Showing 4 changed files with 41,516 additions and 83 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ public static void beforeClass() throws Exception {
// where auxilery ontologies are not caught. The best wat 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.obo"));
//OWLOntology ont_scnd = pw.parse(getResourceIRIString("eco-basic.20211012.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 @@ -60,51 +62,71 @@ public static void afterClass() throws Exception {
@Test
public void testSimpleEco() throws Exception{

///
/// From: http://purl.obolibrary.org/obo/ECO_0000316
/// IGI should be: "experimental evidence used in manual assertion" in:
// Create EcoTools instance.
TraversingEcoMapper eco = EcoMapperFactory.createTraversingEcoMapper(g, g.getReasoner(), true);

///
/// 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.
TraversingEcoMapper eco = EcoMapperFactory.createTraversingEcoMapper(g, g.getReasoner(), true);

OWLClass igi = eco.getEcoClassForCode("IGI");
assertNotNull("IGI must map to one OWLClass", igi);

assertEquals("http://purl.obolibrary.org/obo/ECO_0000316", igi.getIRI().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
///


OWLClass igi = eco.getEcoClassForCode("IGI");
assertNotNull("IGI must map to one OWLClass", igi);
assertEquals("http://purl.obolibrary.org/obo/ECO_0000316", igi.getIRI().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");
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);

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

Set<OWLClass> ecoSuperClasses = eco.getAncestors(igi, 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());
foo.add("evidence used in manual assertion");

Set<OWLClass> ecoSuperClasses = eco.getAncestors(igi, 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(8, ecoSuperClasses.size());

///
/// IEA
///

OWLClass iea = eco.getEcoClassForCode("IEA");
assertNotNull("IEA must map to one OWLClass", iea);
assertEquals("http://purl.obolibrary.org/obo/ECO_0007669", iea.getIRI().toString());
String ieaId = g.getIdentifier(iea);
assertEquals("ECO:0007669", ieaId);

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

String ieaLabel = g.getLabel(iea);
assertEquals("computational evidence used in automatic assertion", ieaLabel);

assertEquals(4, ecoIeaSuperClasses.size());

}


}
Loading

0 comments on commit 7557c2b

Please sign in to comment.