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