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