annotate oases_optimiser.py @ 2:b5df930313cc draft

planemo upload for repository https://bitbucket.org/drosofff/gedtools/
author drosofff
date Mon, 22 Jun 2015 10:39:20 -0400
parents eedbe32980bb
children dc684e37f668
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
2
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
20 def oases_optimiser(starthash, endhash, input, job_dir):
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
21 '''
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
22 Replaces call to oases_optimiser.sh. For all k-mers between
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
23 starthash and endhash run velvet and oases.
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
24 '''
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
25 for i in xrange(starthash, endhash, 2):
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
26 cmd1="velveth {0}/outputFolder_{1} {1} {2} && ".format(job_dir, i, input)
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
27 cmd2="velvetg {0}/outputFolder_{1} -read_trkg yes && ".format(job_dir, i)
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
28 cmd3="oases {0}/outputFolder_{1}".format(job_dir, i)
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
29 proc = subprocess.call( args=cmd1+cmd2+cmd3, shell=True, stdout=sys.stdout, stderr=sys.stderr )
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
30 cmd4="velveth {0}/MergedAssemblyFolder 27 -long outputFolder_*/transcripts.fa && ".format(job_dir)
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
31 cmd5="velvetg {0}/MergedAssemblyFolder -read_trkg yes -conserveLong yes && ".format(job_dir)
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
32 cmd6="oases {0}/MergedAssemblyFolder -merge yes".format(job_dir)
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
33 proc = subprocess.call( args=cmd4+cmd5+cmd6, shell=True, stdout=sys.stdout, stderr=sys.stderr )
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
34
0
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
35 def __main__():
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
36 job_dir= os.getcwd()
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
37 #Parse Command Line
2
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
38 starthash = int(sys.argv[1])
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
39 endhash = int(sys.argv[2])
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
40 input = sys.argv[3]
0
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
41 transcripts = sys.argv[4]
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
42 transcripts_path = ''
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
43 print >> sys.stdout, "PATH = %s" % (os.environ['PATH'])
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
44 try:
2
b5df930313cc planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents: 0
diff changeset
45 oases_optimiser(starthash, endhash, input, job_dir)
0
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
46 except Exception, e:
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
47 stop_err( 'Error running oases_optimiser.py' + str( e ) )
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
48 out = open(transcripts,'w')
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
49 transcript_path = os.path.join(job_dir, "MergedAssemblyFolder", 'transcripts.fa')
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
50 print >> sys.stdout, transcript_path
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
51 for line in open(transcript_path):
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
52 out.write( "%s" % (line) )
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
53 out.close()
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
54
eedbe32980bb planemo upload for repository https://bitbucket.org/drosofff/gedtools/
drosofff
parents:
diff changeset
55 if __name__ == "__main__": __main__()