Browse Source

Added link-out functionality

Lacey Sanderson 10 years ago
parent
commit
b87c9d28d6
4 changed files with 134 additions and 56 deletions
  1. 31 1
      api/blast_ui.api.inc
  2. 20 2
      includes/blast_ui.node.inc
  3. 80 53
      theme/blast_report.tpl.php
  4. 3 0
      theme/blast_ui.theme.inc

+ 31 - 1
api/blast_ui.api.inc

@@ -6,6 +6,36 @@
  * Plug-in to the BLAST UI functionality
  */
 
+/**
+ * Get a specific BlastDB.
+ *
+ * @param $identifiers
+ *   An array of identifiers used to determine which BLAST DB to retrieve.
+ *
+ * @return
+ *   A fully-loaded BLAST DB Node
+ */
+function get_blast_database($identifiers) {
+  $node = FALSE;
+
+  if (isset($identifiers['nid'])) {
+    $node = node_load($identifiers['nid']);
+  }
+  elseif (isset($identifiers['name'])) {
+
+    $nid = db_query('SELECT nid FROM {blastdb} WHERE name=:name', array(':name' => $identifiers['name']))->fetchField();
+    $node = node_load($nid);
+
+  } elseif (isset($identifiers['path'])) {
+
+    $nid = db_query('SELECT nid FROM {blastdb} WHERE path=:path', array(':path' => $identifiers['path']))->fetchField();
+    $node = node_load($nid);
+
+  }
+
+  return $node;
+}
+
 /**
  * Returns a list BLAST DATABASE options
  *
@@ -216,7 +246,7 @@ function get_blastdb_linkout_regex($node, $options = array()) {
   if (empty($node->linkout->regex)) {
     switch ($node->linkout->regex_type) {
       case 'default':
-        $regex = '/^(\s+) .*/';
+        $regex = '/^(\S+).*/';
         break;
       case 'genbank':
         $regex = '/^gb\|([^\|])*\|.*/';

+ 20 - 2
includes/blast_ui.node.inc

@@ -176,7 +176,7 @@ function blastdb_form($node, &$form_state) {
       . 'you would like to link-out to is not included you can add it '
       . '<a href="" target="_blank">Here</a>.',
     '#options' => $db_options,
-    '#default_value' => $node->linkout->db_id
+    '#default_value' => $node->linkout->db_id->db_id
   );
 
   return $form;
@@ -194,6 +194,23 @@ function blastdb_form_validate($form, $form_state) {
       . '<a href="http://php.net/manual/en/reference.pcre.pattern.syntax.php" target="_blank">PHP.net Regular '
       . 'Expression Documentation</a> for more information.');
   }
+
+  // Check that the supplied db actually contains a URL prefix.
+  if ($form_state['values']['db_id']) {
+    $db = tripal_get_db(array('db_id' => $form_state['values']['db_id']));
+    if (empty($db)) {
+      form_set_error('db_id', 'The database chosen no longer exists.');
+    }
+    if (empty($db->urlprefix)) {
+      form_set_error('db_id', 'The database choosen does not have a URL prefix '
+        . 'listed which means a link-out could not be created for BLAST hits. '
+        . 'Please edit the database '
+        . l('here', 'admin/tripal/chado/tripal_db/edit/' . $db->db_id,
+            array('attributes' => array('target' => '_blank')))
+        . ' to include a URL prefix before continuing'
+      );
+    }
+  }
 }
 
 /**
@@ -295,7 +312,8 @@ function blastdb_load($nodes) {
         $nodes[$record->nid]->linkout->regex_type = $record->dbxref_id_regex;
         $nodes[$record->nid]->linkout->regex = get_blastdb_linkout_regex($nodes[$record->nid]);
       }
-      $nodes[$record->nid]->linkout->db_id = $record->dbxref_db_id;
+      $nodes[$record->nid]->linkout->db_id = tripal_get_db(array('db_id' => $record->dbxref_db_id));
+      $nodes[$record->nid]->linkout->none = FALSE;
     }
     else {
       $nodes[$record->nid]->linkout = new stdClass();

+ 80 - 53
theme/blast_report.tpl.php

@@ -6,6 +6,14 @@
  * Variables Available in this template:
  *   $xml_filename: The full path & filename of XML file containing the BLAST results
  */
