annotate commons/launcher/launchPhyML.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 #!/usr/bin/env python
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 import sys
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 import getopt
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 from pyRepet.launcher.programLauncher import programLauncher
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 from commons.tools.ChangeSequenceHeaders import ChangeSequenceHeaders
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 def help():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 print
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 print "usage: ",sys.argv[0],"[ options ]"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 print "options:"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 print " -h: this help"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 print " -i: name of the input file (aligned fasta)"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 print " -c: clean"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 print " -v: verbose (default=0)"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 print
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 def main():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 inFileName = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 clean = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 verbose = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 opts,args=getopt.getopt(sys.argv[1:],"hi:cv:")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 except getopt.GetoptError, err:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 print str(err)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 help(); sys.exit(1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 for o,a in opts:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 if o == "-h":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 help(); sys.exit(0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 elif o == "-i":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 inFileName = a
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 elif o == "-c":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 clean = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 elif o == "-v":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 verbose = int(a)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 if inFileName == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 print "ERROR: missing compulsory options"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 help(); sys.exit(1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 if verbose > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 print "START %s" % (sys.argv[0].split("/")[-1])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 sys.stdout.flush()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 csh = ChangeSequenceHeaders()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 csh.setInputFile( inFileName )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 csh.setFormat( "fasta" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 csh.setStep( 1 )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 csh.setPrefix( "seq" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 csh.setLinkFile( inFileName+".shortHlink" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 csh.setOutputFile( inFileName+".shortH" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 csh.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 pL = programLauncher( inFileName+".shortH" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 pL.launchSreformat( outFormat="phylip", outFileName=inFileName+".shortH.phylip", verbose=verbose )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 pL.reset( inFileName+".shortH.phylip" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 pL.launchPhyML( verbose=verbose )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 csh.setInputFile( inFileName+".shortH.phylip_phyml_tree.txt" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 csh.setFormat( "newick" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 csh.setStep( 2 )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 csh.setLinkFile( inFileName+".shortHlink" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 csh.setOutputFile( inFileName+"_phyml.newick" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 csh.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 if clean:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 for f in [ inFileName+".shortH", inFileName+".shortHlink", inFileName+".shortH.phylip",
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 inFileName+".shortH.phylip_phyml_lk.txt", inFileName+".shortH.phylip_phyml_tree.txt" ]:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 os.remove( f )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77 os.system( "mv %s.shortH.phylip_phyml_stat.txt %s_phyml.txt" % ( inFileName, inFileName ) )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 if verbose > 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 print "END %s" % (sys.argv[0].split("/")[-1])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 sys.stdout.flush()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 return 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 main()