comparison velveth_wrapper.py @ 0:08256557922f draft

planemo upload commit 4720b3dfa114d790b597fef6ccf3c17e8c11e111
author devteam
date Tue, 13 Oct 2015 16:38:28 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:08256557922f
1 #!/usr/bin/env python
2
3 """
4 Classes encapsulating decypher tool.
5 James E Johnson - University of Minnesota
6 """
7 import pkg_resources
8 import logging, os, string, sys, tempfile, glob, shutil, types, urllib
9 import shlex, subprocess
10 from optparse import OptionParser, OptionGroup
11 from stat import *
12
13
14 log = logging.getLogger( __name__ )
15
16 assert sys.version_info[:2] >= ( 2, 4 )
17
18 def stop_err( msg ):
19 sys.stderr.write( "%s\n" % msg )
20 sys.exit()
21
22 def __main__():
23 #Parse Command Line
24 s = 'velveth_wrapper.py: argv = %s\n' % (sys.argv)
25 argcnt = len(sys.argv)
26 html_file = sys.argv[1]
27 working_dir = sys.argv[2]
28 try: # for test - needs this done
29 os.makedirs(working_dir)
30 except Exception, e:
31 stop_err( 'Error running velveth ' + str( e ) )
32 hash_length = sys.argv[3]
33 inputs = string.join(sys.argv[4:],' ')
34 cmdline = 'velveth %s %s %s > /dev/null' % (working_dir, hash_length, inputs)
35 try:
36 proc = subprocess.Popen( args=cmdline, shell=True, stderr=subprocess.PIPE )
37 returncode = proc.wait()
38 # get stderr, allowing for case where it's very large
39 stderr = ''
40 buffsize = 1048576
41 try:
42 while True:
43 stderr += proc.stderr.read( buffsize )
44 if not stderr or len( stderr ) % buffsize != 0:
45 break
46 except OverflowError:
47 pass
48 if returncode != 0:
49 raise Exception, stderr
50 except Exception, e:
51 stop_err( 'Error running velveth ' + str( e ) )
52 sequences_path = os.path.join(working_dir,'Sequences')
53 roadmaps_path = os.path.join(working_dir,'Roadmaps')
54 rval = ['<html><head><title>Velvet Galaxy Composite Dataset </title></head><p/>']
55 rval.append('<div>%s<p/></div>' % (cmdline) )
56 rval.append('<div>This composite dataset is composed of the following files:<p/><ul>')
57 rval.append( '<li><a href="%s" type="text/plain">%s </a>%s</li>' % (sequences_path,'Sequences','Sequences' ) )
58 rval.append( '<li><a href="%s" type="text/plain">%s </a>%s</li>' % (roadmaps_path,'Roadmaps','Roadmaps' ) )
59 rval.append( '</ul></div></html>' )
60 f = file(html_file,'w')
61 f.write("\n".join( rval ))
62 f.write('\n')
63 f.close()
64
65 if __name__ == "__main__": __main__()