annotate velvetg_wrapper.py @ 0:08256557922f draft

planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
author devteam
date Tue, 13 Oct 2015 16:38:28 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
1 #!/usr/bin/env python
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
2
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
3 """
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
4 Classes encapsulating decypher tool.
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
5 James E Johnson - University of Minnesota
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
6 """
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
7 import os
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
8 import sys
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
9 import subprocess
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
10
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
11 assert sys.version_info[:2] >= ( 2, 4 )
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
12
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
13 def stop_err( msg ):
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
14 sys.stderr.write( "%s\n" % msg )
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
15 sys.exit()
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
16
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
17
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
18 def __main__():
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
19 #Parse Command Line
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
20 working_dir = sys.argv[1]
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
21 inputs = ' '.join(sys.argv[2:])
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
22 for _ in ('Roadmaps', 'Sequences'):
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
23 os.symlink(os.path.join(working_dir, _), _)
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
24 cmdline = 'velvetg . %s' % (inputs)
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
25 print "Command to be executed: %s" % cmdline
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
26 try:
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
27 proc = subprocess.Popen( args=cmdline, shell=True, stderr=subprocess.PIPE )
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
28 returncode = proc.wait()
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
29 # get stderr, allowing for case where it's very large
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
30 stderr = ''
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
31 buffsize = 1048576
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
32 try:
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
33 while True:
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
34 stderr += proc.stderr.read( buffsize )
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
35 if not stderr or len( stderr ) % buffsize != 0:
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
36 break
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
37 except OverflowError:
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
38 pass
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
39 if returncode != 0:
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
40 raise Exception, stderr
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
41 except Exception, e:
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
42 stop_err( 'Error running velvetg ' + str( e ) )
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
43
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
44
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
45 if __name__ == "__main__":
08256557922f planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
devteam
parents:
diff changeset
46 __main__()