|  | @@ -199,7 +199,7 @@ function tripal_cv_obo_process_terms($terms, $defaultcv, $obo, $jobid = NULL, &$
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    
 | 
	
		
			
				|  |  |    // calculate the interval for updates
 | 
	
		
			
				|  |  | -  $interval = intval($count * 0.01);
 | 
	
		
			
				|  |  | +  $interval = intval($count * 0.0001);
 | 
	
		
			
				|  |  |    if ($interval < 1) {
 | 
	
		
			
				|  |  |      $interval = 1;
 | 
	
		
			
				|  |  |    }
 | 
	
	
		
			
				|  | @@ -259,8 +259,10 @@ function tripal_cv_obo_process_term($term, $defaultcv, $obo, $is_relationship =
 | 
	
		
			
				|  |  |    if (!$cvterm) {
 | 
	
		
			
				|  |  |      tripal_cv_obo_quiterror("Cannot add the term " . $term['id']);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  if ($term['namespace']) {
 | 
	
		
			
				|  |  | -    $newcvs[$term['namespace']] = $cvterm->cv_id;
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  | +  if (isset($term['namespace'])) {
 | 
	
		
			
				|  |  | +    $newcvs[$term['namespace'][0]] = $cvterm->cv_id;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    
 | 
	
		
			
				|  |  |    // now handle other properites
 | 
	
	
		
			
				|  | @@ -274,6 +276,7 @@ function tripal_cv_obo_process_term($term, $defaultcv, $obo, $is_relationship =
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  |    if (isset($term['subset'])) {
 | 
	
		
			
				|  |  |      //print "WARNING: unhandled tag: subset\n";
 | 
	
		
			
				|  |  |    }
 | 
	
	
		
			
				|  | @@ -310,6 +313,7 @@ function tripal_cv_obo_process_term($term, $defaultcv, $obo, $is_relationship =
 | 
	
		
			
				|  |  |        tripal_cv_obo_quiterror("Cannot add/update synonyms");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  |    // add the comment to the cvtermprop table
 | 
	
		
			
				|  |  |    if (isset($term['comment'])) {
 | 
	
		
			
				|  |  |      $comments = $term['comment'];
 | 
	
	
		
			
				|  | @@ -321,6 +325,7 @@ function tripal_cv_obo_process_term($term, $defaultcv, $obo, $is_relationship =
 | 
	
		
			
				|  |  |        $j++;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  |    // add any other external dbxrefs
 | 
	
		
			
				|  |  |    if (isset($term['xref'])) {
 | 
	
		
			
				|  |  |      foreach ($term['xref'] as $xref) {
 | 
	
	
		
			
				|  | @@ -329,6 +334,7 @@ function tripal_cv_obo_process_term($term, $defaultcv, $obo, $is_relationship =
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  |    if (isset($term['xref_analog'])) {
 | 
	
		
			
				|  |  |      foreach ($term['xref_analog'] as $xref) {
 | 
	
		
			
				|  |  |        if (!tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref)) {
 | 
	
	
		
			
				|  | @@ -352,6 +358,7 @@ function tripal_cv_obo_process_term($term, $defaultcv, $obo, $is_relationship =
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  |    if (isset($term['intersection_of'])) {
 | 
	
		
			
				|  |  |      //print "WARNING: unhandled tag: intersection_of\n";
 | 
	
		
			
				|  |  |    }
 | 
	
	
		
			
				|  | @@ -400,7 +407,8 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $obo, $rel,
 | 
	
		
			
				|  |  |      'definition' => '',
 | 
	
		
			
				|  |  |      'is_obsolete' => 0,
 | 
	
		
			
				|  |  |    );
 | 
	
		
			
				|  |  | -  $relcvterm = tripal_cv_add_cvterm($term, $defaultcv, 1, 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
 | 
	
	
		
			
				|  | @@ -410,7 +418,7 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $obo, $rel,
 | 
	
		
			
				|  |  |        'definition' => '',
 | 
	
		
			
				|  |  |        'is_obsolete' => 0,
 | 
	
		
			
				|  |  |      ); 
 | 
	
		
			
				|  |  | -    $relcvterm = tripal_cv_add_cvterm($term, $defaultcv, 1, 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");
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -421,15 +429,23 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $obo, $rel,
 | 
	
		
			
				|  |  |    if (!$oterm) {
 | 
	
		
			
				|  |  |      tripal_cv_obo_quiterror("Could not find object term $objname\n");
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  $objterm = array(
 | 
	
		
			
				|  |  | -    'name' => $oterm['name'][0],
 | 
	
		
			
				|  |  | -    'id' => $oterm['id'][0],
 | 
	
		
			
				|  |  | -    'definition' => $oterm['def'][0],
 | 
	
		
			
				|  |  | -    'is_obsolete' => $oterm['is_obsolete'][0],
 | 
	
		
			
				|  |  | -  );
 | 
	
		
			
				|  |  | -  $objcvterm = tripal_cv_add_cvterm($objterm, $defaultcv, $object_is_relationship, 1);
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  | +  $objterm = array(); 
 | 
	
		
			
				|  |  | +  $objterm['id']            = $oterm['id'][0];
 | 
	
		
			
				|  |  | +  $objterm['name']          = $oterm['name'][0];
 | 
	
		
			
				|  |  | +  $objterm['def']           = $oterm['def'][0];
 | 
	
		
			
				|  |  | +  if (isset($oterm['subset'])) {
 | 
	
		
			
				|  |  | +    $objterm['subset']      = $oterm['subset'][0];  
 | 
	
		
			
				|  |  | +  }  
 | 
	
		
			
				|  |  | +  if (isset($oterm['namespace'])) {
 | 
	
		
			
				|  |  | +    $objterm['namespace']   = $oterm['namespace'][0];
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  if (isset($oterm['is_obsolete'])) {
 | 
	
		
			
				|  |  | +    $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/find cvterm");
 | 
	
		
			
				|  |  | +    tripal_cv_obo_quiterror("Cannot add cvterm " . $oterm['name'][0]);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // check to see if the cvterm_relationship already exists, if not add it
 | 
	
	
		
			
				|  | @@ -441,9 +457,10 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $obo, $rel,
 | 
	
		
			
				|  |  |    $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');
 | 
	
		
			
				|  |  | -    $sql = "INSERT INTO {cvterm_relationship} ".
 | 
	
		
			
				|  |  | -           "(type_id,subject_id,object_id) VALUES (%d,%d,%d)";
 | 
	
		
			
				|  |  | +    $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'");
 | 
	
	
		
			
				|  | @@ -458,6 +475,7 @@ function tripal_cv_obo_add_relationship($cvterm, $defaultcv, $obo, $rel,
 | 
	
		
			
				|  |  |   * @ingroup tripal_obo_loader
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  function tripal_cv_obo_get_term($obo, $id) {
 | 
	
		
			
				|  |  | +  /*
 | 
	
		
			
				|  |  |    foreach ($obo as $type) {
 | 
	
		
			
				|  |  |      foreach ($type as $term) {
 | 
	
		
			
				|  |  |        $accession = $term['id'][0];
 | 
	
	
		
			
				|  | @@ -465,6 +483,14 @@ function tripal_cv_obo_get_term($obo, $id) {
 | 
	
		
			
				|  |  |          return $term;
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +  } */
 | 
	
		
			
				|  |  | +  // iterate through each of the types in the
 | 
	
		
			
				|  |  | +  // obo file (parsed into memory) and look
 | 
	
		
			
				|  |  | +  // for this term.  If found, return it.
 | 
	
		
			
				|  |  | +  foreach ($obo as $type) {
 | 
	
		
			
				|  |  | +    if (array_key_exists($id, $type)) {
 | 
	
		
			
				|  |  | +      return $type[$id];
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    return FALSE;
 | 
	
	
		
			
				|  | @@ -505,12 +531,12 @@ function tripal_cv_obo_add_synonyms($term, $cvterm) {
 | 
	
		
			
				|  |  |        if (!$results) {
 | 
	
		
			
				|  |  |          // build a 'term' object so we can add the missing term
 | 
	
		
			
				|  |  |          $term = array(
 | 
	
		
			
				|  |  | -           'name' => array($scope),
 | 
	
		
			
				|  |  | -           'id' => array("internal:$scope"),
 | 
	
		
			
				|  |  | -           'definition' => array(''),
 | 
	
		
			
				|  |  | -           'is_obsolete' => array(0),
 | 
	
		
			
				|  |  | +           'name' => $scope,
 | 
	
		
			
				|  |  | +           'id' => "internal:$scope",
 | 
	
		
			
				|  |  | +           'definition' => '',
 | 
	
		
			
				|  |  | +           'is_obsolete' => 0,
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  | -        $syntype = tripal_cv_add_cvterm($term, $syncv, 0, 1);
 | 
	
		
			
				|  |  | +        $syntype = tripal_cv_add_cvterm($term, $syncv->name, 0, 1);
 | 
	
		
			
				|  |  |          if (!$syntype) {
 | 
	
		
			
				|  |  |            tripal_cv_obo_quiterror("Cannot add synonym type: internal:$scope");
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -532,7 +558,10 @@ function tripal_cv_obo_add_synonyms($term, $cvterm) {
 | 
	
		
			
				|  |  |            'synonym' => $def,
 | 
	
		
			
				|  |  |            'type_id' => $syntype->cvterm_id
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  | -        $options = array('statement_name' => 'ins_cvtermsynonym_cvsy');
 | 
	
		
			
				|  |  | +        $options = array(
 | 
	
		
			
				|  |  | +          'statement_name' => 'ins_cvtermsynonym_cvsy',
 | 
	
		
			
				|  |  | +          'return_record' => FALSE
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  |          $success = tripal_core_chado_insert('cvtermsynonym', $values, $options);
 | 
	
		
			
				|  |  |          if (!$success) {
 | 
	
		
			
				|  |  |            tripal_cv_obo_quiterror("Failed to insert the synonym for term: $name ($def)");
 | 
	
	
		
			
				|  | @@ -591,7 +620,7 @@ function tripal_cv_obo_parse($obo_file, &$obo, &$header) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      if (preg_match('/^\s*\[/', $line)) {  // at the first stanza we're out of header
 | 
	
		
			
				|  |  |        $in_header = 0;
 | 
	
		
			
				|  |  | -      // load the stanza we just finished reading
 | 
	
		
			
				|  |  | +      // store the stanza we just finished reading
 | 
	
		
			
				|  |  |        if (sizeof($stanza) > 0) {
 | 
	
		
			
				|  |  |          if (!isset($obo[$type])) {
 | 
	
		
			
				|  |  |            $obo[$type] = array();
 | 
	
	
		
			
				|  | @@ -689,12 +718,21 @@ function tripal_cv_obo_add_cvterm_dbxref($cvterm, $xref) {
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // finally add the cvterm_dbxref but first check to make sure it exists
 | 
	
		
			
				|  |  | -  $sql = "SELECT * from {cvterm_dbxref} WHERE cvterm_id = %d and dbxref_id = %d";
 | 
	
		
			
				|  |  | -  if (!db_fetch_object(db_query($sql, $cvterm->cvterm_id, $dbxref->dbxref_id))) {
 | 
	
		
			
				|  |  | -    $sql = "INSERT INTO {cvterm_dbxref} (cvterm_id,dbxref_id)".
 | 
	
		
			
				|  |  | -           "VALUES (%d,%d)";
 | 
	
		
			
				|  |  | -    if (!db_query($sql, $cvterm->cvterm_id, $dbxref->dbxref_id)) {
 | 
	
		
			
				|  |  | +  $values = array(
 | 
	
		
			
				|  |  | +    'cvterm_id' => $cvterm->cvterm_id,
 | 
	
		
			
				|  |  | +    'dbxref_id' => $dbxref->dbxref_id,
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +  $options = array('statement_name' => 'sel_cvtermdbxref_cvdb');
 | 
	
		
			
				|  |  | +  $result = tripal_core_chado_select('cvterm_dbxref', array('*'), $values, $options);
 | 
	
		
			
				|  |  | +  if (count($result) == 0) {    
 | 
	
		
			
				|  |  | +    $ins_options = array(
 | 
	
		
			
				|  |  | +      'statement_name' => 'ins_cvtermdbxref_cvdb',
 | 
	
		
			
				|  |  | +      'return_record' => FALSE
 | 
	
		
			
				|  |  | +    );
 | 
	
		
			
				|  |  | +    $result = tripal_core_chado_insert('cvterm_dbxref', $values, $ins_options);
 | 
	
		
			
				|  |  | +    if (!$result){
 | 
	
		
			
				|  |  |        tripal_cv_obo_quiterror("Cannot add cvterm_dbxref: $xref");
 | 
	
		
			
				|  |  | +      return FALSE;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -714,13 +752,13 @@ function tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) {
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // get the property type cvterm.  If it doesn't exist then we want to add it
 | 
	
		
			
				|  |  | -  $sql = "
 | 
	
		
			
				|  |  | -      SELECT *
 | 
	
		
			
				|  |  | -      FROM {cvterm} CVT INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
 | 
	
		
			
				|  |  | -      WHERE CVT.name = '%s' and CV.name = '%s'
 | 
	
		
			
				|  |  | -  ";
 | 
	
		
			
				|  |  | -  $cvproptype = db_fetch_object(db_query($sql, $property, 'cvterm_property_type'));
 | 
	
		
			
				|  |  | -  if (!$cvproptype) {
 | 
	
		
			
				|  |  | +  $values = array(
 | 
	
		
			
				|  |  | +    'name' => $property,
 | 
	
		
			
				|  |  | +    'cv_id' => $cv->cv_id,
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +  $options = array('statement_name' => 'sel_cvterm_nacv_na');
 | 
	
		
			
				|  |  | +  $results = tripal_core_chado_select('cvterm', array('*'), $values, $options);
 | 
	
		
			
				|  |  | +  if (count($results) == 0) {    
 | 
	
		
			
				|  |  |      $term = array(
 | 
	
		
			
				|  |  |        'name' => $property,
 | 
	
		
			
				|  |  |        'id' => "internal:$property",
 | 
	
	
		
			
				|  | @@ -730,25 +768,41 @@ function tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) {
 | 
	
		
			
				|  |  |      $cvproptype = tripal_cv_add_cvterm($term, $cv->name, 0, 0);
 | 
	
		
			
				|  |  |      if (!$cvproptype) {
 | 
	
		
			
				|  |  |        tripal_cv_obo_quiterror("Cannot add cvterm property: internal:$property");
 | 
	
		
			
				|  |  | +      return FALSE;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +  else {
 | 
	
		
			
				|  |  | +    $cvproptype = $results[0];
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // remove any properties that currently exist for this term.  We'll reset them
 | 
	
		
			
				|  |  |    if ($rank == 0) {
 | 
	
		
			
				|  |  | -    $sql = "DELETE FROM {cvtermprop} WHERE cvterm_id = %d";
 | 
	
		
			
				|  |  | -    db_query($sql, $cvterm->cvterm_id);
 | 
	
		
			
				|  |  | +    $values = array('cvterm_id' => $cvterm->cvterm_id);
 | 
	
		
			
				|  |  | +    $options = array('statement_name' => 'del_cvtermprop_cv');
 | 
	
		
			
				|  |  | +    $success = tripal_core_chado_delete('cvtermprop', $values, $options);
 | 
	
		
			
				|  |  | +    if (!$success) {
 | 
	
		
			
				|  |  | +       tripal_cv_obo_quiterror("Could not remove existing properties to update property $property for term\n");
 | 
	
		
			
				|  |  | +       return FALSE;
 | 
	
		
			
				|  |  | +    }    
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // now add the property
 | 
	
		
			
				|  |  | -  $sql = "INSERT INTO {cvtermprop} (cvterm_id,type_id,value,rank) ".
 | 
	
		
			
				|  |  | -        "VALUES (%d, %d, '%s',%d)";
 | 
	
		
			
				|  |  | -  if (!db_query($sql, $cvterm->cvterm_id, $cvproptype->cvterm_id, $value, $rank)) {
 | 
	
		
			
				|  |  | +  $values = array(
 | 
	
		
			
				|  |  | +    'cvterm_id' => $cvterm->cvterm_id,
 | 
	
		
			
				|  |  | +    'type_id' => $cvproptype->cvterm_id,
 | 
	
		
			
				|  |  | +    'value' => $value,
 | 
	
		
			
				|  |  | +    'rank' => $rank,
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +  $options = array(
 | 
	
		
			
				|  |  | +    'statement_name' => 'ins_cvtermprop_cvtyvara',
 | 
	
		
			
				|  |  | +    'return_record' => FALSE,
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +  $result = tripal_core_chado_insert('cvtermprop', $values, $options);
 | 
	
		
			
				|  |  | +  if (!$result) {
 | 
	
		
			
				|  |  |      tripal_cv_obo_quiterror("Could not add property $property for term\n");
 | 
	
		
			
				|  |  | +    return FALSE;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |    return TRUE;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -759,20 +813,30 @@ function tripal_cv_obo_add_cvterm_prop($cvterm, $property, $value, $rank) {
 | 
	
		
			
				|  |  |  function tripal_cv_obo_add_dbxref($db_id, $accession, $version='', $description='') {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // check to see if the dbxref exists if not, add it
 | 
	
		
			
				|  |  | -  $dbxsql = "SELECT dbxref_id FROM {dbxref} WHERE db_id = %d and accession = '%s'";
 | 
	
		
			
				|  |  | -  $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
 | 
	
		
			
				|  |  | -  if (!$dbxref) {
 | 
	
		
			
				|  |  | -    $sql = "
 | 
	
		
			
				|  |  | -       INSERT INTO {dbxref} (db_id, accession, version, description)
 | 
	
		
			
				|  |  | -       VALUES (%d,'%s','%s','%s')
 | 
	
		
			
				|  |  | -    ";
 | 
	
		
			
				|  |  | -    if (!db_query($sql, $db_id, $accession, $version, $description)) {
 | 
	
		
			
				|  |  | +  $values = array(
 | 
	
		
			
				|  |  | +    'db_id' => $db_id,
 | 
	
		
			
				|  |  | +    'accession' => $accession,
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +  $options = array('statement_name' => 'sel_dbxref_idac');
 | 
	
		
			
				|  |  | +  $result = tripal_core_chado_select('dbxref', array('dbxref_id'), $values, $options);
 | 
	
		
			
				|  |  | +  if (count($result) == 0){
 | 
	
		
			
				|  |  | +    $ins_values = array(
 | 
	
		
			
				|  |  | +      'db_id'       => $db_id,
 | 
	
		
			
				|  |  | +      'accession'   => $accession,
 | 
	
		
			
				|  |  | +      'version'     => $version,
 | 
	
		
			
				|  |  | +      'description' => $description,
 | 
	
		
			
				|  |  | +    );
 | 
	
		
			
				|  |  | +    $ins_options = array(
 | 
	
		
			
				|  |  | +      'statement_name' => 'ins_dbxref_idacvede',
 | 
	
		
			
				|  |  | +      'return_record' => FALSE
 | 
	
		
			
				|  |  | +    );
 | 
	
		
			
				|  |  | +    $result = tripal_core_chado_insert('dbxref', $ins_values, $ins_options);
 | 
	
		
			
				|  |  | +    if (!$result) {
 | 
	
		
			
				|  |  |        tripal_cv_obo_quiterror("Failed to insert the dbxref record $accession");
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    print "Added Dbxref accession: $accession\n";
 | 
	
		
			
				|  |  | -    $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
 | 
	
		
			
				|  |  | +      return FALSE;
 | 
	
		
			
				|  |  | +    } 
 | 
	
		
			
				|  |  | +    $result = tripal_core_chado_select('dbxref', array('dbxref_id'), $values, $options);    
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  return $dbxref;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +  return $result[0];
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |