Pass additional information to the trackhub.
authorDiane Trout <diane@caltech.edu>
Mon, 21 Oct 2013 21:51:14 +0000 (14:51 -0700)
committerDiane Trout <diane@caltech.edu>
Mon, 21 Oct 2013 21:51:14 +0000 (14:51 -0700)
This allows adding a term to control visibility of tracks.

There's also a hack to pull out the min/max bigWig values when generating
the trackDb.txt file.

It unfortunately depends on having bigWigInfo from UCSC on your path.

htsworkflow/submission/trackhub_submission.py
htsworkflow/templates/trackhub_samples.sparql

index 7a83e8770ee39515ffe90fa223bce3ea19767e47..e383175a16884c3d1d24a69042bf916a44aa71c9 100644 (file)
@@ -1,5 +1,6 @@
 import logging
 import os
+from pprint import pformat
 import string
 import re
 
@@ -13,6 +14,7 @@ from htsworkflow.util.rdfhelp import \
      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
@@ -104,20 +106,24 @@ class TrackHubSubmission(Submission):
             track_name = self.make_track_name(track)
 
             track_subgroup = self.make_track_subgroups(subgroups, track)
+            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
 
-            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=str(track_label),
-                subgroups=track_subgroup,
-                )
+            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()
@@ -136,13 +142,20 @@ class TrackHubSubmission(Submission):
         """
         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
@@ -173,6 +186,21 @@ class TrackHubSubmission(Submission):
                 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"""
index 95152747b43a5ed4109e8dd8fb020edb120bfc80..6259fce15d646aba5864e91d23f22823ce233cac 100644 (file)
@@ -4,14 +4,18 @@ PREFIX htswlib: <http://jumpgate.caltech.edu/wiki/LibraryOntology#>
 PREFIX submissionOntology: <http://jumpgate.caltech.edu/wiki/UcscSubmissionOntology#>
 PREFIX ucscDaf: <http://jumpgate.caltech.edu/wiki/UcscDaf#>
 PREFIX ncbiTaxon: <http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=>
+PREFIX trackdb: <http://genome.ucsc.edu/goldenPath/help/trackDb/trackDbHub.html#>
 PREFIX geoSoft: <http://www.ncbi.nlm.nih.gov/geo/info/soft2.html#>
 PREFIX cells: <http://encodewiki.ucsc.edu/EncodeDCC/index.php/Cell_lines#>
 PREFIX encode3: <http://jumpgate.caltech.edu/wiki/Encode3#>
 
-select distinct ?lab_library_id ?library_id ?filename ?relative_path ?output_type ?file_type ?cell ?replicate ?assay ?rna_type ?protocol ?file_label
+select distinct ?lab_library_id ?library_id ?filename ?relative_path ?output_type ?file_type ?cell ?replicate ?assay ?rna_type ?protocol ?file_label ?autoScale ?maxHeightPixels ?visibility
 WHERE {
-  ?trackType geoSoft:fileTypeLabel ?file_type ;
+  ?trackType trackdb:type ?file_type ;
              ucscDaf:output_type ?output_type .
+  OPTIONAL { ?trackType trackdb:autoScale ?autoScale . }
+  OPTIONAL { ?trackType trackdb:maxHeightPixels ?maxHeightPixels . }
+  OPTIONAL { ?trackType trackdb:visibility ?visibility . }
   ?file ucscDaf:filename ?filename ;
         ucscDaf:relative_path ?relative_path ;
         htswlib:library ?library ;