private function OBOImporter::addRelationship
3.x OBOImporter.inc | private OBOImporter::addRelationship($cvterm, $defaultcv, $rel,
$objname, $object_is_relationship = 0, $default_db = 'OBO_REL') |
Adds a cvterm relationship
@object_is_relationship Set to 1 if this term is a relationship term @default_db The name of the default database.
Parameters
$cvterm: A database object for the cvterm
$rel: The relationship name
$objname: The relationship term name
$defaultcv: A database object containing a record from the cv table for the default controlled vocabulary
1 call to OBOImporter::addRelationship()
- OBOImporter::processTerm in tripal_chado/
includes/ TripalImporter/ OBOImporter.inc - Uses the provided term array to add/update information to Chado about the term including the term, dbxref, synonyms, properties, and relationships.
File
- tripal_chado/
includes/ TripalImporter/ OBOImporter.inc, line 956
Class
Code
private function addRelationship($cvterm, $defaultcv, $rel,
$objname, $object_is_relationship = 0, $default_db = 'OBO_REL') {
// If an accession was passed we need to see if we can find the actual label.
if (strpos($rel, ':')) {
$pair = explode(":", $rel);
$ontology_id = $pair[0];
$accession_num = $pair[1];
if (is_numeric($accession_num)) {
$results = $this->oboEbiLookup($rel, 'query');
if (!empty($results)) {
if (array_key_exists('docs', $results)) {
if (!empty($results['docs'])) {
$rel = $results['docs']['label'];
}
else {
// The first search doesn't work, so let's try a broader one.
$results = $this->oboEbiLookup($rel, 'query-non-local');
if (!empty($results)) {
if (array_key_exists('docs', $results)) {
if (!empty($results['docs'])) {
$accession = $rel;
$accession_underscore = str_replace(":", "_", $accession);
foreach ($results['docs'] as $item) {
if ($item['label'] != $accession && $item['label'] != $accession_underscore) {
//Found the first place a label is other than the accession is used, so take
// that info and then end the loop.
$rel = $item['label'];
break;
}
}
}
}
}
}
}
}
}
}
// Make sure the relationship cvterm exists.
$term = array(
'name' => $rel,
'id' => "$default_db:$rel",
'definition' => '',
'is_obsolete' => 0,
'cv_name' => $defaultcv,
'is_relationship' => TRUE,
'db_name' => $default_db
);
$relcvterm = chado_insert_cvterm($term, array('update_existing' => FALSE));
if (!$relcvterm) {
// If the relationship term couldn't be found in the default_db provided
// then do on more check to find it in the relationship ontology
$term = array(
'name' => $rel,
'id' => "OBO_REL:$rel",
'definition' => '',
'is_obsolete' => 0,
'cv_name' => $defaultcv,
'is_relationship' => TRUE,
'db_name' => 'OBO_REL'
);
$relcvterm = chado_insert_cvterm($term, array('update_existing' => FALSE));
if (!$relcvterm) {
throw new Exception("Cannot find the relationship term in the current ontology or in the relationship ontology: $rel\n");
}
}
// Get the object term.
$oterm = $this->getTerm($objname);
if (!$oterm) {
throw new Exception("Could not find object term $objname\n");
}
$objterm = array();
$objterm['id'] = $oterm['id'][0];
$objterm['name'] = $oterm['name'][0];
if (array_key_exists('def', $oterm)) {
$objterm['definition'] = $oterm['def'][0];
}
if (array_key_exists('subset', $oterm)) {
$objterm['subset'] = $oterm['subset'][0];
}
if (array_key_exists('namespace', $oterm)) {
$objterm['namespace'] = $oterm['namespace'][0];
}
if (array_key_exists('is_obsolete', $oterm)) {
$objterm['is_obsolete'] = $oterm['is_obsolete'][0];
}
$objterm['cv_name'] = $defaultcv;
$objterm['is_relationship'] = $object_is_relationship;
$objterm['db_name'] = $default_db;
$objcvterm = chado_insert_cvterm($objterm, array('update_existing' => TRUE));
if (!$objcvterm) {
throw new Exception("Cannot add cvterm " . $oterm['name'][0]);
}
// check to see if the cvterm_relationship already exists, if not add it
$values = array(
'type_id' => $relcvterm->cvterm_id,
'subject_id' => $cvterm->cvterm_id,
'object_id' => $objcvterm->cvterm_id
);
$result = chado_select_record('cvterm_relationship', array('*'), $values);
if (count($result) == 0) {
$options = array('return_record' => FALSE);
$success = chado_insert_record('cvterm_relationship', $values, $options);
if (!$success) {
throw new Exception("Cannot add term relationship: '$cvterm->name' $rel '$objcvterm->name'");
}
}
return TRUE;
}