from collections import namedtuple

Junction = namedtuple('Junction',
        ['ref', 'ref_count', 'contig', 'contig_count'])


def get_ref_jbrowse_link(contig, loc):
        return (contig.parent_reference_genome.get_client_jbrowse_link() +
                '&loc=' + str(loc))


def decorate_with_link_to_loc(contig, loc, text):
    return ('<a href="' + get_ref_jbrowse_link(contig, loc) +
        '&tracks=' + contig.get_contig_reads_track() +
        '" target="_blank">' + text + '</a>')


def make_html_list(li, css_class='list-unstyled'):
    return ('<ul class="' + css_class + '"><li>' +
            '</li><li>'.join(li) +
            '</li></ul>')


def create_contig_junction_links(contig, junctions):
    link_list = ['<span>&rarr;</span>'.join(
            [decorate_with_link_to_loc(contig, j.ref,
                    '%s(%s)' % (j.ref, j.ref_count)),
            '%s(%s)' % (j.contig, j.contig_count)])
            for j in map(Junction._make, junctions)]
    return make_html_list(link_list)

from collections import namedtuple

import settings


Junction = namedtuple('Junction',
        ['ref', 'ref_count', 'contig', 'contig_count'])


def get_ref_jbrowse_link(contig, loc):
    sample_alignment = contig.experiment_sample_to_alignment
    bam_dataset = sample_alignment.dataset_set.get(
            type='BWA BAM')

    sample_bam_track = '_'.join([
            bam_dataset.internal_string(sample_alignment.experiment_sample),
            str(sample_alignment.alignment_group.uid)])

    track_labels = settings.JBROWSE_DEFAULT_TRACKS + [sample_bam_track]
    return (contig.parent_reference_genome.get_client_jbrowse_link() +
            '&loc=' + str(loc) +
            '&tracks=' + ','.join(track_labels))


def decorate_with_link_to_loc(contig, loc, text):
    return ('<a href="' + get_ref_jbrowse_link(contig, loc) +
        ',' + contig.get_contig_reads_track() +
        '" target="_blank">' + text + '</a>')


def make_html_list(li, css_class='list-unstyled'):
    return ('<ul class="' + css_class + '"><li>' +
            '</li><li>'.join(li) +
            '</li></ul>')


def create_contig_junction_links(contig, junctions):
    link_list = ['<span>&rarr;</span>'.join(
            [decorate_with_link_to_loc(contig, j.ref,
                    '%s(%s)' % (j.ref, j.ref_count)),
            '%s(%s)' % (j.contig, j.contig_count)])
            for j in map(Junction._make, junctions)]
    return make_html_list(link_list)

Include more tracks in jbrowsing of junctions
Include more tracks in jbrowsing of junctions

  from collections import namedtuple
+ 
+ import settings
+ 
  
  Junction = namedtuple('Junction',
          ['ref', 'ref_count', 'contig', 'contig_count'])
  
  
  def get_ref_jbrowse_link(contig, loc):
+     sample_alignment = contig.experiment_sample_to_alignment
+     bam_dataset = sample_alignment.dataset_set.get(
+             type='BWA BAM')
+ 
+     sample_bam_track = '_'.join([
+             bam_dataset.internal_string(sample_alignment.experiment_sample),
+             str(sample_alignment.alignment_group.uid)])
+ 
+     track_labels = settings.JBROWSE_DEFAULT_TRACKS + [sample_bam_track]
-         return (contig.parent_reference_genome.get_client_jbrowse_link() +
+     return (contig.parent_reference_genome.get_client_jbrowse_link() +
-                 '&loc=' + str(loc))
+             '&loc=' + str(loc) +
+             '&tracks=' + ','.join(track_labels))
  
  
  def decorate_with_link_to_loc(contig, loc, text):
      return ('<a href="' + get_ref_jbrowse_link(contig, loc) +
-         '&tracks=' + contig.get_contig_reads_track() +
+         ',' + contig.get_contig_reads_track() +
          '" target="_blank">' + text + '</a>')
  
  
  def make_html_list(li, css_class='list-unstyled'):
      return ('<ul class="' + css_class + '"><li>' +
              '</li><li>'.join(li) +
              '</li></ul>')
  
  
  def create_contig_junction_links(contig, junctions):
      link_list = ['<span>&rarr;</span>'.join(
              [decorate_with_link_to_loc(contig, j.ref,
                      '%s(%s)' % (j.ref, j.ref_count)),
              '%s(%s)' % (j.contig, j.contig_count)])
              for j in map(Junction._make, junctions)]
      return make_html_list(link_list)
  
Include more tracks in jbrowsing of junctions
## Code Before:
from collections import namedtuple

Junction = namedtuple('Junction',
        ['ref', 'ref_count', 'contig', 'contig_count'])


def get_ref_jbrowse_link(contig, loc):
        return (contig.parent_reference_genome.get_client_jbrowse_link() +
                '&loc=' + str(loc))


def decorate_with_link_to_loc(contig, loc, text):
    return ('<a href="' + get_ref_jbrowse_link(contig, loc) +
        '&tracks=' + contig.get_contig_reads_track() +
        '" target="_blank">' + text + '</a>')


def make_html_list(li, css_class='list-unstyled'):
    return ('<ul class="' + css_class + '"><li>' +
            '</li><li>'.join(li) +
            '</li></ul>')


def create_contig_junction_links(contig, junctions):
    link_list = ['<span>&rarr;</span>'.join(
            [decorate_with_link_to_loc(contig, j.ref,
                    '%s(%s)' % (j.ref, j.ref_count)),
            '%s(%s)' % (j.contig, j.contig_count)])
            for j in map(Junction._make, junctions)]
    return make_html_list(link_list)

## Instruction:
Include more tracks in jbrowsing of junctions
## Code After:
from collections import namedtuple

import settings


Junction = namedtuple('Junction',
        ['ref', 'ref_count', 'contig', 'contig_count'])


def get_ref_jbrowse_link(contig, loc):
    sample_alignment = contig.experiment_sample_to_alignment
    bam_dataset = sample_alignment.dataset_set.get(
            type='BWA BAM')

    sample_bam_track = '_'.join([
            bam_dataset.internal_string(sample_alignment.experiment_sample),
            str(sample_alignment.alignment_group.uid)])

    track_labels = settings.JBROWSE_DEFAULT_TRACKS + [sample_bam_track]
    return (contig.parent_reference_genome.get_client_jbrowse_link() +
            '&loc=' + str(loc) +
            '&tracks=' + ','.join(track_labels))


def decorate_with_link_to_loc(contig, loc, text):
    return ('<a href="' + get_ref_jbrowse_link(contig, loc) +
        ',' + contig.get_contig_reads_track() +
        '" target="_blank">' + text + '</a>')


def make_html_list(li, css_class='list-unstyled'):
    return ('<ul class="' + css_class + '"><li>' +
            '</li><li>'.join(li) +
            '</li></ul>')


def create_contig_junction_links(contig, junctions):
    link_list = ['<span>&rarr;</span>'.join(
            [decorate_with_link_to_loc(contig, j.ref,
                    '%s(%s)' % (j.ref, j.ref_count)),
            '%s(%s)' % (j.contig, j.contig_count)])
            for j in map(Junction._make, junctions)]
    return make_html_list(link_list)
