| 
					
				 | 
			
			
				@@ -64,7 +64,7 @@ function blast_ui_blast_linkout_info() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     'require_regex' => FALSE, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     'require_db' => FALSE, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $types['link'] = array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // Human-readable Type name to display to users in the BLAST Database 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // create/edit form. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -73,7 +73,7 @@ function blast_ui_blast_linkout_info() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // This function will have full access to the blast hit and database 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // prefix information and is expected to return a URL. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     'process function' => 'tripal_blast_generate_linkout_link', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // Help text to show in the BLAST Database create/edit form so that  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // Help text to show in the BLAST Database create/edit form so that 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // users will know how to use this link-out type. Specifically, info 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // about your assumptions for the URL prefix are very helpful. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // HTML is aloud but do not enclose in <p>. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -197,13 +197,13 @@ function tripal_blast_generate_linkout_gbrowse($url_prefix, $hit, $info, $option 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // calculate the smallest and largest coordinate. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $coords = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   foreach($info['HSPs'] as $hsp) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $start = min($hsp['Hsp_hit-from'], $hsp['Hsp_hit-to']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $stop = max($hsp['Hsp_hit-from'], $hsp['Hsp_hit-to']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // Format the hsp for inclusion in the new track later. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     array_push($ranges, "$start..$stop"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // Add both the start & stop to the coordinate list. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     array_push($coords, $start, $stop); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -228,7 +228,7 @@ function tripal_blast_generate_linkout_gbrowse($url_prefix, $hit, $info, $option 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       '!hspcoords' => join ("," , $ranges), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // Highlight our newly added feature. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $query['h_feat'] = 'BlastHit'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -236,16 +236,16 @@ function tripal_blast_generate_linkout_gbrowse($url_prefix, $hit, $info, $option 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $url = l( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $hit->{'linkout_id'}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $hit_url, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    array(  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       'query' => $query, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       'attributes' => array('target' => '_blank') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  // For some reason GBrowse expects semi-colons (;&) to delineate query paramters  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // For some reason GBrowse expects semi-colons (;&) to delineate query paramters 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // whereas Drupal throws ampherstands (&) in. This is to fix that. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $url = str_replace('&',';&', $url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   return $url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -259,7 +259,7 @@ function tripal_blast_generate_linkout_gbrowse($url_prefix, $hit, $info, $option 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *  allow your default tracks to be visible and give contect to your blast hit. You 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *  should include "blast" in your jbrowse.conf default track list to ensure your 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *  users can always see their hits. If you don't have access to the jbrowse.conf, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- *  you can place the tracks you want to see including 'blast' in the url prefix  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ *  you can place the tracks you want to see including 'blast' in the url prefix 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *  (see example below under @param $url_prefix). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @param $url_prefix 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -268,7 +268,7 @@ function tripal_blast_generate_linkout_gbrowse($url_prefix, $hit, $info, $option 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *   For example, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *     http://myserver.com/jbrowse/databasica/? 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *     http://myserver.com/jbrowse/databasica/?tracks=myfavtrack,anoktrack,blast& 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- *  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @param $hit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *   The blast XML hit object. This object has the following keys based on the 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  *   XML: Hit_num, Hit_id, Hit_def, Hit_accession, Hit_len and Hit_hsps. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -297,20 +297,22 @@ function tripal_blast_generate_linkout_jbrowse($url_prefix, $hit, $info, $option 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // calculate the smallest and largest coordinate. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $coords = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $count = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  $strands = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   foreach($info['HSPs'] as $hsp) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $count++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $strand = '1'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $hsp_start = $hsp['Hsp_hit-from']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $hsp_end = $hsp['Hsp_hit-to']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $strands[] = $strand; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // Handle alignments on the negative strand. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (($hsp_end - $hsp_start) < 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       $strand = '-1'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       $hsp_start = $hsp['Hsp_hit-to']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       $hsp_end = $hsp['Hsp_hit-from']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // Add both the start & stop to the coordinate list. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     array_push($coords,$hsp['Hsp_hit-from'] , $hsp['Hsp_hit-to'] ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -329,8 +331,8 @@ function tripal_blast_generate_linkout_jbrowse($url_prefix, $hit, $info, $option 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // Calculate the minimum & maximum coordinates. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $min = min($coords); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $max = max($coords); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  // We also want some white-space on either side of out hit  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // We also want some white-space on either side of out hit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // when we show it in the JBrowse. To make this generic, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // we want our blast hit to take up 2/3 of the screen thus 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // we have 1/6 per side for white-space. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -350,19 +352,37 @@ function tripal_blast_generate_linkout_jbrowse($url_prefix, $hit, $info, $option 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  // Next we want to add our BLAST hit to the JBrowse. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  $jbrowse_query['addFeatures'] = format_string( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    'addFeatures=[{"seq_id":"!id","start":!min,"end":!max,"name":"!name","subfeatures":[!hspcoords]}]', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      '!id' => $hit->{'linkout_id'}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      '!name' => $info['query_name'] . ' Blast Hit', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      '!min' => $min, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      '!max' => $max, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      '!hspcoords' => join ("," , $ranges) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    )); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  $unique_strands = array_unique($strands); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  if (count($unique_strands) === 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $strand = end($strands); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // Next we want to add our BLAST hit to the JBrowse. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $jbrowse_query['addFeatures'] = format_string( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'addFeatures=[{"seq_id":"!id","start":!min,"end":!max,"name":"!name","strand":!strand,"subfeatures":[!hspcoords]}]', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!id' => $hit->{'linkout_id'}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!name' => $info['query_name'] . ' Blast Hit', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!min' => $min, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!max' => $max, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!hspcoords' => join(",", $ranges), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!strand' => $strand, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $jbrowse_query['addFeatures'] = format_string( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'addFeatures=[{"seq_id":"!id","start":!min,"end":!max,"name":"!name","subfeatures":[!hspcoords]}]', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!id' => $hit->{'linkout_id'}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!name' => $info['query_name'] . ' Blast Hit', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!min' => $min, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!max' => $max, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        '!hspcoords' => join(",", $ranges), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // Then add a track to display our new feature. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  $jbrowse_query['addTracks'] = 'addTracks=[{"label":"blast","key":"BLAST Result","type":"JBrowse/View/Track/HTMLFeatures","store":"url"}]'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  $jbrowse_query['addTracks'] = 'addTracks=[{"label":"blast","key":"BLAST Result","type":"JBrowse/View/Track/CanvasFeatures","store":"url"}]'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $url_postfix = implode('&', $jbrowse_query); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |