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