comparison BedSimpleRepeats.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 from Datatype import Datatype
7 from Track import Track
8 from TrackDb import TrackDb
9 from util import subtools
10
11
12 class BedSimpleRepeats( Datatype ):
13 def __init__( self, input_bed_simple_repeats_false_path, data_bed_simple_repeats,
14 input_fasta_file, extra_files_path, tool_directory ):
15
16 super(BedSimpleRepeats, self).__init__(
17 input_fasta_file, extra_files_path, tool_directory
18 )
19
20 self.input_bed_simple_repeats_false_path = input_bed_simple_repeats_false_path
21 self.name_bed_simple_repeats = data_bed_simple_repeats["name"]
22 self.priority = data_bed_simple_repeats["order_index"]
23
24 sortedBedFile = tempfile.NamedTemporaryFile(suffix=".sortedBed")
25 twoBitInfoFile = tempfile.NamedTemporaryFile(bufsize=0)
26 chromSizesFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".chrom.sizes")
27
28 # Sort processing
29 subtools.sort(self.input_bed_simple_repeats_false_path, sortedBedFile.name)
30
31 # TODO: Regroup in an mother class which handles the Chrom.sizes creation with Gff3 and Gtf
32 # Generate the chrom.sizes
33
34 subtools.twoBitInfo(self.twoBitFile.name, twoBitInfoFile.name)
35
36 # Then we get the output to inject into the sort
37 # TODO: Check if no errors
38 subtools.sortChromSizes(twoBitInfoFile.name, chromSizesFile.name)
39
40 # bedToBigBed processing
41 # TODO: Change the name of the bb, to tool + genome + .bb
42 trackName = "".join( ( self.name_bed_simple_repeats, '.bb' ) )
43 myBigBedFilePath = os.path.join(self.myTrackFolderPath, trackName)
44 auto_sql_option = "%s%s" % ('-as=', os.path.join(self.tool_directory, 'trf_simpleRepeat.as'))
45 with open(myBigBedFilePath, 'w') as bigBedFile:
46 subtools.bedToBigBed(sortedBedFile.name, chromSizesFile.name, bigBedFile.name,
47 typeOption='-type=bed4+12',
48 autoSql=auto_sql_option)
49
50 # Create the Track Object
51 dataURL = "tracks/%s" % trackName
52
53 trackDb = TrackDb(
54 trackName=trackName,
55 longLabel=self.name_bed_simple_repeats,
56 shortLabel=self.getShortName( self.name_bed_simple_repeats ),
57 trackDataURL=dataURL,
58 trackType='bigBed 4 +',
59 visibility='dense',
60 priority=self.priority,
61 )
62
63 self.track = Track(
64 trackFile=myBigBedFilePath,
65 trackDb=trackDb,
66 )
67
68 print("- %s created in %s" % (trackName, myBigBedFilePath))