123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- <?php
- function blast_ui_blast_linkout_info() {
- $types = array();
-
- $types['none'] = array(
- 'name' => 'None',
- 'process function' => 'tripal_blast_generate_linkout_none',
- 'help' => 'This will leave the blast results hits as plain text.',
- 'require_regex' => FALSE,
- 'require_db' => FALSE,
- );
- $types['link'] = array(
-
-
- 'name' => 'Generic Link',
-
-
-
- 'process function' => 'tripal_blast_generate_linkout_link',
-
-
-
-
- 'help' => 'The External Database choosen below provides its URL prefix when
- determining the URL to link-out to. If the link-out type is "Generic Link" then
- the hit identifier (determined using fasta header format or regular expression) is
- concatenated to the end of the url prefix. For example, if your hit is for "Chr01"
- and the URL prefix is "http://myfriendstripalsite.org/name/" then the complete URL
- is simply <a href="http://myfriendstripalsite.org/name/Chr01">Chr01</a>.',
-
- 'require_regex' => TRUE,
- 'require_db' => TRUE,
- );
- $types['gbrowse'] = array(
- 'name' => 'GBrowse',
- 'process function' => 'tripal_blast_generate_linkout_gbrowse',
- 'help' => 'The link created will add a BLAST track to the GBrowse (specified by the
- External Database) that shows the HSPs as well as indicating the overall hit.
- <strong><em>It is assumed that the Reference of the GBrowse is the same as this BLAST
- database (even the names must be consistent).</em></strong> Furthermore, the URL prefix
- supplied is expected to have an empty query (?) or be properly ended (;). For
- example, "http://mydomain.com/gb/gbrowse/tripalus_databasica/?" OR
- "http://mydomain.com/gb/gbrowse/tripalus_databasica/?label=genes+markers;"',
-
- 'require_regex' => TRUE,
- 'require_db' => TRUE,
- );
- $types['jbrowse'] = array(
- 'name' => 'JBrowse',
- 'process function' => 'tripal_blast_generate_linkout_jbrowse',
- 'help' => 'The link created will add a "Blast Result" track to the JBrowse (specified by the
- External Database) that shows the HSPs as well as indicating the overall hit.
- <strong><em>It is assumed that the Reference of the JBrowse is the same as this BLAST
- database (even the names must be consistent).</em></strong> Furthermore, the URL prefix
- supplied is expected to have an empty query (?) or be properly ended (&). For
- example, "http://mydomain.com/jbrowse/tripalus_databasica/?" OR
- "http://mydomain.com/jbrowse/tripalus_databasica/?tracks=genes,markers,blast&".
- Also <strong><em>the Blast Result track is NOT Displayed by default</em></strong>. Either include "blast"
- using the "tracks" directive in the URL prefix or specify it in your JBrowse.conf.',
-
- 'require_regex' => TRUE,
- 'require_db' => TRUE,
- );
- return $types;
- }
- function tripal_blast_generate_linkout_link($url_prefix, $hit, $info, $options = array()) {
- if (isset($hit->{'linkout_id'})) {
- $hit_url = $url_prefix . $hit->{'linkout_id'};
-
-
- $params = array();
- if (!$paramstr=strstr($hit_url, '?')) {
- $url_prefix = $hit_url;
- }
- else {
- $url_parts = preg_split("/\?/", $hit_url);
- $url_prefix = $url_parts[0];
- $param_list = preg_split("/\&/", $url_parts[1]);
- foreach ($param_list as $param) {
- $param_parts = preg_split("/=/", $param, 2);
- $params[$param_parts[0]] = $param_parts[1];
- }
- }
-
- return l(
- $hit->{'linkout_id'},
- $url_prefix,
- array('attributes' => array('target' => '_blank'), 'query' => $params)
- );
- }
- else {
- return FALSE;
- }
- }
- function tripal_blast_generate_linkout_gbrowse($url_prefix, $hit, $info, $options = array()) {
-
-
- $ranges = array();
-
-
- $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']);
-
- array_push($ranges, "$start..$stop");
-
- array_push($coords, $start, $stop);
- }
-
- $min = min($coords);
- $max = max($coords);
-
-
- $query = array();
- $query['ref'] = $hit->{'linkout_id'};
- $query['start'] = $min;
- $query['stop'] = $max;
-
- $query['add'] = format_string(
- '!ref !trackname !featurename !hspcoords',
- array(
- '!ref' => $hit->{'linkout_id'},
- '!trackname' => 'BLAST',
- '!featurename' => 'BlastHit',
- '!hspcoords' => join ("," , $ranges),
- )
- );
-
- $query['h_feat'] = 'BlastHit';
- $hit_url = $url_prefix;
- $url = l(
- $hit->{'linkout_id'},
- $hit_url,
- array(
- 'query' => $query,
- 'attributes' => array('target' => '_blank')
- )
- );
-
-
- $url = str_replace('&',';&', $url);
- return $url;
- }
- function tripal_blast_generate_linkout_jbrowse($url_prefix, $hit, $info, $options = array()) {
-
-
- $ranges = array();
-
-
- $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;
-
- if (($hsp_end - $hsp_start) < 0) {
- $strand = '-1';
- $hsp_start = $hsp['Hsp_hit-to'];
- $hsp_end = $hsp['Hsp_hit-from'];
- }
-
- array_push($coords,$hsp['Hsp_hit-from'] , $hsp['Hsp_hit-to'] );
-
- $hsp_def = format_string(
- '{"start":!start,"end":!end,"strand":"!strand","type":"!type"}',
- array(
- '!start' => $hsp_start,
- '!end' => $hsp_end,
- '!strand' => $strand,
- '!type' => 'match_part'
- )
- );
- array_push($ranges, $hsp_def);
- }
-
- $min = min($coords);
- $max = max($coords);
-
-
-
-
- $buffer = round(($max - $min) / 6);
- $screen_start = $min - $buffer;
- $screen_end = $max + $buffer;
-
-
- $jbrowse_query = array();
- $jbrowse_query['loc'] = format_string(
- 'loc=!ref:!start..!stop',
- array(
- '!ref' => $hit->{'linkout_id'},
- '!start' => $screen_start,
- '!stop' => $screen_end,
- )
- );
- $unique_strands = array_unique($strands);
- if (count($unique_strands) === 1) {
- $strand = end($strands);
-
- $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),
- )
- );
- }
-
- $jbrowse_query['addTracks'] = 'addTracks=[{"label":"blast","key":"BLAST Result","type":"JBrowse/View/Track/CanvasFeatures","store":"url"}]';
- $url_postfix = implode('&', $jbrowse_query);
- $hit_url = $url_prefix . $url_postfix;
- return l(
- $hit->{'linkout_id'},
- $hit_url,
- array('attributes' => array('target' => '_blank'))
- );
- }
|