+
+ // Set ourselves up to do link-out if our blast database is configured to do so.
+ $linkout = FALSE;
+if ($blastdb->linkout->none === FALSE) {
+  $linkout = TRUE;
+  $linkout_regex = $blastdb->linkout->regex;
+  $linkout_urlprefix = $blastdb->linkout->db_id->urlprefix;
+}
 ?>
 
 <!-- JQuery controlling display of the alignment information (hidden by default) -->
@@ -66,69 +74,88 @@ if ($xml) {
     $children_count = $iteration->{'Iteration_hits'}->children()->count();
     if($children_count != 0) {
       foreach($iteration->{'Iteration_hits'}->children() as $hit) {
-	if (is_object($hit)) {
-	  $count +=1;
-   	  $zebra_class = ($count % 2 == 0) ? 'even' : 'odd';
+        if (is_object($hit)) {
+          $count +=1;
+          $zebra_class = ($count % 2 == 0) ? 'even' : 'odd';
+
+          // SUMMARY ROW
+          // If the id is of the form gnl|BL_ORD_ID|### then the parseids flag
+          // to makeblastdb did a really poor job. In thhis case we want to use
+          // the def to provide the original FASTA header.
+          $hit_name = (preg_match('/BL_ORD_ID/', $hit->{'Hit_id'})) ? $hit->{'Hit_def'} : $hit->{'Hit_id'};
 
-	  // SUMMARY ROW
-	  // If the id is of the form gnl|BL_ORD_ID|### then the parseids flag
-	  // to makeblastdb did a really poor job. In thhis case we want to use
-	  // the def to provide the original FASTA header.
-	  $hit_name = (preg_match('/BL_ORD_ID/', $hit->{'Hit_id'})) ? $hit->{'Hit_def'} : $hit->{'Hit_id'};
+          // If our BLAST DB is configured to handle link-outs then use the
+          // regex & URL prefix provided to create one.
+          if ($linkout) {
+            if (preg_match($linkout_regex, $hit_name, $linkout_match)) {
+              $hit_name = l(
+                $linkout_match[1],
+                $linkout_urlprefix . $linkout_match[1],
+                array('attributes' => array('target' => '_blank'))
+              );
+            }
+          }
 
           $score = $hit->{'Hit_hsps'}->{'Hsp'}->{'Hsp_score'};
-	  $evalue = $hit->{'Hit_hsps'}->{'Hsp'}->{'Hsp_evalue'};
-	  $query_name = $iteration->{'Iteration_query-def'};
-
-	  $row = array(
-	  		'data' => array(
-			'number' => array('data' => $count, 'class' => array('number')),
-			'query' => array('data' => $query_name, 'class' => array('query')),
-			'hit' => array('data' => $hit_name, 'class' => array('hit')),
-			'evalue' => array('data' => $evalue, 'class' => array('evalue')),
-			'arrow-col' => array('data' => '<div class="arrow"></div>', 'class' => array('arrow-col'))
-		      ),
-		     'class' => array('result-summary')
-	            );
-	  $rows[] = $row;
-	  // ALIGNMENT ROW (collapsed by default)
-	  // Process HSPs
-	  $HSPs = array();
-	  foreach ($hit->{'Hit_hsps'}->children() as $hsp_xml) {
-	    $HSPs[] = (array) $hsp_xml;
-	  }
+          $evalue = $hit->{'Hit_hsps'}->{'Hsp'}->{'Hsp_evalue'};
+          $query_name = $iteration->{'Iteration_query-def'};
+
           $row = array(
-			'data' => array(
-			'number' => '',
-			'query' => array(
-			'data' => theme('blast_report_alignment_row', array('HSPs' => $HSPs)),
-			'colspan' => 4,
-			)
-	              ),
-			'class' => array('alignment-row', $zebra_class),
-			'no_striping' => TRUE
-		    );
+            'data' => array(
+              'number' => array('data' => $count, 'class' => array('number')),
+              'query' => array('data' => $query_name, 'class' => array('query')),
+              'hit' => array('data' => $hit_name, 'class' => array('hit')),
+              'evalue' => array('data' => $evalue, 'class' => array('evalue')),
+              'arrow-col' => array('data' => '<div class="arrow"></div>', 'class' => array('arrow-col'))
+            ),
+            'class' => array('result-summary')
+          );
           $rows[] = $row;
-	 }// end of if - checks $hit
+
+          // ALIGNMENT ROW (collapsed by default)
+          // Process HSPs
+          $HSPs = array();
+          foreach ($hit->{'Hit_hsps'}->children() as $hsp_xml) {
+            $HSPs[] = (array) $hsp_xml;
+          }
+
+          $row = array(
+            'data' => array(
+              'number' => '',
+              'query' => array(
+                'data' => theme('blast_report_alignment_row', array('HSPs' => $HSPs)),
+                'colspan' => 4,
+              )
+            ),
+            'class' => array('alignment-row', $zebra_class),
+            'no_striping' => TRUE
+          );
+          $rows[] = $row;
+
+        }// end of if - checks $hit
       } //end of foreach - iteration_hits
     }	// end of if - check for iteration_hits
     else {
-	$count +=1;
-        $query_id = $iteration->{'Iteration_query-ID'};
-        $query_name = $iteration->{'Iteration_query-def'};
-        $row = array(
-                'data' => array(
-                   'number' => array('data' => $count , 'class' => array('number')),
-                   'query' => array('data' => $query_name, 'class' => array('query')),
-                   'hit' => array('data' =>  $iteration->{'Iteration_message'}, 'class' => array('hit')),
-                   'evalue' => array('data' => "-", 'class' => array('evalue')),
-                   'arrow-col' => array('data' => '', 'class' => array('arrow-col'))
-                ),
-                'class' => array('result-summary')
-            );
-        $rows[] = $row;
+
+      // Currently where the "no results" is added.
+	    $count +=1;
+      $query_id = $iteration->{'Iteration_query-ID'};
+      $query_name = $iteration->{'Iteration_query-def'};
+      $row = array(
+        'data' => array(
+           'number' => array('data' => $count , 'class' => array('number')),
+           'query' => array('data' => $query_name, 'class' => array('query')),
+           'hit' => array('data' =>  $iteration->{'Iteration_message'}, 'class' => array('hit')),
+           'evalue' => array('data' => "-", 'class' => array('evalue')),
+           'arrow-col' => array('data' => '', 'class' => array('arrow-col'))
+        ),
+        'class' => array('result-summary')
+      );
+      $rows[] = $row;
 		} // end of else
   }
+
+  // Actually print the table.
   print theme('table', array(
       'header' => $header,
       'rows' => $rows,

+ 3 - 0
theme/blast_ui.theme.inc

@@ -28,6 +28,9 @@ function blast_ui_preprocess_show_blast_report(&$vars) {
   $vars['tsv_filename'] = variable_get('file_public_path', conf_path() . '/files') . '/' . $job_args['output_filename'] . '.blast.tsv';
   $vars['html_filename'] = variable_get('file_public_path', conf_path() . '/files') . '/' . $job_args['output_filename'] . '.blast.html';
 
+  // Add the blast database node.
+  // This is needed for link-out functionality.
+  $vars['blastdb'] = get_blast_database(array('path' => $job_args['database']));
 }
 
 /**