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