GithubHelp home page GithubHelp logo

Comments (4)

laceysanderson avatar laceysanderson commented on June 26, 2024

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 :-)

from tripal_blast.

almasaeed2010 avatar almasaeed2010 commented on June 26, 2024

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!

from tripal_blast.

laceysanderson avatar laceysanderson commented on June 26, 2024

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

from tripal_blast.

laceysanderson avatar laceysanderson commented on June 26, 2024

Fixed by PRs

from tripal_blast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.