function tripal_feature_load_gff3_featureloc

2.x tripal_feature.gff_loader.inc tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fmin, $fmax, $strand, $phase, $is_fmin_partial, $is_fmax_partial, $residue_info, $locgroup, $landmark_type_id = '', $landmark_organism_id = '', $create_landmark = 0, $landmark_is_target = 0)
1.x gff_loader.inc tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fmin, $fmax, $strand, $phase, $is_fmin_partial, $is_fmax_partial, $residue_info, $locgroup, $landmark_type_id = '', $landmark_organism_id = '', $create_landmark = 0, $landmark_is_target = 0)

Insert the location of the feature

Parameters

$feature:

$organism:

$landmark:

$fmin:

$fmax:

$strand:

$phase:

$is_fmin_partial:

$is_fmax_partial:

$residue_info:

$locgroup: _type_id _organism_id

$create_landmark: _is_target

Related topics

2 calls to tripal_feature_load_gff3_featureloc()
tripal_feature_load_gff3 in tripal_feature/includes/tripal_feature.gff_loader.inc
Actually load a GFF3 file. This is the function called by tripal jobs
tripal_feature_load_gff3_target in tripal_feature/includes/tripal_feature.gff_loader.inc
Load the target attribute of a gff3 record

File

tripal_feature/includes/tripal_feature.gff_loader.inc, line 1831
Provides gff3 loading functionality. Creates features based on their specification in a GFF3 file.

Code

