Browse Source

Added warning to blastdb node pages when cvitjs is enabled but there is no config.

Lacey Sanderson 7 years ago
parent
commit
989190ff3c
3 changed files with 92 additions and 17 deletions
  1. 42 3
      api/blast_ui.api.inc
  2. 28 14
      includes/blast_ui.node.inc
  3. 22 0
      theme/node--blastdb.tpl.php

+ 42 - 3
api/blast_ui.api.inc

@@ -875,14 +875,53 @@ function printGFF_parent_children ($gff,$blast_feature_array){
 /**
  * Get text from cvitjs conf file, if possible.
  *
+ * @param $genome_target
+ *   The section of the config to return. Should consist of "data."+[blastdb name].
+ *
  * @return
  *   A string containing the entire contents of the cvitjs configuration file. FALSE otherwise.
  */
-function blast_ui_get_cvit_conf_text() {
-  if ($cvit_conf=blast_ui_get_cvit_conf(variable_get('blast_ui_cvitjs_location', false))) {
-    if ($contents=file_get_contents($cvit_conf)) {
+function blast_ui_get_cvit_conf_text($genome_target = FALSE) {
+
+  // Retrieve the full path and filename of the conf.
+  $cvit_conf = blast_ui_get_cvit_conf(variable_get('blast_ui_cvitjs_location', false));
+  if ($cvit_conf) {
+
+    // Retrieve the contents of the file.
+    $contents = file_get_contents($cvit_conf);
+
+    // If no genome target was provided then return the full file.
+    if ($contents && $genome_target == FALSE) {
       return $contents;
     }
+
+    // If a genome target was provided, then only return that section.
+    if ($genome_target) {
+      $section = array();
+      $in_section = FALSE;
+
+      // For each line of the configuration file...
+      $section_header = '['.$genome_target.']';
+      $lines = preg_split('/\r\n|\n|\r/', trim($contents));
+      foreach($lines as $l) {
+
+        // Are we in the section for this genome target?
+        if (trim($l) == $section_header) {
+          $in_section = TRUE; }
+
+        // Id so and we haven't fallen out of it through an empty line,
+        // then add it to saved section for returning.
+        if ($in_section) {
+          if (trim($l) == '') { break; }
+          $section[] = trim($l);
+        }
+      }
+
+      // If we found the section, then return it ;-).
+      if (!empty($section)) {
+        return implode("\n", $section);
+      }
+    }
   }
 
   return false;

+ 28 - 14
includes/blast_ui.node.inc

@@ -245,24 +245,25 @@ function blastdb_form($node, &$form_state) {
       '#title' => t('Show BLAST hits on the genome in the results page.'),
       '#description' => t('Uses CViTjs to display BLAST hits on the entire genome'),
       '#default_value' => (isset($node->cvitjs_enabled)) ? $node->cvitjs_enabled : false,
-//      '#ajax' => array(
-//        'callback' => 'ajax_blast_ui_node_cvitjs_custom_callback',
-//        'wrapper' => 'cvitjs-settings',
-//      )
     );
-    $form['cvitjs']['cvitjs_enabled']['#description'] .= '
-        <p class="blastdb-extra-info">Target Genome Configuration should be under <strong>[data.'.$node->db_name.']</strong> in the main cvit.conf.</p>';
-
-
-    if (isset($form_state['values'])) {
-      $cvitjs_enabled = $form_state['values']['cvitjs_enabled'];
-    }
-    else if (isset($node->cvitjs_enabled))  {
-      $cvitjs_enabled = $node->cvitjs_enabled;
+    $cvitjs_msg_class = 'blastdb-extra-info';
+    $cvitjs_msg = 'Target Genome Configuration should be under <strong>[data.'.$node->db_name.']</strong> in the main cvit.conf.';
+
+    $conf_section = blast_ui_get_cvit_conf_text('data.'.$node->db_name);
+    if (!$conf_section) {
+      $cvitjs_msg_class .= ' messages warning';
+      $cvitjs_msg .= '<br /><br />There is no section for this genome target defined in the CViTjs
+        configuration file. <strong>No genome visualization will be shown until you define a
+        configuration section, "[data.'.$form_state['values']['db_name'].']", at '
+        .l('Admin > Tripal > Extensions > Tripal BLAST > BLAST UI', 'admin/tripal/extension/tripal_blast')
+        .'</strong>.';
     }
     else {
-      $cvitjs_enabled = false;
+      $cvitjs_msg .= '<br /><br /><strong>Current Configuration:</strong><pre>'.$conf_section.'</pre>';
     }
+
+    $form['cvitjs']['cvitjs_enabled']['#description'] .= '<div class="'.$cvitjs_msg_class.'">'.$cvitjs_msg.'</p>';
+
   }
 
   return $form;
@@ -299,6 +300,19 @@ function blastdb_form_validate($form, $form_state) {
       );
     }
   }
+
+  // Check that there is a cvitjs section for the current
+  if ($form_state['values']['cvitjs_enabled']) {
+    $conf_section = blast_ui_get_cvit_conf_text('data.'.$form_state['values']['db_name']);
+    if (!$conf_section) {
+      drupal_set_message('There is no section for this genome target defined in the CViTjs
+        configuration file. <strong>No genome visualization will be shown until you define a
+        configuration section, "[data.'.$form_state['values']['db_name'].']", at '
+        .l('Admin > Tripal > Extensions > Tripal BLAST > BLAST UI', 'admin/tripal/extension/tripal_blast')
+        .'</strong>.',
+      'warning');
+    }
+  }
 }
 
 /**

+ 22 - 0
theme/node--blastdb.tpl.php

@@ -108,6 +108,28 @@
       <tr><th>Whole Genome Viewer</th><td><?php print ($node->cvitjs_enabled) ? 'Enabled' : 'Disabled'; ?></td></tr>
     </table>
 
+
+    <?php
+      if ($node->cvitjs_enabled) {
+
+        print '<h3>Whole Genome Viewer</h3>';
+
+        $conf_section = blast_ui_get_cvit_conf_text('data.'.$node->db_name);
+
+        if (!$conf_section) {
+
+          print '<div class="messages warning">There is no section for this genome target defined in the CViTjs
+            configuration file. <strong>No genome visualization will be shown until you define a
+            configuration section, "[data.'.$form_state['values']['db_name'].']", at '
+            .l('Admin > Tripal > Extensions > Tripal BLAST > BLAST UI', 'admin/tripal/extension/tripal_blast')
+            .'</strong>.</div>';
+        }
+        else {
+          print '<h4>Configuration</h4>'
+            . '<pre>'.$conf_section.'</pre>';
+        }
+    }
+    ?>
     <?php
       // Add in any remaining content
       print render($content);