annotate tools/sr_assembly/velveth_wrapper.py @ 1:cdcb0ce84a1b

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