Mercurial > repos > yating-l > hubarchivecreator
comparison TrackDb.py @ 66:4ca7cbf2d9b8 draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 159730602ff500b59aefc7080fb49b726c88d655-dirty
| author | yating-l |
|---|---|
| date | Tue, 26 Sep 2017 16:44:58 -0400 |
| parents | b39dd0b5a166 |
| children | 39a32cb31623 |
comparison
equal
deleted
inserted
replaced
| 65:5a4206366b41 | 66:4ca7cbf2d9b8 |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 import collections | |
| 3 from util import santitizer | |
| 2 | 4 |
| 3 class TrackDb(object): | 5 class TrackDb(object): |
| 4 """docstring for TrackDb""" | 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) | |
| 5 | 20 |
| 6 def __init__(self, trackName="", longLabel="", shortLabel="", trackDataURL="", trackType="", visibility="", | 21 def createTrackDb(self, track_name, long_label, short_label, file_path, track_type, extraSettings = None): |
| 7 thickDrawItem='off', priority="0", track_color="#000000", group_name="Default", database=""): | 22 |
| 8 super(TrackDb, self).__init__() | 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("_", " ") | |
| 9 | 31 |
| 10 self.trackName = trackName | 32 #sanitize the track_name |
| 11 self.longLabel = longLabel | 33 sanitized_name = santitizer.prefixTrackName(track_name) |
| 12 self.shortLabel = shortLabel | 34 |
| 13 self.trackDataURL = trackDataURL | 35 self.track_db = collections.OrderedDict([("track",sanitized_name), |
| 14 self.trackType = trackType | 36 ("type",track_type), |
| 15 self.visibility = visibility | 37 ("shortLabel",short_label), |
| 16 self.thickDrawItem = thickDrawItem | 38 ("longLabel",long_label), |
| 17 self.priority = priority | 39 ("bigDataUrl",data_url)] |
| 18 self.track_color = track_color | 40 ) |
| 19 self.group_name = group_name | 41 |
| 20 self.database = database | 42 |
| 21 | 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: | |
| 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 |
