Browse Source

Fixed location on map field. Added a new term and hence an updatedb

Stephen Ficklin 7 years ago
parent
commit
d7d64839d4

+ 5 - 2
legacy/tripal_core/api/tripal_core.chado_nodes.api.inc

@@ -1000,7 +1000,9 @@ function chado_node_sync_records($base_table, $max_sync = FALSE,
  *
  * @ingroup tripal_chado_node_api
  */
-function chado_cleanup_orphaned_nodes($table, $nentries = 25000, $linking_table = NULL, $node_type = NULL, $job_id = NULL) {
+function chado_cleanup_orphaned_nodes($table, $nentries = 25000,
+    $linking_table = NULL, $node_type = NULL, $job_id = NULL) {
+
   // The max number of records either as nodes or linked records.
   $count = 0;
   // Will hold the number of nodes of this type.
@@ -1038,7 +1040,8 @@ function chado_cleanup_orphaned_nodes($table, $nentries = 25000, $linking_table
     $m = ceil($count / $nentries);
     for ($i = 0; $i < $m; $i++) {
       $offset = ($nentries * $i);
-      chado_cleanup_orphaned_nodes_part($table, $job_id, $nentries, $offset, $linking_table, $node_type);
+      chado_cleanup_orphaned_nodes_part($table, $job_id, $nentries, $offset,
+          $linking_table, $node_type);
     }
   }
   catch (Exception $e) {

+ 151 - 19
tripal_chado/includes/TripalFields/ogi__location_on_map/ogi__location_on_map.inc

@@ -60,54 +60,172 @@ class ogi__location_on_map extends ChadoField {
   public function elementInfo() {
     $field_term = $this->getFieldTermID();
 
+    $map_term = 'data:1274';
     $name_term = tripal_get_chado_semweb_term('featuremap', 'name');
     $description_term = tripal_get_chado_semweb_term('featuremap', 'description');
     $mappos_term = tripal_get_chado_semweb_term('featurepos', 'mappos');
+    $ref_feature_term = tripal_get_chado_semweb_term('featurepos', 'map_feature_id');
+    $ref_feature_name = tripal_get_chado_semweb_term('feature', 'name');
+    $ref_feature_id = tripal_get_chado_semweb_term('feature', 'uniquename');
+    $ref_feature_type = 'rdfs:type';
 
     return array(
       $field_term => array(
         'sortable' => FALSE,
         'searchable' => FALSE,
         'elements' => array(
-          'data:1274' => array(
-            'name' => 'Map',
+          $map_term => array(
             'searchable' => FALSE,
             'sortable' => FALSE,
             'elements' => array(
               $name_term => array(
-                'name' => 'map_name',
                 'label' => 'Map Name',
                 'help' => 'The name of the map.',
                 'searchable' => TRUE,
-                'operations' => array('eq', 'ne', 'contains', 'starts'),
-                'sortable' => FALSE,
+                'sortable' => TRUE,
               ),
               $description_term => array(
-                'name' => 'map_description',
                 'label' => 'Map Description',
                 'help' => 'A description of the map.',
                 'searchable' => TRUE,
-                'operations' => array('eq', 'ne', 'contains', 'starts'),
                 'sortable' => FALSE,
               ),
+              'entity' => array(
+                'searchable' => FALSE,
+                'sortable' => FALSE,
+              ),
+            ),
+          ),
+          $ref_feature_term => array(
+            'searchable' => FALSE,
+            'sortable' => FALSE,
+            'elements' => array(
+              $ref_feature_name => array(
+                'label' => 'Map Reference Feature Name',
+                'help' => 'The genomic or genetic feature Nameof the map on which this feature is mapped.',
+                'searchable' => TRUE,
+                'sortable' => TRUE,
+              ),
+              $ref_feature_id=> array(
+                'label' => 'Map Reference Feature Identifier',
+                'help' => 'The genomic or genetic feature of the map on which this feature is mapped.',
+                'searchable' => TRUE,
+                'sortable' => TRUE,
+              ),
+              $ref_feature_type=> array(
+                'label' => 'Map Reference Feature Type',
+                'help' => 'The type of genomic or genetic feature of the map on which this feature is mapped.',
+                'searchable' => TRUE,
+                'sortable' => TRUE,
+              ),
             ),
           ),
           $mappos_term => array(
-            'name' => 'map_position_type',
-            'label' => 'Map Position Type',
+            'label' => 'Map Reference Position',
             'help' => 'Maps may use different coordinate systems. This indicates the type of coordinate.',
             'searchable' => TRUE,
-            'operations' => array('eq', 'ne', 'contains', 'starts'),
-            'sortable' => FALSE,
-          ),
-          'entity' => array(
-            'searchable' => FALSE,
-            'sortable' => FALSE,
+            'sortable' => TRUE,
           ),
         ),
       ),
     );
   }
+
+  /**
+   * @see ChadoField::query()
+   */
+  public function query($query, $condition) {
+    $alias = $this->field['field_name'];
+    $operator = $condition['operator'];
+
+    // Map details.
+    $field_term_id = $this->getFieldTermID();
+    $map_term = 'data:1274';
+    $name_term = $field_term_id . ',' . $map_term . ',' . tripal_get_chado_semweb_term('featuremap', 'name');
+    $description_term = $field_term_id . ',' . $map_term . ',' . tripal_get_chado_semweb_term('featuremap', 'description');
+    $mappos_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featurepos', 'mappos');
+
+    // Reference sequence details.
+    $ref_feature_term = tripal_get_chado_semweb_term('featurepos', 'map_feature_id');
+    $ref_feature_name = $field_term_id . ',' . $ref_feature_term . ',' .tripal_get_chado_semweb_term('feature', 'name');
+    $ref_feature_id = $field_term_id . ',' . $ref_feature_term . ',' .tripal_get_chado_semweb_term('feature', 'uniquename');
+    $ref_feature_type = $field_term_id . ',' . $ref_feature_term . ',' .'rdfs:type';
+
+    $this->queryJoinOnce($query, 'featurepos', $alias, "base.feature_id = $alias.feature_id");
+
+    if ($condition['column'] == $name_term) {
+      $this->queryJoinOnce($query, 'featuremap', $alias . '_map', $alias . '_map.featuremap_id = ' . $alias . '.featuremap_id');
+      $query->condition($alias . '_map.name', $condition['value'], $operator);
+    }
+    if ($condition['column'] == $description_term) {
+      $this->queryJoinOnce($query, 'featuremap', $alias . '_map', $alias . '_map.featuremap_id = ' . $alias . '.featuremap_id');
+      $query->condition($alias . '_map.description', $condition['value'], $operator);
+    }
+    if ($condition['column'] == $mappos_term) {
+      $query->condition($alias . '.mappos', $condition['value'], $operator);
+    }
+
+    if ($condition['column'] == $ref_feature_name) {
+      $this->queryJoinOnce($query, 'feature', $alias . '_mapref', $alias . '_mapref.feature_id = ' . $alias . '.map_feature_id');
+      $query->condition($alias . '_mapref.name', $condition['value'], $operator);
+    }
+    if ($condition['column'] == $ref_feature_id) {
+      $this->queryJoinOnce($query, 'feature', $alias . '_mapref', $alias . '_mapref.feature_id = ' . $alias . '.map_feature_id');
+      $query->condition($alias . '_mapref.uniquename', $condition['value'], $operator);
+    }
+    if ($condition['column'] == $ref_feature_type) {
+      $this->queryJoinOnce($query, 'feature', $alias . '_mapref', $alias . '_mapref.feature_id = ' . $alias . '.map_feature_id');
+      $this->queryJoinOnce($query, 'cvterm', $alias . '_mapref_cvterm', $alias . '_mapref_cvterm.cvterm_id = ' . $alias . '_mapref.type_id');
+      $query->condition($alias . '_mapref_cvterm.name', $condition['value'], $operator);
+    }
+  }
+  /**
+   * @see ChadoField::queryOrder()
+   */
+  public function queryOrder($query, $order) {
+    $alias = $this->field['field_name'];
+
+    // Map details.
+    $field_term_id = $this->getFieldTermID();
+    $map_term = 'data:1274';
+    $name_term = $field_term_id . ',' . $map_term . ',' . tripal_get_chado_semweb_term('featuremap', 'name');
+    $description_term = $field_term_id . ',' . $map_term . ',' . tripal_get_chado_semweb_term('featuremap', 'description');
+    $mappos_term = $field_term_id . ',' . tripal_get_chado_semweb_term('featurepos', 'mappos');
+
+    // Reference sequence details.
+    $ref_feature_term = tripal_get_chado_semweb_term('featurepos', 'map_feature_id');
+    $ref_feature_name = $field_term_id . ',' . $ref_feature_term . ',' .tripal_get_chado_semweb_term('feature', 'name');
+    $ref_feature_id = $field_term_id . ',' . $ref_feature_term . ',' .tripal_get_chado_semweb_term('feature', 'uniquename');
+    $ref_feature_type = $field_term_id . ',' . $ref_feature_term . ',' .'rdfs:type';
+
+    $this->queryJoinOnce($query, 'featurepos', $alias, "base.feature_id = $alias.feature_id", 'LEFT OUTER');
+
+    if ($order['column'] == $name_term) {
+      $this->queryJoinOnce($query, 'featuremap', $alias . '_map', $alias . '_map.featuremap_id = ' . $alias . '.featuremap_id', 'LEFT OUTER');
+      $query->orderBy($alias . '_map.name', $order['direction']);
+    }
+    if ($order['column'] == $description_term) {
+      $this->queryJoinOnce($query, 'featuremap', $alias . '_map', $alias . '_map.featuremap_id = ' . $alias . '.featuremap_id', 'LEFT OUTER');
+      $query->orderBy($alias . '_map.description', $order['direction']);
+    }
+    if ($order['column'] == $mappos_term) {
+      $query->orderBy($alias . '.mappos', $order['direction']);
+    }
+
+    if ($order['column'] == $ref_feature_name) {
+      $this->queryJoinOnce($query, 'feature', $alias . '_mapref', $alias . '_mapref.feature_id = ' . $alias . '.map_feature_id', 'LEFT OUTER');
+      $query->orderBy($alias . '_mapref.name', $order['direction']);
+    }
+    if ($order['column'] == $ref_feature_id) {
+      $this->queryJoinOnce($query, 'feature', $alias . '_mapref', $alias . '_mapref.feature_id = ' . $alias . '.map_feature_id', 'LEFT OUTER');
+      $query->orderBy($alias . '_mapref.uniquename', $order['direction']);
+    }
+    if ($order['column'] == $ref_feature_type) {
+      $this->queryJoinOnce($query, 'feature', $alias . '_mapref', $alias . '_mapref.feature_id = ' . $alias . '.map_feature_id', 'LEFT OUTER');
+      $this->queryJoinOnce($query, 'cvterm', $alias . '_mapref_cvterm', $alias . '_mapref_cvterm.cvterm_id = ' . $alias . '_mapref.type_id', 'LEFT OUTER');
+      $query->orderBy($alias . '_mapref_cvterm.name', $order['direction']);
+    }
+  }
   /**
    *
    * @see TripalField::load()
@@ -119,27 +237,33 @@ class ogi__location_on_map extends ChadoField {
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
 
+    // Map details
     $map_term = 'data:1274';
     $name_term = tripal_get_chado_semweb_term('featuremap', 'name');
     $description_term = tripal_get_chado_semweb_term('featuremap', 'description');
     $mappos_term = tripal_get_chado_semweb_term('featurepos', 'mappos');
 
+    // Reference sequence details.
+    $ref_feature_term = tripal_get_chado_semweb_term('featurepos', 'map_feature_id');
+    $ref_feature_name = tripal_get_chado_semweb_term('feature', 'name');
+    $ref_feature_id = tripal_get_chado_semweb_term('feature', 'uniquename');
+    $ref_feature_type = 'rdfs:type';
+
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
       'value' => array(),
     );
 
     // Add the featurepos records to our $record.
-    $options = array(
-      'return_array' => TRUE,
+    $options = array('return_array' => TRUE,
       'include_fk' => array(
-        'srcfeature_id' => array(
+        'map_feature_id' => array(
           'type_id' => 1,
         ),
         'feature_id' => array(
           'type_id' => 1
         ),
-      )
+      ),
     );
     $feature = chado_expand_var($record, 'table', 'featurepos', $options);
 
@@ -155,11 +279,19 @@ class ogi__location_on_map extends ChadoField {
             $name_term => $featuremap->name,
             $description_term => $featuremap->description,
           ),
+          $ref_feature_term => array(
+            $ref_feature_name => $featurepos->map_feature_id->name,
+            $ref_feature_id => $featurepos->map_feature_id->uniquename,
+            $ref_feature_type => $featurepos->map_feature_id->type_id->name,
+          ),
           $mappos_term => $featurepos->mappos
         );
         if (property_exists($featuremap, 'entity_id')) {
           $entity->{$field_name}['und'][$i]['value'][$map_term]['entity'] = 'TripalEntity:' . $featuremap->entity_id;
         }
+        if (property_exists($featurepos->map_feature_id, 'entity_id')) {
+          $entity->{$field_name}['und'][$i]['value'][$map_term]['entity'] = 'TripalEntity:' . $featurepos->map_feature_id->entity_id;
+        }
         $i++;
       }
     }

+ 1 - 1
tripal_chado/includes/TripalFields/ogi__location_on_map/ogi__location_on_map_formatter.inc

@@ -12,7 +12,7 @@ class ogi__location_on_map_formatter extends ChadoFieldFormatter {
    * @see TripalFieldFormatter::view()
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
-
+dpm($items);
     $rows = array();
     $headers = array('Map', 'Position', 'Map Description');
     foreach ($items as $delta => $item) {

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

@@ -629,8 +629,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();
 

+ 20 - 2
tripal_chado/includes/tripal_chado.semweb.inc

@@ -530,8 +530,8 @@ function tripal_chado_populate_vocab_ERO() {
     'urlprefix' => 'http://purl.bioontology.org/ontology/ERO/{db}:{accession}',
   ));
   tripal_insert_cv(
-      'ero',
-      'The Eagle-I Research Resource Ontology models research resources such instruments. protocols, reagents, animal models and biospecimens. It has been developed in the context of the eagle-i project (http://eagle-i.net/).'
+    'ero',
+    'The Eagle-I Research Resource Ontology models research resources such instruments. protocols, reagents, animal models and biospecimens. It has been developed in the context of the eagle-i project (http://eagle-i.net/).'
   );
 
   $term = tripal_insert_cvterm(array(
@@ -1232,6 +1232,24 @@ function tripal_chado_populate_vocab_LOCAL() {
     'db_name' => 'local'
   ));
 
+  tripal_insert_cvterm(array(
+    'name' => 'Software',
+    'definition' => 'The software used to construct the map.',
+    'cv_name' => 'featuremap_property',
+    'is_relationship' => 0,
+    'db_name' => 'local'
+  ));
+
+  $term = tripal_insert_cvterm(array(
+    'name' => 'Reference Feature',
+    'definition' => 'A genomic or genetic feature on which other features are mapped.',
+    'cv_name' => 'local',
+    'is_relationship' => 0,
+    'db_name' => 'local'
+  ));
+  tripal_associate_chado_semweb_term('featurepos', 'map_feature_id', $term);
+
+
   //--------------
   // Featureloc Terms
   //--------------

+ 20 - 0
tripal_chado/tripal_chado.install

@@ -1201,4 +1201,24 @@ function tripal_chado_update_7313() {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Could not perform update: '. $error);
   }
+}
+
+/**
+ * Adds a local term for the featuremap.feature_id column.
+ */
+function tripal_chado_update_7314() {
+  try {
+    $term = tripal_insert_cvterm(array(
+      'name' => 'Reference Feature',
+      'definition' => 'A genomic or genetic feature on which other features are mapped.',
+      'cv_name' => 'local',
+      'is_relationship' => 0,
+      'db_name' => 'local'
+    ));
+    tripal_associate_chado_semweb_term('featurepos', 'map_feature_id', $term);
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
 }

+ 1 - 1
tripal_ws/includes/TripalWebService/TripalEntityService_v0_1.inc

@@ -63,7 +63,7 @@ class TripalEntityService_v0_1 extends TripalWebService {
    */
   private function doExpandedField($ctype, $entity_id, $expfield) {
     $service_path = $this->getServicePath() . '/' . urlencode($ctype) . '/' . $entity_id;
-    $this->resource = new TripalWebServiceResource($service_path, $this->doc_path);
+    $this->resource = new TripalWebServiceResource($service_path);
 
     // Get the TripalBundle, TripalTerm and TripalVocab for this type.
     $bundle = tripal_load_bundle_entity(array('label' => $ctype));