comparison Gtf.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 Gtf( Datatype ):
14 def __init__( self, input_gtf_false_path, data_gtf,
15 input_fasta_file, extra_files_path, tool_directory ):
16 super(Gtf, self).__init__( input_fasta_file=input_fasta_file,
17 extra_files_path=extra_files_path,
18 tool_directory=tool_directory )
19
20 self.track = None
21
22 self.input_gtf_false_path = input_gtf_false_path
23 self.name_gtf = data_gtf["name"]
24 self.priority = data_gtf["order_index"]
25
26 print "Creating TrackHub GTF from (falsePath: %s; name: %s)" % ( self.input_gtf_false_path, self.name_gtf)
27
28 # TODO: See if we need these temporary files as part of the generated files
29 genePredFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".genePred")
30 unsortedBedFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".unsortedBed")
31 sortedBedFile = tempfile.NamedTemporaryFile(suffix=".sortedBed")
32
33 twoBitInfoFile = tempfile.NamedTemporaryFile(bufsize=0)
34 chromSizesFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".chrom.sizes")
35
36 # GtfToGenePred
37 subtools.gtfToGenePred(self.input_gtf_false_path, genePredFile.name)
38
39 # TODO: From there, refactor because common use with Gff3.py
40 # genePredToBed processing
41 subtools.genePredToBed(genePredFile.name, unsortedBedFile.name)
42
43 # Sort processing
44 subtools.sort(unsortedBedFile.name, sortedBedFile.name)
45
46 # TODO: Chehck if the twoBitInfo / ChromSizes is redundant and make an intermediate class
47 # Generate the twoBitInfo
48 subtools.twoBitInfo(self.twoBitFile.name, twoBitInfoFile.name)
49
50 # Then we get the output to generate the chromSizes
51 # TODO: Check if no errors
52 subtools.sortChromSizes(twoBitInfoFile.name, chromSizesFile.name)
53
54 # bedToBigBed processing
55 # TODO: Change the name of the bb, to tool + genome + possible adding if multiple + .bb
56 trackName = "".join( ( self.name_gtf, ".bb") )
57 myBigBedFilePath = os.path.join(self.myTrackFolderPath, trackName)
58 with open(myBigBedFilePath, 'w') as bigBedFile:
59 subtools.bedToBigBed(sortedBedFile.name, chromSizesFile.name, bigBedFile.name)
60
61 # Create the Track Object
62 dataURL = "tracks/%s" % trackName
63
64 trackDb = TrackDb(
65 trackName=trackName,
66 longLabel=self.name_gtf,
67 shortLabel=self.getShortName( self.name_gtf ),
68 trackDataURL=dataURL,
69 trackType='bigBed 12 +',
70 visibility='dense',
71 priority=self.priority,
72 )
73 self.track = Track(
74 trackFile=myBigBedFilePath,
75 trackDb=trackDb,
76 )
77
78 print("- %s created in %s" % (trackName, myBigBedFilePath))