Introduction

Today

Today

Knowledge Pre-requisites

Outcomes

Notes on Notes

Motivation

Use Case (karyotypes)

Use Case (karyotypes)

A partonomy?

ChromXISCN09.jpg

Protege

protege-pizza.png

Protege

click.gif

Protege

click-fast.gif

Can we do this programmatically?

// Create ontology
OWLOntologyManager m = create();
OWLOntology o = m.createOntology(example_iri);
// Add the OWL classes
OWLClass nucleus = df.getOWLClass(IRI.create(example_iri + "#Nucleus"));
OWLClass cell = df.getOWLClass(IRI.create(example_iri + "#Cell"));
// Add the OWL object property
OWLObjectProperty partOf = df.getOWLObjectProperty(IRI.create(example_iri + "#partOf"));
// Assert the axiom
// 1. Create the class expression
OWLClassExpression partOfSomecell = df.getOWLObjectSomeValuesFrom(partOf, cell);
// 2. Now create the axiom
OWLAxiom axiom = df.getOWLSubClassOfAxiom(nucleus, partOfSomeCell);
// 2. Add the axiom to the ontology
AddAxiom addAxiom = new AddAxiom(o, axiom);
// 3. We now use the manager to apply the change
m.applyChange(addAxiom);

Brain

// Create ontology
Brain brain = new Brain();
// Add the OWL classes
brain.addClass("Nucleus");
brain.addClass("Cell");
// Add the OWL object property
brain.addObjectProperty("partOf");
// Assert the axiom
brain.subClassOf("Nucleus", "partOf some Cell");

The Paragon : R

Constraints

Karyotype Ontology

Tawny-OWL Key Features

Ontology Building Tool

Unprogrammatic Syntax

(defontology o)

Unprogrammatic Syntax

Class: o:A
    Annotations:
        rdfs:label "A"@en,
        rdfs:comment "A is a kind of thing."@en

Unprogrammatic Syntax

(defclass A
  :label "A"
  :comment "A is a kind of thing.")

Unprogrammatic Syntax

(defclass B
  :super A
  :label "B")

Unprogrammatic Syntax

Evaluative

Compiled

Broadcasting

> c(1,2,3) + 4
[1] 5 6 7

Broadcasting

(defoproperty r)
(defclass C
  :super (owl-some r A B))
Class: o:C
    SubClassOf:
        o:r some o:B,
        o:r some o:A

Patternised

(defclass D
  :super (some-only r A B))
Class: o:D

    SubClassOf:
        o:r some o:A,
        o:r some o:B,
        o:r only
            (o:A or o:B)

Single fully extensible syntax

(defn and-not [a b]
  (owl-and a (owl-not b)))

(defn some-and-not [r a b]
  (owl-some r (and-not a b)))

(defclass E
  :super (some-and-not r A B))
Class: o:E
    SubClassOf:
        o:r some
            (o:A or (not (o:B)))

Reasoned Over

(defclass F
   :equivalent (owl-some r (owl-or A B)))

;; #{}
(subclasses F)

(reasoner-factory :hermit)

;; #{C D E}
(isubclasses F)

Commodity Language

Commodity Toolchain

Tawny-OWL Tutorial

Other Technical Pre-Requisites

Or: the alternative

Task 1: Ontological Hello World

The namespace

(ns tawny.tutorial.onto-hello
  (:use [tawny.owl]))

Define an Ontology

(defontology hello
  :iri "http://www.w3id.org/ontolink/tutorial/hello")

Introduce a Class

(defclass Hello)

Properties

(defoproperty hasObject)
(defclass World)

A complex class

(defclass HelloWorld
  :super Hello
  (owl-some hasObject World))

On the use of "owl" (a quick diversion)

(owl-some hasObject World)
(only hasObject World)

On the use of "owl"

On the use of "owl"

Saving the Ontology

(save-ontology "o.omn" :omn)

More Frames

(refine HelloWorld
        :label "Hello World"
        :comment "Hello World is a kind of greeting directed generally at everything."
        :annotation (label "Aalreet world" "gb_ncl"))

Task 1: Conclusions

Task 2: Defining a Tree

Amino Acids

A namespace

(ns tawny.tutorial.amino-acid-tree
  (:use [tawny.owl]))

Tree

(defontology aa)

(defclass AminoAcid)

(defclass Alanine
          :super AminoAcid)

(defclass Arginine
          :super AminoAcid)

(defclass Asparagine
          :super AminoAcid)

;; and the rest...

Disjoint

(defclass Asparagine
    :super AminoAcid
    :disjoint Alanine Arginine)

