annotate TrackDb.py @ 85:a65e52152476 draft default tip

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