Skip to content

Instantly share code, notes, and snippets.

View balhoff's full-sized avatar

Jim Balhoff balhoff

View GitHub Profile
@balhoff
balhoff / phenotypes.rb
Created December 10, 2010 16:31
Code for adding phenotypes and external ontology terms to mx.
class AddPhenotypesAndOntologyRefs < ActiveRecord::Migration
def self.up
create_table :phenotypes do |table|
table.string :type
# common Phenotype attributes
table.integer :entity_id # OntologyTerm or OntologyComposition
table.string :entity_type # OntologyTerm or OntologyComposition
require 'rubygems'
require 'rdf'
require 'rdf/rdfxml'
graph = RDF::Graph.new
jaw = RDF::URI.new("http://example.org/jaw")
graph << RDF::Statement.new(jaw, RDF.type, RDF::OWL.Class)
bone = RDF::URI.new("http://example.org/bone")
graph << RDF::Statement.new(bone, RDF.type, RDF::OWL.Class)
jawbone = RDF::URI.new("http://example.org/jawbone")
require 'rubygems'
require 'rdf'
require 'rdf/rdfxml'
# Phenotype1 == (has_part some (leg and has_part min 10 seta and has_part max 30 seta))
graph = RDF::Graph.new
has_part = RDF::URI.new("http://example.org/has_part")
graph << RDF::Statement.new(has_part, RDF.type, RDF::OWL.ObjectProperty)
leg = RDF::URI.new("http://example.org/leg")
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:ns2="http://www.w3.org/2000/01/rdf-schema#" xmlns:ns0="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ns1="http://example.org/">
<ns0:AnnotationProperty rdf:about="http://example.org/describe_state"/>
<ns0:Class rdf:about="http://example.org/phenotype1">
<ns1:describe_state>
<ns1:state rdf:about="http://example.org/state1">
<ns2:label>leg has more than 10 and less than 30 setae</ns2:label>
</ns1:state>
</ns1:describe_state>
<ns0:equivalentClass>
#NEXUS
[written Mon Feb 20 15:22:05 EST 2012 by Mesquite version 2.75 (build 564) at NI7549.local/10.0.1.4]
BEGIN TAXA;
TITLE Taxa;
DIMENSIONS NTAX=49;
TAXLABELS
Acanthostega Proterogyrinus Balanerpeton Dendrerpeton Tuditanus Asaphestera Hapsidoparion Llistrofus Saxonerpeton Pantylus Cardiocephalus_sternbergi Cardiocephalus_peabodyi Euryodus_primus Euryodus_dalyae Pelodosotis Micraroter Rhynchonkos Eocaecilia Microbrachis Hyloplesion Mazon_Creek Batropetes Carrolla Quasicaecilia Odonterpeton Utaherpeton Stegotretus Sparodus_ Sauropleura_pectinata Sauropleura_scalaris Sauropleura_bairdi Lepterpeton Ptyonius Ctenerpeton Urocordylus Keraterpeton_galvani Batrachiderpeton Diceratosaurus Diplocaulus_magnicornis Diplocaulus_primus Diploceraspis Scincosaurus Brachydectes Adelogyrinus Oestocephalus Phlegethontia Greererpeton Seymouria_baylorensis Limnoscelis
;
<?xml version="1.0" encoding="UTF-8"?>
<nex:nexml xmlns:nex="http://www.nexml.org/2009" xmlns="http://www.nexml.org/2009" xmlns:bean="http://mesquiteproject.org/bean#" xmlns:msq="http://mesquiteproject.org#" xmlns:nr="http://mesquiteproject.org/namereference#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" generator="org.nexml.model.impl.DocumentImpl" version="0.9">
<otus about="#otus1155" id="otus1155" label="Taxa">
<meta content="1686792977142215911" datatype="xsd:long" id="meta1176" property="bean:AssignedIDNumber" xsi:type="nex:LiteralMeta"/>
<meta content="Default Bush (id 6, version 16)" datatype="xsd:anySimpleType" id="meta1175" property="bean:DefaultTree" xsi:type="nex:LiteralMeta"/>
<meta content="3" datatype="xsd:integer" id="meta1174" property="bean:NumberOfParts" xsi:type="nex:LiteralMeta"/>
<meta content="true" datatype="xsd:boolean" id="meta1173" property="bean:Writable"
@balhoff
balhoff / Scala OWLAPI
Last active December 14, 2015 23:29
Testing Manchester syntax-like wrapper for OWLAPI in Scala.
package org.nescent.ontology
import scala.collection.JavaConversions._
import org.nescent.ontology.OWL._
import org.nescent.ontology.OWLConversions._
import org.semanticweb.owlapi.apibinding.OWLManager
object OWLAPITest extends App {
val manager = OWLManager.createOWLOntologyManager();
@balhoff
balhoff / GetLabelExample.scala
Last active August 29, 2015 13:56
Getting OWLEntity label in Scala
package org.nescent.informatics.script
import org.semanticweb.owlapi.model.OWLEntity
import org.semanticweb.owlapi.model.OWLOntology
import scala.collection.JavaConversions._
import org.semanticweb.owlapi.model.OWLLiteral
import org.semanticweb.owlapi.model.OWLDataFactory
import org.semanticweb.owlapi.apibinding.OWLManager
object GetLabelExample {
@balhoff
balhoff / nearest_ancestors.rq
Last active September 3, 2021 16:08
Retrieve the nearest common ancestors for two terms using SPARQL
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX Term1: <http://purl.obolibrary.org/obo/PATO_0000587>
PREFIX Term2: <http://purl.obolibrary.org/obo/PATO_0000586>
SELECT ?nearest
FROM <http://purl.obolibrary.org/obo/pato.owl>
WHERE {
Term1: rdfs:subClassOf* ?nearest .
Term2: rdfs:subClassOf* ?nearest .
Term1: rdfs:subClassOf* ?indirect .
Term2: rdfs:subClassOf* ?indirect .
@balhoff
balhoff / test-shapes.ttl
Created June 30, 2016 14:35
Test whether sh:qualifiedValueShape works with sh:inverseProperty
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@prefix sh: <http://www.w3.org/ns/shacl#>
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@prefix owl: <http://www.w3.org/2002/07/owl#>
@prefix oboInOwl: <http://www.geneontology.org/formats/oboInOwl#>
@prefix obo: <http://purl.obolibrary.org/obo/>
@prefix ex: <http://example.org/>