annotate Bam.py @ 0:f493979f1408 draft default tip

planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
author yating-l
date Wed, 21 Dec 2016 12:13:04 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
1 #!/usr/bin/python
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
2 # -*- coding: utf8 -*-
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
3
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
4 """
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
5 Class to handle Bam files to UCSC TrackHub
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
6 """
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
7
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
8 import logging
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
9 import os
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
10 import shutil
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
11
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
12 from Datatype import Datatype
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
13 from Track import Track
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
14 from TrackDb import TrackDb
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
15 from util import subtools
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
16
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
17
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
18 class Bam( Datatype ):
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
19 def __init__(self, input_bam_false_path, data_bam):
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
20 super(Bam, self).__init__()
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
21
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
22 self.track = None
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
23
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
24 self.input_bam_false_path = input_bam_false_path
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
25
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
26 self.data_bam = data_bam
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
27 # TODO: Check if it already contains the .bam extension / Do a function in Datatype which check the extension
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
28 if ".bam" not in self.data_bam["name"]:
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
29 self.name_bam = self.data_bam["name"] + ".bam"
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
30 else:
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
31 self.name_bam = self.data_bam["name"]
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
32
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
33 self.priority = self.data_bam["order_index"]
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
34 self.index_bam = self.data_bam["index"]
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
35 # TODO: Think about how to avoid repetition of the color treatment
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
36 self.track_color = self.data_bam["track_color"]
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
37
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
38 # TODO: Think about how to avoid repetition of the group_name everywhere
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
39 self.group_name = self.data_bam["group_name"]
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
40
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
41 # First: Add the bam file
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
42 # Second: Add the bam index file, in the same folder (https://genome.ucsc.edu/goldenpath/help/bam.html)
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
43
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
44 bam_file_path = os.path.join(self.myTrackFolderPath, self.name_bam)
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
45 shutil.copyfile(self.input_bam_false_path, bam_file_path)
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
46
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
47 # Create and add the bam index file to the same folder
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
48 name_index_bam = self.name_bam + ".bai"
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
49 bam_index_file_path = os.path.join(self.myTrackFolderPath, name_index_bam)
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
50 shutil.copyfile(self.index_bam, bam_index_file_path)
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
51
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
52 # Create the Track Object
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
53 self.createTrack(file_path=self.name_bam,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
54 track_name=self.name_bam,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
55 long_label=self.name_bam, track_type='bam', visibility='pack', priority=self.priority,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
56 track_file=bam_index_file_path,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
57 track_color=self.track_color,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
58 group_name=self.group_name
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
59 )
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
60 #
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
61 # dataURL = "tracks/%s" % self.name_bam
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
62 #
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
63 # trackDb = TrackDb(
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
64 # trackName=self.name_bam,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
65 # longLabel=self.name_bam,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
66 # shortLabel=self.getShortName( self.name_bam ),
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
67 # trackDataURL=dataURL,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
68 # trackType='bam',
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
69 # visibility='pack',
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
70 # priority=self.priority,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
71 # )
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
72 #
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
73 # # Return the Bam Track Object
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
74 # self.track = Track(
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
75 # trackFile=bam_index_file_path,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
76 # trackDb=trackDb,
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
77 # )
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
78
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
79 print("- Bam %s created" % self.name_bam)
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
80 #print("- %s created in %s" % (self.name_bam, bam_file_path))
f493979f1408 planemo upload for repository https://github.com/Yating-L/hubarchivecreator-test commit 48b59e91e2dcc2e97735ee35d587960cbfbce932-dirty
yating-l
parents:
diff changeset
81 #print("- %s created in %s" % (self.index_bam, bam_index_file_path))