Mercurial > repos > yating-l > hubarchivecreatortest
annotate TrackDb.py @ 1:85195e0d4b71 draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
| author | yating-l | 
|---|---|
| date | Fri, 29 Sep 2017 13:32:23 -0400 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 1 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 1 #!/usr/bin/python | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 2 import collections | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 3 from util import santitizer | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 4 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 5 class TrackDb(object): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 6 """docstring for TrackDb""" | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 7 def __init__(self, trackName="", longLabel="", shortLabel="", trackDataURL="", trackType="", extraSettings=None): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 8 #super(TrackDb, self).__init__() | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 9 not_init_message = "The {0} is not initialized." | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 10 if trackName is None: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 11 raise TypeError(not_init_message.format('trackName')) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 12 if longLabel is None: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 13 raise TypeError(not_init_message.format('longLabel')) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 14 if trackType is None: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 15 raise TypeError(not_init_message.format('trackType')) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 16 if trackDataURL is None: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 17 raise TypeError(not_init_message.format('trackDataURL')) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 18 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 19 self.createTrackDb(trackName, longLabel, shortLabel, trackDataURL, trackType, extraSettings) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 20 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 21 def createTrackDb(self, track_name, long_label, short_label, file_path, track_type, extraSettings = None): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 22 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 23 # TODO: Remove the hardcoded "tracks" by the value used as variable from myTrackFolderPath | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 24 data_url = "tracks/%s" % track_name | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 25 if not short_label: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 26 short_label = TrackDb.getShortName(long_label) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 27 # Replace '_' by ' ', to invert the sanitization mecanism | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 28 # TODO: Find a better way to manage the sanitization of file path | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 29 long_label = long_label.replace("_", " ") | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 30 short_label = short_label.replace("_", " ") | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 31 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 32 #sanitize the track_name | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 33 sanitized_name = santitizer.prefixTrackName(track_name) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 34 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 35 self.track_db = collections.OrderedDict([("track",sanitized_name), | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 36 ("type",track_type), | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 37 ("shortLabel",short_label), | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 38 ("longLabel",long_label), | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 39 ("bigDataUrl",data_url)] | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 40 ) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 41 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 42 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 43 TrackDb.prepareExtraSetting(extraSettings) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 44 self.track_db.update(extraSettings) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 45 #print self.track_db | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 46 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 47 # TODO: Rename for PEP8 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 48 @staticmethod | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 49 def getShortName(name_to_shortify): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 50 # Slice to get from Long label the short label | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 51 short_label_slice = slice(0, 17) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 52 return name_to_shortify[short_label_slice] | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 53 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 54 @staticmethod | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 55 def getRgb(track_color): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 56 #TODO: Check if rgb or hexa | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 57 # Convert hexa to rgb array | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 58 hexa_without_sharp = track_color.lstrip('#') | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 59 rgb_array = [int(hexa_without_sharp[i:i+2], 16) for i in (0, 2, 4)] | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 60 rgb_ucsc = ','.join(map(str, rgb_array)) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 61 return rgb_ucsc | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 62 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 63 @staticmethod | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 64 def prepareExtraSetting(extraSettings): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 65 if not extraSettings: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 66 extraSettings = collections.OrderedDict() | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 67 if not "color" in extraSettings: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 68 extraSettings["color"] = "#000000" | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 69 extraSettings["color"] = TrackDb.getRgb(extraSettings["color"]) | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 70 if not "group" in extraSettings or not extraSettings["group"]: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 71 extraSettings["group"] = "Default group" | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 72 if not "thickDrawItem" in extraSettings: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 73 extraSettings["thickDrawItem"] = "off" | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 74 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 75 def get(self, item_name): | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 76 if item_name in self.track_db: | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 77 return self.track_db[item_name] | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 78 return None | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 79 | 
| 
85195e0d4b71
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
 yating-l parents: diff
changeset | 80 | 
