function tripal_cv_obo_add_relationship

2.x tripal_cv.obo_loader.inc tripal_cv_obo_add_relationship($cvterm, $defaultcv, $rel, $objname, $object_is_relationship = 0, $default_db = 'OBO_REL')
1.x obo_loader.inc tripal_cv_obo_add_relationship($cvterm, $defaultcv, $rel, $objname, $object_is_relationship = 0, $default_db = 'OBO_REL')

Add a cvterm relationship

Related topics

1 call to tripal_cv_obo_add_relationship()

File

tripal_cv/includes/obo_loader.inc, line 629
Tripal Ontology Loader

Code

function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $rel, 
$objname, $object_is_relationship = 0, $default_db = 'OBO_REL') {

  // make sure the relationship cvterm exists
  $term = array(
    'name' => $rel,
    'id' => "$default_db:$rel",
    'definition' => '',
    'is_obsolete' => 0,
  );
  $relcvterm = tripal_cv_add_cvterm($term, $defaultcv, 1, 0, $default_db);

  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,
    );
    $relcvterm = tripal_cv_add_cvterm($term, $defaultcv, 1, 0, 'OBO_REL');
    if (!$relcvterm) {
      tripal_cv_obo_quiterror("Cannot find the relationship term in the current ontology or in the relationship ontology: $rel\n");
    }
  }

  // get the object term
  $oterm = tripal_cv_obo_get_term($objname);
  if (!$oterm) {
    tripal_cv_obo_quiterror("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['def'] = $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];
  }
  $objcvterm = tripal_cv_add_cvterm($objterm, $defaultcv, $object_is_relationship, 1, $default_db);
  if (!$objcvterm) {
    tripal_cv_obo_quiterror("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
  );
  $options = array('statement_name' => 'sel_cvtermrelationship_tysuob');
  $result = tripal_core_chado_select('cvterm_relationship', array('*'), $values, $options);
  if (count($result) == 0) {
    $options = array(
      'statement_name' => 'ins_cvtermrelationship_tysuob',
      'return_record' => FALSE
    );
    $success = tripal_core_chado_insert('cvterm_relationship', $values, $options);
    if (!$success) {
      tripal_cv_obo_quiterror("Cannot add term relationship: '$cvterm->name' $rel '$objcvterm->name'");
    }
  }

  return TRUE;
}