Mercurial > repos > yating-l > hubarchivecreator
annotate BigBed.py @ 59:f311e21ef362 draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 72268f816f10341dbe3f6b33f8d9170d859c9697-dirty
author | yating-l |
---|---|
date | Fri, 30 Jun 2017 15:50:57 -0400 |
parents | b39dd0b5a166 |
children |
rev | line source |
---|---|
55
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
1 #!/usr/bin/python |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
2 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
3 import os |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
4 import shutil |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
5 from subprocess import Popen, PIPE |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
6 import re |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
7 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
8 # Internal dependencies |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
9 from Datatype import Datatype |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
10 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
11 class BigBed(Datatype): |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
12 """ Configurations for creating the bigBed evidence track """ |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
13 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
14 def __init__(self, input_bigbed_path, data_bigbed): |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
15 super(BigBed, self).__init__() |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
16 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
17 self.track = None |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
18 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
19 self.input_bigbed_path = input_bigbed_path |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
20 self.name_bigbed = data_bigbed["name"] |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
21 self.priority = data_bigbed["order_index"] |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
22 self.track_color = data_bigbed["track_color"] |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
23 self.group_name = data_bigbed["group_name"] |
57
b39dd0b5a166
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit ce28781f52a4f84039de300cb41e3982f2e8bf51-dirty
yating-l
parents:
55
diff
changeset
|
24 self.database = data_bigbed["database"] |
55
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
25 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
26 track_name = "".join((self.name_bigbed, ".bigbed")) |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
27 if data_bigbed["long_label"]: |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
28 self.long_label = data_bigbed["long_label"] |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
29 else: |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
30 self.long_label = self.name_bigbed |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
31 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
32 bigbed_file_path = os.path.join(self.myTrackFolderPath, track_name) |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
33 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
34 track_type = self.determine_track_type(input_bigbed_path) |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
35 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
36 shutil.copy(self.input_bigbed_path, bigbed_file_path) |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
37 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
38 # Create the Track Object |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
39 self.createTrack(file_path=track_name, |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
40 track_name=track_name, |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
41 long_label=self.long_label, |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
42 track_type=track_type, |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
43 visibility='hide', |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
44 priority=self.priority, |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
45 track_file=bigbed_file_path, |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
46 track_color=self.track_color, |
57
b39dd0b5a166
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit ce28781f52a4f84039de300cb41e3982f2e8bf51-dirty
yating-l
parents:
55
diff
changeset
|
47 group_name=self.group_name, |
b39dd0b5a166
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit ce28781f52a4f84039de300cb41e3982f2e8bf51-dirty
yating-l
parents:
55
diff
changeset
|
48 database=self.database) |
55
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
49 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
50 print "- BigBed %s created" % self.name_bigbed |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
51 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
52 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
53 def determine_track_type(self, bb_file): |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
54 """ |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
55 Determine the number of standard and extra fields using bigBedSummary |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
56 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
57 Implementation of reading from stdout is based on a Stackoverflow post: |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
58 http://stackoverflow.com/questions/2715847/python-read-streaming-input-from-subprocess-communicate |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
59 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
60 :param bb_file: path to a bigBed file |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
61 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
62 :returns: the bigBed track type |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
63 """ |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
64 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
65 cmd_ph = Popen(["bigBedSummary", "-fields", bb_file, "stdout"], |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
66 stdout=PIPE, bufsize=1) |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
67 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
68 pattern = r"(\d+) bed definition fields, (\d+) total fields" |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
69 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
70 with cmd_ph.stdout: |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
71 for line in iter(cmd_ph.stdout.readline, b''): |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
72 match = re.match(pattern, line) |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
73 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
74 if match: |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
75 extra_mark = "." if match.group(1) == match.group(2) else "+" |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
76 bed_type = "bigBed %s %s" % (match.group(1), extra_mark) |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
77 break |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
78 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
79 cmd_ph.wait() |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
80 |
ba9997c847dc
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b2894a39921adaa6a93b12523820b61a78e11f20-dirty
yating-l
parents:
diff
changeset
|
81 return bed_type |