annotate TrackDb.py @ 30:e7c4be523cb7 draft

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