Disjoint

(defclass Arginine
    :super AminoAcid
    :disjoint Alanine Asparagine)

Explicit definition

Simplifying the definition

(defclass AminoAcid)

(as-subclasses
  AminoAcid

  (defclass Alanine)
  (defclass Arginine)
  (defclass Asparagine)
  ;; and the rest...
  )

And disjoint!

(defclass AminoAcid)

(as-subclasses
 AminoAcid
 :disjoint

 (defclass Alanine)
 (defclass Arginine)
 (defclass Asparagine)
 ;; and the rest...
 )

And, finally, covering

And, finally, covering

(defclass AminoAcid)

(as-subclasses
 AminoAcid
 :disjoint :cover

 (defclass Alanine)
 (defclass Arginine)
 (defclass Asparagine)
 (defclass Aspartate)
 (defclass Cysteine)
 (defclass Glutamate)
 (defclass Glutamine)
 (defclass Glycine)
 (defclass Histidine)
 (defclass Isoleucine)
 (defclass Leucine)
 (defclass Lysine)
 (defclass Methionine)
 (defclass Phenylalanine)
 (defclass Proline)
 (defclass Serine)
 (defclass Threonine)
 (defclass Tryptophan)
 (defclass Tyrosine)
 (defclass Valine))

And, finally, covering

Class: aa:AminoAcid
    EquivalentTo:
        aa:Alanine or aa:Arginine or aa:Asparagine
        or aa:Aspartate or aa:Cysteine or aa:Glutamate
        or aa:Glutamine or aa:Glycine or aa:Histidine
        or aa:Isoleucine or aa:Leucine or aa:Lysine
        or aa:Methionine or aa:Phenylalanine or aa:Proline
        or aa:Serine or aa:Threonine or aa:Tryptophan
        or aa:Tyrosine or aa:Valine

DisjointClasses:
    aa:Alanine, aa:Arginine, aa:Asparagine, aa:Aspartate,
    aa:Cysteine, aa:Glutamate, aa:Glutamine, aa:Glycine,
    aa:Histidine, aa:Isoleucine, aa:Leucine, aa:Lysine,
    aa:Methionine, aa:Phenylalanine, aa:Proline, aa:Serine,
    aa:Threonine, aa:Tryptophan, aa:Tyrosine, aa:Valine

Task 2: Conclusions

Task 3: Defining some properties

Namespace

(ns tawny.tutorial.amino-acid-props
  (:use [tawny owl pattern]))

Starting our ontology

(defontology aa)

(defclass AminoAcid)

Amino Acid properties

The Value Partition

(defclass Size)
(defoproperty hasSize
  :domain AminoAcid
  :range Size
  :characteristic :functional)

The Value Partition

(as-subclasses
 Size
 :disjoint :cover

 (defclass Tiny)
 (defclass Small)
 (defclass Large))

Using the values


(as-subclasses
 AminoAcid
 :disjoint :cover

 (defclass Alanine
   :super (owl-some hasSize Tiny))

 (defclass Arginine
   :super (owl-some hasSize Large))

 (defclass Asparagine
   :super (owl-some hasSize Small)))

 ;;and the rest

Interim Summary

Using Facets

(defclass Charge)
(defoproperty hasCharge
  :domain AminoAcid
  :range Charge
  :characteristic :functional)

(as-subclasses
 Charge
 :disjoint :cover

 (defclass Positive)
 (defclass Neutral)
 (defclass Negative))

Facet

(as-facet
 hasCharge

 Positive Neutral Negative)

Using the facet


(refine Alanine
        :super (facet Neutral))

(refine Arginine
         :super (facet Positive))

(refine Asparagine
        :super (facet Neutral))

And others

(defclass Hydrophobicity)
(defoproperty hasHydrophobicity
  :domain AminoAcid
  :range Hydrophobicity
  :characteristic :functional)

(as-subclasses
 Hydrophobicity
 :disjoint :cover

 (defclass Hydrophobic)
 (defclass Hydrophilic))

(as-facet
 hasHydrophobicity

 Hydrophilic Hydrophobic)

Using Facets

(defclass Polarity)
(defoproperty hasPolarity)

(as-subclasses
 Polarity
 :disjoint :cover

 (defclass Polar)
 (defclass NonPolar))

(as-facet
 hasPolarity

 Polar NonPolar)

Using Facets

(refine
 Alanine
 :super (facet Hydrophobic NonPolar))

(refine
 Arginine
 :super (facet Hydrophilic Polar))

(refine
 Asparagine
 :super (facet Hydrophilic Polar))

Using Facets

