import logging
import os
+from pprint import pformat
+import string
import re
import RDF
from htsworkflow.util.rdfhelp import \
fromTypedNode, \
geoSoftNS, \
- stripNamespace, \
submissionOntology
from htsworkflow.util.url import parse_ssh_url
+from htsworkflow.util.ucsc import bigWigInfo
from django.conf import settings
from django.template import Context, loader
name=self.sanitize_name(self.name),
short_label = self.sanitize_name(self.name),
long_label = str(self.name),
- tracktype="bigWig",
+ tracktype="bed 3",
dragAndDrop='subtracks',
visibility='full',
)
track_name = self.make_track_name(track)
track_subgroup = self.make_track_subgroups(subgroups, track)
-
- newtrack = Track(
- name=track_name,
- tracktype = str(track['file_type']),
- url= hub_url + str(track['relative_path']),
- short_label=str(track['library_id']),
- long_label=track_name,
- subgroups=track_subgroup,
- )
+ track_type = self.make_track_type(track)
+
+ if 'file_label' in track:
+ track_label = self.sanitize_name(track['file_label'])
+ else:
+ track_label = track_name
+
+ attributes = {
+ 'name': track_name,
+ 'tracktype': track_type,
+ 'url': hub_url + str(track['relative_path']),
+ 'short_label': str(track['library_id']),
+ 'long_label': str(track_label),
+ 'subgroups': track_subgroup,
+ }
+
+ LOGGER.debug('track attributes: %s', pformat(attributes))
+ newtrack = Track(**attributes)
view.add_tracks([newtrack])
results = hub.render()
"""
current_view_type = str(track['output_type'])
if not view or current_view_type != view.name:
- view = ViewTrack(
- name=current_view_type,
- view=current_view_type,
- visibility='squish',
- short_label=current_view_type,
- tracktype=str(track['file_type']),
- )
+ attributes = {
+ 'name': current_view_type,
+ 'view': current_view_type,
+ 'visibility': str(track.get('visibility', 'squish')),
+ 'short_label': current_view_type,
+ 'tracktype': str(track['file_type'])
+ }
+ maxHeightPixels = track.get('maxHeightPixels')
+ if maxHeightPixels:
+ attributes['maxHeightPixels'] = str(maxHeightPixels)
+ autoScale = track.get('autoScale')
+ if autoScale:
+ attributes['autoScale'] = str(autoScale)
+ view = ViewTrack(**attributes)
composite.add_view(view)
view_type = current_view_type
return view
return str(template.render(context))
def make_track_name(self, track):
- name = '{}_{}_{}'.format(
+ return '{}_{}_{}'.format(
track['library_id'],
track['replicate'],
track['output_type'],
)
- return name
def make_track_subgroups(self, subgroups, track):
track_subgroups = {}
value = self.sanitize_name(track[k])
track_subgroups[k] = value
return track_subgroups
+
+ def make_track_type(self, track):
+ """Further annotate tracktype.
+
+ bigWig files can have additional information. Add it if we can
+ """
+ track_type = track['file_type']
+ if track_type.lower() == 'bigwig':
+ # something we can enhance
+ info = bigWigInfo(track['relative_path'])
+ if info.min is not None and info.max is not None:
+ track_type = '{} {} {}'.format(track_type, int(info.min), int(info.max))
+
+ LOGGER.debug("track_type: %s", track_type)
+ return str(track_type)
def add_subgroups(self, composite):
"""Add subgroups to composite track"""
search = [ ('htswlib:cell_line', 'cell'),
+ ('encode3:rna_type', 'rna_type'),
+ ('encode3:protocol', 'protocol'),
('htswlib:replicate', 'replicate'),
('encode3:library_id', 'library_id'),
('encode3:assay', 'assay'),
- ('encode3:rna_type', 'rna_type'),
- ('encode3:protocol', 'protocol'),
]
subgroups = []
names = []
+ sortorder = []
+ dimnames = ('dim{}'.format(x) for x in string.ascii_uppercase)
+ dimensions = []
+ filtercomposite = []
for term, name in search:
- subgroups.append(self.make_subgroupdefinition(term, name))
- names.append(name)
+ definitions = self.make_subgroupdefinition(term, name)
+ if definitions:
+ subgroups.append(definitions)
+ names.append(name)
+ sortorder.append("{}=+".format(name))
+ d = dimnames.next()
+ dimensions.append("{}={}".format(d, name))
+ filtercomposite.append("{}=multi".format(d))
+
composite.add_subgroups(subgroups)
+ composite.add_params(sortOrder=' '.join(sortorder))
+ composite.add_params(dimensions=' '.join(dimensions))
+ composite.add_params(filterComposite=' '.join(filtercomposite))
return names
value = str(row['name'])
values[self.sanitize_name(value)] = value
- return SubGroupDefinition(
- name=name,
- label=name,
- mapping=values,
- )
+ if values:
+ return SubGroupDefinition(
+ name=name,
+ label=name,
+ mapping=values,
+ )
+ else:
+ return None
def get_tracks(self):
"""Collect information needed to describe trackhub tracks.
return name
def get_manifest_metadata(self, analysis_node):
-
query_template = loader.get_template('trackhub_manifest.sparql')
context = Context({