Application Programming Interface

BioInterchange offers Application Programming Interfaces (APIs) for multiple programming languages, but only Ruby is supporting the full range of functinality that BioInterchange provides. For Python and Java, a subset of the Ruby API is available: vocabulary wrappers for convenient access to ontologies used in BioInterchange.

Ruby API

The Ruby API — including vocabulary wrapper classes — are available via RubyGems:

sudo gem install biointerchange

The BioInterchange Framework

TODO... sorry.

Vocabulary Wrappers

Usage example (see also vocabulary.rb):

require 'rubygems'
require 'biointerchange'

include BioInterchange

# Get the URI of an ontology term by label:
GFF3O.seqid()

# Ambiguous labels will return an array of URIs:
# "start" can refer to a sub-property of "feature_properties" or "target_properties"
GFF3O.start()
# "feature_properties" can be either a datatype or object property
GFF3O.feature_properties()

# Use build-in method "is_datatype_property" to resolve ambiguity:
# (Note: there is exactly one item in the result set, so the selection of the first item is acceptable.)
feature_properties = GFF3O.feature_properties().select { |uri| GFF3O.is_datatype_property(uri) }[0]

# Use build-in method "with_parent" to pick properties based on their context:
GFF3O.with_parent(GFF3O.start(), feature_properties)

Python API

Vocabulary wrappers in Python are available as an egg, that can be installed via easy_install:

sudo easy_install rdflib
sudo easy_install http://www.biointerchange.org/eggs/biointerchange-0.1.2-py2.7.egg

Usage example (see also example.py):

import biointerchange
from biointerchange import *

# Get the URI of an ontology term by label:
GFF3O.seqid()

# Ambiguous labels will return an array of URIs:
# "start" can refer to a sub-property of "feature_properties" or "target_properties"
GFF3O.start()
# "feature_properties" can be either a datatype or object property
GFF3O.feature_properties()

# Use build-in method "is_datatype_property" to resolve ambiguity:
# (Note: there is exactly one item in the result set, so the selection of the first item is acceptable.)
feature_properties = filter(lambda uri: GFF3O.is_datatype_property(uri), GFF3O.feature_properties())[0]

# Use build-in method "with_parent" to pick properties based on their context:
GFF3O.with_parent(GFF3O.start(), feature_properties)

Java API

Vocabulary wrappers in Java are available as a Maven artifact. Add the following repository and dependency setting to your Project Object Model (POM) file:

<repositories>
  <repository>
    <id>biointerchange</id>
    <name>BioInterchange</name>
    <url>http://www.biointerchange.org/artifacts</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>org.biointerchange</groupId>
    <artifactId>vocabularies</artifactId>
    <version>0.1.2</version>
  </dependency>
</dependencies>

Usage example (see also App.java):

package org.biointerchange;

import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.vocabulary.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;

import java.util.Set;

import org.biointerchange.vocabulary.*;

/**
 * Demo on how to make use of BioInterchange's vocabulary classes.
 *
 * @author Joachim Baran
 */
public class App 
{
    public static void main(String[] args) {
        Resource seqid = GFF3O.seqid();
        System.out.println("'seqid' property:");
        printResource(seqid);

        System.out.println("'start' properties:");
        Set start = GFF3O.start();
        for (Resource startSynonym : start)
            printResource(startSynonym);

        System.out.println("'feature_properties' properties:");
        Set featureProperties = GFF3O.feature_properties();
        for (Resource featurePropertiesSynonym : featureProperties)
            printResource(featurePropertiesSynonym);

        System.out.println("'feature_properties' properties, which are a datatype property:");
        CollectionUtils.filter(featureProperties, new Predicate() {
            public boolean evaluate(Object o) {
                return GFF3O.isDatatypeProperty((Resource)o);
            }
        });
        for (Resource featurePropertiesSynonym : featureProperties)
            printResource(featurePropertiesSynonym);

        System.out.println("'start' property with parent datatype property 'feature_properties':");
        Set startUnderDatatypeFeatureProperties = GFF3O.withParent(start, featureProperties.iterator().next());
        for (Resource startSynonym : startUnderDatatypeFeatureProperties)
            printResource(startSynonym);
    }

    private static void printResource(Resource resource) {
        System.out.println("    " + resource.toString());
        System.out.println("        Namespace:                            " + resource.getNameSpace());
        System.out.println("        Local name:                           " + resource.getLocalName());
        System.out.println("        Jena Property (rather than Resource): " + (resource instanceof Property));
        System.out.println("        Ontology class:                       " + GFF3O.isClass(resource));
        System.out.println("        Ontology object property:             " + GFF3O.isObjectProperty(resource));
        System.out.println("        Ontology datatype property:           " + GFF3O.isDatatypeProperty(resource));
    }
}