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