protected HttpUriRequest createGoodAnnotProfileRequest(int n) throws URISyntaxException {
    URIBuilder uriBuilder =
        new URIBuilder()
            .setScheme("http")
            .setHost("localhost")
            .setPort(9031)
            .setPath("/owlsim/getAttributeInformationProfile/");

    List<OWLClass> allClasses = new ArrayList<OWLClass>();
    allClasses.addAll(g.getAllOWLClasses());
    Collections.shuffle(allClasses);
    int i = 0;

    for (OWLClass c : allClasses) {
      String id = g.getIdentifier(c);
      uriBuilder.addParameter("a", id);

      i++;
      if (i >= n) break;
    }

    uriBuilder.addParameter("limit", "5");
    URI uri = uriBuilder.build();
    LOG.info("Getting URL=" + uri);
    HttpUriRequest httpUriRequest = new HttpGet(uri);
    LOG.info("Got URL=" + uri);
    return httpUriRequest;
  }
  protected OWLGraphWrapper loadOntology(String location) throws Exception {
    // load server ontology
    ParserWrapper pw = new ParserWrapper();
    OWLGraphWrapper g = pw.parseToOWLGraph(location);

    // prepare ontology
    ABoxUtils.makeDefaultIndividuals(g.getSourceOntology());
    return g;
  }
Esempio n. 3
0
  @Test
  public void testNonCycle3() throws Exception {
    ParserWrapper parser = new ParserWrapper();
    IRI iri = IRI.create(getResource("verification/self_references.obo").getAbsoluteFile());
    OWLGraphWrapper graph = parser.parseToOWLGraph(iri.toString());

    OntologyCheck check = new CycleCheck();

    Collection<CheckWarning> warnings = check.check(graph, graph.getAllOWLObjects());
    assertTrue(warnings.isEmpty());
  }
