Parcourir la source

Fixing bugs with fields. Fixed major bug with field filtering

Stephen Ficklin il y a 7 ans
Parent
commit
31ab1431e3

+ 3 - 2
tripal/includes/TripalFields/TripalField.inc

@@ -343,7 +343,7 @@ class TripalField {
     if (array_key_exists('searchable', $field_details) and $field_details['searchable']) {
       $filter_handler = 'tripal_views_handler_filter_string';
       if (array_key_exists('type', $field_details) and $field_details['type'] == 'numeric') {
-        $filter_handler = 'tripal_views_handler_filter';
+        $filter_handler = 'tripal_views_handler_filter_numeric';
       }
       $data[$view_base_id][$field_name]['filter'] = array(
         'handler' => $filter_handler,
@@ -357,6 +357,7 @@ class TripalField {
         $this->_addViewsDataElement($data, $view_base_id, $field_name, $element_name, $element_details);
       }
     }
+
     return $data;
   }
 
@@ -406,7 +407,7 @@ class TripalField {
     if (array_key_exists('searchable', $element_details) and $element_details['searchable']) {
       $filter_handler = 'tripal_views_handler_filter_element_string';
       if (array_key_exists('type', $element_details) and $element_details['type'] == 'numeric') {
-        $filter_handler = 'tripal_views_handler_filter';
+        $filter_handler = 'tripal_views_handler_filter_numeric';
       }
       $data[$view_base_id][$field_name]['filter'] = array(
         'handler' => $filter_handler,

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

@@ -108,6 +108,7 @@ function tripal_field_views_data($field) {
       $data += $tfield->viewsData($view_base_id);
     }
   }
+
   return $data;
 }
 

+ 1 - 0
tripal/tripal.info

@@ -19,6 +19,7 @@ files[] = views_handlers/tripal_views_handler_field_image.inc
 files[] = views_handlers/tripal_views_handler_field_boolean.inc
 files[] = views_handlers/tripal_views_handler_filter.inc
 files[] = views_handlers/tripal_views_handler_filter_string.inc
+files[] = views_handlers/tripal_views_handler_filter_numeric.inc
 files[] = views_handlers/tripal_views_handler_filter_element_string.inc
 files[] = views_handlers/tripal_views_handler_filter_boolean_operator.inc
 files[] = views_handlers/tripal_views_handler_filter_entity_string.inc

+ 34 - 63
tripal/tripal_views_query.inc

@@ -2,35 +2,6 @@
 
 class tripal_views_query extends views_plugin_query {
 
-  /**
-   * The EntityFieldQuery object used to perform the query
-   */
-  var $query;
-
-  /**
-   * The EntityFieldQuery object used to perform the count query.
-   * It will not include the order by and only fields that are used in
-   * filters.
-   */
-  var $cquery;
-
-  /**
-   * The fields that are to be included in the query.
-   */
-  var $fields;
-
-  /**
-   * The filters that are to be included in the query.
-   */
-  var $filters;
-
-  /**
-   * The sort item that are to be included in the query.
-   */
-  var $order;
-
-
-
   /**
    * Ensure a table exists in the queue.
    *
@@ -116,15 +87,16 @@ class tripal_views_query extends views_plugin_query {
    *   here.
    */
   public function add_where($group, $field_name, $value = NULL, $operator = NULL) {
-    $this->filters[] = array(
-      'group' => $group,
-      'field_name' => $field_name,
-      'value' => $value,
-      'op' => $operator
-    );
 
     if ($value) {
 
+      $this->filters[] = array(
+        'group' => $group,
+        'field_name' => $field_name,
+        'value' => $value,
+        'op' => $operator
+      );
+
       // Handle the bundle properties separate from real fields.
       if ($field_name == 'entity_id' or $field_name == 'status') {
         $this->query->propertyCondition($field_name, $value, $operator);
@@ -132,34 +104,32 @@ class tripal_views_query extends views_plugin_query {
         return;
       }
 
-      // If the field_name comes to us with a period in it then it means that
-      // we need to separate the field name from sub-element names.
-      $matches = array();
-      if (preg_match('/^(.+?)\.(.*)$/', $field_name, $matches)) {
-         $field_name = $matches[1];
-         $element_name = $matches[2];
-         $field = field_info_field($field_name);
-         $instance = field_info_instance('TripalEntity', $field_name, $this->query->entityConditions['bundle']['value']);
-         $field_class = $field['type'];
-         if (tripal_load_include_field_class($field_class)) {
-
-           $field_obj = new $field_class($field, $instance);
-           $element_name = $field_obj->getFieldTermID() . ',' . $element_name;
-           // Replace periods with commas.
-           $element_name = preg_replace('/\./', ',', $element_name);
-           $this->query->fieldCondition($field_name, $element_name, $value, $operator);
-           $this->cquery->fieldCondition($field_name, $element_name, $value, $operator);
-         }
-         else {
-           throw new Exception("Unkown element id: '$element_name'.");
-         }
+      // For Tripal create fields the name of the field is an encoded
+      // string that contains the bundle term, field name and any
+      // sub elements. We need to extract them.
+      $elements = explode('.', $field_name);
+      $bundle_term = array_shift($elements);
+      $field_name = array_shift($elements);
+      $element_name = implode(',', $elements);
+
+      // Get the field and instance.
+      $field = field_info_field($field_name);
+      $instance = field_info_instance('TripalEntity', $field_name, $this->query->entityConditions['bundle']['value']);
+
+      // Construct the field term.
+      $field_term = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];
+
+      // Let's add add on the $field_term to the element_name and add the
+      // query condition.
+      if ($element_name) {
+        $element_name = $field_term . ',' . $element_name;
       }
       else {
-        $instance = field_info_instance('TripalEntity', $field_name, $this->query->entityConditions['bundle']['value']);
-        $field_term = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];
-        $this->query->fieldCondition($field_name, $field_term, $value, $operator);
-        $this->cquery->fieldCondition($field_name, $field_term, $value, $operator);
+        $element_name = $field_term;
       }
+
+      $this->query->fieldCondition($field_name, $element_name, $value, $operator);
+      $this->cquery->fieldCondition($field_name, $element_name, $value, $operator);
     }
   }
 
@@ -167,12 +137,13 @@ class tripal_views_query extends views_plugin_query {
    * Overrides add_orderby().
    */
   public function add_orderby($table, $field_name = NULL, $order = 'ASC', $alias = '', $params = array()) {
-
     if ($field_name) {
-      // Make sure we don't put the orderby in more than once.
+      // If we already have an orderBy for this field then remove it so
+      // we can reset it.
       foreach ($this->order as $index => $order_details) {
         if ($order_details['field'] == $field_name) {
-          return;
+          $this->order[$index]['direction'] = $order;
+          unset($this->order[$index]);
         }
       }
       $this->order[] = array(

+ 2 - 6
tripal/views_handlers/tripal_views_handler_filter_string.inc

@@ -1,6 +1,6 @@
 <?php
 class tripal_views_handler_filter_string extends tripal_views_handler_filter {
-  // exposed filter options
+
   var $always_multiple = TRUE;
 
   function option_definition() {
@@ -223,14 +223,10 @@ class tripal_views_handler_filter_string extends tripal_views_handler_filter {
 
   /**
    * Add this filter to the query.
-   *
-   * Due to the nature of fapi, the value and the operator have an unintended
-   * level of indirection. You will find them in $this->operator
-   * and $this->value respectively.
    */
   function query() {
     $this->ensure_my_table();
-    $field = $this->real_field;
+    $field = "$this->table_alias.$this->real_field";
 
     $info = $this->operators();
     if (!empty($info[$this->operator]['method'])) {

+ 21 - 0
tripal_chado/includes/TripalFields/ChadoField.inc

@@ -85,6 +85,27 @@ class ChadoField extends TripalField {
    */
   public function queryOrder($query, $order) {
 
+
+    // If we are here it is because the child class did not implement the
+    // queryOrder function.  So, we will do our best to make the query work.
+    $chado_table = $this->instance['settings']['chado_table'];
+    $base_table = $this->instance['settings']['base_table'];
+    $bschema = chado_get_schema($base_table);
+    $bpkey = $bschema['primary key'][0];
+    $alias = 'dbx_linker';
+    $operator = $condition['operator'];
+
+    // If the chado_table and the base_table are the same then this is easy.
+    if ($chado_table == $base_table) {
+      // Get the base table column that is associated with the term
+      // passed as $condition['column'].
+      $base_field = tripal_get_chado_semweb_column($chado_table, $order['column']);
+      $query->orderBy('base.' . $base_field, $order['direction']);
+    }
+    else {
+      // If the two are not the same then we expect that the child class
+      // will implement a query() function.
+    }
   }
 
   /**

+ 0 - 3
tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact.inc

@@ -76,7 +76,6 @@ class chado_linker__contact extends ChadoField {
         'elements' => array(
           $type_term => array(
             'searchable' => TRUE,
-            'name' => 'type',
             'label' => 'Contact Type',
             'help' => 'The type of contact',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
@@ -84,7 +83,6 @@ class chado_linker__contact extends ChadoField {
           ),
           $name_term => array(
             'searchable' => TRUE,
-            'name' => 'name',
             'label' => 'Contact Name',
             'help' => 'The name of the contact.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
@@ -92,7 +90,6 @@ class chado_linker__contact extends ChadoField {
           ),
           $description_term => array(
             'searchable' => TRUE,
-            'name' => 'description',
             'label' => 'Contact Description',
             'help' => 'A descriptoin of the contact.',
             'operations' => array('contains'),

+ 11 - 4
tripal_chado/includes/TripalFields/data__protein_sequence/data__protein_sequence.inc

@@ -49,13 +49,15 @@ class data__protein_sequence extends ChadoField {
    */
   public function elementInfo() {
     $field_term = $this->getFieldTermID();
-    return array(
+    $info = array(
       $field_term => array(
-        'operations' => array(),
+        'label' => 'Protein sequence',
+        'help' => 'The polypeptide sequence derived from mRNA',
         'sortable' => FALSE,
         'searchable' => FALSE,
       ),
     );
+    return $info;
   }
   /**
    * @see TripalField::load()
@@ -85,9 +87,14 @@ class data__protein_sequence extends ChadoField {
     ";
     $proteins = chado_query($sql, array(':feature_id' => $feature->feature_id));
     while ($protein = $proteins->fetchObject()) {
-      if ($protein->residues) {
-        $entity->{$field_name}['und'][$num_seqs++]['value'] = $protein->residues;
+      $entity->{$field_name}['und'][$num_seqs]['value'] = $protein->residues;
+      // Because we'll be saving a feature we need to maintain all of it's
+      // columns in the feature table. The following will add them all.
+      $columns = get_object_vars($protein);
+      foreach ($columns as $colname => $value) {
+        $entity->{$field_name}['und'][$num_seqs]['chado-feature__' . $colname] = $value;
       }
+      $num_seqs++;
     }
   }
 }

+ 4 - 10
tripal_chado/includes/TripalFields/data__protein_sequence/data__protein_sequence_widget.inc

@@ -14,15 +14,9 @@ class data__protein_sequence_widget extends ChadoFieldWidget {
   public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
-    // TODO: add the form for setting a protein sequence.
-  }
-
-  /**
-   *
-   * @see TripalFieldWidget::submit()
-   */
-  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-    $field_name = $this->field['field_name'];
-
+    // TODO: before we can create a widget we must have a way to
+    // save another record whose table matches the same as the base base
+    // table with the chado_storage backend getting confused as to what value
+    // belongs to which feature record.
   }
 }

+ 15 - 3
tripal_chado/includes/TripalFields/data__sequence/data__sequence_widget.inc

@@ -31,6 +31,11 @@ class data__sequence_widget extends ChadoFieldWidget {
     }
 
     $widget['value'] = array(
+      '#type' => 'value',
+      '#value' => $residues,
+    );
+
+    $widget['chado-' . $field_table . '__' . $field_column] = array(
       '#type' => 'textarea',
       '#title' => $element['#title'],
       '#description' => $element['#description'],
@@ -46,14 +51,21 @@ class data__sequence_widget extends ChadoFieldWidget {
    *
    * @see TripalFieldWidget::submit()
    */
-  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
     $field_name = $this->field['field_name'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
 
     // Remove any white spaces.
-    $residues = isset($form_state['values'][$field_name][$langcode][$delta]['value']) ? $form_state['values'][$field_name][$langcode][$delta]['value'] : '';
+    $residues = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column];
     if ($residues) {
       $residues = preg_replace('/\s/', '', $residues);
-      $form_state['values'][$field_name][$langcode][$delta]['value'] = $residues;
+      $form_state['values'][$field_name]['und'][$delta]['value'] = $residues;
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column] = $residues;
+    }
+    else {
+      $form_state['values'][$field_name]['und'][$delta]['value'] = 'delete_me';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column] = '';
     }
   }
 }

+ 9 - 9
tripal_chado/includes/TripalFields/data__sequence_checksum/data__sequence_checksum_widget.inc

@@ -30,7 +30,7 @@ class data__sequence_checksum_widget extends ChadoFieldWidget {
       '#type' => 'value',
       '#value' => $md5checksum,
     );
-    $widget['chado-feature__md5checksum'] = array(
+    $widget['chado-' . $field_table . '__md5checksum'] = array(
       '#type' => 'value',
       '#value' => $md5checksum,
     );
@@ -40,8 +40,8 @@ class data__sequence_checksum_widget extends ChadoFieldWidget {
    *
    * @see TripalFieldWidget::submit()
    */
-  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-    $field = $this->field;
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
+  $field = $this->field;
     $settings = $field['settings'];
     $field_name = $field['field_name'];
     $field_type = $field['type'];
@@ -49,17 +49,17 @@ class data__sequence_checksum_widget extends ChadoFieldWidget {
     $field_column = $this->instance['settings']['chado_column'];
 
     // Get the residues so we can calculate the length.
-    $residues = isset($form_state['values']['data__sequence'][$langcode][0]['chado-feature__residues']) ? $form_state['values']['data__sequence'][$langcode][0]['chado-feature__residues'] : '';
-
-    if ($residues) {
+    if ($form_state['values']['data__sequence']['und'][0]['chado-feature__residues']){
       // Remove spaces and new lines from the residues string.
+      $residues =  $form_state['values']['data__sequence']['und'][0]['chado-feature__residues'];
       $residues = preg_replace('/\s/', '', $residues);
-      $form_state['values']['data__sequence'][$langcode][0]['chado-feature__residues'] = $residues;
-      $form_state['values'][$field_name][$langcode][$delta]['chado-feature__md5checksum'] = md5($residues);
+      $checksum = md5($residues);
+      $form_state['values'][$field_name]['und'][0]['chado-feature__md5checksum'] = $checksum;
+      $form_state['values'][$field_name]['und'][0]['value'] = $checksum;
     }
     else {
       // Otherwise, remove the md5 value
-      $form_state['values'][$field_name][$langcode][$delta]['chado-feature__md5checksum'] = '__NULL__';
+      $form_state['values'][$field_name]['und'][0]['chado-feature__md5checksum'] = '__NULL__';
     }
   }
 }

+ 106 - 30
tripal_chado/includes/TripalFields/data__sequence_coordinates/data__sequence_coordinates.inc

@@ -60,61 +60,136 @@ class data__sequence_coordinates extends ChadoField {
    */
   public function elementInfo() {
     $field_term = $this->getFieldTermID();
+
+    $reference_term = 'data:3002';
+    $fmin_term = tripal_get_chado_semweb_term('featureloc', 'fmin');
+    $fmax_term = tripal_get_chado_semweb_term('featureloc', 'fmax');
+    $strand_term = tripal_get_chado_semweb_term('featureloc', 'strand');
+    $phase_term = tripal_get_chado_semweb_term('featureloc', 'phase');
+
     return array(
       $field_term => array(
         'operations' => array(),
         'sortable' => FALSE,
         'searchable' => FALSE,
+        'label' => 'Location Coordinates',
+        'help' => 'The locations on other genomic sequences where this record has been aligned.',
         'elements' => array(
-          'data:3002' => array(
+          $reference_term => array(
             'searchable' => TRUE,
-            'name' => 'source_feature',
             'label' => 'Location Reference Name',
             'help' => 'The genomic feature on which this feature is localized.',
             'operations' => array('eq', 'ne', 'contains', 'starts'),
             'sortable' => TRUE,
           ),
-          'local:fmin' => array(
+          $fmin_term => array(
             'searchable' => TRUE,
-            'name' => 'feature min',
             'label' => 'Location Start Position',
             'help' => 'The start position',
             'type' => 'numeric',
             'operations' => array('eq', 'gt', 'lt', 'gte' ,'lte'),
             'sortable' => TRUE,
           ),
-          'local:fmax' => array(
+          $fmax_term => array(
             'searchable' => TRUE,
-            'name' => 'feature max',
             'label' => 'Location End Position',
             'help' => 'The end position',
             'type' => 'numeric',
             'operations' => array('eq', 'gt', 'lt', 'gte' ,'lte'),
             'sortable' => TRUE,
           ),
-          'data:2336' => array(
+          $phase_term => array(
             'searchable' => TRUE,
-            'name' => 'phase',
             'type' => 'numeric',
             'label' => 'Location Phase',
             'help' => 'The phase of the feature (applicable only to coding sequences).',
             'operations' => array('eq', 'gt', 'lt', 'gte' ,'lte'),
             'sortable' => TRUE,
           ),
-          'data:0853' => array(
+          $strand_term => array(
             'searchable' => TRUE,
-            'name' => 'strand',
-            'type' => 'numeric',
             'label' => 'Location Strand',
             'help' => 'The orientation of this feature where it is localized',
             'operations' => array('eq', 'gt', 'lt', 'gte' ,'lte'),
-            'sortable' => TRUE,
+            'sortable' => FALSE,
           ),
         ),
       ),
     );
   }
 
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition) {
+    $alias = $this->field['field_name'];
+    $operator = $condition['operator'];
+
+    $field_term_id = $this->getFieldTermID();
+    $reference_term = $field_term_id . ',' . 'data:3002';
+    $fmin_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featureloc', 'fmin');
+    $fmax_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featureloc', 'fmax');
+    $strand_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featureloc', 'strand');
+    $phase_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featureloc', 'phase');
+
+    // Join to the organism table for this field.
+    $this->queryJoinOnce($query, 'featureloc', $alias, "base.feature_id = $alias.feature_id");
+    if ($condition['column'] == $reference_term) {
+      $salias = $alias . '_src';
+      $this->queryJoinOnce($query, 'feature', $salias, "$alias.srcfeature_id = $salias.feature_id");
+      $query->condition("$salias.name", $condition['value'], $operator);
+    }
+    if ($condition['column'] == $strand_term) {
+      $strand = '';
+      if ($condition['value'] == '-') {
+        $strand = -1;
+      }
+      if ($condition['value'] == '+') {
+        $strand = 1;
+      }
+      $query->condition("$alias.strand", $strand, $operator);
+    }
+    if ($condition['column'] == $fmin_term) {
+      $query->condition("$alias.fmin", $condition['value'] - 1, $operator);
+    }
+    if ($condition['column'] == $fmax_term) {
+      $query->condition("$alias.fmax", $condition['value'], $operator);
+    }
+    if ($condition['column'] == $phase_term) {
+      $query->condition("$alias.phase", $condition['value'], $operator);
+    }
+  }
+
+  /**
+   * @see ChadoField::queryOrder()
+   */
+  public function queryOrder($query, $order) {
+    $alias = $this->field['field_name'];
+
+    $field_term_id = $this->getFieldTermID();
+    $reference_term = $field_term_id . ',' . 'data:3002';
+    $fmin_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featureloc', 'fmin');
+    $fmax_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featureloc', 'fmax');
+    $strand_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featureloc', 'strand');
+    $phase_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featureloc', 'phase');
+
+    $this->queryJoinOnce($query, 'featureloc', $alias, "base.feature_id = $alias.feature_id", "LEFT OUTER");
+    if ($order['column'] == $reference_term) {
+      $salias = $alias . '_src';
+      $this->queryJoinOnce($query, 'feature', $salias, "$alias.srcfeature_id = $salias.feature_id", "LEFT OUTER");
+      $query->orderBy("$salias.name", $order['direction']);
+    }
+    if ($order['column'] == $fmin_term) {
+      $query->orderBy("$alias.fmin", $order['direction']);
+    }
+    if ($order['column'] == $fmax_term) {
+      $query->orderBy("$alias.fmax", $order['direction']);
+    }
+    if ($order['column'] == $phase_term) {
+      $query->orderBy("$alias.phase", $order['direction']);
+    }
+  }
+
   /**
    *
    * @see TripalField::load()
@@ -124,6 +199,12 @@ class data__sequence_coordinates extends ChadoField {
     $feature = $entity->chado_record;
     $num_seqs = 0;
 
+    $reference_term = 'data:3002';
+    $fmin_term = tripal_get_chado_semweb_term('featureloc', 'fmin');
+    $fmax_term = tripal_get_chado_semweb_term('featureloc', 'fmax');
+    $strand_term = tripal_get_chado_semweb_term('featureloc', 'strand');
+    $phase_term = tripal_get_chado_semweb_term('featureloc', 'phase');
+
     $options = array(
       'return_array' => TRUE,
       'order_by' => array('rank' => 'ASC'),
@@ -132,19 +213,7 @@ class data__sequence_coordinates extends ChadoField {
 
     // Set some defauls for the empty record
     $entity->{$field_name}['und'][0] = array(
-      'value' => array(
-        /*
-        // Types of elements that will appear in the value array.
-        // Annotation track
-        'data:3002' => '',
-        'local:fmin' => '',
-        'local:fmax' => '',
-        // phase
-        'data:2336' => '',
-        // strand
-        'data:0853' => '',
-        */
-      ),
+      'value' => '',
     );
 
     // Get the featureloc records that this feature is aligned to.
@@ -152,13 +221,20 @@ class data__sequence_coordinates extends ChadoField {
     if ($aligned) {
       foreach ($aligned as $index => $featureloc) {
         $srcfeature = $featureloc->srcfeature_id->name;
+        $strand = '';
+        if ($featureloc->strand == 1) {
+          $strand = '+';
+        }
+        else {
+          $strand = '-';
+        }
         $entity->{$field_name}['und'][0] = array(
           'value' => array(
-            'data:3002' => $srcfeature,
-            'local:fmin' => $featureloc->fmin + 1,
-            'local:fmax' => $featureloc->fmax,
-            'data:2336' => $featureloc->phase,
-            'data:0853' => $featureloc->strand,
+            $reference_term => $srcfeature,
+            $fmin_term => $featureloc->fmin + 1,
+            $fmax_term => $featureloc->fmax,
+            $strand_term => $strand,
+            $phase_term => $featureloc->phase,
           ),
         );
         $sentity_id = chado_get_record_entity_by_table('feature_id', $featureloc->srcfeature_id->feature_id);

+ 11 - 11
tripal_chado/includes/TripalFields/data__sequence_coordinates/data__sequence_coordinates_formatter.inc

@@ -14,20 +14,20 @@ class data__sequence_coordinates_formatter extends ChadoFieldFormatter {
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
 
+    $reference_term = 'data:3002';
+    $fmin_term = tripal_get_chado_semweb_term('featureloc', 'fmin');
+    $fmax_term = tripal_get_chado_semweb_term('featureloc', 'fmax');
+    $strand_term = tripal_get_chado_semweb_term('featureloc', 'strand');
+    $phase_term = tripal_get_chado_semweb_term('featureloc', 'phase');
+
     $content = '';
     foreach ($items as $item) {
       if (!empty($item['value'])) {
-        $srcfeature = $item['value']['data:3002'];
-        $fmin = $item['value']['local:fmin'];
-        $fmax = $item['value']['local:fmax'];
-        $phase = $item['value']['data:2336'];
-        $strand = $item['value']['data:0853'];
-        if ($strand == 1) {
-          $strand = '+';
-        }
-        else {
-          $strand = '-';
-        }
+        $srcfeature = $item['value'][$reference_term];
+        $fmin = $item['value'][$fmin_term];
+        $fmax = $item['value'][$fmax_term];
+        $phase = $item['value'][$phase_term];
+        $strand = $item['value'][$strand_term];
         $content .= $srcfeature . ':' . $fmin . '..' . $fmax . $strand;
       }
     }

+ 9 - 7
tripal_chado/includes/TripalFields/data__sequence_length/data__sequence_length_widget.inc

@@ -43,16 +43,18 @@ class data__sequence_length_widget extends ChadoFieldWidget {
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
 
-    // Get the residues so we can calculate teh length.
-    $residues = $form_state['values']['data__sequence']['und'][0]['value'];
-    // Remove any white spaces.
-    if ($residues) {
+    // Get the residues so we can calculate the length.
+    if ($form_state['values']['data__sequence']['und'][0]['chado-feature__residues']){
+      $residues =  $form_state['values']['data__sequence']['und'][0]['chado-feature__residues'];
+      // Remove spaces and new lines from the residues string.
       $residues = preg_replace('/\s/', '', $residues);
-      $form_state['values']['data__sequence']['und'][0]['value'] = $residues;
-      $form_state['values']['data__sequence_length']['und'][0]['chado-feature__seqlen'] = strlen($residues);
+      $length = strlen($residues);
+      $form_state['values'][$field_name]['und'][0]['chado-feature__seqlen'] = $length;
+      $form_state['values'][$field_name]['und'][0]['value'] = $length;
     }
     else {
-      $form_state['values']['data__sequence_length']['und'][0]['chado-feature__seqlen'] = '__NULL__';
+      // Otherwise, remove the md5 value
+      $form_state['values'][$field_name]['und'][0]['chado-feature__seqlen'] = '__NULL__';
     }
   }
 }

+ 2 - 2
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -628,8 +628,8 @@ function tripal_chado_field_storage_query($query) {
     } // end if ($sort['type'] == 'field') {
   } // end foreach ($query->order as $index => $sort) {
 
-    dpm($cquery->__toString());
-    dpm($cquery->getArguments());
+//     dpm($cquery->__toString());
+//     dpm($cquery->getArguments());
 
   $records = $cquery->execute();
 

+ 0 - 11
tripal_chado/includes/tripal_chado.semweb.inc

@@ -1249,17 +1249,6 @@ function tripal_chado_populate_vocab_LOCAL() {
   ));
   tripal_associate_chado_semweb_term('featureloc', 'fmax', $term);
 
-  $term = tripal_insert_cvterm(array(
-    'id' => 'local:unknown_fmin',
-    'name' => ' minimal boundary',
-    'definition' => 'The leftmost, minimal boundary in the linear range ' .
-    'represented by the feature location. Sometimes this is called ' .
-    'start although this is confusing because it does not necessarily ' .
-    'represent the 5-prime coordinate.',
-    'cv_name' => 'local',
-  ));
-  tripal_associate_chado_semweb_term('featureloc', 'fmin', $term);
-
 
   //--------------
   // Analysis Terms

+ 21 - 0
tripal_chado/tripal_chado.install

@@ -1138,4 +1138,25 @@ function tripal_chado_update_7310() {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Could not perform update: '. $error);
   }
+}
+/**
+ * Fix a mistake with the association of the term with featureloc.fmin.
+ */
+function tripal_chado_update_7311() {
+  try {
+    $term = tripal_insert_cvterm(array(
+      'id' => 'local:fmin',
+      'name' => 'minimal boundary',
+      'definition' => 'The leftmost, minimal boundary in the linear range ' .
+        'represented by the feature location. Sometimes this is called ' .
+        'start although this is confusing because it does not necessarily ' .
+        'represent the 5-prime coordinate.',
+      'cv_name' => 'local',
+    ));
+    tripal_associate_chado_semweb_term('featureloc', 'fmin', $term);
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
 }