Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure BLAST linkout to allow arrows tracks #27

Closed
bradfordcondon opened this issue Mar 21, 2018 · 4 comments
Closed

configure BLAST linkout to allow arrows tracks #27

bradfordcondon opened this issue Mar 21, 2018 · 4 comments

Comments

@bradfordcondon
Copy link
Member

bradfordcondon commented Mar 21, 2018

Hello,

I was wondering if there's a way to change the styling of the generated Jbrowse blast track.

./includes/blast_ui.linkouts.inc:  $jbrowse_query['addTracks'] = 'addTracks=[{"label":"blast","key":"BLAST Result","type":"JBrowse/View/Track/HTMLFeatures","store":"url"}]';

We've added arrows for orientation of our JBrowse tracks (for our features), and want to do the same for the blast result. We've done it for our tracks by setting the type to "Canvas Feature" and setting the style properties from there.

Does the module already provide a way to do this?

Cheers

B

@laceysanderson
Copy link
Member

Hi @bradfordcondon, sorry for not getting to this question in a timely manner! This cannot be altered through the UI and adding it would complicate the UI without adding a lot of value. That said, the suggestion of changing the track type to the more modern CanvasFeatures feels like a good generic update.

I see in the referenced issue that @almasaeed2010 has already fixed this issue in your site. Perhaps you would like to contribute the change back to the core module? That way you don't have to worry about maintenance complexity :-)

@almasaeed2010
Copy link
Contributor

Hello @laceysanderson

We simply changed the line where the track is defined to use CanvasFeatures as shown here
https://github.com/statonlab/tripal_blast_jbrowse/blob/master/tripal_blast_jbrowse.module#L158

$jbrowse_query['addTracks'] = 'addTracks=[{"label":"blast","key":"BLAST Result","type":"JBrowse/View/Track/CanvasFeatures","store":"url"}]';

In our case, we also wanted to specify the strand's direction by specifying - or + strands to display an arrow in JBrowse which had to be added to the main feature rather than sub features. So we altered the method as follows to make sure the arrow appears only if all the strands of the sub features have the same direction. Here is the full method:

function tripal_blast_generate_linkout_jbrowse($url_prefix, $hit, $info, $options = []) {

  // First we need to collect the HSPs to define the ranges we want to
  // display on the JBrowse.
  $ranges = [];
  // We also keep track of all the coordinates in order to later
  // calculate the smallest and largest coordinate.
  $coords = [];
  $count = 0;
  $strands = [];
  foreach ($info['HSPs'] as $hsp) {
    $count++;

    $strand = '1';
    $hsp_start = $hsp['Hsp_hit-from'];
    $hsp_end = $hsp['Hsp_hit-to'];

    // 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'];
    }

    $strands[] = $strand;

    // Add both the start & stop to the coordinate list.
    array_push($coords, $hsp['Hsp_hit-from'], $hsp['Hsp_hit-to']);

    // Format the hsp for inclusion in the subfeatures section of the track later.
    $hsp_def = format_string(
      '{"start":!start,"end":!end,"strand":"!strand","type":"!type"}',
      [
        '!start' => $hsp_start,
        '!end' => $hsp_end,
        '!strand' => $strand,
        '!type' => 'match_part',
      ]
    );
    array_push($ranges, $hsp_def);
  }
  // Calculate the minimum & maximum coordinates.
  $min = min($coords);
  $max = max($coords);

  // 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.
  $buffer = round(($max - $min) / 6);
  $screen_start = $min - $buffer;
  $screen_end = $max + $buffer;

  // Now we are finally ready to build the URL.
  // First lets set the location of the hit so the JBrowse focuses in on the correct region.
  $jbrowse_query = [];
  $jbrowse_query['loc'] = format_string(
    'loc=!ref:!start..!stop',
    [
      '!ref' => $hit->{'linkout_id'},
      '!start' => $screen_start,
      '!stop' => $screen_end,
    ]
  );

  $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]}]',
      [
        '!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]}]',
      [
        '!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/CanvasFeatures","store":"url"}]';

  $url_postfix = implode('&', $jbrowse_query);

  $hit_url = $url_prefix . $url_postfix;
  return l(
    $hit->{'linkout_id'},
    $hit_url,
    ['attributes' => ['target' => '_blank']]
  );
}

We can create a PR if this implementation seems reasonable enough to you.

Thanks!

@laceysanderson
Copy link
Member

Seems reasonable enough to me :-) A PR would be great 👍

almasaeed2010 added a commit to statonlab/tripal_blast that referenced this issue Apr 10, 2018
laceysanderson added a commit that referenced this issue Apr 19, 2018
@laceysanderson
Copy link
Member

Fixed by PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants