annotate oases_optimiser.py @ 0:eedbe32980bb draft

planemo upload for repository https://bitbucket.org/drosofff/gedtools/
author drosofff
date Sun, 21 Jun 2015 14:38:06 -0400
parents
children b5df930313cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
1 #!/usr/bin/env python
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
2
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
3 """
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
4 VelvetOptimiser Wrapper
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
5 refactored using the adaptation of
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
6 Konrad Paszkiewicz University of Exeter, UK.
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
7
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
8 """
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
9 import pkg_resources;
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
10 import logging, os, string, sys, tempfile, glob, shutil, types, urllib
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
11 import shlex, subprocess
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
12 from optparse import OptionParser, OptionGroup
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
13 from stat import *
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
14
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
15
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
16 def stop_err( msg ):
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
17 sys.stderr.write( "%s\n" % msg )
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
18 sys.exit()
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
19
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
20 def __main__():
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
21 job_dir= os.getcwd()
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
22 #tmp_work_dir = tempfile.mkdtemp(dir = job_dir) # make temp directory in the job_dir
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
23 #Parse Command Line
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
24 starthash = sys.argv[1]
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
25 endhash = sys.argv[2]
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
26 inputs = sys.argv[3]
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
27 transcripts = sys.argv[4]
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
28 transcripts_path = ''
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
29 cmdline = "oases_optimiser.sh %s %s '%s' %s 2&1>/dev/null" % (starthash, endhash, inputs, job_dir) # 2&1>/dev/null
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
30 print >> sys.stdout, cmdline # so will appear as blurb for file
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
31 print >> sys.stdout, job_dir
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
32 print >> sys.stdout, "PATH = %s" % (os.environ['PATH'])
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
33 try:
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
34 proc = subprocess.Popen( args=cmdline, shell=True, stderr=subprocess.PIPE ) # cwd=job_dir
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
35 returncode = proc.wait()
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
36 # get stderr, allowing for case where it's very large
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
37 stderr = ''
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
38 buffsize = 1048576
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
39 try:
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
40 while True:
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
41 stderr += proc.stderr.read( buffsize )
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
42 if not stderr or len( stderr ) % buffsize != 0:
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
43 break
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
44 except OverflowError:
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
45 pass
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
46 if returncode != 0:
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
47 raise Exception, stderr
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
48 except Exception, e:
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
49 stop_err( 'Error running oases_optimiser.py' + str( e ) )
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
50 out = open(transcripts,'w')
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
51 transcript_path = os.path.join(job_dir, "MergedAssemblyFolder", 'transcripts.fa')
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
52 print >> sys.stdout, transcript_path
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
53 for line in open(transcript_path):
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
54 out.write( "%s" % (line) )
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
55 out.close()
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
56
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
57 if __name__ == "__main__": __main__()