Mercurial > repos > yating-l > hubarchivecreator
comparison 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 |
comparison
equal
deleted
inserted
replaced
51:364b8db8de17 | 52:c66803bff0cc |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 import os | 3 import os |
4 import shutil | 4 import shutil |
5 from subprocess import Popen, PIPE | |
6 import re | |
5 | 7 |
6 # Internal dependencies | 8 # Internal dependencies |
7 from Datatype import Datatype | 9 from Datatype import Datatype |
8 from Track import Track | 10 from Track import Track |
9 from TrackDb import TrackDb | 11 from TrackDb import TrackDb |
19 self.name_bigwig = data_bigwig["name"] | 21 self.name_bigwig = data_bigwig["name"] |
20 self.priority = data_bigwig["order_index"] | 22 self.priority = data_bigwig["order_index"] |
21 self.track_color = data_bigwig["track_color"] | 23 self.track_color = data_bigwig["track_color"] |
22 # TODO: Think about how to avoid repetition of the group_name everywhere | 24 # TODO: Think about how to avoid repetition of the group_name everywhere |
23 self.group_name = data_bigwig["group_name"] | 25 self.group_name = data_bigwig["group_name"] |
24 | 26 if data_bigwig["long_label"]: |
27 self.long_label = data_bigwig["long_label"] | |
28 else: | |
29 self.long_label = self.name_bigwig | |
25 #print "Creating TrackHub BigWig from (falsePath: %s; name: %s)" % ( self.input_bigwig_path, self.name_bigwig ) | 30 #print "Creating TrackHub BigWig from (falsePath: %s; name: %s)" % ( self.input_bigwig_path, self.name_bigwig ) |
26 | 31 |
27 trackName = "".join( ( self.name_bigwig, ".bigwig" ) ) | 32 trackName = "".join( ( self.name_bigwig, ".bigwig" ) ) |
28 | 33 |
29 myBigWigFilePath = os.path.join(self.myTrackFolderPath, trackName) | 34 myBigWigFilePath = os.path.join(self.myTrackFolderPath, trackName) |
30 shutil.copy(self.input_bigwig_path, myBigWigFilePath) | 35 shutil.copy(self.input_bigwig_path, myBigWigFilePath) |
31 | 36 |
32 # Create the Track Object | 37 # Create the Track Object |
33 self.createTrack(file_path=trackName, | 38 self.createTrack(file_path=trackName, |
34 track_name=trackName, | 39 track_name=trackName, |
35 long_label=self.name_bigwig, | 40 long_label=self.long_label, |
36 track_type='bigWig', visibility='full', | 41 track_type=self.determine_track_type(myBigWigFilePath), |
42 visibility='full', | |
37 priority=self.priority, | 43 priority=self.priority, |
38 track_file=myBigWigFilePath, | 44 track_file=myBigWigFilePath, |
39 track_color=self.track_color, | 45 track_color=self.track_color, |
40 group_name=self.group_name) | 46 group_name=self.group_name) |
41 | 47 |
42 # dataURL = "tracks/%s" % trackName | |
43 # | |
44 # # Return the BigBed track | |
45 # | |
46 # trackDb = TrackDb( | |
47 # trackName=trackName, | |
48 # longLabel=self.name_bigwig, | |
49 # shortLabel=self.getShortName( self.name_bigwig ), | |
50 # trackDataURL=dataURL, | |
51 # trackType='bigWig', | |
52 # visibility='full', | |
53 # priority=self.priority, | |
54 # ) | |
55 # | |
56 # self.track = Track( | |
57 # trackFile=myBigWigFilePath, | |
58 # trackDb=trackDb, | |
59 # ) | |
60 | |
61 print("- BigWig %s created" % self.name_bigwig) | 48 print("- BigWig %s created" % self.name_bigwig) |
62 #print("- %s created in %s" % (trackName, myBigWigFilePath)) | 49 #print("- %s created in %s" % (trackName, myBigWigFilePath)) |
50 | |
51 def determine_track_type(self, bw_file): | |
52 """ | |
53 bigWig tracks must declare the expected signal range for the data | |
54 (See https://genome.ucsc.edu/goldenpath/help/trackDb/trackDbHub.html). | |
55 This method determines the range of values for a bigWig file using | |
56 the bigWigInfo program. | |
57 | |
58 Implementation of reading from stdout is based on a Stackoverflow post: | |
59 http://stackoverflow.com/questions/2715847/python-read-streaming-input-from-subprocess-communicate | |
60 | |
61 :param bw_file: path to a bigWig file | |
62 | |
63 :returns: the bigWig track type | |
64 """ | |
65 cmd_ph = Popen(["bigWigInfo", "-minMax", bw_file], | |
66 stdout=PIPE, bufsize=1) | |
67 | |
68 with cmd_ph.stdout: | |
69 for line in iter(cmd_ph.stdout.readline, b''): | |
70 bw_type = "bigWig %s" % line.rstrip() | |
71 | |
72 cmd_ph.wait() | |
73 | |
74 return bw_type |