Mercurial > repos > rmarenco > hubarchivecreator
comparison Bam.py @ 1:fb5e60d4d18a draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 64cfc08088d11f6818c1b4e5514ef9e67969eaff-dirty
author | rmarenco |
---|---|
date | Wed, 13 Jul 2016 13:36:37 -0400 |
parents | |
children | acc233161f50 |
comparison
equal
deleted
inserted
replaced
0:0f3bc17e5ede | 1:fb5e60d4d18a |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf8 -*- | |
3 | |
4 """ | |
5 Class to handle Bam files to UCSC TrackHub | |
6 """ | |
7 | |
8 import os | |
9 import shutil | |
10 | |
11 from Datatype import Datatype | |
12 from Track import Track | |
13 from TrackDb import TrackDb | |
14 from util import subtools | |
15 | |
16 | |
17 class Bam( Datatype ): | |
18 def __init__( self, input_bam_false_path, data_bam , | |
19 inputFastaFile, extra_files_path, tool_directory ): | |
20 super(Bam, self).__init__( input_fasta_file=inputFastaFile, | |
21 extra_files_path=extra_files_path, | |
22 tool_directory=tool_directory, | |
23 ) | |
24 | |
25 self.track = None | |
26 | |
27 self.input_bam_false_path = input_bam_false_path | |
28 | |
29 self.data_bam = data_bam | |
30 # TODO: Check if it already contains the .bam extension / Do a function in Datatype which check the extension | |
31 self.name_bam = self.data_bam["name"] + ".bam" | |
32 self.priority = self.data_bam["order_index"] | |
33 self.index_bam = self.data_bam["index"] | |
34 | |
35 print "Creating TrackHub BAM from (falsePath: %s; name: %s)" % ( self.input_bam_false_path, self.name_bam) | |
36 | |
37 # First: Add the bam file | |
38 # Second: Add the bam index file, in the same folder (https://genome.ucsc.edu/goldenpath/help/bam.html) | |
39 | |
40 bam_file_path = os.path.join(self.myTrackFolderPath, self.name_bam) | |
41 shutil.copyfile(self.input_bam_false_path, bam_file_path) | |
42 | |
43 # Create and add the bam index file to the same folder | |
44 name_index_bam = self.name_bam + ".bai" | |
45 bam_index_file_path = os.path.join(self.myTrackFolderPath, name_index_bam) | |
46 shutil.copyfile(self.index_bam, bam_index_file_path) | |
47 | |
48 # Create the Track Object | |
49 dataURL = "tracks/%s" % self.name_bam | |
50 | |
51 trackDb = TrackDb( | |
52 trackName=self.name_bam, | |
53 longLabel=self.name_bam, | |
54 shortLabel=self.getShortName( self.name_bam ), | |
55 trackDataURL=dataURL, | |
56 trackType='bam', | |
57 visibility='pack', | |
58 priority=self.priority, | |
59 ) | |
60 | |
61 # Return the Bam Track Object | |
62 self.track = Track( | |
63 trackFile=bam_index_file_path, | |
64 trackDb=trackDb, | |
65 ) | |
66 | |
67 print("- %s created in %s" % (self.name_bam, bam_file_path)) | |
68 print("- %s created in %s" % (self.index_bam, bam_index_file_path)) |