Răsfoiți Sursa

Fixed bug in GFF loader with storing temp CDS features. Also updated tempalate to improve readability of english sentences constructed from relationships

Stephen Ficklin 9 ani în urmă
părinte
comite
99f5b77330

+ 7 - 5
tripal_feature/includes/tripal_feature.gff_loader.inc

@@ -946,6 +946,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
             else {
               $pfmin += $min_phase[0]->phase;
             }
+
             // Add the new protein record.
             $feature = tripal_feature_load_gff3_feature($organism, $analysis_id,
               $protein_cvterm, $uname, $name, '', 'f', 'f', 1, 0);
@@ -961,10 +962,9 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
         }
       }
 
-
       print "\nSetting ranks of children...\n";
 
-      // get features in a relationship that are also children of an alignment
+      // Get features in a relationship that are also children of an alignment.
       $sql = "
         SELECT DISTINCT F.feature_id, F.organism_id, F.type_id,
           F.uniquename, FL.strand
@@ -977,15 +977,17 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
       ";
       $parents = chado_query($sql);
 
-      // build and prepare the SQL for selecting the children relationship
+      // Build and prepare the SQL for selecting the children relationship.
       $sel_gffchildren_sql = "
         SELECT DISTINCT FR.feature_relationship_id, FL.fmin, FR.rank
         FROM {feature_relationship} FR
           INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
-        WHERE FR.object_id = :feature_id ORDER BY FL.fmin ASC
+          INNER JOIN {cvterm} CVT on CVT.cvterm_id = FR.type_id
+        WHERE FR.object_id = :feature_id AND CVT.name = 'part_of'
+        ORDER BY FL.fmin ASC
       ";
 
-      // now set the rank of any parent/child relationships.  The order is based
+      // Now set the rank of any parent/child relationships.  The order is based
       // on the fmin.  The start rank is 1.  This allows features with other
       // relationships to be '0' (the default), and doesn't interfer with the
       // ordering defined here.

+ 93 - 26
tripal_feature/theme/templates/tripal_feature_relationships.tpl.php

