comparison BigWig.py @ 24:fcc1021bd496 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 93e2e2fb59f99677425104a80c17f665fa7b2b4a-dirty
author yating-l
date Wed, 31 May 2017 11:35:16 -0400
parents 2677f1899aa8
children df42241d3731
comparison
equal deleted inserted replaced
23:2677f1899aa8 24:fcc1021bd496
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
34 36
35 # Create the Track Object 37 # Create the Track Object
36 self.createTrack(file_path=trackName, 38 self.createTrack(file_path=trackName,
37 track_name=trackName, 39 track_name=trackName,
38 long_label=self.long_label, 40 long_label=self.long_label,
39 track_type='bigWig', visibility='full', 41 track_type=self.determine_track_type(myBigWigFilePath),
42 visibility='full',
40 priority=self.priority, 43 priority=self.priority,
41 track_file=myBigWigFilePath, 44 track_file=myBigWigFilePath,
42 track_color=self.track_color, 45 track_color=self.track_color,
43 group_name=self.group_name) 46 group_name=self.group_name)
44 47
45 # dataURL = "tracks/%s" % trackName
46 #
47 # # Return the BigBed track
48 #
49 # trackDb = TrackDb(
50 # trackName=trackName,
51 # longLabel=self.name_bigwig,
52 # shortLabel=self.getShortName( self.name_bigwig ),
53 # trackDataURL=dataURL,
54 # trackType='bigWig',
55 # visibility='full',
56 # priority=self.priority,
57 # )
58 #
59 # self.track = Track(
60 # trackFile=myBigWigFilePath,
61 # trackDb=trackDb,
62 # )
63
64 print("- BigWig %s created" % self.name_bigwig) 48 print("- BigWig %s created" % self.name_bigwig)
65 #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