Mercurial > repos > artbio > oases
comparison oases_optimiser.py @ 0:f7dd852c8f4c draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/oases commit 48b8101fd53263212839ecb14d3029811a3278f4
author | artbio |
---|---|
date | Sun, 15 Oct 2017 19:07:38 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f7dd852c8f4c |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 VelvetOptimiser Wrapper | |
5 refactored using the adaptation of | |
6 Konrad Paszkiewicz University of Exeter, UK. | |
7 | |
8 """ | |
9 import os | |
10 import subprocess | |
11 import sys | |
12 | |
13 | |
14 def stop_err(msg): | |
15 sys.stderr.write("%s\n" % msg) | |
16 sys.exit() | |
17 | |
18 | |
19 def oases_optimiser(starthash, endhash, input): | |
20 ''' | |
21 Replaces call to oases_optimiser.sh. For all k-mers between | |
22 starthash and endhash run velvet and oases. | |
23 ''' | |
24 for i in range(starthash, endhash, 2): | |
25 cmd1 = "velveth outputFolder_{0} {0} {1} && ".format(i, input) | |
26 cmd2 = "velvetg outputFolder_{0} -read_trkg yes && ".format(i) | |
27 cmd3 = "oases outputFolder_{0}".format(i) | |
28 proc = subprocess.call(args=cmd1 + cmd2 + cmd3, shell=True, | |
29 stdout=sys.stdout, stderr=sys.stdout) | |
30 if not proc == 0: | |
31 print("Oases failed at k-mer %s, skipping" % i) | |
32 continue | |
33 cmd4 = "velveth MergedAssemblyFolder 27 -long\ | |
34 outputFolder_*/transcripts.fa && " | |
35 cmd5 = "velvetg MergedAssemblyFolder -read_trkg yes -conserveLong yes && " | |
36 cmd6 = "oases MergedAssemblyFolder -merge yes" | |
37 proc = subprocess.call(args=cmd4 + cmd5 + cmd6, shell=True, | |
38 stdout=sys.stdout, stderr=sys.stdout) | |
39 if not proc == 0: | |
40 raise Exception("Oases could not merge assembly") | |
41 | |
42 | |
43 def __main__(): | |
44 starthash = int(sys.argv[1]) | |
45 endhash = int(sys.argv[2]) | |
46 input = sys.argv[3] | |
47 transcripts = sys.argv[4] | |
48 try: | |
49 oases_optimiser(starthash, endhash, input) | |
50 except Exception as e: | |
51 stop_err('Error running oases_optimiser.py\n' + str(e)) | |
52 with open(transcripts, 'w') as out: | |
53 transcript_path = os.path.join('MergedAssemblyFolder', | |
54 'transcripts.fa') | |
55 for line in open(transcript_path): | |
56 out.write("%s" % (line)) | |
57 | |
58 | |
59 if __name__ == "__main__": | |
60 __main__() |