Просмотр исходного кода

Limited number of results shown to reduce WSOD shown to users and added empty option to max_target_seq options.

Lacey Sanderson 8 лет назад
Родитель
Сommit
9558927bb7

+ 2 - 1
api/blast_ui.api.inc

@@ -192,7 +192,8 @@ function run_BLAST_tripal_job($program, $query, $database, $output_filestub, $op
   $blast_cmd = "$program -query '$query' -db '$database' -out '$output_file' -outfmt=11";
   if (!empty($options)) {
     foreach ($options as $opt => $val) {
-      if ($val) {
+      $val = trim($val);
+      if (!empty($val)) {
         print "\t$opt: $val\n";
         $blast_cmd .= " -$opt $val";
       }

+ 3 - 2
includes/blast_ui.form_advanced_options.inc

@@ -48,7 +48,7 @@ function blast_ui_blastn_advanced_options_form(&$form, $form_state) {
     '#title' => t('Max target sequences:'),
     '#options' => _get_max_target('blastn'),
     '#default_value' => $defaults['max_target_seqs'],
-    '#description' => t('Select the maximum number of aligned sequences to display'),
+    '#description' => t('Select the maximum number of unique target sequences per query sequence to show results for.'),
   );
 
 /*eksc- remove until we learn how this is implemented by NCBI
@@ -1085,7 +1085,7 @@ function blast_ui_tblastn_advanced_options_form_submit($form, $form_state) {
 function _get_default_values($options) {
   // restore previous values or set to default
   $max_target = (isset($options['max_target_seqs']))
-            ? $options['max_target_seqs'] : 10;
+            ? $options['max_target_seqs'] : 0;
   $short_queries = (isset($options['shortQueries']))
             ? $options['shortQueries'] : true;
   $evalue = (isset($options['evalue']))
@@ -1169,6 +1169,7 @@ function _get_max_target($which) {
     case 'blastp':
     case 'tblastn':
       return array(
+        0 => t(' '),
         10 => t('10'),
         50 => t('50'),
         100 => t('100'),

+ 8 - 2
theme/blast_report.tpl.php

@@ -94,6 +94,10 @@ $no_hits = TRUE;
     <?php print format_date($blast_job->date_submitted, 'medium');?></div>
   <div class="blast-cmd-info"><strong>BLAST Command executed</strong>:
     <?php print $blast_job->blast_cmd;?></div>
+
+  <br />
+  <div class="num-results"><strong>Number of Results</strong>: <?php print $num_results; ?></div>
+
 </div>
 <br />
 
@@ -310,10 +314,12 @@ and click the <em>target name </em> to get more information about the target hit
     }
   }//handle no hits
 }//XML exists
-
+elseif ($too_many_results) {
+  print '<div class="messages error">Your BLAST resulted in '. number_format(floatval($num_results)) .' results which is too many to reasonably display. We have provided the result files for Download at the top of this page; however, we suggest you re-submit your query using a more stringent e-value (i.e. a smaller number).</div>';
+}
 else {
   drupal_set_title('BLAST: Error Encountered');
-  print '<p class="blast-no-results">We encountered an error and are unable to load your BLAST results.</p>';
+  print '<div class="messages error">We encountered an error and are unable to load your BLAST results.</div>';
 }
 ?>
 

+ 31 - 20
theme/blast_ui.theme.inc

@@ -23,13 +23,13 @@ function blast_ui_preprocess_show_blast_report(&$vars) {
 
   // Get blast job details.
   $vars['blast_job'] = get_BLAST_job($vars['job_id']);
-  
+
   // Determine the blast command for display.
   $vars['blast_job']->blast_cmd = $vars['blast_job']->program;
   foreach($vars['blast_job']->options as $key => $value) {
       $vars['blast_job']->blast_cmd .= ' -' . $key. ' ' . $value ;
   }
-  
+
   // Determine the URL of the blast form.
   $vars['blast_form_url'] = 'blast/nucleotide/nucleotide';
   switch($vars['blast_job']->program) {
@@ -46,12 +46,23 @@ function blast_ui_preprocess_show_blast_report(&$vars) {
       $vars['blast_form_url'] = 'blast/protein/protein';
       break;
   }
-  
+
   // Load the XML file.
   $vars['xml'] = NULL;
+  $vars['num_results'] = FALSE;
+  $vars['too_many_results'] = FALSE;
+
   $full_path_xml = DRUPAL_ROOT . DIRECTORY_SEPARATOR . $vars['blast_job']->files->result->xml;
   if (is_readable($full_path_xml)) {
-    $vars['xml'] = simplexml_load_file($full_path_xml);
+
+    $vars['num_results'] = `grep -c "<Hit>" $full_path_xml`;
+
+    if ($vars['num_results'] < 500) {
+      $vars['xml'] = simplexml_load_file($full_path_xml);
+    }
+    else {
+      $vars['too_many_results'] = TRUE;
+    }
   }
 }
 
@@ -85,7 +96,7 @@ function blast_ui_theme_registry_alter(&$theme_registry) {
 
 /**
  * Makes the tripal job_id unrecognizable.
- * 
+ *
  * @param $job_id
  *   The tripal job_id of the blast you want to make secret.
  *
@@ -96,7 +107,7 @@ function blast_ui_make_secret($job_id) {
 
   $mapping = blast_ui_secret_mapping();
   $secret = str_replace(array_keys($mapping), $mapping, $job_id);
-  
+
   return $secret;
 }
 
@@ -113,7 +124,7 @@ function blast_ui_reveal_secret($secret) {
 
   $mapping = blast_ui_secret_mapping(TRUE);
   $job_id = str_replace(array_keys($mapping), $mapping, $secret);
-  
+
   // Check that the job_id exists if it is an integer.
   if (is_numeric($job_id)) {
 
@@ -129,7 +140,7 @@ function blast_ui_reveal_secret($secret) {
     else {
       return $job_id;
     }
-  }  
+  }
   // Last ditch effort: maybe this job was encoded before the upgrade?
   else {
 
@@ -157,7 +168,7 @@ function blast_ui_reveal_secret($secret) {
       );
     }
   }
-  
+
   return FALSE;
 }
 
@@ -177,19 +188,19 @@ function blast_ui_secret_mapping($reveal = FALSE) {
     9 => 'Km',
     0 => 'jVo',
   );
-  
-  // Since this is an open-source module with all the code publically available, 
-  // our secret is not very secret... We are ok with this since the liklihood of 
+
+  // Since this is an open-source module with all the code publically available,
+  // our secret is not very secret... We are ok with this since the liklihood of
   // profiting by stealing random blast results is pretty low. That said, if this bothers
   // you, feel free to implement the following function in a private module to change
   // this mapping to something that cannot easily be looked up on github. ;-).
   // NOTE: Ensure that the mapping you come up with is unique to ensure that the
-  // job_id can be consistently revealed or your users might end up unable to find 
+  // job_id can be consistently revealed or your users might end up unable to find
   // their own blast results...
   if (function_exists('private_make_mapping_ultra_secret')) {
     $mapping = private_make_mapping_ultra_secret($mapping);
   }
-  
+
   if ($reveal) {
     return array_flip($mapping);
   }
@@ -199,7 +210,7 @@ function blast_ui_secret_mapping($reveal = FALSE) {
 }
 
 /**
- * Tests your secret mapping over a set of random integers 
+ * Tests your secret mapping over a set of random integers
  * to ensure the job_id can be recovered.
  *
  * @param $num_iterations
@@ -208,21 +219,21 @@ function blast_ui_secret_mapping($reveal = FALSE) {
 function blast_ui_test_secret_mapping($num_iterations = 10000) {
 
   $all_work = TRUE;
-  
+
   for($i = 0; $i <= $num_iterations; $i++) {
     $job_id = mt_rand(0,100000);
-    
+
     $secret = blast_ui_make_secret($job_id);
     $recovered_job_id = blast_ui_reveal_secret($secret);
-    
+
     if ($job_id != $recovered_job_id) {
       drupal_set_message("Unable to recover job_id: $job_id; Secret: $secret.",'error');
       $all_work = FALSE;
     }
   }
-  
+
   if ($all_work) {
     drupal_Set_message("Secret Mapping works over $num_iterations iterations with random integers.");
   }
-  
+
 }