Esempio n. 4
0
  @Test
  public void testCycle1() throws Exception {
    ParserWrapper parser = new ParserWrapper();
    IRI iri = IRI.create(getResource("verification/cycle.obo").getAbsoluteFile());
    OWLGraphWrapper graph = parser.parseToOWLGraph(iri.toString());

    OntologyCheck check = new CycleCheck();

    Collection<CheckWarning> warnings = check.check(graph, graph.getAllOWLObjects());
    assertEquals(1, warnings.size());
    CheckWarning warning = warnings.iterator().next();
    List<IRI> iris = warning.getIris();
    assertEquals(3, iris.size());
  }
  @Test
  public void testServerSearchByAttributeSetCommand() throws Exception {
    g = loadOntology("../OWLTools-Sim/src/test/resources/sim/mp-subset-1.obo");

    ABoxUtils.createRandomClassAssertions(g.getSourceOntology(), 200, 20);

    OwlSimFactory owlSimFactory = new FastOwlSimFactory();
    OwlSim sos = owlSimFactory.createOwlSim(g.getSourceOntology());

    sos.createElementAttributeMapFromOntology();

    final HttpUriRequest httppost = createSearchByAttributeSetRequest(5);
    runServerCommunication(httppost, sos);
  }
  @Test
  public void testServerGetAnnotationSufficiencyScoreCommandBad() throws Exception {
    g = loadOntology("../OWLTools-Sim/src/test/resources/sim/mp-subset-1.obo");

    ABoxUtils.createRandomClassAssertions(g.getSourceOntology(), 200, 20);
    // set sim
    OwlSimFactory owlSimFactory = new FastOwlSimFactory();
    OwlSim sos = owlSimFactory.createOwlSim(g.getSourceOntology());

    sos.createElementAttributeMapFromOntology();

    HttpUriRequest httppost = createBogusAnnotSufRequest(5);

    runServerCommunication(httppost, sos);
  }
  /*
   * Add specified closure of OWLObject to annotation and bioentity docs.
   * Not the map for bio.
   */
  private Map<String, String> addClosureToAnnAndBio(
      List<String> relations,
      String closureName,
      String closureNameLabel,
      String closureMap,
      OWLObject cls,
      OWLGraphWrapper graph,
      SolrInputDocument ann_doc,
      SolrInputDocument bio_doc,
      boolean isNegated) {

    // Add closures to doc; label and id.
    graph.addPropertyIdsForMaterialization(relations);
    final Map<String, String> cmap = graph.getRelationClosureMap(cls, relations);
    List<String> idClosure = new ArrayList<String>(cmap.keySet());
    List<String> labelClosure = new ArrayList<String>(cmap.values());

    ann_doc.addField(closureName, idClosure);
    ann_doc.addField(closureNameLabel, labelClosure);

    // WARNING this is a side effect for the bio-entity
    // only add the class and closure, if it is a non-negated annotation
    if (isNegated == false) {
      for (String tid : idClosure) {
        addFieldUnique(bio_doc, closureName, tid);
      }
      for (String tlabel : labelClosure) {
        addFieldUnique(bio_doc, closureNameLabel, tlabel);
      }
    }

    // Compile closure maps to JSON.
    if (!cmap.isEmpty()) {
      String jsonized_cmap = gson.toJson(cmap);
      ann_doc.addField(closureMap, jsonized_cmap);
      // NOTE: This is harder since we'd be adding multiple, so the is done on a collector variable
      // elsewhere.
      // bio_doc.addField(closureMap, jsonized_cmap);
    }

    if (isNegated) {
      // WARNING this is a side effect for the bio-entity
      // only add the class and closure, if it is a non-negated annotation
      return Collections.emptyMap();
    }
    return cmap;
  }
  protected HttpUriRequest createBadAnnotProfileWithSubgraphsRequest(int n)
      throws URISyntaxException {
    URIBuilder uriBuilder =
        new URIBuilder()
            .setScheme("http")
            .setHost("localhost")
            .setPort(9031)
            .setPath("/owlsim/getAttributeInformationProfile/");

    List<OWLClass> allClasses = new ArrayList<OWLClass>();
    allClasses.addAll(g.getAllOWLClasses());
    Collections.shuffle(allClasses);
    int i = 0;

    for (OWLClass c : allClasses) {
      String id = g.getIdentifier(c);
      uriBuilder.addParameter("a", id);

      // get at least one ancestor of each class
      OWLClass r = (OWLClass) g.getAncestors(c).iterator().next();
      uriBuilder.addParameter("r", g.getIdentifier(r));
      i++;
      if (i >= n) break;
    }

    uriBuilder.addParameter("a", "BOGUS:1234567");
    uriBuilder.addParameter("r", "BOGUS:0000003");

    Random rand = new Random();
    int r = 0;
    // get some random classes
    for (i = 0; i < n; i++) {
      r = rand.nextInt(allClasses.size());
      OWLClass c = allClasses.get(r);
      String id = g.getIdentifier(c);
      uriBuilder.addParameter("r", id);
      i++;
      if (i >= n) break;
    }

    uriBuilder.addParameter("limit", "5");
    URI uri = uriBuilder.build();
    LOG.info("Getting URL=" + uri);
    HttpUriRequest httpUriRequest = new HttpGet(uri);
    LOG.info("Got URL=" + uri);
    return httpUriRequest;
  }
  protected HttpUriRequest createCompareByAttributeSetsRequest(int nA, int nB)
      throws URISyntaxException {
    URIBuilder uriBuilder =
        new URIBuilder()
            .setScheme("http")
            .setHost("localhost")
            .setPort(9031)
            .setPath("/owlsim/compareAttributeSets/");

    List<OWLClass> allClasses = new ArrayList<OWLClass>();
    allClasses.addAll(g.getAllOWLClasses());
    Collections.shuffle(allClasses);
    int i = 0;

    for (OWLClass c : allClasses) {
      String id = g.getIdentifier(c);
      uriBuilder.addParameter("a", id);

      // get at least one ancestor of each class
      i++;
      if (i >= nA) break;
    }

    Collections.shuffle(allClasses);
    i = 0;

    for (OWLClass c : allClasses) {
      String id = g.getIdentifier(c);
      uriBuilder.addParameter("b", id);

      // get at least one ancestor of each class
      i++;
      if (i >= nB) break;
    }

    URI uri = uriBuilder.build();
    LOG.info("Getting URL=" + uri);
    HttpUriRequest httpUriRequest = new HttpGet(uri);
    LOG.info("Got URL=" + uri);
    return httpUriRequest;
  }
 protected HttpUriRequest createPartiallyBogusAnnotSufRequest(int n) throws URISyntaxException {
   URIBuilder uriBuilder =
       new URIBuilder()
           .setScheme("http")
           .setHost("localhost")
           .setPort(9031)
           .setPath("/owlsim/getAnnotationSufficiencyScore/");
   int i = 0;
   for (OWLClass c : g.getAllOWLClasses()) {
     String id = g.getIdentifier(c);
     uriBuilder.addParameter("a", id);
     uriBuilder.addParameter("a", "BOGUS:000000" + i);
     i++;
     if (i >= n) break;
   }
   uriBuilder.addParameter("limit", "5");
   URI uri = uriBuilder.build();
   LOG.info("Getting URL=" + uri);
   HttpUriRequest httpUriRequest = new HttpGet(uri);
   LOG.info("Got URL=" + uri);
   return httpUriRequest;
 }
  @Test
  public void testServerGetCoAnnotationSuggestions() throws Exception {
    g = loadOntology("../OWLTools-Sim/src/test/resources/sim/mp-subset-1.obo");
    String file = "../OWLTools-Sim/src/test/resources/sim/mgi-gene2mp-subset-1.tbl";
    //		g = loadOntology("/Users/Nicole/work/MONARCH/phenotype-ontologies/src/ontology/hp.obo");
    //		String
    // file="/Users/Nicole/work/MONARCH/phenotype-ontologies/data/Homo_sapiens/Hs-disease-to-phenotype-O.txt";

    TableToAxiomConverter ttac = new TableToAxiomConverter(g);
    ttac.config.axiomType = AxiomType.CLASS_ASSERTION;
    ttac.config.isSwitchSubjectObject = true;
    ttac.parse(file);

    OwlSimFactory owlSimFactory = new FastOwlSimFactory();
    OwlSim sos = owlSimFactory.createOwlSim(g.getSourceOntology());

    sos.createElementAttributeMapFromOntology();
    //		sos.populateFullCoannotationMatrix();
    LOG.info("Finished populating the big matrix");

    HttpUriRequest httppost = createGoodCoAnnotationRequest(1);

    runServerCommunication(httppost, sos);
  }
  public static void main(String[] args) throws Exception {
    String catalog = args[0];
    String file = args[1];
    final ParserWrapper pw = new ParserWrapper();
    pw.addIRIMapper(new CatalogXmlIRIMapper(catalog));
    final OWLOntology ontology = pw.parse(file);
    final OWLGraphWrapper g = new OWLGraphWrapper(ontology);
    OWLObjectProperty part_of = g.getOWLObjectPropertyByIdentifier("part_of");
    OWLObjectProperty has_part = g.getOWLObjectPropertyByIdentifier("has_part");
    OWLObjectProperty regulates = g.getOWLObjectPropertyByIdentifier("regulates");
    OWLObjectProperty negatively_regulates =
        g.getOWLObjectPropertyByIdentifier("negatively_regulates");
    OWLObjectProperty positively_regulates =
        g.getOWLObjectPropertyByIdentifier("positively_regulates");
    final OWLClassFilter filter =
        new OWLClassFilter() {

          @Override
          public boolean use(OWLClass cls) {
            String id = g.getIdentifier(cls.getIRI());
            return id.startsWith("GO:");
          }
        };
    Set<OWLObjectProperty> props = Sets.newHashSet(part_of);
    Map<OWLClass, Set<OWLObjectSomeValuesFrom>> expressions =
        getExpressions(ontology, props, filter);
    List<OWLClass> classes = new ArrayList<OWLClass>(expressions.keySet());
    Collections.sort(classes);
    OWLPrettyPrinter pp = new OWLPrettyPrinter(g);
    int count = 0;
    for (OWLClass cls : classes) {
      Set<OWLObjectSomeValuesFrom> svfs = expressions.get(cls);
      for (OWLObjectSomeValuesFrom svf : svfs) {
        StringBuilder sb = new StringBuilder();
        sb.append(pp.render(cls)).append("\t");
        sb.append(pp.render(svf.getProperty())).append("\t");
        sb.append(pp.render(svf.getFiller()));
        System.out.println(sb);
        count += 1;
      }
    }
    System.out.println("Count: " + count);
  }