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