diff TEiso/GFFToBed_Wrapper.py @ 1:15d6811e6bf5 draft

Uploaded
author urgi-team
date Tue, 24 May 2016 08:59:28 -0400
parents 3d22562b4489
children
line wrap: on
line diff
--- a/TEiso/GFFToBed_Wrapper.py	Fri Apr 29 09:11:18 2016 -0400
+++ b/TEiso/GFFToBed_Wrapper.py	Tue May 24 08:59:28 2016 -0400
@@ -3,7 +3,7 @@
 
 import subprocess, tempfile, sys, os, glob, shutil, time
 from optparse import OptionParser
-from commons.core.utils.RepetOptionParser import RepetOptionParser
+#from commons.core.utils.RepetOptionParser import RepetOptionParser
 
 
 class GFFToBedWrapper(object):
@@ -18,12 +18,13 @@
         
         
     def setAttributesFromCmdLine(self):
-        self._toolVersion = "1.0"
-        description = "GFFToBed version %s" % self._toolVersion
-        epilog = "\n parses a GFF file and create a bed file. \n"
+       ## self._toolVersion = "1.0"
+        description = "GFFToBed version"
+        epilog = "\n parses a GFF3 file and create a bed file. \n"
         epilog += "example: GFFToBed.py -i <inputFile> -o  <outputFile>\n"
-        parser = RepetOptionParser(description = description, epilog = epilog, version = self._toolVersion) 
-        parser.add_option("-i", "--inputFile",  dest = "inputFile",  action = "store", type = "string", help = "Input GFF File name.",  default = "")
+        #parser = RepetOptionParser(description = description, epilog = epilog, version = self._toolVersion)
+        parser = OptionParser(description = description, version = "1.0") 
+        parser.add_option("-i", "--inputFile",  dest = "inputFile",  action = "store", type = "string", help = "Input GFF3 File name.",  default = "")
         parser.add_option("-o", "--outputFile", dest = "outputFile", action = "store", type = "string", help = "output Bed File name", default = "")
         parser.add_option("-v", "--verbosity",  dest = "verbosity",  action = "store", type = "int",    help = "Verbosity [optional] [default: 3]",default = 3)
         options = parser.parse_args()[0]
@@ -33,12 +34,15 @@
         self._options = options
 
     def run(self):
-        prg = "GFFToBed.py"
+	tmp = "%s_tmp" % ((os.path.splitext(self._options.outputFile)[0]))
+	prg = "GFFToBed.py"
         args = ""
         args += "-i %s" % self._options.inputFile
+        args += " "
+        args += "-o %s" % tmp
         cmd = "%s %s" %(prg, args)
         print cmd
-        
+ 
         try:
             tmp_err = tempfile.NamedTemporaryFile().name
             tmp_stderr = open( tmp_err, 'wb' )
@@ -61,7 +65,16 @@
                 raise Exception, stderr
         except Exception, e:
             self.stop_err( 'Error in GFFToBed:\n' + str( e ) ) 
-        
+
+	
+	try:
+	    cmdsort= "bedtools sort -i %s > %s" % (tmp, self._options.outputFile)
+	    os.system(cmdsort)
+        except Exception, e:
+            self.stop_err( 'Error in bedtools sort:\n' + str( e ) )
+
+
+
 if __name__ == "__main__":
     iWrapper = GFFToBedWrapper()
     iWrapper.setAttributesFromCmdLine()