Mercurial > repos > rmarenco > hubarchivecreator
comparison Bed.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 | |
3 import os | |
4 import tempfile | |
5 | |
6 # Internal dependencies | |
7 from Datatype import Datatype | |
8 from Track import Track | |
9 from TrackDb import TrackDb | |
10 from util import subtools | |
11 | |
12 | |
13 class Bed( Datatype ): | |
14 def __init__( self, inputBedGeneric, data_bed_generic, | |
15 inputFastaFile, extra_files_path, tool_directory ): | |
16 super(Bed, self).__init__( | |
17 inputFastaFile, extra_files_path, tool_directory | |
18 ) | |
19 | |
20 self.track = None | |
21 | |
22 self.inputBedGeneric = inputBedGeneric | |
23 | |
24 self.sortedBedFile = tempfile.NamedTemporaryFile(suffix=".sortedBed") | |
25 self.chromSizesFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".chrom.sizes") | |
26 self.twoBitInfoFile = tempfile.NamedTemporaryFile(bufsize=0) | |
27 | |
28 self.data_bed_generic = data_bed_generic | |
29 self.name_bed_generic = self.data_bed_generic["name"] | |
30 self.priority = self.data_bed_generic["order_index"] | |
31 | |
32 # Sort processing | |
33 subtools.sort(self.inputBedGeneric, self.sortedBedFile.name) | |
34 | |
35 # Generate the chrom.sizes | |
36 # TODO: Isolate in a function | |
37 # We first get the twoBit Infos | |
38 subtools.twoBitInfo(self.twoBitFile.name, self.twoBitInfoFile.name) | |
39 | |
40 # Then we get the output to inject into the sort | |
41 # TODO: Check if no errors | |
42 subtools.sortChromSizes(self.twoBitInfoFile.name, self.chromSizesFile.name) | |
43 | |
44 # bedToBigBed processing | |
45 # TODO: Change the name of the bb, to tool + genome + possible adding if multiple + .bb | |
46 trackName = "".join( ( self.name_bed_generic, ".bb") ) | |
47 | |
48 myBigBedFilePath = os.path.join(self.myTrackFolderPath, trackName) | |
49 with open(myBigBedFilePath, 'w') as self.bigBedFile: | |
50 subtools.bedToBigBed(self.sortedBedFile.name, self.chromSizesFile.name, self.bigBedFile.name) | |
51 | |
52 # Create the Track Object | |
53 dataURL = "tracks/%s" % trackName | |
54 | |
55 trackDb = TrackDb( | |
56 trackName=trackName, | |
57 longLabel=self.name_bed_generic, | |
58 shortLabel=self.getShortName(self.name_bed_generic), | |
59 trackDataURL=dataURL, | |
60 trackType='bigBed', | |
61 visibility='dense', | |
62 thickDrawItem='on', | |
63 priority=self.priority, | |
64 ) | |
65 | |
66 # Return the BigBed track | |
67 self.track = Track( | |
68 trackFile=myBigBedFilePath, | |
69 trackDb=trackDb, | |
70 ) | |
71 | |
72 print("- %s created in %s" % (trackName, myBigBedFilePath)) |