Class: aa:Alanine

    SubClassOf:
        aa:hasCharge some aa:Neutral,
        aa:AminoAcid,
        aa:hasSize some aa:Tiny,
        aa:hasHydrophobicity some aa:Hydrophobic,
        aa:hasPolarity some aa:NonPolar

Task 3: Conclusions

Task 4: Patternising

The problem

Namespace

(ns tawny.tutorial.amino-acid-pattern
  (:use [tawny owl pattern]))

And the preamble

(defontology aa)

(defclass AminoAcid)

The Size value partition

(defpartition Size
  [Tiny Small Large]
  :domain AminoAcid)

The size value partition

ObjectProperty: aa:hasSize
    Domain:
        aa:AminoAcid

    Range:
        aa:Size

    Characteristics:
        Functional

Class: aa:Size
    EquivalentTo:
        aa:Large or aa:Small or aa:Tiny

More value partitions

(defpartition Charge
  [Positive Neutral Negative]
  :domain AminoAcid)

(defpartition Hydrophobicity
  [Hydrophobic Hydrophilic]
  :domain AminoAcid)

(defpartition Polarity
  [Polar NonPolar]
  :domain AminoAcid)

(defpartition SideChainStructure
  [Aromatic Aliphatic]
  :domain AminoAcid)

Using these partitions

(as-subclasses
 AminoAcid

 (defclass Alanine
   :super (facet Neutral Hydrophobic NonPolar Aliphatic Tiny))

 (defclass Arginine
   :super (facet Positive Hydrophilic Polar Aliphatic Large))

 (defclass Asparagine
   :super (facet Neutral Hydrophilic Polar Aliphatic Small))

 ;; and the rest
 )

Task 4: Conclusions

Task 5: Understanding Names

Namespace

(ns tawny.tutorial.whats-in-a-name
  (:use [tawny.owl])
  (:require [tawny.obo])
  (:require [clojure.string :as s]))

Background

IRIs

Symbols

Symbols and IRIs

(defontology o)

;; => #<OWLClassImpl <8d9d3120-d374-4ffb-99d8-ffd93a7d5fdd#o#A>>
(defclass A
  :ontology o)

Symbols and IRIs

(defontology i
   :iri "http://www.w3id.org/ontolink/example/i")

;; => #<OWLClassImpl <http://www.w3id.org/ontolink/example/i#B>>
(defclass B
  :ontology i)

Symbols and IRIs

(defontology r
  :iri "http://www.w3id.org/ontolink/example/r"
  :iri-gen (fn [ont name]
             (iri (str (as-iri ont)
                       "#"
                       (s/reverse name)))))

;; => #<OWLClassImpl <http://www.w3id.org/ontolink/example/r#EDC>>
(defclass CDE
  :ontology r)

OBO Identifiers

(defclass GO:00004324
  :super (owl-some RO:0000013 GO:00003143)
  :annotation (annotation IAO:0504303 "Transporters are..."))

OBO Identifiers

(defontology obo
  :iri "http://www.w3id.org/ontolink/example/obo"
  :iri-gen tawny.obo/obo-iri-generate)

(tawny.obo/obo-restore-iri obo "./src/tawny/tutorial/whats_in_a_name.edn")

OBO Identifiers

;; => #<OWLClassImpl <http://purl.obolibrary.org/obo/EXAM_000003>>
(defclass F
  :ontology obo)

;; => #<OWLClassImpl <http://purl.obolibrary.org/obo/EXAM_000002>>
(defclass G
  :ontology obo)

;; => #<OWLObjectPropertyImpl <http://purl.obolibrary.org/obo/EXAM_000001>>
(defoproperty ro
  :ontology obo)

Task 5: Conclusions

Task 6: Importing other Ontologies

Importing

The ontology to import

(ns tawny.tutorial.abc
  (:use [tawny.owl]))

(defontology abc
  :iri "http://www.w3id.org/ontolink/example/abc.owl")

(defclass A)
(defclass B)
(defclass C)

Namespace

(ns tawny.tutorial.use-abc
  (:use [tawny.owl])
  (:require [tawny.tutorial.abc]))

Using

(defontology myABC)

(owl-import tawny.tutorial.abc/abc)

Using

(defclass MyA
  :super tawny.tutorial.abc/A)

(defclass MyB
  :super tawny.tutorial.abc/B)
Class: myABC:MyA
    SubClassOf:
        abc:A

Class: myABC:MyB
    SubClassOf:
        abc:B

Task 6: Conclusions

Task 7: Reading an Ontology

The problem

Namespace

(ns tawny.tutorial.read-abc
  (:require [tawny owl read]))

