function tripal_feature_load_featurelocs

2.x tripal_feature.theme.inc tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1)
3.x tripal_feature.theme.inc tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1)
1.x tripal_feature.module tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1)

Related topics

1 call to tripal_feature_load_featurelocs()

File

tripal_feature/tripal_feature.module, line 1076
@todo Add file header description

Code

function tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1) {

  $sql = "SELECT
           F.name, F.feature_id, F.uniquename,
           FS.name as src_name,
           FS.feature_id as src_feature_id,
           FS.uniquename as src_uniquename,
           CVT.name as cvname, CVT.cvterm_id,
           CVTS.name as src_cvname, CVTS.cvterm_id as src_cvterm_id,
           FL.fmin, FL.fmax, FL.is_fmin_partial, FL.is_fmax_partial,FL.strand,
           FL.phase
         FROM {featureloc} FL
            INNER JOIN {feature} F on FL.feature_id = F.feature_id
            INNER JOIN {feature} FS on FS.feature_id = FL.srcfeature_id
            INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id
            INNER JOIN {cvterm} CVTS on FS.type_id = CVTS.cvterm_id
         ";
  if (strcmp($side, 'as_parent') == 0) {
    $sql .= "WHERE FL.srcfeature_id = %d ";
  }
  if (strcmp($side, 'as_child') == 0) {
    $sql .= "WHERE FL.feature_id = %d ";
  }

  $flresults = chado_query($sql, $feature_id);

  // copy the results into an array
  $i = 0;
  $featurelocs = array();
  while ($loc = db_fetch_object($flresults)) {
    // if a drupal node exists for this feature then add the nid to the
    // results object
    $sql = 'SELECT nid FROM {chado_feature} WHERE feature_id = %d';

    $ffeature = db_fetch_object(db_query($sql, $loc->feature_id));
    $sfeature = db_fetch_object(db_query($sql, $loc->src_feature_id));
    $loc->fnid = $ffeature->nid;
    $loc->snid = $sfeature->nid;
    // add the result to the array
    $featurelocs[$i++] = $loc;
  }

  // Add the relationship feature locs if aggregate is turned on
  if ($aggregate and strcmp($side, 'as_parent') == 0) {
    // get the relationships for this feature without substituting any children
    // for the parent. We want all relationships
    $relationships = tripal_feature_get_aggregate_relationships($feature_id, 0);
    foreach ($relationships as $rindex => $rel) {
      // get the featurelocs for each of the relationship features
      $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
      foreach ($rel_featurelocs as $findex => $rfloc) {
        $featurelocs[$i++] = $rfloc;
      }
    }
  }

  usort($featurelocs, 'tripal_feature_sort_locations');
  return $featurelocs;
}