Browse Source

Merged 6.x-dev

Stephen Ficklin 12 years ago
parent
commit
8b1c0f7555

+ 2 - 1
tripal_bulk_loader/tripal_bulk_loader.module

@@ -295,7 +295,8 @@ function tripal_bulk_loader_form($node, $form_state) {
     '#title'         => t('Data File'),
     '#description'   => t('Please specify the data file to be loaded. This must be a tab-delimited text file with UNIX line endings.'),
     '#weight'        => -8,
-    '#default_value' => $node->file
+    '#default_value' => $node->file,
+    '#maxlength'     => 1024,
   );
 
   $form['loader']['has_header'] = array(

+ 77 - 0
tripal_core/api/tripal_core.ahah.inc

@@ -0,0 +1,77 @@
+<?php
+
+/*
+ * @file
+ * Part of the Tripal Core API.
+ *
+ * Provides support for dynamic forms through AHAH
+ */
+
+/*
+ * This function simply gets the posted form ID, builds the form
+ * and retrieves the specified element
+ */
+function tripal_core_ahah_prepare_form() {
+  
+  // Retrieve the form from the cache
+  $form_state = array('storage' => NULL);
+  $form_build_id = filter_xss($_POST['form_build_id']);
+  $form = form_get_cache($form_build_id, $form_state);
+
+  // Preparing to process the form
+  $args = $form['#parameters'];
+  $form_id = array_shift($args);
+  $form_state['post'] = $form['#post'] = $_POST;
+  $form['#programmed'] = $form['#redirect'] = FALSE;
+
+  // we don't want to submit the form or have required fields validated on
+  // an ahah callback.
+  $form_state['submitted'] = TRUE;
+  $form['#validate'] = NULL;
+  $form['#submit'] = NULL;
+  $form_state['submit_handlers'] = NULL;
+  $form_state['validate_handlers'] = NULL;
+  tripal_core_ahah_form_element_disable_validation($form);
+
+  // Sets the form_state so that the validate and submit handlers can tell
+  // when the form is submitted via AHAH
+  $form_state['ahah_submission'] = TRUE;
+
+  // Process the form with drupal_process_form. This function calls the submit
+  // handlers, which put whatever was worthy of keeping into $form_state.
+  drupal_process_form($form_id, $form, $form_state);
+  
+  // You call drupal_rebuild_form which destroys $_POST.
+  // The form generator function is called and creates the form again but since
+  // it knows to use $form_state, the form will be different.
+  // The new form gets cached and processed again, but because $_POST is
+  // destroyed, the submit handlers will not be called again.
+  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
+  
+
+  return $form;
+}
+
+/*
+ * 
+ */
+function tripal_core_ahah_bind_events() {
+  
+  // Get the JS settings so we can merge them.
+  $javascript = drupal_add_js(NULL, NULL, 'header');
+  $settings = call_user_func_array('array_merge_recursive', $javascript['setting']);
+  
+  return array('ahah' => $settings['ahah']);
+}
+
+/*
+ * 
+ */
+function tripal_core_ahah_form_element_disable_validation(&$form) {
+  // --START code borrowed from ahah_helper module
+  foreach (element_children($form) as $child) {
+    $form[$child]['#validated'] = TRUE;
+    tripal_core_ahah_form_element_disable_validation($form[$child]);
+  }
+  // --END code borrowed from ahah_helper module
+}

+ 4 - 5
tripal_core/api/tripal_core.api.inc

@@ -2750,8 +2750,7 @@ function tripal_core_is_sql_prepared($statement_name) {
   // @coder-ignore: acting on postgres tables rather then drupal schema therefore, table prefixing does not apply
   $sql = "SELECT name FROM pg_prepared_statements WHERE name = '%s'";
   // do not use 'chado_query' here or it causes memory-leaks
-  //$result = db_fetch_object(db_query($sql, $statement_name));
-  $result = db_fetch_object(chado_query($sql, $statement_name));
+  $result = db_fetch_object(db_query($sql, $statement_name));
 
   if ($result) {
     $_SESSION[$connection][] = $statement_name;
@@ -2794,9 +2793,9 @@ function tripal_core_chado_prepare($statement_name, $psql, $args) {
     }
     else {
       // Although a statement with this name is already prepared it is not the same!
-      watchdog('tripal_core', "chado_prepare: statement, '%name', is already prepared with different arguments! The current statement: \n%sql. The current arguments: \n%args. The already prepared statement: \n%esql\nThe current arguments: \n%existing. ",
-        array('%name' => $statement_name, '%sql' => $psql, '%esql' => $prepared_sql,
-          '%existing' => print_r($prepared_args, TRUE), '%args' => print_r($args, TRUE)), WATCHDOG_ERROR);
+      watchdog('tripal_core', "chado_prepare: '%name' statement already prepared with different arguments! You want to prepare %sql with %values and the existing statement is %esql with %existing",
+        array('%name' => $statement_name, '%sql' => $psql, '%values' => print_r($args, TRUE), '%esql' => $prepared_sql,
+          '%existing' => print_r($prepared_args, TRUE)), WATCHDOG_ERROR);
       return FALSE;
     }
   }

+ 9 - 2
tripal_core/includes/mviews.php

@@ -326,12 +326,17 @@ function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
 function tripal_update_mview($mview_id) {
   $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
   $mview = db_fetch_object(db_query($sql, $mview_id));
-  if ($mview) {
+  if ($mview) {    
+    // execute the query inside a transaction so that it doesn't destroy existing data
+    // that may leave parts of the site unfunctional
+    tripal_db_start_transaction();
     $previous_db = tripal_db_set_active('chado');  // use chado database
     $results = db_query("DELETE FROM {%s}", $mview->mv_table);
-    $results = db_query("INSERT INTO {%s} ($mview->query)", $mview->mv_table);
+    $results = db_query("INSERT INTO {%s} ($mview->query)", $mview->mv_table);    
     tripal_db_set_active($previous_db);  // now use drupal database
     if ($results) {
+      // commit the transaction
+      tripal_db_commit_transaction();
       $sql = "SELECT count(*) as cnt FROM {%s}";
       $previous_db = tripal_db_set_active('chado');  // use chado database
       $count = db_fetch_object(db_query($sql, $mview->mv_table));
@@ -344,6 +349,8 @@ function tripal_update_mview($mview_id) {
       return TRUE;
     }
     else {
+      // rollback the transaction
+      tripal_db_rollback_transaction()
       // print and save the error message
       $record = new stdClass();
       $record->mview_id = $mview_id;

+ 9 - 7
tripal_feature/includes/fasta_loader.inc

@@ -603,7 +603,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       return 0;
     } 
     if (count($results) == 1) {  
-      $reature = $results[0];
+      $feature = $results[0];
     } 
   }
   // check to see if this feature already exists if the match_type is 'Unique Name'
@@ -613,6 +613,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       'uniquename' => $uname,
       'type_id' => $cvterm->cvterm_id,    
     );
+
     $options = array('statement_name' => 'sel_feature_oruqty');
     $results = tripal_core_chado_select('feature', array('feature_id'), $values, $options);
     if (count($results) > 1) {
@@ -621,7 +622,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
       return 0;
     } 
     if (count($results) == 1) {  
-      $reature = $results[0];
+      $feature = $results[0];
     } 
   }
 
@@ -678,7 +679,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
   
   // if we don't have a feature and the uesr wants to do an update then fail
   if (!$feature and (strcmp($method, 'Update only')==0 or drupal_strcmp($method, 'Insert and update')==0)) {
-    watchdog('T_fasta_loader', "Failed to find feature '%name' ('%name') while matching on " . 
+    watchdog('T_fasta_loader', "Failed to find feature '%name' ('%uiname') while matching on " . 
       drupal_strtolower($match_type), array('%name' => $name, '%uiname' => $uname), WATCHDOG_ERROR);
     return 0;
   }
@@ -791,7 +792,7 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
     }
   }
 
-   // now add the database cross reference
+  // now add the database cross reference
   if ($db_id) {
     // check to see if this accession reference exists, if not add it
     $values = array(
@@ -800,10 +801,11 @@ function tripal_feature_fasta_loader_handle_feature($name, $uname, $db_id, $acce
     );
     $sel_options = array('statement_name' => 'sel_dbxref_dbac');
     $results = tripal_core_chado_select('dbxref', array('dbxref_id'), $values, $sel_options);
+    // if the accession doesn't exist then add it
     if (count($results) == 0) {   
-      $ins_options = array('statement_name' => 'sel_dbxref_dbac');
-      $success = tripal_core_chado_insert('dbxref', $values, $ins_options);
-      if (!$success) {
+      $ins_options = array('statement_name' => 'ins_dbxref_dbac');
+      $results = tripal_core_chado_insert('dbxref', $values, $ins_options);
+      if (!$results) {
         watchdog('T_fasta_loader', "Failed to add database accession '%accession'", 
           array('%accession' => $accession), WATCHDOG_ERROR);
         return 0;

+ 41 - 19
tripal_feature/includes/gff_loader.inc

@@ -589,27 +589,47 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
           
         // add target relationships
         if (array_key_exists('Target', $tags)) {
-          preg_match('/^(.*)\s+\d+\s+\d+\s+(\+|\-)*$/', $tags['Target'][0], $matches);
-          $target_feature = $matches[1]; 
-          $start = $matches[2]; 
-          $end = $matches[3]; 
-          if ($matches[4]) {
-             $target_strand = $matches[4]; 
+          // format is: "target_id start end [strand]", where strand is optional and may be "+" or "-"
+          $matched = preg_match('/^(.*?)\s+(\d+)\s+(\d+)(\s+[\+|\-])*$/', $tags['Target'][0], $matches);
+          
+          // if we have matches and the Target is in the correct format then load the alignment 
+          if ($matched) {
+            $target_feature = $matches[1]; 
+            $start = $matches[2]; 
+            $end = $matches[3]; 
+            // if we have an optional strand, convert it to a numeric value. 
+            if ($matches[4]) {
+              if (preg_match('/^+$/', trim($matches[4]))) {
+                $target_strand = 1;
+              }
+              elseif (preg_match('/^-$/', trim($matches[4]))) {
+                $target_strand = -1;
+              }
+              else {
+                $target_strand = 0;
+              }
+            }
+            else {
+               $target_strand = 0;
+            }
+            
+            $target_fmin = $start - 1;
+            $target_fmax = $end;
+            if ($end < $start) {
+              $target_fmin = $end - 1;
+              $target_fmax = $start;
+            }
+            
+            #print "Target: $target_feature, $target_fmin-$target_fmax $target_dir\n";
+            tripal_feature_load_gff3_featureloc($feature, $organism,
+              $target_feature, $target_fmin, $target_fmax, $target_strand, $phase, $attr_fmin_partial,
+              $attr_fmax_partial, $attr_residue_info, $attr_locgroup);
           }
+          // the target attribute is not correctly formatted
           else {
-             $target_strand = '.';
-          }
-          $target_fmin = $start - 1;
-          $target_fmax = $end;
-          if ($end < $start) {
-            $target_fmin = $end - 1;
-            $target_fmax = $start;
+            watchdog('T_gff3_loader', "Could not add 'Target' alignment as it is improperly formatted:  '%target'",
+              array('%target' => $tags['Target'][0]), WATCHDOG_ERROR);            
           }
-          
-          #print "Target: $target_feature, $target_fmin-$target_fmax $target_dir\n";
-          tripal_feature_load_gff3_featureloc($feature, $organism,
-            $target_feature, $target_fmin, $target_fmax, $target_strand, $phase, $attr_fmin_partial,
-            $attr_fmax_partial, $attr_residue_info, $attr_locgroup);
         }
         
         
@@ -1508,8 +1528,10 @@ function tripal_feature_load_gff3_property($feature, $property, $value) {
       watchdog("T_gff3_loader", "Cannot add cvterm, $property", array(), WATCHDOG_WARNING);
       return 0;  
     }
+  } 
+  else {
+    $cvterm = $result[0];
   }
-  $cvterm = $result[0];
   
 
   // check to see if the property already exists for this feature

+ 1 - 1
tripal_feature/includes/syncFeatures.inc

@@ -71,7 +71,7 @@ function tripal_feature_sync_form() {
   $form['organism_id'] = array(
     '#title'       => t('Organism'),
     '#type'        => t('select'),
-    '#description' => t("Choose the organism for which features will be deleted."),
+    '#description' => t("Choose the organism for which features set above will be synced."),
     '#options'     => $organisms,
   );
 

+ 4 - 0
tripal_organism/tripal_organism.module

@@ -638,6 +638,10 @@ function tripal_organism_theme() {
        'arguments' => array('node' => NULL),
        'template' => 'tripal_organism_image',
     ),
+    'tripal_organism_teaser' => array(
+       'arguments' => array('node' => NULL),
+       'template' => 'tripal_organism_teaser',
+    ),
   );
 }
 /**