Mercurial > repos > drosofff > msp_oases
diff 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 |
line wrap: on
line diff
--- a/oases_optimiser.py Tue Sep 29 06:29:42 2015 -0400 +++ b/oases_optimiser.py Thu May 12 10:45:03 2016 -0400 @@ -6,50 +6,48 @@ Konrad Paszkiewicz University of Exeter, UK. """ -import pkg_resources; -import logging, os, string, sys, tempfile, glob, shutil, types, urllib -import shlex, subprocess -from optparse import OptionParser, OptionGroup -from stat import * +import os, sys +import subprocess -def stop_err( msg ): - sys.stderr.write( "%s\n" % msg ) +def stop_err(msg): + sys.stderr.write("%s\n" % msg) sys.exit() -def oases_optimiser(starthash, endhash, input, job_dir): + +def oases_optimiser(starthash, endhash, input): ''' Replaces call to oases_optimiser.sh. For all k-mers between starthash and endhash run velvet and oases. ''' for i in xrange(starthash, endhash, 2): - cmd1="velveth {0}/outputFolder_{1} {1} {2} && ".format(job_dir, i, input) - cmd2="velvetg {0}/outputFolder_{1} -read_trkg yes && ".format(job_dir, i) - cmd3="oases {0}/outputFolder_{1}".format(job_dir, i) - proc = subprocess.call( args=cmd1+cmd2+cmd3, shell=True, stdout=sys.stdout, stderr=sys.stderr ) - cmd4="velveth {0}/MergedAssemblyFolder 27 -long outputFolder_*/transcripts.fa && ".format(job_dir) - cmd5="velvetg {0}/MergedAssemblyFolder -read_trkg yes -conserveLong yes && ".format(job_dir) - cmd6="oases {0}/MergedAssemblyFolder -merge yes".format(job_dir) - proc = subprocess.call( args=cmd4+cmd5+cmd6, shell=True, stdout=sys.stdout, stderr=sys.stderr ) + cmd1 = "velveth outputFolder_{0} {0} {1} && ".format(i, input) + cmd2 = "velvetg outputFolder_{0} -read_trkg yes && ".format(i) + cmd3 = "oases outputFolder_{0}".format(i) + proc = subprocess.call(args=cmd1 + cmd2 + cmd3, shell=True, stdout=sys.stdout, stderr=sys.stdout) + if not proc == 0: + print("Oases failed at k-mer %s, skipping" % i) + continue + cmd4 = "velveth MergedAssemblyFolder 27 -long outputFolder_*/transcripts.fa && " + cmd5 = "velvetg MergedAssemblyFolder -read_trkg yes -conserveLong yes && " + cmd6 = "oases MergedAssemblyFolder -merge yes" + proc = subprocess.call(args=cmd4 + cmd5 + cmd6, shell=True, stdout=sys.stdout, stderr=sys.stdout) + if not proc == 0: + raise Exception("Oases could not merge assembly") def __main__(): - job_dir= os.getcwd() - #Parse Command Line starthash = int(sys.argv[1]) endhash = int(sys.argv[2]) input = sys.argv[3] transcripts = sys.argv[4] - transcripts_path = '' - print >> sys.stdout, "PATH = %s" % (os.environ['PATH']) try: - oases_optimiser(starthash, endhash, input, job_dir) + oases_optimiser(starthash, endhash, input) except Exception, e: - stop_err( 'Error running oases_optimiser.py' + str( e ) ) - out = open(transcripts,'w') - transcript_path = os.path.join(job_dir, "MergedAssemblyFolder", 'transcripts.fa') - print >> sys.stdout, transcript_path - for line in open(transcript_path): - out.write( "%s" % (line) ) - out.close() - + stop_err('Error running oases_optimiser.py\n' + str(e)) + with open(transcripts, 'w') as out: + transcript_path = os.path.join("MergedAssemblyFolder", 'transcripts.fa') + for line in open(transcript_path): + out.write("%s" % (line)) + + if __name__ == "__main__": __main__()