Mercurial > repos > rmarenco > hubarchivecreator
comparison TrackHub.py @ 29:7e8a8b732db3 draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1a81ebd0ddea950b84af3fc830e9267a4814b29f
author | yating-l |
---|---|
date | Wed, 16 May 2018 18:04:20 -0400 |
parents | d786bca6a75d |
children |
comparison
equal
deleted
inserted
replaced
28:6aa28a85cc38 | 29:7e8a8b732db3 |
---|---|
4 import logging | 4 import logging |
5 import os | 5 import os |
6 import tempfile | 6 import tempfile |
7 import shutil | 7 import shutil |
8 import zipfile | 8 import zipfile |
9 from mako.lookup import TemplateLookup | |
9 | 10 |
10 # Internal dependencies | 11 # Internal dependencies |
11 from Datatype import Datatype | 12 from datatypes.Datatype import Datatype |
12 from util import subtools | 13 from util import subtools |
13 | 14 from util import santitizer |
14 from mako.lookup import TemplateLookup | 15 |
16 | |
15 | 17 |
16 | 18 |
17 class TrackHub(object): | 19 class TrackHub(object): |
18 """docstring for TrackHub""" | 20 """docstring for TrackHub""" |
19 | 21 |
20 def __init__(self, inputFastaFile, user_email, outputFile, extra_files_path, tool_directory): | 22 def __init__(self, inputFastaFile, user_email, outputFile, extra_files_path, tool_directory): |
21 super(TrackHub, self).__init__() | 23 super(TrackHub, self).__init__() |
22 | |
23 self.rootAssemblyHub = None | 24 self.rootAssemblyHub = None |
24 | 25 |
25 self.mySpecieFolderPath = None | 26 self.mySpecieFolderPath = None |
26 self.myTracksFolderPath = None | 27 self.myTracksFolderPath = None |
27 self.tool_directory = tool_directory | 28 self.tool_directory = tool_directory |
66 | 67 |
67 # Init the Datatype | 68 # Init the Datatype |
68 Datatype.pre_init(self.reference_genome, self.two_bit_final_path, self.chromSizesFile, | 69 Datatype.pre_init(self.reference_genome, self.two_bit_final_path, self.chromSizesFile, |
69 self.extra_files_path, self.tool_directory, | 70 self.extra_files_path, self.tool_directory, |
70 self.mySpecieFolderPath, self.myTracksFolderPath) | 71 self.mySpecieFolderPath, self.myTracksFolderPath) |
71 | 72 ''' |
72 def createZip(self): | 73 def createZip(self): |
73 for root, dirs, files in os.walk(self.rootAssemblyHub): | 74 for root, dirs, files in os.walk(self.rootAssemblyHub): |
74 # Get all files and construct the dir at the same time | 75 # Get all files and construct the dir at the same time |
75 for file in files: | 76 for file in files: |
76 self.outputZip.write(os.path.join(root, file)) | 77 self.outputZip.write(os.path.join(root, file)) |
77 | 78 |
78 self.outputZip.close() | 79 self.outputZip.close() |
79 | 80 ''' |
80 def addTrack(self, trackDbObject=None): | 81 def addTrack(self, trackDbObject=None): |
81 # Create the trackDb.txt file in the specie folder, if not exists | 82 # Create the trackDb.txt file in the specie folder, if not exists |
82 # Else append the new track | 83 # Else append the new track |
83 # TODO: Get this out of the function | 84 # TODO: Get this out of the function |
84 trackDbTxtFilePath = os.path.join(self.mySpecieFolderPath, 'trackDb.txt') | 85 trackDbTxtFilePath = os.path.join(self.mySpecieFolderPath, 'trackDb.txt') |
85 | |
86 # Append to trackDbTxtFilePath the trackDbTemplate populate with the newTrack object | 86 # Append to trackDbTxtFilePath the trackDbTemplate populate with the newTrack object |
87 with open(trackDbTxtFilePath, 'a+') as trackDbFile: | 87 with open(trackDbTxtFilePath, 'a+') as trackDbFile: |
88 group_name = trackDbObject["group"] | |
89 trackDbObject["group"] = santitizer.sanitize_group_name(trackDbObject["group"]) | |
88 trackDbs = [trackDbObject] | 90 trackDbs = [trackDbObject] |
89 | |
90 # TODO: The addGroup does not belong here. Move it when the group becomes more than just a label | 91 # 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 # Add the group as well, if exists in trackDbObject |
92 self.addGroup(trackDbObject.group_name) | 93 self.addGroup(group_name) |
93 | 94 |
94 htmlMakoRendered = self.trackDbTemplate.render( | 95 htmlMakoRendered = self.trackDbTemplate.render( |
95 trackDbs=trackDbs | 96 trackDbs=trackDbs |
96 ) | 97 ) |
97 trackDbFile.write(htmlMakoRendered) | 98 trackDbFile.write(htmlMakoRendered) |
98 | 99 |
99 logging.debug("We just added track {0} (in group {1})".format(trackDbObject.trackName, | 100 #logging.debug("We just added track {0} (in group {1})".format(trackDbObject.trackName, |
100 trackDbObject.group_name.lower().replace(' ', '_'))) | 101 # trackDbObject.group_name.lower().replace(' ', '_'))) |
101 | 102 logging.debug("We just added track {0} (in group {1})".format(trackDbObject.get("track"), |
103 trackDbObject.get("group").lower().replace(' ', '_'))) | |
102 def addGroup(self, group_name="Default"): | 104 def addGroup(self, group_name="Default"): |
103 # If not already present in self.groups, add to groups.txt | 105 # If not already present in self.groups, add to groups.txt |
104 # Create the trackDb.txt file in the specie folder, if not exists | 106 # Create the trackDb.txt file in the specie folder, if not exists |
105 # Else append the new track | 107 # Else append the new track |
106 # TODO: Get this out of the function | 108 # TODO: Get this out of the function |
166 htmlMakoRendered = mytemplate.render( | 168 htmlMakoRendered = mytemplate.render( |
167 walkable_tree=walkable_tree | 169 walkable_tree=walkable_tree |
168 ) | 170 ) |
169 htmlOutput.write(htmlMakoRendered) | 171 htmlOutput.write(htmlMakoRendered) |
170 | 172 |
173 | |
171 def __createAssemblyHub__(self, extra_files_path): | 174 def __createAssemblyHub__(self, extra_files_path): |
172 # Get all necessaries infos first | 175 # Get all necessaries infos first |
173 # 2bit file creation from input fasta | 176 # 2bit file creation from input fasta |
174 | 177 |
175 # baseNameFasta = os.path.basename(fasta_file_name) | 178 # baseNameFasta = os.path.basename(fasta_file_name) |