Reading

(tawny.read/defread abc
  :iri "http://www.w3id.org/ontolink/example/abcother.owl"
  :location (tawny.owl/iri (clojure.java.io/resource "abcother.owl")))

Reading

(tawny.owl/defontology myABC)

(tawny.owl/owl-import abc)

Reading

(tawny.owl/defclass MyA
  :super A)

(tawny.owl/defclass MyB
  :super B)

Task 7: Conclusions

Task 8: Create New Syntax

The Finale

The namespace

(ns tawny.tutorial.amino-acid-build
  (:use [tawny owl pattern reasoner util]))

The Upper Ontology

(defontology aabuild)

(defclass AminoAcid)

(defclass PhysicoChemicalProperty)

(defpartition Size
  [Tiny Small Large]
  :domain AminoAcid
  :super PhysicoChemicalProperty)

(defpartition Charge
  [Positive Neutral Negative]
  :domain AminoAcid
  :super PhysicoChemicalProperty)

(defpartition Hydrophobicity
  [Hydrophobic Hydrophilic]
  :domain AminoAcid
  :super PhysicoChemicalProperty)

(defpartition Polarity
  [Polar NonPolar]
  :domain AminoAcid
  :super PhysicoChemicalProperty)

(defpartition SideChainStructure
  [Aromatic Aliphatic]
  :domain AminoAcid
  :super PhysicoChemicalProperty)

Defining our amino-acid

Defining our amino-acid

(defdontfn amino-acid [o entity & properties]
  (owl-class o entity
     :super
     (facet properties)))

Defining lots of amino-acids

(defdontfn amino-acids [o & definitions]
  (map
   (fn [[entity & properties]]
     ;; need the "Named" constructor here
     (->Named entity
              (amino-acid o entity properties)))
   definitions))

And make variables