function tripal_feature_load_gff3_featureloc($feature, $organism, $landmark, $fmin, 
$fmax, $strand, $phase, $is_fmin_partial, $is_fmax_partial, $residue_info, $locgroup, 
$landmark_type_id = '', $landmark_organism_id = '', $create_landmark = 0, 
$landmark_is_target = 0) {

  $select = array(
    'organism_id' => $landmark_organism_id ? $landmark_organism_id : $organism->organism_id,
    'uniquename' => $landmark,
  );
  if ($landmark_type_id) {
    $select['type_id'] = $landmark_type_id;
  }
  $results = chado_select_record('feature', array('feature_id'), $select);

  $srcfeature = '';
  if (count($results) == 0) {
    // so we couldn't find the landmark using the uniquename. Let's try the 'name'.
    // if we return only a single result then we can proceed. Otherwise give an
    $select = array(
      'organism_id' => $landmark_organism_id ? $landmark_organism_id : $organism->organism_id,
      'name' => $landmark,
    );
    if ($landmark_type_id) {
      $select['type_id'] = $landmark_type_id;
    }
    $results = chado_select_record('feature', array('feature_id'), $select);
    if (count($results) == 0) {
      // if the landmark is the target feature in a matched alignment then try one more time to
      // find it by querying any feature with the same uniquename. If we find one then use it.
      if ($landmark_is_target) {
        $select = array('uniquename' => $landmark);
        $results = chado_select_record('feature', array('feature_id'), $select);
        if (count($results) == 1) {
          $srcfeature = $results[0];
        }
      }

      if (!$srcfeature) {
        // we couldn't find the landmark feature, so if the user has requested we create it then do so
        // but only if we have a type id
        if ($create_landmark and $landmark_type_id) {
          $values = array(
            'organism_id' => $landmark_organism_id ? $landmark_organism_id : $organism->organism_id,
            'name' => $landmark,
            'uniquename' => $landmark,
            'type_id' => $landmark_type_id
          );
          $results = chado_insert_record('feature', $values);
          if (!$results) {
            tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot find landmark feature: '%landmark', nor could it be inserted", 
            array('%landmark' => $landmark));
            return 0;
          }
          $srcfeature = new stdClass();
          $srcfeature->feature_id = $results['feature_id'];
        }
        else {
          tripal_report_error("tripal_feature", TRIPAL_WARNING, "Cannot find unique landmark feature: '%landmark'.", 
          array('%landmark' => $landmark));
          return 0;
        }
      }
    }
    elseif (count($results) > 1) {
      tripal_report_error("tripal_feature", TRIPAL_WARNING, "multiple landmarks exist with the name: '%landmark'.  Cannot
         resolve which one to use. Cannot add the feature location record", 
      array('%landmark' => $landmark));
      return 0;
    }
    else {
      $srcfeature = $results[0];
    }
  }
  elseif (count($results) > 1) {
    tripal_report_error("tripal_feature", TRIPAL_WARNING, "multiple landmarks exist with the name: '%landmark'.  Cannot
      resolve which one to use. Cannot add the feature location record", 
    array('%landmark' => $landmark));
    return 0;
  }
  else {
    $srcfeature = $results[0];
  }

  // TODO: create an attribute that recognizes the residue_info,locgroup,
  //  is_fmin_partial and is_fmax_partial, right now these are
  //  hardcoded to be false and 0 below.

  // check to see if this featureloc already exists, but also keep track of the
  // last rank value
  $rank = 0;
  $exists = 0;
  $select = array('feature_id' => $feature->feature_id);
  $options = array(
    'order_by' => array(
      'rank' => 'ASC'
    ),
  );

  $locrecs = chado_select_record('featureloc', array('*'), $select, $options);

  foreach ($locrecs as $featureloc) {
    // it is possible for the featureloc->srcfeature_id to be NULL. This can happen if the srcfeature
    // is not known (according to chado table field descriptions).  If it's null then just skip this entry
    if (!$featureloc->srcfeature_id) {
      continue;
    }
    $select = array('feature_id' => $featureloc->srcfeature_id);
    $columns = array('feature_id', 'name');
    $locsfeature = chado_select_record('feature', $columns, $select);

    // the source feature name and at least the fmin and fmax must be the same
    // for an update of the featureloc, otherwise we'll insert a new record.
    if (strcmp($locsfeature[0]->name, $landmark) == 0 and 
      ($featureloc->fmin == $fmin or $featureloc->fmax == $fmax)) {
      $match = array('featureloc_id' => $featureloc->featureloc_id);
      $values = array();
      $exists = 1;
      if ($featureloc->fmin != $fmin) {
        $values['fmin'] = $fmin;
      }
      if ($featureloc->fmax != $fmax) {
        $values['fmax'] = $fmax;
      }
      if ($featureloc->strand != $strand) {
        $values['strand'] = $strand;
      }
      if (count($values) > 0) {
        chado_update_record('featureloc', $match, $values);
      }
    }
    $rank = $featureloc->rank + 1;
  }
  if (!$exists) {

    // this feature location is new so add it
    if (strcmp($is_fmin_partial, 'f') == 0 or !$is_fmin_partial) {
      $is_fmin_partial = 'FALSE';
    }
    elseif (strcmp($is_fmin_partial, 't') == 0 or $is_fmin_partial = 1) {
      $is_fmin_partial = 'TRUE';
    }
    if (strcmp($is_fmax_partial, 'f') == 0 or !$is_fmax_partial) {
      $is_fmax_partial = 'FALSE';
    }
    elseif (strcmp($is_fmax_partial, 't') == 0 or $is_fmax_partial = 1) {
      $is_fmax_partial = 'TRUE';
    }
    $values = array(
      'feature_id' => $feature->feature_id,
      'srcfeature_id' => $srcfeature->feature_id,
      'fmin' => $fmin,
      'is_fmin_partial' => $is_fmin_partial,
      'fmax' => $fmax,
      'is_fmax_partial' => $is_fmax_partial,
      'strand' => $strand,
      'residue_info' => $residue_info,
      'locgroup' => $locgroup,
      'rank' => $rank
    );
    if ($phase) {
      $values['phase'] = $phase;
    }
    $success = chado_insert_record('featureloc', $values);
    if (!$success) {
      tripal_report_error("tripal_feature", TRIPAL_WARNING, "Failed to insert featureloc", array());
      exit;
      return 0;
    }
  }
  return 1;
}