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