@@ -1,17 +1,17 @@
 <?php
 /* Typically in a Tripal template, the data needed is retrieved using a call to
- * chado_expand_var function.  For example, to retrieve all 
+ * chado_expand_var function.  For example, to retrieve all
  * of the feature relationships for this node, the following function call would be made:
- * 
+ *
  *   $feature = chado_expand_var($feature,'table','feature_relationship');
- * 
+ *
  * However, this function call can be extremely slow when there are numerous relationships.
- * This is because the chado_expand_var function is recursive and expands 
+ * This is because the chado_expand_var function is recursive and expands
  * all data following the foreign key relationships tree.  Therefore, to speed retrieval
  * of data, a special variable is provided to this template:
- * 
+ *
  *   $feature->all_relationships;
- *   
+ *
  * This variable is an array with two sub arrays with the keys 'object' and 'subject'.  The array with
  * key 'object' contains relationships where the feature is the object, and the array with
  * the key 'subject' contains relationships where the feature is the subject
@@ -24,23 +24,57 @@ $subject_rels = $all_relationships['subject'];
 
 if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
   <div class="tripal_feature-data-block-desc tripal-data-block-desc"></div> <?php
-  
-  // first add in the subject relationships.  
+
+  // first add in the subject relationships.
   foreach ($subject_rels as $rel_type => $rels){
-    foreach ($rels as $obj_type => $objects){ ?>
-      <p>This <?php print $feature->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> feature(s): <?php
-       
+    foreach ($rels as $obj_type => $objects){
+
+      // Make the verb in the sentence make sense in English.
+      switch ($rel_type) {
+        case 'integral part of':
+        case 'instance of':
+          $verb = 'is an';
+          break;
+        case 'proper part of':
+        case 'transformation of':
+        case 'genome of':
+        case 'part of':
+        case 'position of':
+        case 'sequence of':
+        case 'variant of':
+          $verb = 'is a';
+          break;
+        case 'derives from':
+        case 'connects on':
+        case 'contains':
+        case 'finishes':
+        case 'guides':
+        case 'has origin':
+        case 'has part':
+        case 'has quality':
+        case 'is consecutive sequence of':
+        case 'maximally overlaps':
+        case 'overlaps':
+        case 'starts':
+          $verb = '';
+          break;
+        default:
+          $verb = 'is';
+      } ?>
+
+      <p>This <?php print $feature->type_id->name;?> <?php print $verb ?> <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> feature(s): <?php
+
       // 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('Feature Name' ,'Unique Name', 'Species', 'Type');
-      
+
       // 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 ($objects as $object){
         // link the feature to it's node
         $feature_name = $object->record->object_id->name;
@@ -54,12 +88,12 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
           $organism_name = l("<i>" . $organism->genus . " " . $organism->species . "</i>", "node/" . $organism->nid, array('html' => TRUE));
         }
         $rows[] = array(
-          array('data' => $feature_name, 'width' => '30%'), 
+          array('data' => $feature_name, 'width' => '30%'),
           array('data' => $object->record->object_id->uniquename, 'width' => '30%'),
           array('data' => $organism_name, 'width' => '30%'),
           array('data' => $object->record->object_id->type_id->name, 'width' => '10%'),
-        ); 
-       } 
+        );
+       }
        // 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:
@@ -76,7 +110,7 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
          'colgroups' => array(),
          'empty' => '',
        );
-       
+
        // once we have our table array structure defined, we call Drupal's theme_table()
        // function to generate the table.
        print theme_table($table); ?>
@@ -84,22 +118,55 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
        <br><?php
      }
   }
-  
-  // second add in the object relationships.  
+
+  // second add in the object relationships.
   foreach ($object_rels as $rel_type => $rels){
-    foreach ($rels as $subject_type => $subjects){?>
-      <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> feature(s) are <?php print $rel_type ?> this <?php print $feature->type_id->name;?>: <?php 
+    foreach ($rels as $subject_type => $subjects){
+
+      // Make the verb in the sentence make sense in English.
+      switch ($rel_type) {
+        case 'integral part of':
+        case 'instance of':
+          $verb = 'are an';
+          break;
+        case 'proper part of':
+        case 'transformation of':
+        case 'genome of':
+        case 'part of':
+        case 'position of':
+        case 'sequence of':
+        case 'variant of':
+          $verb = 'are a';
+          break;
+        case 'derives from':
+        case 'connects on':
+        case 'contains':
+        case 'finishes':
+        case 'guides':
+        case 'has origin':
+        case 'has part':
+        case 'has quality':
+        case 'is consecutive sequence of':
+        case 'maximally overlaps':
+        case 'overlaps':
+        case 'starts':
+          $verb = '';
+          break;
+        default:
+          $verb = 'are';
+      } ?>
+      <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> feature(s) <?php print $verb ?> <?php print $rel_type ?> this <?php print $feature->type_id->name;?>: <?php
       // 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('Feature Name' ,'Unique Name', 'Species', 'Type');
-      
+
       // 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 ($subjects as $subject){
         // link the feature to it's node
         $feature_name = $subject->record->subject_id->name;
@@ -117,8 +184,8 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
           array('data' =>$subject->record->subject_id->uniquename, 'width' => '30%'),
           array('data' =>$organism_name, 'width' => '30%'),
           array('data' =>$subject->record->subject_id->type_id->name, 'width' => '10%'),
-        ); 
-       } 
+        );
+       }
        // 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:
@@ -135,7 +202,7 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
          'colgroups' => array(),
          'empty' => '',
        );
-       
+
        // once we have our table array structure defined, we call Drupal's theme_table()
        // function to generate the table.
        print theme_table($table); ?>

+ 24 - 8
tripal_feature/tripal_feature.install

@@ -112,7 +112,7 @@ function tripal_feature_add_tripal_gff_temp_table() {
 /**
  *
  */
-function tripal_feature_add_tripal_gffcds_temp_table() {
+function tripal_feature_add_tripal_gffcds_temp_table($skip_recreate = TRUE) {
   $schema = array(
     'table' => 'tripal_gffcds_temp',
     'fields' => array(
@@ -145,11 +145,8 @@ function tripal_feature_add_tripal_gffcds_temp_table() {
       'tripal_gff_temp_idx0' => array('feature_id'),
       'tripal_gff_temp_idx0' => array('parent_id'),
     ),
-    'unique keys' => array(
-      'tripal_gff_temp_uq0' => array('feature_id'),
-    ),
   );
-  chado_create_custom_table('tripal_gffcds_temp', $schema, TRUE);
+  chado_create_custom_table('tripal_gffcds_temp', $schema, $skip_recreate);
 }
 
 /**
@@ -498,7 +495,26 @@ function tripal_feature_update_7201() {
  * Adds the temporary tables used for loading GFF files.
  */
 function tripal_feature_update_7202() {
-  tripal_feature_add_tripal_gff_temp_table();
-  tripal_feature_add_tripal_gffcds_temp_table();
-  tripal_feature_add_tripal_gffprotein_temp_table();
+  try {
+    tripal_feature_add_tripal_gff_temp_table();
+    tripal_feature_add_tripal_gffcds_temp_table();
+    tripal_feature_add_tripal_gffprotein_temp_table();
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Failed to complete update' . $error);
+  }
+}
+
+/**
+ * Removes the unique constraint on the tripal_gffcds_temp table.
+ */
+function tripal_feature_update_7203() {
+  try {
+    tripal_feature_add_tripal_gffcds_temp_table(FALSE);
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Failed to complete update' . $error);
+  }
 }