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