Mercurial > repos > drosofff > msp_oases
comparison 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 |
comparison
equal
deleted
inserted
replaced
1:070f9de358fc | 2:b5df930313cc |
---|---|
15 | 15 |
16 def stop_err( msg ): | 16 def stop_err( msg ): |
17 sys.stderr.write( "%s\n" % msg ) | 17 sys.stderr.write( "%s\n" % msg ) |
18 sys.exit() | 18 sys.exit() |
19 | 19 |
20 def oases_optimiser(starthash, endhash, input, job_dir): | |
21 ''' | |
22 Replaces call to oases_optimiser.sh. For all k-mers between | |
23 starthash and endhash run velvet and oases. | |
24 ''' | |
25 for i in xrange(starthash, endhash, 2): | |
26 cmd1="velveth {0}/outputFolder_{1} {1} {2} && ".format(job_dir, i, input) | |
27 cmd2="velvetg {0}/outputFolder_{1} -read_trkg yes && ".format(job_dir, i) | |
28 cmd3="oases {0}/outputFolder_{1}".format(job_dir, i) | |
29 proc = subprocess.call( args=cmd1+cmd2+cmd3, shell=True, stdout=sys.stdout, stderr=sys.stderr ) | |
30 cmd4="velveth {0}/MergedAssemblyFolder 27 -long outputFolder_*/transcripts.fa && ".format(job_dir) | |
31 cmd5="velvetg {0}/MergedAssemblyFolder -read_trkg yes -conserveLong yes && ".format(job_dir) | |
32 cmd6="oases {0}/MergedAssemblyFolder -merge yes".format(job_dir) | |
33 proc = subprocess.call( args=cmd4+cmd5+cmd6, shell=True, stdout=sys.stdout, stderr=sys.stderr ) | |
34 | |
20 def __main__(): | 35 def __main__(): |
21 job_dir= os.getcwd() | 36 job_dir= os.getcwd() |
22 #tmp_work_dir = tempfile.mkdtemp(dir = job_dir) # make temp directory in the job_dir | |
23 #Parse Command Line | 37 #Parse Command Line |
24 starthash = sys.argv[1] | 38 starthash = int(sys.argv[1]) |
25 endhash = sys.argv[2] | 39 endhash = int(sys.argv[2]) |
26 inputs = sys.argv[3] | 40 input = sys.argv[3] |
27 transcripts = sys.argv[4] | 41 transcripts = sys.argv[4] |
28 transcripts_path = '' | 42 transcripts_path = '' |
29 cmdline = "oases_optimiser.sh %s %s '%s' %s 2&1>/dev/null" % (starthash, endhash, inputs, job_dir) # 2&1>/dev/null | |
30 print >> sys.stdout, cmdline # so will appear as blurb for file | |
31 print >> sys.stdout, job_dir | |
32 print >> sys.stdout, "PATH = %s" % (os.environ['PATH']) | 43 print >> sys.stdout, "PATH = %s" % (os.environ['PATH']) |
33 try: | 44 try: |
34 proc = subprocess.Popen( args=cmdline, shell=True, stderr=subprocess.PIPE ) # cwd=job_dir | 45 oases_optimiser(starthash, endhash, input, job_dir) |
35 returncode = proc.wait() | |
36 # get stderr, allowing for case where it's very large | |
37 stderr = '' | |
38 buffsize = 1048576 | |
39 try: | |
40 while True: | |
41 stderr += proc.stderr.read( buffsize ) | |
42 if not stderr or len( stderr ) % buffsize != 0: | |
43 break | |
44 except OverflowError: | |
45 pass | |
46 if returncode != 0: | |
47 raise Exception, stderr | |
48 except Exception, e: | 46 except Exception, e: |
49 stop_err( 'Error running oases_optimiser.py' + str( e ) ) | 47 stop_err( 'Error running oases_optimiser.py' + str( e ) ) |
50 out = open(transcripts,'w') | 48 out = open(transcripts,'w') |
51 transcript_path = os.path.join(job_dir, "MergedAssemblyFolder", 'transcripts.fa') | 49 transcript_path = os.path.join(job_dir, "MergedAssemblyFolder", 'transcripts.fa') |
52 print >> sys.stdout, transcript_path | 50 print >> sys.stdout, transcript_path |