comparison oases_optimiser.py @ 4:dc684e37f668 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/msp_oases commit 47a8a06faad1aa3c36503934ee2fd9e6031d3b75
author drosofff
date Thu, 12 May 2016 10:45:03 -0400
parents b5df930313cc
children
comparison
equal deleted inserted replaced
3:f08d9c814ffb 4:dc684e37f668
4 VelvetOptimiser Wrapper 4 VelvetOptimiser Wrapper
5 refactored using the adaptation of 5 refactored using the adaptation of
6 Konrad Paszkiewicz University of Exeter, UK. 6 Konrad Paszkiewicz University of Exeter, UK.
7 7
8 """ 8 """
9 import pkg_resources; 9 import os, sys
10 import logging, os, string, sys, tempfile, glob, shutil, types, urllib 10 import subprocess
11 import shlex, subprocess
12 from optparse import OptionParser, OptionGroup
13 from stat import *
14 11
15 12
16 def stop_err( msg ): 13 def stop_err(msg):
17 sys.stderr.write( "%s\n" % msg ) 14 sys.stderr.write("%s\n" % msg)
18 sys.exit() 15 sys.exit()
19 16
20 def oases_optimiser(starthash, endhash, input, job_dir): 17
18 def oases_optimiser(starthash, endhash, input):
21 ''' 19 '''
22 Replaces call to oases_optimiser.sh. For all k-mers between 20 Replaces call to oases_optimiser.sh. For all k-mers between
23 starthash and endhash run velvet and oases. 21 starthash and endhash run velvet and oases.
24 ''' 22 '''
25 for i in xrange(starthash, endhash, 2): 23 for i in xrange(starthash, endhash, 2):
26 cmd1="velveth {0}/outputFolder_{1} {1} {2} && ".format(job_dir, i, input) 24 cmd1 = "velveth outputFolder_{0} {0} {1} && ".format(i, input)
27 cmd2="velvetg {0}/outputFolder_{1} -read_trkg yes && ".format(job_dir, i) 25 cmd2 = "velvetg outputFolder_{0} -read_trkg yes && ".format(i)
28 cmd3="oases {0}/outputFolder_{1}".format(job_dir, i) 26 cmd3 = "oases outputFolder_{0}".format(i)
29 proc = subprocess.call( args=cmd1+cmd2+cmd3, shell=True, stdout=sys.stdout, stderr=sys.stderr ) 27 proc = subprocess.call(args=cmd1 + cmd2 + cmd3, shell=True, stdout=sys.stdout, stderr=sys.stdout)
30 cmd4="velveth {0}/MergedAssemblyFolder 27 -long outputFolder_*/transcripts.fa && ".format(job_dir) 28 if not proc == 0:
31 cmd5="velvetg {0}/MergedAssemblyFolder -read_trkg yes -conserveLong yes && ".format(job_dir) 29 print("Oases failed at k-mer %s, skipping" % i)
32 cmd6="oases {0}/MergedAssemblyFolder -merge yes".format(job_dir) 30 continue
33 proc = subprocess.call( args=cmd4+cmd5+cmd6, shell=True, stdout=sys.stdout, stderr=sys.stderr ) 31 cmd4 = "velveth MergedAssemblyFolder 27 -long outputFolder_*/transcripts.fa && "
32 cmd5 = "velvetg MergedAssemblyFolder -read_trkg yes -conserveLong yes && "
33 cmd6 = "oases MergedAssemblyFolder -merge yes"
34 proc = subprocess.call(args=cmd4 + cmd5 + cmd6, shell=True, stdout=sys.stdout, stderr=sys.stdout)
35 if not proc == 0:
36 raise Exception("Oases could not merge assembly")
34 37
35 def __main__(): 38 def __main__():
36 job_dir= os.getcwd()
37 #Parse Command Line
38 starthash = int(sys.argv[1]) 39 starthash = int(sys.argv[1])
39 endhash = int(sys.argv[2]) 40 endhash = int(sys.argv[2])
40 input = sys.argv[3] 41 input = sys.argv[3]
41 transcripts = sys.argv[4] 42 transcripts = sys.argv[4]
42 transcripts_path = ''
43 print >> sys.stdout, "PATH = %s" % (os.environ['PATH'])
44 try: 43 try:
45 oases_optimiser(starthash, endhash, input, job_dir) 44 oases_optimiser(starthash, endhash, input)
46 except Exception, e: 45 except Exception, e:
47 stop_err( 'Error running oases_optimiser.py' + str( e ) ) 46 stop_err('Error running oases_optimiser.py\n' + str(e))
48 out = open(transcripts,'w') 47 with open(transcripts, 'w') as out:
49 transcript_path = os.path.join(job_dir, "MergedAssemblyFolder", 'transcripts.fa') 48 transcript_path = os.path.join("MergedAssemblyFolder", 'transcripts.fa')
50 print >> sys.stdout, transcript_path 49 for line in open(transcript_path):
51 for line in open(transcript_path): 50 out.write("%s" % (line))
52 out.write( "%s" % (line) ) 51
53 out.close() 52
54
55 if __name__ == "__main__": __main__() 53 if __name__ == "__main__": __main__()