Mercurial > repos > rmarenco > hubarchivecreator
annotate Bam.py @ 26:df42241d3731 draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit c11beb58525fe6453a2180fe7783f6e8b0151901-dirty
author | yating-l |
---|---|
date | Mon, 03 Jul 2017 17:30:20 -0400 |
parents | 2677f1899aa8 |
children |
rev | line source |
---|---|
1
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
1 #!/usr/bin/python |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
2 # -*- coding: utf8 -*- |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
3 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
4 """ |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
5 Class to handle Bam files to UCSC TrackHub |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
6 """ |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
7 |
16
3233451a3bd6
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit fc73ec22a0db3ab09c4ac13dc58f0b54ae37845c
rmarenco
parents:
11
diff
changeset
|
8 import logging |
1
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
9 import os |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
10 import shutil |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
11 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
12 from Datatype import Datatype |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
13 from Track import Track |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
14 from TrackDb import TrackDb |
21
884ee2a71680
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 6ac76e7da539ca1773fb809054679f0bf8a06972-dirty
yating-l
parents:
17
diff
changeset
|
15 |
1
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
16 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
17 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
18 class Bam( Datatype ): |
10
acc233161f50
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1b1063f90004764bcf504f4340738eca5c4b1f9d
rmarenco
parents:
1
diff
changeset
|
19 def __init__(self, input_bam_false_path, data_bam): |
acc233161f50
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1b1063f90004764bcf504f4340738eca5c4b1f9d
rmarenco
parents:
1
diff
changeset
|
20 super(Bam, self).__init__() |
1
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
21 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
22 self.track = None |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
23 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
24 self.input_bam_false_path = input_bam_false_path |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
25 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
26 self.data_bam = data_bam |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
27 # TODO: Check if it already contains the .bam extension / Do a function in Datatype which check the extension |
11
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
28 if ".bam" not in self.data_bam["name"]: |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
29 self.name_bam = self.data_bam["name"] + ".bam" |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
30 else: |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
31 self.name_bam = self.data_bam["name"] |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
32 |
1
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
33 self.priority = self.data_bam["order_index"] |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
34 self.index_bam = self.data_bam["index"] |
17
c02720d1afee
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1adbf397de1fc7af4d91e026093d7fff983e21cf
rmarenco
parents:
16
diff
changeset
|
35 # TODO: Think about how to avoid repetition of the color treatment |
16
3233451a3bd6
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit fc73ec22a0db3ab09c4ac13dc58f0b54ae37845c
rmarenco
parents:
11
diff
changeset
|
36 self.track_color = self.data_bam["track_color"] |
3233451a3bd6
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit fc73ec22a0db3ab09c4ac13dc58f0b54ae37845c
rmarenco
parents:
11
diff
changeset
|
37 |
17
c02720d1afee
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1adbf397de1fc7af4d91e026093d7fff983e21cf
rmarenco
parents:
16
diff
changeset
|
38 # TODO: Think about how to avoid repetition of the group_name everywhere |
c02720d1afee
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1adbf397de1fc7af4d91e026093d7fff983e21cf
rmarenco
parents:
16
diff
changeset
|
39 self.group_name = self.data_bam["group_name"] |
26
df42241d3731
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit c11beb58525fe6453a2180fe7783f6e8b0151901-dirty
yating-l
parents:
23
diff
changeset
|
40 self.database = self.data_bam["database"] |
23
2677f1899aa8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents:
21
diff
changeset
|
41 if self.data_bam["long_label"]: |
2677f1899aa8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents:
21
diff
changeset
|
42 self.long_label = self.data_bam["long_label"] |
2677f1899aa8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents:
21
diff
changeset
|
43 else: |
2677f1899aa8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents:
21
diff
changeset
|
44 self.long_label = self.name_bam |
1
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
45 # First: Add the bam file |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
46 # Second: Add the bam index file, in the same folder (https://genome.ucsc.edu/goldenpath/help/bam.html) |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
47 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
48 bam_file_path = os.path.join(self.myTrackFolderPath, self.name_bam) |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
49 shutil.copyfile(self.input_bam_false_path, bam_file_path) |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
50 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
51 # Create and add the bam index file to the same folder |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
52 name_index_bam = self.name_bam + ".bai" |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
53 bam_index_file_path = os.path.join(self.myTrackFolderPath, name_index_bam) |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
54 shutil.copyfile(self.index_bam, bam_index_file_path) |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
55 |
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
56 # Create the Track Object |
11
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
57 self.createTrack(file_path=self.name_bam, |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
58 track_name=self.name_bam, |
23
2677f1899aa8
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 07210e24fe7d22f5dfc84061310280f67f781fb1-dirty
yating-l
parents:
21
diff
changeset
|
59 long_label=self.long_label, track_type='bam', visibility='pack', priority=self.priority, |
16
3233451a3bd6
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit fc73ec22a0db3ab09c4ac13dc58f0b54ae37845c
rmarenco
parents:
11
diff
changeset
|
60 track_file=bam_index_file_path, |
17
c02720d1afee
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1adbf397de1fc7af4d91e026093d7fff983e21cf
rmarenco
parents:
16
diff
changeset
|
61 track_color=self.track_color, |
26
df42241d3731
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit c11beb58525fe6453a2180fe7783f6e8b0151901-dirty
yating-l
parents:
23
diff
changeset
|
62 group_name=self.group_name, |
df42241d3731
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit c11beb58525fe6453a2180fe7783f6e8b0151901-dirty
yating-l
parents:
23
diff
changeset
|
63 database=self.database |
17
c02720d1afee
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1adbf397de1fc7af4d91e026093d7fff983e21cf
rmarenco
parents:
16
diff
changeset
|
64 ) |
11
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
65 # |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
66 # dataURL = "tracks/%s" % self.name_bam |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
67 # |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
68 # trackDb = TrackDb( |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
69 # trackName=self.name_bam, |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
70 # longLabel=self.name_bam, |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
71 # shortLabel=self.getShortName( self.name_bam ), |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
72 # trackDataURL=dataURL, |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
73 # trackType='bam', |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
74 # visibility='pack', |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
75 # priority=self.priority, |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
76 # ) |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
77 # |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
78 # # Return the Bam Track Object |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
79 # self.track = Track( |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
80 # trackFile=bam_index_file_path, |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
81 # trackDb=trackDb, |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
82 # ) |
1
fb5e60d4d18a
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
rmarenco
parents:
diff
changeset
|
83 |
11
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
84 print("- Bam %s created" % self.name_bam) |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
85 #print("- %s created in %s" % (self.name_bam, bam_file_path)) |
d05236b15f81
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3760d0c8353b924ecf994131a5c2eb381aa81fb2
rmarenco
parents:
10
diff
changeset
|
86 #print("- %s created in %s" % (self.index_bam, bam_index_file_path)) |