annotate velveth_wrapper.py @ 0:c170448acc8a draft

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