Mercurial > repos > rmarenco > hubarchivecreator
comparison TrackHub.py @ 17:c02720d1afee draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1adbf397de1fc7af4d91e026093d7fff983e21cf
author | rmarenco |
---|---|
date | Fri, 30 Sep 2016 15:14:24 -0400 |
parents | 3233451a3bd6 |
children | d786bca6a75d |
comparison
equal
deleted
inserted
replaced
16:3233451a3bd6 | 17:c02720d1afee |
---|---|
31 self.genome_name = inputFastaFile.assembly_id | 31 self.genome_name = inputFastaFile.assembly_id |
32 self.specie_html = self.genome_name + '.html' | 32 self.specie_html = self.genome_name + '.html' |
33 self.default_pos = None | 33 self.default_pos = None |
34 self.user_email = user_email | 34 self.user_email = user_email |
35 | 35 |
36 # Set containing the groups already added. Updated by addGroup() | |
37 self.groups = set() | |
38 | |
36 # TODO: Modify according to the files passed in parameter | 39 # TODO: Modify according to the files passed in parameter |
40 # ---- Templates ---- | |
41 # Template trackDb | |
37 mylookup = TemplateLookup(directories=[os.path.join(tool_directory, 'templates/trackDb')], | 42 mylookup = TemplateLookup(directories=[os.path.join(tool_directory, 'templates/trackDb')], |
38 output_encoding='utf-8', encoding_errors='replace') | 43 output_encoding='utf-8', encoding_errors='replace') |
39 self.trackDbTemplate = mylookup.get_template("layout.txt") | 44 self.trackDbTemplate = mylookup.get_template("layout.txt") |
45 | |
46 # Template groups | |
47 mylookup = TemplateLookup(directories=[os.path.join(self.tool_directory, 'templates/groupsTxt')], | |
48 output_encoding='utf-8', encoding_errors='replace') | |
49 self.groupsTemplate = mylookup.get_template("layout.txt") | |
50 | |
51 # ---- End Templates ---- | |
40 | 52 |
41 self.extra_files_path = extra_files_path | 53 self.extra_files_path = extra_files_path |
42 self.outputFile = outputFile | 54 self.outputFile = outputFile |
43 | 55 |
44 # Create the structure of the Assembly Hub | 56 # Create the structure of the Assembly Hub |
66 self.outputZip.close() | 78 self.outputZip.close() |
67 | 79 |
68 def addTrack(self, trackDbObject=None): | 80 def addTrack(self, trackDbObject=None): |
69 # Create the trackDb.txt file in the specie folder, if not exists | 81 # Create the trackDb.txt file in the specie folder, if not exists |
70 # Else append the new track | 82 # Else append the new track |
83 # TODO: Get this out of the function | |
71 trackDbTxtFilePath = os.path.join(self.mySpecieFolderPath, 'trackDb.txt') | 84 trackDbTxtFilePath = os.path.join(self.mySpecieFolderPath, 'trackDb.txt') |
72 | 85 |
73 # Append to trackDbTxtFilePath the trackDbTemplate populate with the newTrack object | 86 # Append to trackDbTxtFilePath the trackDbTemplate populate with the newTrack object |
74 with open(trackDbTxtFilePath, 'a+') as trackDbFile: | 87 with open(trackDbTxtFilePath, 'a+') as trackDbFile: |
75 trackDbs = [trackDbObject] | 88 trackDbs = [trackDbObject] |
89 | |
90 # TODO: The addGroup does not belong here. Move it when the group becomes more than just a label | |
91 # Add the group as well, if exists in trackDbObject | |
92 self.addGroup(trackDbObject.group_name) | |
93 | |
76 htmlMakoRendered = self.trackDbTemplate.render( | 94 htmlMakoRendered = self.trackDbTemplate.render( |
77 trackDbs=trackDbs | 95 trackDbs=trackDbs |
78 ) | 96 ) |
79 trackDbFile.write(htmlMakoRendered) | 97 trackDbFile.write(htmlMakoRendered) |
98 | |
99 def addGroup(self, group_name="Default"): | |
100 # If not already present in self.groups, add to groups.txt | |
101 # Create the trackDb.txt file in the specie folder, if not exists | |
102 # Else append the new track | |
103 # TODO: Get this out of the function | |
104 groupsTxtFilePath = os.path.join(self.mySpecieFolderPath, 'groups.txt') | |
105 | |
106 # If the group is already present, we don't need to add it | |
107 if group_name in self.groups: | |
108 return | |
109 | |
110 # Append to trackDbTxtFilePath the trackDbTemplate populate with the newTrack object | |
111 with open(groupsTxtFilePath, 'a+') as groupFile: | |
112 # Add the group as well, if exists in trackDbObject | |
113 | |
114 htmlMakoRendered = self.groupsTemplate.render( | |
115 label=group_name | |
116 ) | |
117 groupFile.write(htmlMakoRendered) | |
118 self.groups.add(group_name) | |
80 | 119 |
81 def terminate(self): | 120 def terminate(self): |
82 # Just a test to output a simple HTML | 121 # Just a test to output a simple HTML |
83 # TODO: Create a class to handle the file object | 122 # TODO: Create a class to handle the file object |
84 mylookup = TemplateLookup(directories=[os.path.join(self.tool_directory, 'templates')], | 123 mylookup = TemplateLookup(directories=[os.path.join(self.tool_directory, 'templates')], |
180 descriptionHtmlFilePath = os.path.join(mySpecieFolderPath, 'description.html') | 219 descriptionHtmlFilePath = os.path.join(mySpecieFolderPath, 'description.html') |
181 self.__fillDescriptionHtmlFile__(descriptionHtmlFilePath) | 220 self.__fillDescriptionHtmlFile__(descriptionHtmlFilePath) |
182 | 221 |
183 # Create the file groups.txt | 222 # Create the file groups.txt |
184 # TODO: If not inputs for this, do no create the file | 223 # TODO: If not inputs for this, do no create the file |
185 groupsTxtFilePath = os.path.join(mySpecieFolderPath, 'groups.txt') | 224 # groupsTxtFilePath = os.path.join(mySpecieFolderPath, 'groups.txt') |
186 self.__fillGroupsTxtFile__(groupsTxtFilePath) | 225 # self.__fillGroupsTxtFile__(groupsTxtFilePath) |
187 | 226 |
188 # Create the folder tracks into the specie folder | 227 # Create the folder tracks into the specie folder |
189 tracksFolderPath = os.path.join(mySpecieFolderPath, "tracks") | 228 tracksFolderPath = os.path.join(mySpecieFolderPath, "tracks") |
190 if not os.path.exists(tracksFolderPath): | 229 if not os.path.exists(tracksFolderPath): |
191 os.makedirs(tracksFolderPath) | 230 os.makedirs(tracksFolderPath) |