Mercurial > repos > yating-l > jbrowsearchivecreator
diff TrackHub.py @ 39:4a69515eed63 draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 91271a6c0d39c923f0d460b2979247baa297286b-dirty
author | yating-l |
---|---|
date | Fri, 13 Apr 2018 18:21:35 -0400 |
parents | d17f629f5486 |
children | b1553f2a4942 |
line wrap: on
line diff
--- a/TrackHub.py Fri Apr 06 13:44:56 2018 -0400 +++ b/TrackHub.py Fri Apr 13 18:21:35 2018 -0400 @@ -17,14 +17,15 @@ class TrackHub: def __init__(self, inputFastaFile, outputFile, extra_files_path, tool_directory, trackType): - - self.rootAssemblyHub = None self.mySpecieFolderPath = None # Store intermediate files, will be removed if not in debug mode self.myTracksFolderPath = None + # Store interval files and their tabix index + self.myFinalTracksFolderPath = None + # Store binary files: Bam, BigWig self.myBinaryFolderPath = None @@ -38,29 +39,24 @@ # Set all the missing variables of this class, and create physically the folders/files - self.rootAssemblyHub = self.__createAssemblyHub__(extra_files_path=extra_files_path) + self.__createAssemblyHub__(extra_files_path=extra_files_path) # Init the Datatype Datatype.pre_init(self.reference_genome, self.chromSizesFile, self.extra_files_path, self.tool_directory, - self.mySpecieFolderPath, self.myTracksFolderPath, self.myFinalTracksFolderPath, self.myBinaryFolderPath, self.trackType) + self.mySpecieFolderPath, self.myTracksFolderPath, self.myBinaryFolderPath, self.trackType) self._prepareRefseq() self.trackList = os.path.join(self.mySpecieFolderPath, "trackList.json") self._createTrackList() - - self.myTrackStyle = TrackStyles(self.tool_directory, self.mySpecieFolderPath, self.trackList) - #self.cssFolderPath = os.path.join(self.mySpecieFolderPath, 'css') - #self.cssFilePath = os.path.join(self.cssFolderPath, 'custom_track_styles.css') + if Datatype.trackType == 'HTMLFeatures': + self.myTrackStyle = TrackStyles(self.tool_directory, self.mySpecieFolderPath, self.trackList) self.logger = logging.getLogger(__name__) def addTrack(self, trackDbObject): if trackDbObject['dataType'].lower() == 'bam': - #new_track = subprocess.Popen(['echo', trackDbObject['options']], stdout=subprocess.PIPE) - #subprocess.call(['add-track-json.pl', json_file], stdin=new_track.stdout) subtools.add_track_json(self.trackList, trackDbObject['options']) - #subtools.add_track_json(self.trackList, trackDbObject['track_json']) elif trackDbObject['dataType'].lower() == 'bigwig': subtools.add_track_json(self.trackList, trackDbObject['options']) else: @@ -70,7 +66,7 @@ # Use Tabix index tracks by default for CanvasFeatures # TODO: add support for HTMLFeatures else: - subtools.generate_tabix_indexed_track(trackDbObject['trackDataURL'], trackDbObject['dataType'], self.myFinalTracksFolderPath) + subtools.generate_tabix_indexed_track(trackDbObject['trackDataURL'], trackDbObject['dataType'], trackDbObject['track'], self.myFinalTracksFolderPath) subtools.add_track_json(self.trackList, trackDbObject['options']) def terminate(self, debug=False): @@ -78,7 +74,6 @@ self._indexName() if not debug: self._removeRaw() - #self._makeArchive() self._outHtml() print "Success!\n" @@ -107,14 +102,8 @@ def _prepareRefseq(self): subtools.prepare_refseqs(self.reference_genome.false_path, self.mySpecieFolderPath) - #try: - #print os.path.join(self.tool_dir, 'prepare-refseqs.pl') + ", '--fasta', " + self.reference +", '--out', self.json])" - #subprocess.call(['prepare-refseqs.pl', '--fasta', self.reference_genome.false_path, '--out', self.mySpecieFolderPath]) - #except OSError as e: - #print "Cannot prepare reference error({0}): {1}".format(e.errno, e.strerror) def _indexName(self): - #subprocess.call(['generate-names.pl', '-v', '--out', self.mySpecieFolderPath]) subtools.generate_names(self.mySpecieFolderPath) print "finished name index \n" @@ -125,25 +114,14 @@ with open(self.outputFile, 'w') as htmlfile: htmlMakoRendered = htmlTemplate.render( - species_folder = os.path.relpath(self.mySpecieFolderPath, self.extra_files_path), + jbrowse_hub_name = self.reference_genome.assembly_id, trackList = os.path.relpath(self.trackList, self.extra_files_path) ) htmlfile.write(htmlMakoRendered) - #with open(self.outputFile, 'w') as htmlfile: - # htmlstr = 'The new Organism "%s" is created on Apollo: <br>' % self.genome_name - # jbrowse_hub = '<li><a href = "%s" target="_blank">View JBrowse Hub on Apollo</a></li>' % host_name - # htmlstr += jbrowse_hub - # htmlfile.write(htmlstr) - - def __createAssemblyHub__(self, extra_files_path): # Get all necessaries infos first # 2bit file creation from input fasta - - # baseNameFasta = os.path.basename(fasta_file_name) - # suffixTwoBit, extensionTwoBit = os.path.splitext(baseNameFasta) - # nameTwoBit = suffixTwoBit + '.2bit' twoBitFile = tempfile.NamedTemporaryFile(bufsize=0) subtools.faToTwoBit(self.reference_genome.false_path, twoBitFile.name) @@ -153,21 +131,15 @@ # Then we get the output to generate the chromSizes self.chromSizesFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".chrom.sizes") - subtools.sortChromSizes(twoBitInfoFile.name, self.chromSizesFile.name) + subtools.sortChromSizes(twoBitInfoFile.name, self.chromSizesFile.name) # We can get the biggest scaffold here, with chromSizesFile with open(self.chromSizesFile.name, 'r') as chrom_sizes: # TODO: Check if exists self.default_pos = chrom_sizes.readline().split()[0] - # TODO: Manage to put every fill Function in a file dedicated for reading reasons - # Create the root directory - myHubPath = os.path.join(extra_files_path, "myHub") - if not os.path.exists(myHubPath): - os.makedirs(myHubPath) - - # Create the specie folder - mySpecieFolderPath = os.path.join(myHubPath, self.genome_name) + # Create the specie folder, use generic name "myHub", to support display JBrowse with Galaxy display application + mySpecieFolderPath = os.path.join(extra_files_path, "myHub") if not os.path.exists(mySpecieFolderPath): os.makedirs(mySpecieFolderPath) self.mySpecieFolderPath = mySpecieFolderPath @@ -188,5 +160,3 @@ if not os.path.exists(myBinaryFolderPath): os.makedirs(myBinaryFolderPath) self.myBinaryFolderPath = myBinaryFolderPath - - return myHubPath