Browse Source

Fixed featureloc field so 'values' array is exact

Stephen Ficklin 8 years ago
parent
commit
67e6a881c9

+ 1 - 0
tripal_chado/api/modules/tripal_chado.feature.api.inc

@@ -770,6 +770,7 @@ function tripal_get_feature_relationships($feature) {
   // get alignment as child. The $feature->featureloc element
   // is already populated from the alignment preprocess function
   $options = array(
+    'return_array' => 1,
     'include_fk' => array(
       'srcfeature_id' => 1,
       'feature_id' => 1,

+ 332 - 386
tripal_chado/includes/fields/chado_linker__featureloc.inc

@@ -1,430 +1,376 @@
 <?php
 
-/**
- * Implements hook_info() for fields.
- *
- * This is a hook provided by the tripal_chado module for offloading the
- * hook_field_info() hook for each field to specify.
- */
-function chado_linker__featureloc_info() {
-  return array(
-    'label' => t('Alignments'),
-    'description' => t('Locations on landmark sequences where the feature is aligned.'),
-    'default_widget' => 'chado_linker__featureloc_widget',
-    'default_formatter' => 'chado_linker__featureloc_formatter',
-    'settings' => array(),
-    'storage' => array(
-      'type' => 'field_chado_storage',
-      'module' => 'tripal_chado',
-      'active' => TRUE
-    ),
-  );
-}
-/**
- * Implements hook_attach_info().
- *
- * This is a hook provided by the tripal_Chado module. It allows the field
- * to specify which bundles it will attach to and to specify thee settings.
- *
- * @param $entity_type
- * @param $entity
- * @param $term
- *
- * @return
- *   A field array
- */
-function chado_linker__featureloc_attach_info($entity_type, $bundle, $target) {
-  $field_info = array();
-
-  $table_name = $target['data_table'];
-  $type_table = $target['type_table'];
-  $type_field = $target['field'];
-  $cv_id      = $target['cv_id'];
-  $cvterm_id  = $target['cvterm_id'];
+class chado_linker__featureloc extends TripalField {
 
-  // If  this is not the feature table then we don't want to attach.
-  if ($table_name != 'feature') {
-    return $field_info;
+  /**
+   * @see TripalField::field_info()
+   */
+  public function field_info() {
+    return array(
+      'label' => t('Aligned Locations'),
+      'description' => t('Locations on landmark sequences where the feature is aligned.'),
+      'default_widget' => 'chado_linker__featureloc_widget',
+      'default_formatter' => 'chado_linker__featureloc_formatter',
+      'settings' => array(),
+      'storage' => array(
+        'type' => 'field_chado_storage',
+        'module' => 'tripal_chado',
+        'active' => TRUE
+      ),
+    );
   }
 
-  $schema = chado_get_schema('featureloc');
-  $pkey = $schema['primary key'][0];
-
-  // Initialize the field array.
-  $field_info = array(
-    'field_name' => 'featureloc',
-    'field_type' => 'chado_linker__featureloc',
-    'widget_type' => 'chado_linker__featureloc_widget',
-    'widget_settings' => array('display_label' => 1),
-    'description' => '',
-    'label' => 'Alignments',
-    'is_required' => 0,
-    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
-    'storage' => 'field_chado_storage',
-    'field_settings' => array(
-      'chado_table' => 'featureloc',
-      'chado_column' => $pkey,
-      'base_table' => 'feature',
-      'semantic_web' => array(
-        'name' => '',
-        'accession' => '',
-        'ns' => '',
-        'nsurl' => '',
+  /**
+   * @see TripalField::attach_info()
+   */
+  public function attach_info($entity_type, $bundle, $target) {
+    $field_info = array();
+
+    $table_name = $target['data_table'];
+    $type_table = $target['type_table'];
+    $type_field = $target['field'];
+    $cv_id      = $target['cv_id'];
+    $cvterm_id  = $target['cvterm_id'];
+
+    // If  this is not the feature table then we don't want to attach.
+    if ($table_name != 'feature') {
+      return $field_info;
+    }
+
+    $schema = chado_get_schema('featureloc');
+    $pkey = $schema['primary key'][0];
+
+    // Initialize the field array.
+    $field_info = array(
+      'field_name' => 'featureloc',
+      'field_type' => 'chado_linker__featureloc',
+      'widget_type' => 'chado_linker__featureloc_widget',
+      'widget_settings' => array('display_label' => 1),
+      'description' => '',
+      'label' => 'Aligned Locations',
+      'is_required' => 0,
+      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+      'storage' => 'field_chado_storage',
+      'field_settings' => array(
+        'chado_table' => 'featureloc',
+        'chado_column' => $pkey,
+        'base_table' => 'feature',
+        'semantic_web' => array(
+          'name' => '',
+          'accession' => '',
+          'ns' => '',
+          'nsurl' => '',
+        ),
       ),
-    ),
-  );
-}
-/**
- * Implements hook_widget_info.
- *
- * This is a hook provided by the tripal_chado module for offloading
- * the hook_field_widget_info() hook for each field to specify.
- */
-function chado_linker__featureloc_widget_info() {
-  return array(
-    'label' => t('Alignment Settings'),
-    'field types' => array('chado_linker__featureloc')
-  );
-}
-/**
- * Implements hook_formatter_info.
- *
- * This is a hook provided by the tripal_chado module for
- * offloading the hook_field_formatter_info() for each field
- * to specify.
- *
- */
-function chado_linker__featureloc_formatter_info() {
-  return array(
-    'label' => t('Alignments'),
-    'field types' => array('chado_linker__featureloc'),
-    'settings' => array(
-    ),
-  );
-}
+    );
 
-/**
- * Implements hook_formatter_settings_summary.
- *
- * This is a hook provided by the tripal_chado module for
- * offloading the hook_field_formatter_settings_summary() for each field
- * to specify.
- *
- */
-function chado_linker__featureloc_formatter_settings_summary($field, $instance,
-    $view_mode) {
+    return $field_info;
+  }
 
-}
+  /**
+   * @see TripalField::widget_info()
+   */
+  public function widget_info() {
+    return array(
+      'label' => t('Aligned Locations'),
+      'field types' => array('chado_linker__featureloc')
+    );
+  }
 
-/**
- * Provides a settings form for the formatter.
- *
- * This is a hook provided by the tripal_chado module for
- * offloading the hook_field_formatter_settings_form() for each field
- * to specify.
- */
-function chado_linker__featureloc_formatter_settings_form($field, $instance,
-    $view_mode, $form, &$form_state) {
+  /**
+   * @see TripalField::formatter_info()
+   */
+  public function formatter_info() {
+    return array(
+      'label' => t('Aligned Locations'),
+      'field types' => array('chado_linker__featureloc'),
+      'settings' => array(
+      ),
+    );
+  }
 
+  /**
+   * @see TripalField::formatter_settings_summary()
+   */
+  public function formatter_settings_summary($field, $instance,
+      $view_mode) {
 
+  }
 
-}
+  /**
+   * @see TripalField::formatter_settings_form()
+   */
+  public function formatter_settings_form($field, $instance,
+      $view_mode, $form, &$form_state) {
 
-/**
- * Validation function for the chado_linker_featureloc_formatter_settings_form.
- */
-function chado_linker__featureloc_formatter_settings_form_validate(&$form, &$form_state) {
 
-  // Place here as an example for validating the settings form.
-}
 
-/**
- *
- */
-function chado_linker__featureloc_formatter(&$element, $entity_type, $entity,
-    $field, $instance, $langcode, $items, $display) {
-
-  // Get the settings
-  $settings = $display['settings'];
-
-  foreach ($items as $delta => $item) {
-    $alignments = $item['featurelocs'];
-    if (count($alignments) > 0){
-
-      // the $headers array is an array of fields to use as the colum headers.
-      // additional documentation can be found here
-      // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-      $headers = array('Aligned Feature' ,'Feature Type', 'Alignment Location');
-
-      // the $rows array contains an array of rows where each row is an array
-      // of values for each column of the table in that row.  Additional documentation
-      // can be found here:
-      // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-      $rows = array();
-
-      foreach ($alignments as $alignment){
-        $feature_name = $alignment->name;
-        if (property_exists($alignment, 'nid')) {
-          $feature_name = l($feature_name, "node/" . $alignment->nid);
-        }
-        $feature_loc = '';
-        $strand = '.';
-        if ($alignment->strand == -1) {
-          $strand = '-';
-        }
-        elseif ($alignment->strand == 1) {
-           $strand = '+';
-        }
-        // if this is a match then make the other location
-        if(property_exists($alignment, 'right_feature')){
-          $rstrand = '.';
-          if ($alignment->right_strand == -1) {
-            $rstrand = '-';
-          }
-          elseif ($alignment->right_strand == 1) {
-            $rstrand = '+';
-          }
-          $feature_loc = $feature->name .":". ($alignment->fmin + 1) . ".." . $alignment->fmax . " " . $strand;
-          $feature_loc .= "<br>" . $alignment->name .":". ($alignment->right_fmin + 1) . ".." . $alignment->right_fmax . " " . $rstrand;
+  }
+
+  /**
+   * @see TripalField::formatter_view()
+   */
+  function formatter_view(&$element, $entity_type, $entity,
+      $field, $instance, $langcode, $items, $display) {
+
+    // Get the settings
+    $settings = $display['settings'];
+
+    $rows = array();
+    $headers = array('Aligned Feature' ,'Feature Type', 'Alignment Location');
+
+    foreach ($items as $delta => $item) {
+      $alignment = $item['value'];
+      $feature_name = $alignment['name'];
+      $feature_loc = '';
+      $strand = '.';
+      if ($alignment['strand'] == -1) {
+        $strand = '-';
+      }
+      elseif ($alignment['strand'] == 1) {
+         $strand = '+';
+      }
+      // if this is a match then make the other location
+      if(array_key_exists($alignment, 'right_feature')){
+        $rstrand = '.';
+        if ($alignment['right_strand'] == -1) {
+          $rstrand = '-';
         }
-        else {
-          $feature_loc = $alignment->name .":". ($alignment->fmin + 1) . ".." . $alignment->fmax . " " . $strand;
+        elseif ($alignment['right_strand'] == 1) {
+          $rstrand = '+';
         }
-
-        $rows[] = array(
-          $feature_name,
-          $alignment->type,
-          $feature_loc
-        );
+        $feature_loc = $feature['name'] .":". ($alignment['fmin'] + 1) . ".." . $alignment['fmax'] . " " . $strand;
+        $feature_loc .= "<br>" . $alignment['name'] .":". ($alignment['right_fmin'] + 1) . ".." . $alignment['right_fmax'] . " " . $rstrand;
+      }
+      else {
+        $feature_loc = $alignment['name'] .":". ($alignment['fmin'] + 1) . ".." . $alignment['fmax'] . " " . $strand;
       }
 
-      // the $table array contains the headers and rows array as well as other
-      // options for controlling the display of the table.  Additional
-      // documentation can be found here:
-      // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
-      $table = array(
-        'header' => $headers,
-        'rows' => $rows,
-        'attributes' => array(
-          'id' => 'tripal_feature-table-alignments',
-          'class' => 'tripal-data-table'
-        ),
-        'sticky' => FALSE,
-        'caption' => '',
-        'colgroups' => array(),
-        'empty' => '',
-      );
-
-      // once we have our table array structure defined, we call Drupal's theme_table()
-      // function to generate the table.
-      $element[$delta] = array(
-        '#type' => 'markup',
-        '#markup' => theme_table($table),
+      $rows[] = array(
+        $feature_name,
+        $alignment['type'],
+        $feature_loc
       );
     }
-  }
-}
 
-/**
- * Loads the field values with appropriate data.
- *
- * This function is called by the tripal_chado_field_storage_load() for
- * each property managed by the field_chado_storage storage type.  This is
- * an optional hook function that is only needed if the field has
- * multiple form elements.
- */
-function chado_linker__featureloc_load($field, $entity, $base_table, $record) {
-  $field_name = $field['field_name'];
-
-  $options = array(
-    'return_array' => 1,
-    'include_fk' => array(
-      'srcfeature_id' => array(
-        'type_id' => 1,
-      ),
-      'feature_id' => array(
-        'type_id' => 1
+
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_feature-table-alignments',
+        'class' => 'tripal-data-table'
       ),
-    )
-  );
-  $feature = chado_expand_var($record, 'table', 'featureloc', $options);
-
-  // get alignments as child
-  $cfeaturelocs = $feature->featureloc->feature_id;
-  if (!$cfeaturelocs) {
-    $cfeaturelocs = array();
-  }
-  // get alignment as parent
-  $pfeaturelocs = $feature->featureloc->srcfeature_id;
-  if (!$pfeaturelocs) {
-    $pfeaturelocs = array();
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    $element[$delta] = array(
+      '#type' => 'markup',
+      '#markup' => theme_table($table),
+    );
   }
 
-  // get matched alignments (those with an itermediate 'match' or 'EST_match', etc
-  $mfeaturelocs = chado_linker__featureloc_get_matched_alignments($feature);
-  $feature->matched_featurelocs = $mfeaturelocs;
-
-  // combine all three alignments into a single array for printing together in
-  // a single list
-  $alignments = array();
-  foreach ($pfeaturelocs as $featureloc) {
-    // if type is a 'match' then ignore it. We will handle those below
-    if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
-      continue;
+  /**
+   * @see TripalField::load()
+   */
+  function load($field, $entity, $details) {
+    $record = $details['record'];
+    $settings = $field['settings'];
+
+    $field_name = $field['field_name'];
+    $field_type = $field['type'];
+
+    $options = array(
+      'return_array' => TRUE,
+      'include_fk' => array(
+        'srcfeature_id' => array(
+          'type_id' => 1,
+        ),
+        'feature_id' => array(
+          'type_id' => 1
+        ),
+      )
+    );
+    $feature = chado_expand_var($record, 'table', 'featureloc', $options);
+
+    // Get alignments as child
+    $cfeaturelocs = $feature->featureloc->feature_id;
+    if (!$cfeaturelocs) {
+      $cfeaturelocs = array();
     }
-    $alignment = new stdClass();
-    $alignment->record = $featureloc;
-    $alignment->name = $featureloc->feature_id->name;
-    $alignment->type = $featureloc->feature_id->type_id->name;
-    $alignment->fmin = $featureloc->fmin;
-    $alignment->fmax = $featureloc->fmax;
-    $alignment->phase = $featureloc->phase;
-    $alignment->strand = $featureloc->strand;
-    $alignments[] = $alignment;
-    if (property_exists($featureloc->feature_id, 'nid')) {
-      $alignment->nid = $featureloc->feature_id->nid;
+    // Get alignment as parent
+    $pfeaturelocs = $feature->featureloc->srcfeature_id;
+    if (!$pfeaturelocs) {
+      $pfeaturelocs = array();
     }
-  }
-  foreach ($cfeaturelocs as $featureloc) {
-    // if type is a 'match' then ignore it. We will handle those below
-    if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
-      continue;
+
+    // Get matched alignments (those with an itermediate 'match' or 'EST_match', etc
+    $mfeaturelocs = $this->get_matched_alignments($feature);
+    $feature->matched_featurelocs = $mfeaturelocs;
+
+    // Combine all three alignments into a single array for printing together in
+    // a single list
+    $alignments = array();
+    foreach ($pfeaturelocs as $featureloc) {
+      // if type is a 'match' then ignore it. We will handle those below
+      if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
+        continue;
+      }
+      $alignments[] = array(
+        'name' => $featureloc->feature_id->name,
+        'type' => $featureloc->feature_id->type_id->name,
+        'fmin' => $featureloc->fmin,
+        'fmax' => $featureloc->fmax,
+        'phase' => $featureloc->phase,
+        'strand' => $featureloc->strand,
+      );
     }
-    $alignment = new stdClass();
-    $alignment->record = $featureloc;
-    $alignment->name = $featureloc->srcfeature_id->name;
-    $alignment->type = $featureloc->srcfeature_id->type_id->name;
-    $alignment->fmin = $featureloc->fmin;
-    $alignment->is_fmin_partial = $featureloc->is_fmin_partial;
-    $alignment->fmax = $featureloc->fmax;
-    $alignment->is_fmax_partial = $featureloc->is_fmax_partial;
-    $alignment->phase = $featureloc->phase;
-    $alignment->strand = $featureloc->strand;
-    $alignments[] = $alignment;
-    if (property_exists($featureloc->srcfeature_id, 'nid')) {
-      $alignment->nid = $featureloc->srcfeature_id->nid;
+    foreach ($cfeaturelocs as $featureloc) {
+      // if type is a 'match' then ignore it. We will handle those below
+      if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
+        continue;
+      }
+      $alignments[] = array(
+        'name' => $featureloc->srcfeature_id->name,
+        'type' => $featureloc->srcfeature_id->type_id->name,
+        'fmin' => $featureloc->fmin,
+        'is_fmin_partial' => $featureloc->is_fmin_partial,
+        'fmax' => $featureloc->fmax,
+        'is_fmax_partial' => $featureloc->is_fmax_partial,
+        'phase' => $featureloc->phase,
+        'strand' => $featureloc->strand,
+      );
     }
-  }
-  // in matching features, the left feature is always the feature
-  // provided to this function.
-  foreach ($mfeaturelocs as $featureloc) {
-    // get more information about the right feature
-    $select = array('feature_id' => $featureloc->right_srcfeature_id);
-    $rfeature = chado_generate_var('feature', $select);
-    // now add to the list
-    $alignment = new stdClass();
-    $alignment->record = $featureloc;
-    $alignment->right_feature = $rfeature;
-    $alignment->name = $rfeature->name;
-    $alignment->type = $rfeature->type_id->name;
-    $alignment->fmin = $featureloc->left_fmin;
-    $alignment->is_fmin_partial = $featureloc->left_is_fmin_partial;
-    $alignment->fmax = $featureloc->left_fmax;
-    $alignment->is_fmax_partial = $featureloc->left_is_fmax_partial;
-    $alignment->phase = $featureloc->left_phase;
-    $alignment->strand = $featureloc->left_strand;
-    $alignment->right_fmin = $featureloc->right_fmin;
-    $alignment->right_is_fmin_partial = $featureloc->right_is_fmin_partial;
-    $alignment->right_fmax = $featureloc->right_fmax;
-    $alignment->right_is_fmax_partial = $featureloc->right_is_fmax_partial;
-    $alignment->right_phase = $featureloc->right_phase;
-    $alignment->right_strand = $featureloc->right_strand;
-    $alignments[] = $alignment;
-    if (property_exists($rfeature, 'nid')) {
-      $alignment->nid = $rfeature->nid;
+    // in matching features, the left feature is always the feature
+    // provided to this function.
+    foreach ($mfeaturelocs as $featureloc) {
+      // get more information about the right feature
+      $select = array('feature_id' => $featureloc->right_srcfeature_id);
+      $rfeature = chado_generate_var('feature', $select);
+      // now add to the list
+      $alignments[] = array(
+        'name' => $rfeature->name,
+        'type' => $rfeature->type_id->name,
+        'fmin' => $featureloc->left_fmin,
+        'is_fmin_partial' => $featureloc->left_is_fmin_partial,
+        'fmax' => $featureloc->left_fmax,
+        'is_fmax_partial' => $featureloc->left_is_fmax_partial,
+        'phase' => $featureloc->left_phase,
+        'strand' => $featureloc->left_strand,
+        'right_fmin' => $featureloc->right_fmin,
+        'right_is_fmin_partial' => $featureloc->right_is_fmin_partial,
+        'right_fmax' => $featureloc->right_fmax,
+        'right_is_fmax_partial' => $featureloc->right_is_fmax_partial,
+        'right_phase' => $featureloc->right_phase,
+        'right_strand' => $featureloc->right_strand,
+      );
+    }
+    $i = 0;
+    foreach ($alignments as $alignment) {
+      $entity->{$field_name}['und'][$i]['value'] = $alignment;
+      $i++;
     }
   }
-  $entity->{$field_name}['und'][0]['featurelocs'] = $alignments;
-}
-/**
- * This function is for features that align through an intermediate such
- * as 'EST_match' or 'match'.  This occurs in the case where two sequences
- * align but where one does not align perfectly.  Some ESTs may be in a contig
- * but not all of the EST.  Portions may overhang and not be included in the
- * consensus if quality is bad.
- * For example:
- *    Feature 1: Contig --------------------
- *    Feature 2: EST_match           -------
- *    Feature 3: EST                 ---------
- *
- * The feature provided to the function will always be the feature 1.  The
- * featureloc columns prefixed with 'right' (e.g. right_fmin) belong to the
- * alignment of feature 3 with feature 2
- *
- * Features may align to more than one feature and are not matches. We do
-   * not want to include these, so we have to filter on the SO terms:
-   * match, or %_match
+  /**
+   * This function is for features that align through an intermediate such
+   * as 'EST_match' or 'match'.  This occurs in the case where two sequences
+   * align but where one does not align perfectly.  Some ESTs may be in a contig
+   * but not all of the EST.  Portions may overhang and not be included in the
+   * consensus if quality is bad.
+   * For example:
+   *    Feature 1: Contig --------------------
+   *    Feature 2: EST_match           -------
+   *    Feature 3: EST                 ---------
    *
-   * @ingroup tripal_feature
-   */
- function chado_linker__featureloc_get_matched_alignments($feature) {
-
-   $sql = "
-     SELECT
-       FL1.featureloc_id    as left_featureloc_id,
-       FL1.srcfeature_id    as left_srcfeature_id,
-       FL1.feature_id       as left_feature_id,
-       FL1.fmin             as left_fmin,
-       FL1.is_fmin_partial  as left_is_fmin_partial,
-       FL1.fmax             as left_fmax,
-       FL1.is_fmax_partial  as left_is_fmax_partial,
-       FL1.strand           as left_strand,
-       FL1.phase            as left_phase,
-       FL1.locgroup         as left_locgroup,
-       FL1.rank             as left_rank,
-       FL2.featureloc_id    as right_featureloc_id,
-       FL2.srcfeature_id    as right_srcfeature_id,
-       FL2.feature_id       as right_feature_id,
-       FL2.fmin             as right_fmin,
-       FL2.is_fmin_partial  as right_is_fmin_partial,
-       FL2.fmax             as right_fmax,
-       FL2.is_fmax_partial  as right_is_fmax_partial,
-       FL2.strand           as right_strand,
-       FL2.phase            as right_phase,
-       FL2.locgroup         as right_locgroup,
-       FL2.rank             as right_rank
-     FROM {feature} F1
-       INNER JOIN {featureloc} FL1 on FL1.srcfeature_id = F1.feature_id
-       INNER JOIN {feature} F2 on FL1.feature_id = F2.feature_id
-       INNER JOIN {featureloc} FL2 on FL2.feature_id = F2.feature_id
-       INNER JOIN {cvterm} CVT2 on F2.type_id = CVT2.cvterm_id
-     WHERE
-       F1.feature_id = :feature_id  AND
-       (CVT2.name = 'match' or CVT2.name like '%_match')
-     ORDER BY FL1.fmin
-   ";
-
-   $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
-
-   // iterate through the results and add them to our featurelocs array
-   $featurelocs = array();
-   while ($fl = $results->fetchObject()) {
-     // ignore featurelocs where the left and right srcfeature is the same
-     if (strcmp($fl->left_srcfeature_id, $fl->right_srcfeature_id) == 0) {
-       continue;
+   * The feature provided to the function will always be the feature 1.  The
+   * featureloc columns prefixed with 'right' (e.g. right_fmin) belong to the
+   * alignment of feature 3 with feature 2
+   *
+   * Features may align to more than one feature and are not matches. We do
+     * not want to include these, so we have to filter on the SO terms:
+     * match, or %_match
+     *
+     * @ingroup tripal_feature
+     */
+   private  function get_matched_alignments($feature) {
+
+     $sql = "
+       SELECT
+         FL1.featureloc_id    as left_featureloc_id,
+         FL1.srcfeature_id    as left_srcfeature_id,
+         FL1.feature_id       as left_feature_id,
+         FL1.fmin             as left_fmin,
+         FL1.is_fmin_partial  as left_is_fmin_partial,
+         FL1.fmax             as left_fmax,
+         FL1.is_fmax_partial  as left_is_fmax_partial,
+         FL1.strand           as left_strand,
+         FL1.phase            as left_phase,
+         FL1.locgroup         as left_locgroup,
+         FL1.rank             as left_rank,
+         FL2.featureloc_id    as right_featureloc_id,
+         FL2.srcfeature_id    as right_srcfeature_id,
+         FL2.feature_id       as right_feature_id,
+         FL2.fmin             as right_fmin,
+         FL2.is_fmin_partial  as right_is_fmin_partial,
+         FL2.fmax             as right_fmax,
+         FL2.is_fmax_partial  as right_is_fmax_partial,
+         FL2.strand           as right_strand,
+         FL2.phase            as right_phase,
+         FL2.locgroup         as right_locgroup,
+         FL2.rank             as right_rank
+       FROM {feature} F1
+         INNER JOIN {featureloc} FL1 on FL1.srcfeature_id = F1.feature_id
+         INNER JOIN {feature} F2 on FL1.feature_id = F2.feature_id
+         INNER JOIN {featureloc} FL2 on FL2.feature_id = F2.feature_id
+         INNER JOIN {cvterm} CVT2 on F2.type_id = CVT2.cvterm_id
+       WHERE
+         F1.feature_id = :feature_id  AND
+         (CVT2.name = 'match' or CVT2.name like '%_match')
+       ORDER BY FL1.fmin
+     ";
+
+     $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
+
+     // iterate through the results and add them to our featurelocs array
+     $featurelocs = array();
+     while ($fl = $results->fetchObject()) {
+       // ignore featurelocs where the left and right srcfeature is the same
+       if (strcmp($fl->left_srcfeature_id, $fl->right_srcfeature_id) == 0) {
+         continue;
+       }
+       $featurelocs[] = $fl ;
      }
-     $featurelocs[] = $fl ;
+     return $featurelocs;
    }
-   return $featurelocs;
- }
 
-/**
- * Implements hook_ws_formatter().
- */
-function chado_linker__featureloc_ws_formatter(&$element, $entity_type, $entity,
-    $field, $instance, $items) {
+  /**
+   * @see TripalField::widget_form()
+   */
+  function widget_form(&$widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element) {
 
-}
+  }
 
+}
 /**
- *  Implements hook_widget().
+ * Callback function for validating the chado_linker_featureloc_widget.
  */
-function chado_linker__featureloc_widget(&$widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element) {
+function chado_linker__featureloc_widget_validate($element, &$form_state) {
 
 }
 /**
- * Callback function for validating the chado_linker_featureloc_widget.
+ * Validation function for the chado_linker_featureloc_formatter_settings_form.
  */
-function chado_linker__featureloc_widget_validate($element, &$form_state) {
+function chado_linker__featureloc_formatter_settings_form_validate(&$form, &$form_state) {
+
+  // Place here as an example for validating the settings form.
+}
 
-}

+ 2 - 2
tripal_chado/includes/fields/chado_linker__relationship.inc

@@ -57,8 +57,8 @@ function chado_linker__relationship_attach_info($entity_type, $bundle, $target)
     'field_type' => 'chado_linker__relationship',
     'widget_type' => 'chado_linker__relationship_widget',
     'widget_settings' => array('display_label' => 1),
-    'description' => '',
-    'label' => 'Relationsihps',
+    'description' => 'A generic field for displaying relationships between data types',
+    'label' => 'Relationships',
     'is_required' => 0,
     'cardinality' => FIELD_CARDINALITY_UNLIMITED,
     'storage' => 'field_chado_storage',

+ 0 - 1
tripal_chado/includes/tripal_chado.fields.inc

@@ -104,7 +104,6 @@ function tripal_chado_field_formatter_info() {
  * Implements hook_field_settings_form()
  */
 function tripal_chado_field_settings_form($field, $instance, $has_data) {
-  dpm($field);
   $form = '';
   $field_type = $field['type'];
   module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);