function tripal_feature_load_gff3_parents

2.x tripal_feature.gff_loader.inc tripal_feature_load_gff3_parents($feature, $cvterm, $parents, $organism_id, $strand, $phase, $fmin, $fmax)
1.x gff_loader.inc tripal_feature_load_gff3_parents($feature, $cvterm, $parents, $organism_id, $fmin)

Related topics

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

File

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

Code

function tripal_feature_load_gff3_parents($feature, $cvterm, $parents, $organism_id, $fmin) {

  $uname = $feature->uniquename;
  $type = $cvterm->name;
  $rel_type = 'part_of';

  // prepare these SQL statements that will be used repeatedly.
  if (!tripal_core_is_sql_prepared('sel_cvterm_cvname_cvtname_synonym')) {
    $psql = "PREPARE sel_cvterm_cvname_cvtname_synonym (text, text, text) AS
             SELECT CVT.cvterm_id
             FROM {cvterm} CVT
               INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
               LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
             WHERE cv.name = $1 and (CVT.name = $2 or CVTS.synonym = $3)";
    $status = tripal_core_chado_prepare('sel_cvterm_cvname_cvtname_synonym', $psql, array('text', 'text', 'text'));
    if (!$status) {
      watchdog("T_gff3_loader", "Cannot prepare statement 'sel_cvterm_cvname_cvtname_synonym' for ontology term", 
      array(), WATCHDOG_WARNING);
      return '';
    }
  }

  // iterate through the parents in the list
  foreach ($parents as $parent) {
    // get the parent cvterm
    $values = array(
      'organism_id' => $organism_id,
      'uniquename' => $parent,
    );
    $options = array('statement_name' => 'sel_tripalgfftemp_orun');
    $result = tripal_core_chado_select('tripal_gff_temp', array('type_name'), $values, $options);
    if (count($result) == 0) {
      watchdog("T_gff3_loader", "Cannot find parent: %parent", array('%parent' => $parent), WATCHDOG_WARNING);
      return '';
    }
    $parent_type = $result[0]->type_name;

    // try to find the parent
    $parentcvterm = db_fetch_object(chado_query("EXECUTE sel_cvterm_cvname_cvtname_synonym ('%s', '%s', '%s')", 'sequence', $parent_type, $parent_type));
    $relcvterm = db_fetch_object(chado_query("EXECUTE sel_cvterm_cvname_cvtname_synonym ('%s', '%s', '%s')", 'relationship', $rel_type, $rel_type));
    $values = array(
      'organism_id' => $organism_id,
      'uniquename' => $parent,
      'type_id' => $parentcvterm->cvterm_id,
    );
    $options = array('statement_name' => 'sel_feature_orunty');
    $result = tripal_core_chado_select('feature', array('feature_id'), $values, $options);
    $parent_feature = $result[0];

    // if the parent exists then add the relationship otherwise print error and skip
    if ($parent_feature) {

      // check to see if the relationship already exists
      $values = array(
        'object_id' => $parent_feature->feature_id,
        'subject_id' => $feature->feature_id,
        'type_id' => $relcvterm->cvterm_id,
      );
      $options = array('statement_name' => 'sel_featurerelationship_objectid_subjectid_typeid');
      $rel = tripal_core_chado_select('feature_relationship', array('*'), $values, $options);

      if (count($rel) > 0) {
      }
      else {
        // the relationship doesn't already exist, so add it.
        $values = array(
          'subject_id' => $feature->feature_id,
          'object_id' => $parent_feature->feature_id,
          'type_id' => $relcvterm->cvterm_id,
        );
        $options = array('statement_name' => 'ins_featurerelationship_subjectid_objectid_typeid');
        $result = tripal_core_chado_insert('feature_relationship', $values, $options);
        if (!$result) {
          watchdog("T_gff3_loader", "Failed to insert feature relationship '$uname' ($type) $rel_type '$parent' ($parent_type)", 
          array(), WATCHDOG_WARNING);
        }
      }
    }
    else {
      watchdog("T_gff3_loader", "Cannot establish relationship '$uname' ($type) $rel_type '$parent' ($parent_type): Cannot find the parent", 
      array(), WATCHDOG_WARNING);
    }
  }
}