Skip to content

Commit

Permalink
Merge pull request #65 from phenoscape/cleanup
Browse files Browse the repository at this point in the history
Lots of cleanup.
  • Loading branch information
balhoff authored May 9, 2020
2 parents 07254ee + 1c0453b commit e5d0ab8
Show file tree
Hide file tree
Showing 55 changed files with 629 additions and 1,052 deletions.
30 changes: 11 additions & 19 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,33 @@ version := "1.10"

mainClass in Compile := Some("org.phenoscape.owl.build.Command")

scalaVersion := "2.12.8"

crossScalaVersions := Seq("2.12.8")
scalaVersion := "2.12.11"

scalacOptions := Seq("-unchecked", "-deprecation", "-feature", "-encoding", "utf8")

resolvers += "Phenoscape Maven repository" at "https://svn.code.sf.net/p/phenoscape/code/trunk/maven/repository"

//resolvers += "Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"

//resolvers += "apache-repo-releases" at "http://repository.apache.org/content/repositories/releases/"

//resolvers += "BBOP repository" at "http://code.berkeleybop.org/maven/repository"

javaOptions += "-Xmx100G"

testFrameworks += new TestFramework("utest.runner.Framework")

libraryDependencies ++= {
Seq(
"org.apache.commons" % "commons-lang3" % "3.1",
"commons-io" % "commons-io" % "2.4",
"org.apache.commons" % "commons-lang3" % "3.10",
"commons-io" % "commons-io" % "2.6",
"org.jdom" % "jdom" % "2.0.2",
"net.sourceforge.owlapi" % "owlapi-distribution" % "4.5.8",
"net.sourceforge.owlapi" % "owlapi-distribution" % "4.5.16",
"org.semanticweb.elk" % "elk-owlapi" % "0.4.3",
"com.blazegraph" % "bigdata-core" % "2.1.2",
"com.blazegraph" % "bigdata-core" % "2.1.4" exclude("org.slf4j", "slf4j-log4j12"),
"org.openrdf.sesame" % "sesame-rio" % "2.7.12",
"org.phenoscape" %% "scowl" % "1.3.4",
"org.phenoscape" %% "owlet" % "1.6",
"org.phenoscape" %% "owlet" % "1.8.1",
"org.phenoscape" %% "phenoscape-kb-ingest" % "1.6.2",
"log4j" % "log4j" % "1.2.17",
"com.outr" %% "scribe-slf4j" % "2.7.10",
"org.apache.directory.studio" % "org.apache.commons.codec" % "1.8",
"com.github.pathikrit" %% "better-files" % "3.4.0",
"com.lihaoyi" %% "utest" % "0.6.9" % Test,
"org.phenoscape" %% "sparql-interpolator" % "1.0",
"io.monix" %% "monix" % "3.0.0-RC2"
"com.github.pathikrit" %% "better-files" % "3.8.0",
"com.lihaoyi" %% "utest" % "0.7.4" % Test,
"org.phenoscape" %% "sparql-interpolator" % "1.1",
"io.monix" %% "monix" % "3.2.1"
)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.1.6
sbt.version=1.3.10
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.15")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package org.phenoscape.owl

import org.phenoscape.owl.Vocab._
import org.phenoscape.scowl._
import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.model.{OWLAxiom, OWLClass}

object AbsenceClassGenerator extends OWLTask {
object AbsenceClassGenerator {

val factory = OWLManager.getOWLDataFactory
val absenceOf = factory.getOWLAnnotationProperty(Vocab.ABSENCE_OF)

def createAbsenceClass(ontClass: OWLClass): Set[OWLAxiom] = {
Expand Down
9 changes: 3 additions & 6 deletions src/main/scala/org/phenoscape/owl/BuilderIRIMapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ package org.phenoscape.owl
import java.io.File
import java.net.URLEncoder

import org.semanticweb.owlapi.model.IRI
import org.semanticweb.owlapi.model.OWLOntologyIRIMapper
import org.semanticweb.owlapi.model.{IRI, OWLOntologyIRIMapper}

class BuilderIRIMapper(folder: File) extends OWLOntologyIRIMapper {

def getDocumentIRI(iri: IRI): IRI =
if (iri.getScheme == "file")
iri
else
IRI.create(new File(folder, URLEncoder.encode(iri.toURI.toString, "UTF-8")))
if (iri.getScheme == "file") iri
else IRI.create(new File(folder, URLEncoder.encode(iri.toURI.toString, "UTF-8")))

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package org.phenoscape.owl

import scala.collection.JavaConverters._
import org.phenoscape.owl.Vocab._
import org.phenoscape.scowl._
import org.semanticweb.owlapi.model.IRI
import org.semanticweb.owlapi.model.OWLClass
import org.semanticweb.owlapi.model.OWLOntology
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom
import org.semanticweb.owlapi.model.OWLAxiom
import Vocab._
import org.semanticweb.owlapi.model._
import org.semanticweb.owlapi.model.parameters.Imports

import scala.collection.JavaConverters._

object DevelopsFromRuleGenerator extends OWLTask {
object DevelopsFromRuleGenerator {

def generateDevelopsFromRules(ontology: OWLOntology): OWLOntology = {
val manager = ontology.getOWLOntologyManager
val newIRI = ontology.getOntologyID.getOntologyIRI.toString + "/develops_from_rules.owl"
val rules = ontology.getClassesInSignature(false).asScala map createRule
val rules = ontology.getClassesInSignature(Imports.EXCLUDED).asScala map createRule
manager.createOntology(rules.toSet[OWLAxiom].asJava, IRI.create(newIRI))
}

Expand Down
11 changes: 3 additions & 8 deletions src/main/scala/org/phenoscape/owl/EQCharactersGenerator.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package org.phenoscape.owl

import org.semanticweb.owlapi.model.OWLClass
import org.semanticweb.owlapi.model.OWLAxiom
import scala.collection.JavaConversions._
import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.model.IRI
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom
import org.phenoscape.owl.Vocab._
import org.phenoscape.scowl._
import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.model._
import org.semanticweb.owlapi.vocab.DublinCoreVocabulary
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom
import Vocab._

object EQCharactersGenerator {

Expand Down
123 changes: 58 additions & 65 deletions src/main/scala/org/phenoscape/owl/EQCreator.scala
Original file line number Diff line number Diff line change
@@ -1,92 +1,85 @@
package org.phenoscape.owl

import scala.collection.JavaConverters._
import org.phenoscape.scowl._
import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.elk.owlapi.ElkReasonerFactory
import org.semanticweb.owlapi.model.IRI
import org.apache.log4j.BasicConfigurator
import org.apache.log4j.Logger
import org.apache.log4j.Level
import java.io.File
import java.io.{BufferedOutputStream, File, FileOutputStream}
import java.util.Date
import org.semanticweb.owlapi.model.OWLClass
import org.semanticweb.owlapi.model.OWLAxiom
import java.io.FileOutputStream
import java.io.BufferedOutputStream
import java.util.zip.GZIPOutputStream
import org.semanticweb.owlapi.model.AddImport

import org.phenoscape.owl.Vocab._
import org.phenoscape.scowl._
import org.semanticweb.elk.owlapi.ElkReasonerFactory
import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.model.parameters.Imports
import org.semanticweb.owlapi.model.{AddImport, IRI, OWLAxiom, OWLClass}
import org.semanticweb.owlapi.reasoner.InferenceType
import Vocab._

import scala.collection.JavaConverters._

//takes at least 200 GB memory
object EQCreator {

def main(args: Array[String]): Unit = {
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
println(new Date() + ": starting");
val manager = OWLManager.createOWLOntologyManager();
val factory = manager.getOWLDataFactory();
val eqs = manager.createOntology();
manager.addAxiom(eqs, factory.getOWLTransitiveObjectPropertyAxiom(has_part));
manager.addAxiom(eqs, factory.getOWLReflexiveObjectPropertyAxiom(has_part));
manager.addAxiom(eqs, factory.getOWLTransitiveObjectPropertyAxiom(part_of));
manager.addAxiom(eqs, factory.getOWLReflexiveObjectPropertyAxiom(part_of));
manager.addAxiom(eqs, factory.getOWLInverseObjectPropertiesAxiom(has_part, part_of));
val uberon = manager.loadOntologyFromOntologyDocument(new File("uberon.owl"));
val pato = manager.loadOntologyFromOntologyDocument(new File("pato.owl"));
manager.applyChange(new AddImport(eqs, factory.getOWLImportsDeclaration(uberon.getOntologyID.getOntologyIRI.get)));
manager.applyChange(new AddImport(eqs, factory.getOWLImportsDeclaration(pato.getOntologyID.getOntologyIRI.get)));
val anatomicalEntity = Class(IRI.create("http://purl.obolibrary.org/obo/UBERON_0001062"));
val qualityRoot = Class(IRI.create("http://purl.obolibrary.org/obo/PATO_0000001"));
val uberonReasoner = new ElkReasonerFactory().createReasoner(uberon);
val patoReasoner = new ElkReasonerFactory().createReasoner(pato);
val anatomicalEntities = uberonReasoner.getSubClasses(anatomicalEntity, false).getFlattened();
uberonReasoner.dispose();
val qualities = patoReasoner.getSubClasses(qualityRoot, false).getFlattened();
patoReasoner.dispose();
println(new Date() + ": building");
println(new Date() + ": starting")
val manager = OWLManager.createOWLOntologyManager()
val factory = manager.getOWLDataFactory
val eqs = manager.createOntology()
manager.addAxiom(eqs, factory.getOWLTransitiveObjectPropertyAxiom(has_part))
manager.addAxiom(eqs, factory.getOWLReflexiveObjectPropertyAxiom(has_part))
manager.addAxiom(eqs, factory.getOWLTransitiveObjectPropertyAxiom(part_of))
manager.addAxiom(eqs, factory.getOWLReflexiveObjectPropertyAxiom(part_of))
manager.addAxiom(eqs, factory.getOWLInverseObjectPropertiesAxiom(has_part, part_of))
val uberon = manager.loadOntologyFromOntologyDocument(new File("uberon.owl"))
val pato = manager.loadOntologyFromOntologyDocument(new File("pato.owl"))
manager.applyChange(new AddImport(eqs, factory.getOWLImportsDeclaration(uberon.getOntologyID.getOntologyIRI.get)))
manager.applyChange(new AddImport(eqs, factory.getOWLImportsDeclaration(pato.getOntologyID.getOntologyIRI.get)))
val anatomicalEntity = Class(IRI.create("http://purl.obolibrary.org/obo/UBERON_0001062"))
val qualityRoot = Class(IRI.create("http://purl.obolibrary.org/obo/PATO_0000001"))
val uberonReasoner = new ElkReasonerFactory().createReasoner(uberon)
val patoReasoner = new ElkReasonerFactory().createReasoner(pato)
val anatomicalEntities = uberonReasoner.getSubClasses(anatomicalEntity, false).getFlattened
uberonReasoner.dispose()
val qualities = patoReasoner.getSubClasses(qualityRoot, false).getFlattened
patoReasoner.dispose()
println(new Date() + ": building")
for {
entity <- anatomicalEntities.asScala
quality <- qualities.asScala
} manager.addAxiom(eqs, createEQ(entity, quality));
println(new Date() + ": saving EQs");
val outputStream = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(new File(args(0) + ".gz"))));
manager.saveOntology(eqs, outputStream);
outputStream.close();
println(new Date() + ": done saving");
val hierarchy = manager.createOntology();
println(new Date() + ": starting classification");
val eqReasoner = new ElkReasonerFactory().createReasoner(eqs);
eqReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); //
println(new Date() + ": done classification");
//MaterializeInferences.materializeInferences(hierarchy, eqReasoner);
println(new Date() + ": starting axiom generation");
val allClasses = eqs.getClassesInSignature(true).asScala;
} manager.addAxiom(eqs, createEQ(entity, quality))
println(new Date() + ": saving EQs")
val outputStream = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(new File(args(0) + ".gz"))))
manager.saveOntology(eqs, outputStream)
outputStream.close()
println(new Date() + ": done saving")
val hierarchy = manager.createOntology()
println(new Date() + ": starting classification")
val eqReasoner = new ElkReasonerFactory().createReasoner(eqs)
eqReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY) //
println(new Date() + ": done classification")
//MaterializeInferences.materializeInferences(hierarchy, eqReasoner)
println(new Date() + ": starting axiom generation")
val allClasses = eqs.getClassesInSignature(Imports.INCLUDED).asScala
for (owlClass <- allClasses) {
val newAxioms = eqReasoner
.getSuperClasses(owlClass, true)
.getFlattened()
.getFlattened
.asScala
.map(owlClass SubClassOf _)
.filterNot(eqs.containsAxiom(_, true));
manager.addAxioms(hierarchy, newAxioms.asJava);
.filterNot(eqs.containsAxiom(_, true))
manager.addAxioms(hierarchy, newAxioms.asJava)
}
println(new Date() + ": done axiom generation");
println(new Date() + ": saving hierarchy");
println(new Date() + ": done axiom generation")
println(new Date() + ": saving hierarchy")
val hierarchyOutputStream = new GZIPOutputStream(
new BufferedOutputStream(new FileOutputStream(new File(args(1) + ".gz")))
);
manager.saveOntology(hierarchy, hierarchyOutputStream);
hierarchyOutputStream.close();
println(new Date() + ": done saving");
System.exit(0);
)
manager.saveOntology(hierarchy, hierarchyOutputStream)
hierarchyOutputStream.close()
println(new Date() + ": done saving")
System.exit(0)
}

def createEQ(entity: OWLClass, quality: OWLClass): OWLAxiom = {
val eqClass = Class(IRI.create(entity.getIRI().toString() + "+" + quality.getIRI().toString()));
eqClass EquivalentTo (has_part some ((part_of some entity) and (bearer_of some quality)));
val eqClass = Class(IRI.create(entity.getIRI.toString + "+" + quality.getIRI.toString))
eqClass EquivalentTo (has_part some ((part_of some entity) and (bearer_of some quality)))
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.phenoscape.owl

import java.util.UUID

import org.semanticweb.owlapi.model.parameters.Imports
import org.semanticweb.owlapi.model.{AxiomType, IRI, OWLAxiom, OWLOntology}

import scala.collection.JavaConverters._
import org.semanticweb.owlapi.model.AxiomType
import org.semanticweb.owlapi.model.IRI
import org.semanticweb.owlapi.model.OWLOntology
import org.semanticweb.owlapi.model.OWLAxiom

object ExtractNamedClassHierarchy extends OWLTask {
object ExtractNamedClassHierarchy {

def extractHierarchy(ontology: OWLOntology): OWLOntology = {
val manager = ontology.getOWLOntologyManager
val namedClassAxioms = for {
axiom <- ontology.getAxioms(AxiomType.SUBCLASS_OF, true).asScala
axiom <- ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED).asScala
if !axiom.getSubClass.isAnonymous
if !axiom.getSuperClass.isAnonymous
} yield axiom
Expand Down
7 changes: 2 additions & 5 deletions src/main/scala/org/phenoscape/owl/GeneProfiles.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package org.phenoscape.owl

import org.apache.jena.query.Query
import org.openrdf.model.Statement
import org.openrdf.model.impl.StatementImpl
import org.openrdf.model.impl.URIImpl
import org.openrdf.model.impl.{StatementImpl, URIImpl}
import org.openrdf.model.vocabulary.RDF
import org.openrdf.query.QueryLanguage
import org.openrdf.repository.sail.SailRepositoryConnection
import org.phenoscape.owl.Vocab._
import org.phenoscape.owl.util.SesameIterationIterator.iterationToIterator
import org.phenoscape.owlet.SPARQLComposer._
import org.phenoscape.scowl._
import org.semanticweb.owlapi.model.OWLClass
import org.apache.jena.query.Query

object GeneProfiles {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ object HomologyTableDemoRolification extends App {
val evidence = Individual(s"$uniquePrefix#evidence")
val pub = factory.getOWLLiteral(items(13).trim)
if (!negated) {
axioms += ((structure1 and (in_taxon some taxon1)) SubClassOf (role1.Self)) Annotation (axiom_has_evidence, evidence)
axioms += ((structure2 and (in_taxon some taxon2)) SubClassOf (role2.Self)) Annotation (axiom_has_evidence, evidence)
axioms += ((structure1 and (in_taxon some taxon1)) SubClassOf role1.Self) Annotation (axiom_has_evidence, evidence)
axioms += ((structure2 and (in_taxon some taxon2)) SubClassOf role2.Self) Annotation (axiom_has_evidence, evidence)
axioms += (property SubPropertyChain (role1 o factory.getOWLTopObjectProperty o role2)) Annotation (axiom_has_evidence, evidence)
}
axioms += evidence Type evidenceCode
axioms += evidence Annotation (source, pub)
case None =>
if (!negated) {
axioms += ((structure1 and (in_taxon some taxon1)) SubClassOf (role1.Self))
axioms += ((structure2 and (in_taxon some taxon2)) SubClassOf (role2.Self))
axioms += ((structure1 and (in_taxon some taxon1)) SubClassOf role1.Self)
axioms += ((structure2 and (in_taxon some taxon2)) SubClassOf role2.Self)
axioms += (property SubPropertyChain (role1 o factory.getOWLTopObjectProperty o role2))
}
}
Expand Down
Loading

0 comments on commit e5d0ab8

Please sign in to comment.