Mercurial > repos > yating-l > hubarchivecreator
diff BigWig.py @ 52:c66803bff0cc draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit adc1ac50269e02570e7ce12c732637bdd3f9a547-dirty
author | yating-l |
---|---|
date | Thu, 11 May 2017 17:21:15 -0400 |
parents | 3e0c61b52a06 |
children | b39dd0b5a166 |
line wrap: on
line diff
--- a/BigWig.py Wed Apr 12 16:51:03 2017 -0400 +++ b/BigWig.py Thu May 11 17:21:15 2017 -0400 @@ -2,6 +2,8 @@ import os import shutil +from subprocess import Popen, PIPE +import re # Internal dependencies from Datatype import Datatype @@ -21,7 +23,10 @@ self.track_color = data_bigwig["track_color"] # TODO: Think about how to avoid repetition of the group_name everywhere self.group_name = data_bigwig["group_name"] - + if data_bigwig["long_label"]: + self.long_label = data_bigwig["long_label"] + else: + self.long_label = self.name_bigwig #print "Creating TrackHub BigWig from (falsePath: %s; name: %s)" % ( self.input_bigwig_path, self.name_bigwig ) trackName = "".join( ( self.name_bigwig, ".bigwig" ) ) @@ -32,31 +37,38 @@ # Create the Track Object self.createTrack(file_path=trackName, track_name=trackName, - long_label=self.name_bigwig, - track_type='bigWig', visibility='full', + long_label=self.long_label, + track_type=self.determine_track_type(myBigWigFilePath), + visibility='full', priority=self.priority, track_file=myBigWigFilePath, track_color=self.track_color, group_name=self.group_name) - # dataURL = "tracks/%s" % trackName - # - # # Return the BigBed track - # - # trackDb = TrackDb( - # trackName=trackName, - # longLabel=self.name_bigwig, - # shortLabel=self.getShortName( self.name_bigwig ), - # trackDataURL=dataURL, - # trackType='bigWig', - # visibility='full', - # priority=self.priority, - # ) - # - # self.track = Track( - # trackFile=myBigWigFilePath, - # trackDb=trackDb, - # ) - print("- BigWig %s created" % self.name_bigwig) #print("- %s created in %s" % (trackName, myBigWigFilePath)) + + def determine_track_type(self, bw_file): + """ + bigWig tracks must declare the expected signal range for the data + (See https://genome.ucsc.edu/goldenpath/help/trackDb/trackDbHub.html). + This method determines the range of values for a bigWig file using + the bigWigInfo program. + + Implementation of reading from stdout is based on a Stackoverflow post: + http://stackoverflow.com/questions/2715847/python-read-streaming-input-from-subprocess-communicate + + :param bw_file: path to a bigWig file + + :returns: the bigWig track type + """ + cmd_ph = Popen(["bigWigInfo", "-minMax", bw_file], + stdout=PIPE, bufsize=1) + + with cmd_ph.stdout: + for line in iter(cmd_ph.stdout.readline, b''): + bw_type = "bigWig %s" % line.rstrip() + + cmd_ph.wait() + + return bw_type