PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/tools/sr_assembly/velveth_wrapper.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 65 lines | 52 code | 6 blank | 7 comment | 0 complexity | f8a277dc6760ba1dc136971a772d68c2 MD5 | raw file
 1#!/usr/bin/env python
 2
 3"""
 4Classes encapsulating decypher tool.
 5James E Johnson - University of Minnesota
 6"""
 7import pkg_resources
 8import logging, os, string, sys, tempfile, glob, shutil, types, urllib
 9import shlex, subprocess
10from optparse import OptionParser, OptionGroup
11from stat import *
12
13
14log = logging.getLogger( __name__ )
15
16assert sys.version_info[:2] >= ( 2, 4 )
17
18def stop_err( msg ):
19    sys.stderr.write( "%s\n" % msg )
20    sys.exit()
21
22def __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
65if __name__ == "__main__": __main__()