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