Permalink
Please sign in to comment.
Showing
with
143 additions
and 0 deletions.
- +49 −0 owlsim-core/src/main/java/org/monarchinitiative/owlsim/compute/enrich/impl/EnrichmentAllByAll.java
- +43 −0 ...m-core/src/test/java/org/monarchinitiative/owlsim/compute/enrich/impl/AbstractEnrichmentTest.java
- +51 −0 ...m-core/src/test/java/org/monarchinitiative/owlsim/compute/enrich/impl/EnrichmentAllByAllTest.java
| @@ -0,0 +1,49 @@ | ||
| +package org.monarchinitiative.owlsim.compute.enrich.impl; | ||
| + | ||
| +import java.util.ArrayList; | ||
| +import java.util.List; | ||
| +import java.util.Set; | ||
| + | ||
| +import org.apache.log4j.Logger; | ||
| +import org.monarchinitiative.owlsim.compute.enrich.EnrichmentEngine; | ||
| +import org.monarchinitiative.owlsim.compute.enrich.EnrichmentQuery; | ||
| +import org.monarchinitiative.owlsim.compute.enrich.EnrichmentResultSet; | ||
| +import org.monarchinitiative.owlsim.kb.BMKnowledgeBase; | ||
| + | ||
| +import com.googlecode.javaewah.EWAHCompressedBitmap; | ||
| + | ||
| +public class EnrichmentAllByAll { | ||
| + | ||
| + private Logger LOG = Logger.getLogger(EnrichmentAllByAll.class); | ||
| + | ||
| + /** | ||
| + * @param engine | ||
| + * @param rootCls1 | ||
| + * @param rootCls2 | ||
| + * @return list of resultsets | ||
| + */ | ||
| + public List<EnrichmentResultSet> getAllByAll(EnrichmentEngine engine, | ||
| + String rootCls1, String rootCls2) { | ||
| + | ||
| + BMKnowledgeBase kb = engine.getKnowledgeBase(); | ||
| + | ||
| + EWAHCompressedBitmap bm1 = kb.getSubClasses(kb.getClassIndex(rootCls1)); | ||
| + EWAHCompressedBitmap bm2 = kb.getSubClasses(kb.getClassIndex(rootCls2)); | ||
| + Set<String> targetClassIds = kb.getClassIds(bm2); | ||
| + | ||
| + List<EnrichmentResultSet> resultSets = new ArrayList<>(); | ||
| + for (Integer c1ix : bm1.getPositions()) { | ||
| + String c1 = kb.getClassId(c1ix); | ||
| + LOG.info("Performing enrichment for individual set:" +c1); | ||
| + EnrichmentQuery query = new EnrichmentQueryImpl(c1); | ||
| + EnrichmentResultSet rs = engine.calculateEnrichmentAgainstKb(query, targetClassIds); | ||
| + if (rs.getResults().size() > 0) | ||
| + resultSets.add(rs); | ||
| + } | ||
| + | ||
| + return resultSets; | ||
| + } | ||
| + | ||
| +} | ||
| + | ||
| + |
| @@ -0,0 +1,43 @@ | ||
| +package org.monarchinitiative.owlsim.compute.enrich.impl; | ||
| + | ||
| +import java.net.URL; | ||
| + | ||
| +import org.monarchinitiative.owlsim.io.OWLLoader; | ||
| +import org.monarchinitiative.owlsim.kb.BMKnowledgeBase; | ||
| +import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| + | ||
| +public class AbstractEnrichmentTest { | ||
| + | ||
| + protected BMKnowledgeBase kb; | ||
| + | ||
| + /** | ||
| + * Load an ontology from resources folder | ||
| + * | ||
| + * @param fn | ||
| + * @throws OWLOntologyCreationException | ||
| + */ | ||
| + protected void load(String fn) throws OWLOntologyCreationException { | ||
| + OWLLoader loader = new OWLLoader(); | ||
| + loader.load("src/test/resources/"+fn); | ||
| + kb = loader.createKnowledgeBaseInterface(); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Load ontology plus data ontologies | ||
| + * | ||
| + * @param fn | ||
| + * @param ontfns | ||
| + * @throws OWLOntologyCreationException | ||
| + */ | ||
| + protected void load(String fn, String... ontfns) throws OWLOntologyCreationException { | ||
| + OWLLoader loader = new OWLLoader(); | ||
| + loader.load(getClass().getResource(fn).getFile()); | ||
| + for (String ontfn : ontfns) { | ||
| + URL res = getClass().getResource(ontfn); | ||
| + loader.loadOntologies(res.getFile()); | ||
| + } | ||
| + kb = loader.createKnowledgeBaseInterface(); | ||
| + } | ||
| + | ||
| + | ||
| +} |
| @@ -0,0 +1,51 @@ | ||
| +package org.monarchinitiative.owlsim.compute.enrich.impl; | ||
| + | ||
| +import static org.junit.Assert.*; | ||
| + | ||
| +import java.util.List; | ||
| + | ||
| +import org.apache.log4j.Logger; | ||
| +import org.junit.Test; | ||
| +import org.monarchinitiative.owlsim.compute.enrich.EnrichmentEngine; | ||
| +import org.monarchinitiative.owlsim.compute.enrich.EnrichmentQuery; | ||
| +import org.monarchinitiative.owlsim.compute.enrich.EnrichmentResult; | ||
| +import org.monarchinitiative.owlsim.compute.enrich.EnrichmentResultSet; | ||
| +import org.monarchinitiative.owlsim.kb.BMKnowledgeBase; | ||
| +import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| + | ||
| +public class EnrichmentAllByAllTest extends AbstractEnrichmentTest { | ||
| + | ||
| + private Logger LOG = Logger.getLogger(EnrichmentAllByAllTest.class); | ||
| + | ||
| + | ||
| + @Test | ||
| + public void test() throws OWLOntologyCreationException { | ||
| + load("simple-pheno-with-negation.owl"); | ||
| + EnrichmentEngine ee = HypergeometricEnrichmentEngine.create(kb); | ||
| + | ||
| + String root = "http://x.org/phenotype"; | ||
| + EnrichmentAllByAll axa = new EnrichmentAllByAll(); | ||
| + List<EnrichmentResultSet> rsl = axa.getAllByAll(ee, root, root); | ||
| + for (EnrichmentResultSet rs : rsl) { | ||
| + LOG.info("RS="+rs); | ||
| + } | ||
| + | ||
| + | ||
| + } | ||
| + | ||
| + @Test | ||
| + public void testMP() throws OWLOntologyCreationException { | ||
| + load("mp-subset.ttl"); | ||
| + EnrichmentEngine ee = HypergeometricEnrichmentEngine.create(kb); | ||
| + | ||
| + String root = "http://purl.obolibrary.org/obo/MP_0000001"; | ||
| + EnrichmentAllByAll axa = new EnrichmentAllByAll(); | ||
| + List<EnrichmentResultSet> rsl = axa.getAllByAll(ee, root, root); | ||
| + for (EnrichmentResultSet rs : rsl) { | ||
| + LOG.info("RS="+rs); | ||
| + } | ||
| + | ||
| + | ||
| + } | ||
| + | ||
| +} |
0 comments on commit
b4b832f