comparison TEiso/CufflinksGTFToBed_Wrapper.py @ 1:15d6811e6bf5 draft

Uploaded
author urgi-team
date Tue, 24 May 2016 08:59:28 -0400
parents 3d22562b4489
children
comparison
equal deleted inserted replaced
0:3d22562b4489 1:15d6811e6bf5
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2 import subprocess, tempfile, sys, os
3
4 import subprocess, tempfile, sys, os, glob, shutil, time
5 from optparse import OptionParser 3 from optparse import OptionParser
6 from commons.core.utils.RepetOptionParser import RepetOptionParser 4 #from commons.core.utils.RepetOptionParser import RepetOptionParser
7 5
8 6
9 class CufflinksGTFToBedWrapper(object): 7 class CufflinksGTFToBedWrapper(object):
10 8
11 def __init__(self): 9 def __init__(self):
16 sys.stderr.write( "%s\n" % msg ) 14 sys.stderr.write( "%s\n" % msg )
17 sys.exit() 15 sys.exit()
18 16
19 17
20 def setAttributesFromCmdLine(self): 18 def setAttributesFromCmdLine(self):
21 self._toolVersion = "1.0" 19 #self._toolVersion = "1.0"
22 description = "CufflinksGTFToBed version %s" % self._toolVersion 20 description = "CufflinksGTFToBed "
23 epilog = "\n parses a GTF file of Cufflinks and create a bed file. \n" 21 epilog = "\n parses a GTF file of Cufflinks and create a bed file. \n"
24 epilog += "example: CufflinksGTFToBed.py -i <inputFile> -o <outputFile>\n" 22 epilog += "example: CufflinksGTFToBed.py -i <inputFile> -o <outputFile>\n"
25 parser = RepetOptionParser(description = description, epilog = epilog, version = self._toolVersion) 23 #parser = RepetOptionParser(description = description, epilog = epilog, version = self._toolVersion)
24 parser = OptionParser(description = description, version = "1.0")
26 parser.add_option("-i", "--inputFile", dest = "inputFile", action = "store", type = "string", help = "Input GTF File name(transcript.gtf of Cufflinks).", default = "") 25 parser.add_option("-i", "--inputFile", dest = "inputFile", action = "store", type = "string", help = "Input GTF File name(transcript.gtf of Cufflinks).", default = "")
27 parser.add_option("-o", "--outputFile", dest = "outputFile", action = "store", type = "string", help = "output Bed File name", default = "") 26 parser.add_option("-o", "--outputFile", dest = "outputFile", action = "store", type = "string", help = "output Bed File name", default = "")
28 parser.add_option("-v", "--verbosity", dest = "verbosity", action = "store", type = "int", help = "Verbosity [optional] [default: 3]",default = 3) 27 parser.add_option("-v", "--verbosity", dest = "verbosity", action = "store", type = "int", help = "Verbosity [optional] [default: 3]",default = 3)
29 options = parser.parse_args()[0] 28 options = parser.parse_args()[0]
30 self._setAttributesFromOptions(options) 29 self._setAttributesFromOptions(options)
31 30
32 def _setAttributesFromOptions(self, options): 31 def _setAttributesFromOptions(self, options):
33 self._options = options 32 self._options = options
34 33
35 def run(self): 34 def run(self):
35 tmp = "%s_tmp" % ((os.path.splitext(self._options.outputFile)[0]))
36 prg = "CufflinksGTFToBed.py" 36 prg = "CufflinksGTFToBed.py"
37 args = "" 37 args = ""
38 args += "-i %s" % self._options.inputFile 38 args += "-i %s" % self._options.inputFile
39 args += " "
40 args += "-o %s" % tmp
39 cmd = "%s %s" %(prg, args) 41 cmd = "%s %s" %(prg, args)
40 print cmd 42 print cmd
41 43
42 try: 44 try:
43 tmp_err = tempfile.NamedTemporaryFile().name 45 tmp_err = tempfile.NamedTemporaryFile().name
59 tmp_stderr.close() 61 tmp_stderr.close()
60 if stderr: 62 if stderr:
61 raise Exception, stderr 63 raise Exception, stderr
62 except Exception, e: 64 except Exception, e:
63 self.stop_err( 'Error in TranscriptToBed:\n' + str( e ) ) 65 self.stop_err( 'Error in TranscriptToBed:\n' + str( e ) )
66 try:
67 cmdsort= "bedtools sort -i %s > %s" % (tmp, self._options.outputFile)
68 os.system(cmdsort)
69 except Exception, e:
70 self.stop_err( 'Error in bedtools sort:\n' + str( e ) )
71
64 72
65 if __name__ == "__main__": 73 if __name__ == "__main__":
66 iWrapper = CufflinksGTFToBedWrapper() 74 iWrapper = CufflinksGTFToBedWrapper()
67 iWrapper.setAttributesFromCmdLine() 75 iWrapper.setAttributesFromCmdLine()
68 iWrapper.run() 76 iWrapper.run()