function tripal_feature_load_gff3_feature

2.x tripal_feature.gff_loader.inc tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uniquename, $name, $residues, $is_analysis = 'f', $is_obsolete = 'f', $add_only, $score)
1.x gff_loader.inc tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uniquename, $name, $residues, $is_analysis = 'f', $is_obsolete = 'f', $add_only, $score)

Related topics

1 call to tripal_feature_load_gff3_feature()
tripal_feature_load_gff3 in tripal_feature/includes/gff_loader.inc

File

tripal_feature/includes/gff_loader.inc, line 1422
@todo Add file header description

Code

function tripal_feature_load_gff3_feature($organism, $analysis_id, $cvterm, $uniquename, 
$name, $residues, $is_analysis = 'f', $is_obsolete = 'f', $add_only, $score) {

  // check to see if the feature already exists
  $feature = NULL;
  $fselect = array(
    'organism_id' => $organism->organism_id,
    'uniquename' => $uniquename,
    'type_id' => $cvterm->cvterm_id
  );
  $options = array('statement_name' => 'sel_feature_orunty');
  $columns = array('feature_id', 'name', 'uniquename', 'seqlen', 'organism_id', 'type_id');
  $result = tripal_core_chado_select('feature', $columns, $fselect, $options);
  if (count($result) > 0) {
    $feature = $result[0];
  }

  if (strcmp($is_obsolete, 'f') == 0 or $is_obsolete == 0) {
    $is_obsolete = 'FALSE';
  }
  if (strcmp($is_obsolete, 't') == 0 or $is_obsolete == 1) {
    $is_obsolete = 'TRUE';
  }
  if (strcmp($is_analysis, 'f') == 0 or $is_analysis == 0) {
    $is_analysis = 'FALSE';
  }
  if (strcmp($is_analysis, 't') == 0 or $is_analysis == 1) {
    $is_analysis = 'TRUE';
  }

  // insert the feature if it does not exist otherwise perform an update
  if (!$feature) {
    $values = array(
      'organism_id' => $organism->organism_id,
      'name' => $name,
      'uniquename' => $uniquename,
      //       'residues' => $residues,
      //       'seqlen' => drupal_strlen($residues),
      'md5checksum' => md5($residues),
      'type_id' => $cvterm->cvterm_id,
      'is_analysis' => $is_analysis,
      'is_obsolete' => $is_obsolete,
    );
    $options = array('statement_name' => 'ins_feature_all');
    $result = tripal_core_chado_insert('feature', $values, $options);
    if (!$result) {
      watchdog("T_gff3_loader", "Failed to insert feature '$uniquename' ($cvterm->name)", array(), WATCHDOG_WARNING);
      return 0;
    }
  }
  elseif (!$add_only) {
    $values = array(
      'name' => $name,
      //      'residues' => $residues,
      //      'seqlen' => drupal_strlen($residues),
      'md5checksum' => md5($residues),
      'is_analysis' => $is_analysis,
      'is_obsolete' => $is_obsolete,
    );
    $match = array(
      'organism_id' => $organism->organism_id,
      'uniquename' => $uniquename,
      'type_id' => $cvterm->cvterm_id,
    );
    $options = array('statement_name' => 'upd_feature');
    $result = tripal_core_chado_update('feature', $match, $values, $options);
    if (!$result) {
      watchdog("T_gff3_loader", "Failed to update feature '$uniquename' ($cvterm->name)", array(), WATCHDOG_WARNING);
      return 0;
    }
  }
  else {
    // the feature exists and we don't want to update it so return
    // a value of 0.  This will stop all downstream property additions
    return 0;
  }

  // get the newly added feature
  $options = array('statement_name' => 'sel_feature_orunty');
  $columns = array('feature_id', 'name', 'uniquename', 'seqlen', 'organism_id', 'type_id');
  $result = tripal_core_chado_select('feature', $columns, $fselect, $options);
  $feature = $result[0];

  // add the analysisfeature entry to the analysisfeature table if it doesn't already exist
  $af_values = array(
    'analysis_id' => $analysis_id,
    'feature_id' => $feature->feature_id
  );
  $options = array('statement_name' => 'sel_analysisfeature_analysisid_featureid');
  $afeature = tripal_core_chado_select('analysisfeature', array('analysisfeature_id'), $af_values, $options);
  if (count($afeature) == 0) {
    // if a score is available then set that to be the significance field
    if (strcmp($score, '.') != 0) {
      $af_values['significance'] = $score;
      $options = array('statement_name' => 'ins_analysisfeature_analysisid_featureid_significance');
    }
    else {
      $options = array('statement_name' => 'ins_analysisfeature_analysisid_featureid');
    }
    if (!tripal_core_chado_insert('analysisfeature', $af_values, $options)) {
      watchdog("T_gff3_loader", "Could not add analysisfeature record: $analysis_id, $feature->feature_id", array(), WATCHDOG_WARNING);
    }
  }
  else {
    // if a score is available then set that to be the significance field
    $new_vals = array();
    if (strcmp($score, '.') != 0) {
      $new_vals['significance'] = $score;
    }
    else {
      $new_vals['significance'] = '__NULL__';
    }
    if (!$add_only) {
      $options = array('statement_name' => 'upd_analysisfeature');
      $ret = tripal_core_chado_update('analysisfeature', $af_values, $new_vals, $options);
      if (!$ret) {
        watchdog("T_gff3_loader", "Could not update analysisfeature record: $analysis_id, $feature->feature_id", array(), WATCHDOG_WARNING);
      }
    }
  }
  return $feature;
}