(defmacro defaminoacids
  [& definitions]
  `(tawny.pattern/intern-owl-entities
    (apply amino-acids
     (tawny.util/name-tree ~definitions))))

Define the amino acids

(as-subclasses
 AminoAcid
 :disjoint :cover

 (defaminoacids
   [Alanine        Neutral  Hydrophobic NonPolar Aliphatic Tiny]
   [Arginine       Positive Hydrophilic Polar    Aliphatic Large]
   [Asparagine     Neutral  Hydrophilic Polar    Aliphatic Small]
   [Aspartate      Negative Hydrophilic Polar    Aliphatic Small]
   [Cysteine       Neutral  Hydrophobic Polar    Aliphatic Small]
   [Glutamate      Negative Hydrophilic Polar    Aliphatic Small]
   [Glutamine      Neutral  Hydrophilic Polar    Aliphatic Large]
   [Glycine        Neutral  Hydrophobic NonPolar Aliphatic Tiny]
   [Histidine      Positive Hydrophilic Polar    Aromatic  Large]
   [Isoleucine     Neutral  Hydrophobic NonPolar Aliphatic Large]
   [Leucine        Neutral  Hydrophobic NonPolar Aliphatic Large]
   [Lysine         Positive Hydrophilic Polar    Aliphatic Large]
   [Methionine     Neutral  Hydrophobic NonPolar Aliphatic Large]
   [Phenylalanine  Neutral  Hydrophobic NonPolar Aromatic  Large]
   [Proline        Neutral  Hydrophobic NonPolar Aliphatic Small]
   [Serine         Neutral  Hydrophilic Polar    Aliphatic Tiny]
   [Threonine      Neutral  Hydrophilic Polar    Aliphatic Tiny]
   [Tryptophan     Neutral  Hydrophobic NonPolar Aromatic  Large]
   [Tyrosine       Neutral  Hydrophobic Polar    Aromatic  Large]
   [Valine         Neutral  Hydrophobic NonPolar Aliphatic Small]))

Defined Classes

(defclass SmallAminoAcid
  :equivalent (facet Small))

And some more

(defclass
  SmallPolarAminoAcid
  :equivalent (owl-and (facet Small Polar)))

(defclass LargeNonPolarAminoAcid
  :equivalent (owl-and (facet Large NonPolar)))

Where do we stop?

A defined class function

(defn amino-acid-def [partition-values]
  (owl-class
   (str
    (clojure.string/join
     (map
      #(.getFragment
        (.getIRI %))
      partition-values))
    "AminoAcid")
   :equivalent (owl-and (facet partition-values))))

Doing them all

(doall
 (map
  amino-acid-def
  ;; kill the empty list
  (rest
   (map
    #(filter identity %)
    ;; combination of all of them
    (cart
     ;; list of values for each partitions plus nil
     ;; (so we get shorter versions also!)
     (map
      #(cons nil (seq (direct-subclasses %)))
      ;; all our partitions
      (seq (direct-subclasses PhysicoChemicalProperty))))))))

Reasoning

(reasoner-factory :hermit)

;; => true
(consistent?)

Reasoning

;; => 20
(count (subclasses AminoAcid))

;; => 451
(count (isubclasses AminoAcid))

Reasoning

;; => false
(coherent?)

;; => 242
(count (unsatisfiable))

Visualising

(save-ontology "aabuild.owl" :owl)
protege-aabuild.png

Visualising

protege-unsatisfiable.png

As a query

;; => 242
(count
 (isubclasses SmallAminoAcid))

As a query

;; => 0
(count
 (filter
  #(not (.isDefined % aabuild))
  (isubclasses SmallAminoAcid)))

Task 8: Conclusions

Summary

Hiatus

Questions and Answers

Questions

Can I add annotations on axioms?

(defclass Man
 :super
 (annotate Person
           (owl-comment "States that every man is a person")))

How does this affect ontology deployment

How do you version your ontology?

How do you test your ontology

How do you continuously integrate your ontology?

What about advanced documentation for Ontologies?

How do I collaborative develop by ontology?

Can I internationalise my ontology?

(label "Ciao" "it")
(defn etichetta [l]
  (label l "it"))

Can I scaffold my ontology from existing source

What happens if the labels of read ontologies change

How do you convert an existing ontology to Tawny-OWL

How Fast is Tawny

Can I integrate more tightly with Protege?

How does Tawny affect dependency management with ontologies?

Can I link ontologies into software?

What’s this :super? why not :subclass?

How do OBO identifiers work?

How OBO Identifiers work

("ro"
 "http://purl.obolibrary.org/obo/EXAM_000001"
 "G"
 "http://purl.obolibrary.org/obo/EXAM_000002"
 "F"
 "http://purl.obolibrary.org/obo/EXAM_000003")

How OBO Identifiers work

this stores any new IDs we have created
(comment
  (tawny.obo/obo-store-iri obo "./src/tawny/tutorial/whats_in_a_name.edn"))

How OBO Identifiers work

this coins permanent IDS, in a controlled process!
(comment
  (tawny.obo/obo-generate-permanent-iri
   "./src/tawny/tutorial/whats_in_a_name.edn"
   "http://purl.obolibrary.org/obo/EXAM_"))

How OBO Identifiers work

Do I have to conform to the no-use-before-define rule?

String building!
(defontology s)

(owl-class "J" :ontology s)
(object-property "r" :ontology s)
(owl-class "K"
           :ontology s
           :super (owl-some "r" "J"))

What are Tawny Names?

(comment
  (owl-class "L"
             :ontology s
             :super (owl-some r J)))

Tawny Names

(owl-class "M"
           :ontology s
           :super "L")
Class: s:M
    SubClassOf:
        s:L

Class: s:L

Why use strings?

How do we create a new symbol with the amino-acid syntax?

(defentity defaminoacid
  "Defines a new amino acid."
  'amino-acid)

Programming an Autosave

Extending Tawny

Namespace

(ns tawny.tutorial.autosave
  (:require [tawny.owl :as o])
  (:import [org.semanticweb.owlapi.model.OWLOntologyChangeListener]))

Saving the Listener

(def auto-save-listener
  "The current listener for handling auto-saves or nil." (atom nil))

The auto-save function

(defn auto-save
  "Autosave the current ontology everytime any change happens."
  ([o filename format]
   (let [listener (proxy [org.semanticweb.owlapi.model.OWLOntologyChangeListener]
               []
             (ontologiesChanged[l]
               (o/save-ontology o filename format)))]
     (reset! auto-save-listener listener)
     (.addOntologyChangeListener
      (o/owl-ontology-manager) listener)
     listener)))

auto-save in detail

(proxy [org.semanticweb.owlapi.model.OWLOntologyChangeListener]
       []
   (ontologiesChanged[l]
      (o/save-ontology o filename format)))

auto-save in detail

   (reset! auto-save-listener listener)

auto-save in detail

(.addOntologyChangeListener
     (o/owl-ontology-manager) listener)

Remove the auto-save

(defn auto-save-off
  "Stop autosaving ontologies."
  []
  (when @auto-save-listener
    (.removeOntologyChangeListener
     (o/owl-ontology-manager)
     @auto-save-listener)))

auto-save

Conclusions

Conclusions

Lentic talk

UKON 2016 (#ukon2016)

Acknowledgements