OBO::Core::Ontology - An ontology holding terms and their relationships.
use OBO::Core::Ontology;
use OBO::Core::Term;
use OBO::Core::Relationship;
use OBO::Core::RelationshipType;
use strict;
# three new terms
my $n1 = OBO::Core::Term->new();
my $n2 = OBO::Core::Term->new();
my $n3 = OBO::Core::Term->new();
# new ontology
my $onto = OBO::Core::Ontology->new;
$n1->id("CCO:P0000001");
$n2->id("CCO:P0000002");
$n3->id("CCO:P0000003");
$n1->name("One");
$n2->name("Two");
$n3->name("Three");
my $def1 = OBO::Core::Def->new();
$def1->text("Definition of One");
my $def2 = OBO::Core::Def->new();
$def2->text("Definition of Two");
my $def3 = OBO::Core::Def->new();
$def3->text("Definition of Three");
$n1->def($def1);
$n2->def($def2);
$n3->def($def3);
$onto->add_term($n1);
$onto->add_term($n2);
$onto->add_term($n3);
$onto->delete_term($n1);
# new term
my $n4 = OBO::Core::Term->new();
$n4->id("CCO:P0000004");
$n4->name("Four");
my $def4 = OBO::Core::Def->new();
$def4->text("Definition of Four");
$n4->def($def4);
$onto->delete_term($n4);
$onto->add_term($n4);
# add term as string
my $new_term = $onto->add_term_as_string("CCO:P0000005", "Five");
$new_term->def_as_string("This is a dummy definition", "[CCO:vm, CCO:ls, CCO:ea \"Erick Antezana\"]");
my $n5 = $new_term;
# five new relationships
my $r12 = OBO::Core::Relationship->new();
my $r23 = OBO::Core::Relationship->new();
my $r13 = OBO::Core::Relationship->new();
my $r14 = OBO::Core::Relationship->new();
my $r35 = OBO::Core::Relationship->new();
$r12->id("CCO:P0000001_is_a_CCO:P0000002");
$r23->id("CCO:P0000002_part_of_CCO:P0000003");
$r13->id("CCO:P0000001_participates_in_CCO:P0000003");
$r14->id("CCO:P0000001_participates_in_CCO:P0000004");
$r35->id("CCO:P0000003_part_of_CCO:P0000005");
$r12->type("is_a");
$r23->type("part_of");
$r13->type("participates_in");
$r14->type("participates_in");
$r35->type("part_of");
$r12->link($n1, $n2);
$r23->link($n2, $n3);
$r13->link($n1, $n3);
$r14->link($n1, $n4);
$r35->link($n3, $n5);
# get all terms
my $c = 0;
my %h;
foreach my $t (@{$onto->get_terms()}) {
$h{$t->id()} = $t; $c++;
}
# get terms with argument
my @processes = sort {$a->id() cmp $b->id()} @{$onto->get_terms("CCO:P.*")};
my @odd_processes = sort {$a->id() cmp $b->id()} @{$onto->get_terms("CCO:P000000[35]")};
$onto->idspace_as_string("CCO", "http://www.cellcycle.org/ontology/CCO");
my @same_processes = @{$onto->get_terms_by_subnamespace("P")};
my @no_processes = @{$onto->get_terms_by_subnamespace("p")};
# add relationships
$onto->add_relationship($r12);
$onto->add_relationship($r23);
$onto->add_relationship($r13);
$onto->add_relationship($r14);
$onto->add_relationship($r35);
# add relationships and terms linked by this relationship
my $n11 = OBO::Core::Term->new();
my $n21 = OBO::Core::Term->new();
$n11->id("CCO:P0000011"); $n11->name("One one"); $n11->def_as_string("Definition One one", "");
$n21->id("CCO:P0000021"); $n21->name("Two one"); $n21->def_as_string("Definition Two one", "");
my $r11_21 = OBO::Core::Relationship->new();
$r11_21->id("CCO:R0001121"); $r11_21->type("r11-21");
$r11_21->link($n11, $n21);
$onto->add_relationship($r11_21); # adds to the ontology the terms linked by this relationship
# get all relationships
my %hr;
foreach my $r (@{$onto->get_relationships()}) {
$hr{$r->id()} = $r;
# get children
my @children = @{$onto->get_child_terms($n1)};
@children = @{$onto->get_child_terms($n3)};
my %ct;
foreach my $child (@children) {
$ct{$child->id()} = $child;
@children = @{$onto->get_child_terms($n2)};
# get parents
my @parents = @{$onto->get_parent_terms($n3)};
@parents = @{$onto->get_parent_terms($n1)};
@parents = @{$onto->get_parent_terms($n2)};
# get all descendents
my @descendents1 = @{$onto->get_descendent_terms($n1)};
my @descendents2 = @{$onto->get_descendent_terms($n2)};
my @descendents3 = @{$onto->get_descendent_terms($n3)};
my @descendents5 = @{$onto->get_descendent_terms($n5)};
# get all ancestors
my @ancestors1 = @{$onto->get_ancestor_terms($n1)};
my @ancestors2 = @{$onto->get_ancestor_terms($n2)};
my @ancestors3 = @{$onto->get_ancestor_terms($n3)};
# get descendents by term subnamespace
my @descendents4 = @{$onto->get_descendent_terms_by_subnamespace($n1, 'P')};
my @descendents5 = @{$onto->get_descendent_terms_by_subnamespace($n2, 'P')};
my @descendents6 = @{$onto->get_descendent_terms_by_subnamespace($n3, 'P')};
my @descendents6 = @{$onto->get_descendent_terms_by_subnamespace($n3, 'R')};
# get ancestors by term subnamespace
my @ancestors4 = @{$onto->get_ancestor_terms_by_subnamespace($n1, 'P')};
my @ancestors5 = @{$onto->get_ancestor_terms_by_subnamespace($n2, 'P')};
my @ancestors6 = @{$onto->get_ancestor_terms_by_subnamespace($n3, 'P')};
my @ancestors6 = @{$onto->get_ancestor_terms_by_subnamespace($n3, 'R')};
# three new relationships types
my $r1 = OBO::Core::RelationshipType->new();
my $r2 = OBO::Core::RelationshipType->new();
my $r3 = OBO::Core::RelationshipType->new();
$r1->id("CCO:R0000001");
$r2->id("CCO:R0000002");
$r3->id("CCO:R0000003");
$r1->name("is_a");
$r2->name("part_of");
$r3->name("participates_in");
# add relationship types
$onto->add_relationship_type($r1);
$onto->add_relationship_type($r2);
$onto->add_relationship_type($r3);
# get descendents or ancestors linked by a particular relationship type
my $rel_type1 = $onto->get_relationship_type_by_name("is_a");
my $rel_type2 = $onto->get_relationship_type_by_name("part_of");
my $rel_type3 = $onto->get_relationship_type_by_name("participates_in");
my @descendents7 = @{$onto->get_descendent_terms_by_relationship_type($n5, $rel_type1)};
@descendents7 = @{$onto->get_descendent_terms_by_relationship_type($n5, $rel_type2)};
@descendents7 = @{$onto->get_descendent_terms_by_relationship_type($n2, $rel_type1)};
@descendents7 = @{$onto->get_descendent_terms_by_relationship_type($n3, $rel_type3)};
my @ancestors7 = @{$onto->get_ancestor_terms_by_relationship_type($n1, $rel_type1)};
@ancestors7 = @{$onto->get_ancestor_terms_by_relationship_type($n1, $rel_type2)};
@ancestors7 = @{$onto->get_ancestor_terms_by_relationship_type($n1, $rel_type3)};
@ancestors7 = @{$onto->get_ancestor_terms_by_relationship_type($n2, $rel_type2)};
# add relationship type as string
my $relationship_type = $onto->add_relationship_type_as_string("CCO:R0000004", "has_participant");
# get relationship types
my @rt = @{$onto->get_relationship_types()};
my %rrt;
foreach my $relt (@rt) {
$rrt{$relt->name()} = $relt;
my @rtbt = @{$onto->get_relationship_types_by_term($n1)};
my %rtbth;
foreach my $relt (@rtbt) {
$rtbth{$relt} = $relt;
# get_head_by_relationship_type
my @heads_n1 = @{$onto->get_head_by_relationship_type($n1, $onto->get_relationship_type_by_name("participates_in"))};
my %hbrt;
foreach my $head (@heads_n1) {
$hbrt{$head->id()} = $head;
This module has several methods to work with Ontologies in OBO and OWL formats, such as the Cell Cycle Ontology (http://www.cellcycleontology.org). Basically, it is a directed acyclic graph (DAG) holding the terms (OBO::Core::Term) which in turn are linked by relationships (OBO::Core::Relationship). These relationships have an associated relationship type (OBO::Core::RelationshipType).
Erick Antezana, <erant@psb.ugent.be>
Copyright (C) 2006, 2007, 2008 by Erick Antezana
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.
Usage - print $ontology->id() or $ontology->id($id) Returns - the ontology ID (string) Args - the ontology ID (string) Function - gets/sets the ontology ID
Usage - print $ontology->name() or $ontology->name($name) Returns - the name (string) of the ontology Args - the name (string) of the ontology Function - gets/sets the name of the ontology
Usage - $onto->imports() or $onto->imports($id1, $id2, $id3, ...) Returns - a set (OBO::Util::Set) with the imported id ontologies Args - the ontology id(s) (string) Function - gets/sets the id(s) of the ontologies that are imported by this one
Usage - print $ontology->date() Returns - the current date (in dd:MM:yyyy HH:mm format) of the ontology Args - the current date (in dd:MM:yyyy HH:mm format) of the ontology Function - gets/sets the date of the ontology
Usage - print $ontology->default_namespace() or $ontology->default_namespace("cellcycle_ontology") Returns - the default namespace (string) of this ontology Args - the default namespace (string) of this ontology Function - gets/sets the default namespace of this ontology
Usage - print $ontology->idspace() or $ontology->idspace("CCO http://www.cellcycleontology.org/ontology/owl#") Returns - the id space (OBO::Core::IDspace) of this ontology Args - the id space (OBO::Core::IDspace) of this ontology Function - gets/sets the idspace of this ontology
Usage - $ontology->idspace_as_string($local_id, $uri, $description) Returns - the idspace as string (string). Empty string is returned if the IDspace was not defined Args - the local idspace (string), the uri (string) and the description (string) Function - gets/sets the idspace of this ontology
Usage - print $ontology->data_version() Returns - the data version (string) of this ontology Args - the data version (string) of this ontology Function - gets/sets the data version of this ontology
Usage - print $ontology->saved_by() Returns - the username of the person (string) to last save this ontology Args - the username of the person (string) to last save this ontology Function - gets/sets the username of the person to last save this ontology
Usage - print $ontology->remark() Returns - the remark (string) of this ontology Args - the remark (string) of this ontology Function - gets/sets the remark of this ontology
Usage - $onto->subsets() or $onto->subsets($ss1, $ss2, $ss3, ...) Returns - a set (OBO::Util::Set) with the subsets used in this ontology. A subset is a view over an ontology Args - the subset(s) (string) used in this ontology Function - gets/sets the subset(s) of this ontology
Usage - $onto->synonym_type_def_set() or $onto->synonym_type_def_set($st1, $st2, $st3, ...) Returns - a set (OBO::Util::SynonymTypeDefSet) with the synonym type definitions used in this ontology. A synonym type is a description of a user-defined synonym type Args - the synonym type defintion(s) (OBO::Core::SynonymTypeDef) used in this ontology Function - gets/sets the synonym type definitions (s) of this ontology
Usage - $ontology->add_term($term) Returns - the just added term (OBO::Core::Term) Args - the term (OBO::Core::Term) to be added. The ID of the term to be added must have already been defined. Function - adds a term to this ontology
Usage - $ontology->add_term_as_string($term_id, $term_name) Returns - the just added term (OBO::Core::Term) Args - the term id (string) and the term name (string) of term to be added Function - adds a term to this ontology
Usage - $ontology->add_relationship_type($relationship_type) Returns - the just added relationship type (OBO::Core::RelationshipType) Args - the relationship type to be added (OBO::Core::RelationshipType). The ID of the relationship type to be added must have already been defined. Function - adds a relationship type to this ontology
Usage - $ontology->add_relationship_type_as_string($relationship_type_id, $relationship_type_name) Returns - the just added relationship type (OBO::Core::RelationshipType) Args - the relationship type id (string) and the relationship type name (string) of the relationship type to be added Function - adds a relationship type to this ontology
Usage - $ontology->delete_term($term) Returns - none Args - the term (OBO::Core::Term) to be deleted Function - deletes a term from this ontology
Usage - print $ontology->has_term($term) Returns - true or false Args - the term (OBO::Core::Term) to be tested Function - checks if the given term belongs to this ontology
Usage - print $ontology->has_term_id($term_id) Returns - true or false Args - the term id (string) to be tested Function - checks if the given term id corresponds to a term held by this ontology
Usage - print $ontology->has_relationship_type($relationship_type) Returns - true or false Args - the relationship type (OBO::Core::RelationshipType) to be tested Function - checks if the given relationship type belongs to this ontology
Usage - print $ontology->has_relationship_type_id($relationship_type_id) Returns - true or false Args - the relationship type id (string) to be tested Function - checks if the given relationship type id corresponds to a relationship type held by this ontology
Usage - print $ontology->has_relationship_id($rel_id) Returns - true or false Args - the relationship id (string) to be tested Function - checks if the given relationship id corresponds to a relationship held by this ontology
Usage - print $ontology->equals($another_ontology) Returns - either 1 (true) or 0 (false) Args - the ontology (OBO::Core::Ontology) to compare with Function - tells whether this ontology is equal to the parameter
Usage - $ontology->get_terms() or $ontology->get_terms("CCO:I.*") Returns - the terms held by this ontology as a reference to an array of OBO::Core::Term's Args - none or the regular expression for filtering the terms by id's Function - returns the terms held by this ontology
Usage - $ontology->get_terms_by_subnamespace() or $ontology->get_terms_by_subnamespace("P") Returns - the terms held by this ontology corresponding to the requested subnamespace as a reference to an array of OBO::Core::Term's Args - none or the subnamespace: 'P', 'I', and so on. Function - returns the terms held by this ontology corresponding to the requested subnamespace
Usage - $ontology->get_relationships() Returns - the relationships held by this ontology as a reference to an array of OBO::Core::Relationship's Args - none Function - returns the relationships held by this ontology
Usage - $ontology->get_relationship_types() Returns - a reference to an array with the relationship types (OBO::Core::RelationshipType) held by this ontology Args - none Function - returns the relationship types held by this ontology
Usage - $ontology->get_relationships_by_source_term($source_term) Returns - a reference to an array with the relationship (OBO::Core::Relationship) connecting this term to its children Args - the term (OBO::Core::Term) for which its relationships will be found out Function - returns the relationships associated to the given source term
Usage - $ontology->get_relationships_by_target_term($target_term) Returns - a reference to an array with the relationship (OBO::Core::Relationship) connecting this term to its parents Args - the term (OBO::Core::Term) for which its relationships will be found out Function - returns the relationships associated to the given target term
Usage - $ontology->get_term_by_id($id) Returns - the term (OBO::Core::Term) associated to the given ID Args - the term's ID (string) Function - returns the term associated to the given ID
Usage - $ontology->set_term_id($term, $new_id) Returns - the term (OBO::Core::Term) with its new ID Args - the term (OBO::Core::Term) and its new term's ID (string) Function - sets a new term ID for the given term
Usage - $ontology->get_relationship_type_by_id($id) Returns - the relationship type (OBO::Core::RelationshipType) associated to the given id Args - the relationship type's id (string) Function - returns the relationship type associated to the given id
Usage - $ontology->get_term_by_name($name) Returns - the term (OBO::Core::Term) associated to the given name Args - the term's name (string) Function - returns the term associated to the given name Remark - the argument (string) is case sensitive
Usage - $ontology->get_term_by_name_or_synonym($name) Returns - the term (OBO::Core::Term) associated to the given name or *EXACT* synonym Args - the term's name or synonym (string) Function - returns the term associated to the given name or *EXACT* synonym Remark - this function should be carefully used since among ontologies there may be homonyms at the level of the synonyms (e.g. genes) Remark - the argument (string) is case sensitive
Usage - $ontology->get_terms_by_name($name) Returns - the term set (OBO::Util::TermSet) with all the terms (OBO::Core::Term) having $name in their names Args - the term's name (string) Function - returns the terms having $name in their names
Usage - $ontology->get_relationship_type_by_name($name) Returns - the relationship type (OBO::Core::RelationshipType) associated to the given name Args - the relationship type's name (string) Function - returns the relationship type associated to the given name
Usage - $ontology->add_relationship($relationship) Returns - none Args - the relationship (OBO::Core::Relationship) to be added between two existing terms or two relationship types Function - adds a relationship between either two terms or two relationship types. If the terms or relationship types bound by this relationship are not yet in the ontology, they will be added
Usage - print $ontology->get_relationship_by_id() Returns - the relationship (OBO::Core::Relationship) associated to the given id Args - the relationship id (string) Function - returns the relationship associated to the given relationship id
Usage - $ontology->get_child_terms($term) Returns - a reference to an array with the child terms (OBO::Core::Term) of the given term Args - the term (OBO::Core::Term) for which the children will be found Function - returns the child terms of the given term
Usage - $ontology->get_parent_terms($term) Returns - a reference to an array with the parent terms (OBO::Core::Term) of the given term Args - the term (OBO::Core::Term) for which the parents will be found Function - returns the parent terms of the given term
Usage - $ontology->get_head_by_relationship_type($term, $relationship_type) or $ontology->get_head_by_relationship_type($rel_type, $relationship_type) Returns - a reference to an array of terms (OBO::Core::Term) or relationship types (OBO::Core::RelationshipType) pointed out by the relationship of the given type; otherwise undef Args - the term (OBO::Core::Term) or relationship type (OBO::Core::RelationshipType) and the pointing relationship type (OBO::Core::RelationshipType) Function - returns the terms or relationship types pointed out by the relationship of the given type
Usage - $ontology->get_tail_by_relationship_type($term, $relationship_type) or $ontology->get_tail_by_relationship_type($rel_type, $relationship_type) Returns - a reference to an array of terms (OBO::Core::Term) or relationship types (OBO::Core::RelationshipType) pointing out the given term by means of the given relationship type; otherwise undef Args - the term (OBO::Core::Term) or relationship type (OBO::Core::RelationshipType) and the relationship type (OBO::Core::RelationshipType) Function - returns the terms or relationship types pointing out the given term by means of the given relationship type
Usage - $ontology->get_number_of_terms() Returns - the number of terms held by this ontology Args - none Function - returns the number of terms held by this ontology
Usage - $ontology->get_number_of_relationships() Returns - the number of relationships held by this ontology Args - none Function - returns the number of relationships held by this ontology
Usage - $ontology->get_number_of_relationship_types() Returns - the number of relationship types held by this ontology Args - none Function - returns the number of relationship types held by this ontology
Usage - $ontology->export($file_handle, $export_format) Returns - exports this ontology Args - the file handle (STDOUT, STDERR, ...) and the format: obo (by default), xml, owl, dot, gml, xgmml, sbml. Default file handle: STDOUT. Function - exports this ontology
Usage - $ontology->subontology_by_terms($term_set) Returns - a subontology with the given terms from this ontology Args - the terms (OBO::Util::TermSet) that will be included in the subontology Function - creates a subontology based on the given terms from this ontology
Usage - $ontology->get_subontology_from($new_root_term) Returns - a subontology from the given term of this ontology Args - the term (OBO::Core::Term) that is the root of the subontology Function - creates a subontology having as root the given term
Usage - $ontology->obo_id2owl_id($term) Returns - the ID for OWL representation. Args - the OBO-type ID. Function - Transform an OBO-type ID into an OWL-type one. E.g. CCO:I1234567 -> CCO_I1234567
Usage - $ontology->owl_id2obo_id($term) Returns - the ID for OBO representation. Args - the OWL-type ID. Function - Transform an OWL-type ID into an OBO-type one. E.g. CCO_I1234567 -> CCO:I1234567
Usage - $ontology->char_hex_http($seq) Returns - the sequence with the hexadecimal representation for the http special characters Args - the sequence of characters Function - Transforms a http character to its equivalent one in hexadecimal. E.g. : -> %3A
Usage - $ontology->get_descendent_terms($term) Returns - a set with the descendent terms (OBO::Core::Term) of the given term Args - the term (OBO::Core::Term) for which all the descendent will be found Function - returns recursively all the child terms of the given term
Usage - $ontology->get_ancestor_terms($term) Returns - a set with the ancestor terms (OBO::Core::Term) of the given term Args - the term (OBO::Core::Term) for which all the ancestors will be found Function - returns recursively all the parent terms of the given term
Usage - $ontology->get_descendent_terms_by_subnamespace($term, subnamespace) Returns - a set with the descendent terms (OBO::Core::Term) of the given subnamespace Args - the term (OBO::Core::Term), the subnamespace (string, e.g. 'P', 'R' etc) Function - returns recursively the given term's children of the given subnamespace
Usage - $ontology->get_ancestor_terms_by_subnamespace($term, subnamespace) Returns - a set with the ancestor terms (OBO::Core::Term) of the given subnamespace Args - the term (OBO::Core::Term), the subnamespace (string, e.g. 'P', 'R' etc) Function - returns recursively the given term's parents of the given subnamespace
Usage - $ontology->get_descendent_terms_by_relationship_type($term, $rel_type) Returns - a set with the descendent terms (OBO::Core::Term) of the given term linked by the given relationship type Args - OBO::Core::Term object, OBO::Core::RelationshipType object Function - returns recursively all the child terms of the given term linked by the given relationship type
Usage - $ontology->get_ancestor_terms_by_relationship_type($term, $rel_type) Returns - a set with the ancestor terms (OBO::Core::Term) of the given term linked by the given relationship type Args - OBO::Core::Term object, OBO::Core::RelationshipType object Function - returns recursively the parent terms of the given term linked by the given relationship type
Usage - $ontology->create_rel->($tail, $type, $head) Returns - OBO::Core::Ontology object Args - OBO::Core::(Term|Relationship) object, relationship type string, and the OBO::Core::(Term|Relationship) object, Function - creates and adds to the ontology a new relationship
Usage - $ontology->get_term_by_xref($db, $acc) Returns - the term (OBO::Core::Term) associated with the given external database ID. 'undef' is returned if there is no term for the given arguments. Args - the name of the external database and the ID (strings) Function - returns the term associated with the given external database ID
Usage - $ontology->get_paths_term1_term2($term1, $term2) Returns - an array of references to the paths between term1 and term2 Args - the IDs of the terms for which a path (or paths) will be found Function - returns the path(s) linking term1 and terms2, where term1 is more specific than term2
Usage - $ontology->get_paths_term_terms($term, $set_of_terms) Returns - an array of references to the paths between a given term ID and a given set of terms IDs Args - the IDs of the terms for which a path (or paths) will be found Function - returns the path(s) linking term and the given set of terms
Usage - $ontology->get_paths_term_terms_same_rel($term, $set_of_terms) Returns - an array of references to the paths between a given term ID and a given set of terms IDs Args - the IDs of the terms for which a path (or paths) will be found and the ID of the relationship type Function - returns the path(s) linking term and the given set of terms along the same relationship (e.g. is_a)
To install OBO::Core::Def, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OBO::Core::Def
CPAN shell
perl -MCPAN -e shell install OBO::Core::Def
For more information on module installation, please visit the detailed CPAN module installation guide.