Mercurial > repos > yufei-luo > s_mart
diff commons/launcher/launchPhyML.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commons/launcher/launchPhyML.py Mon Apr 29 03:20:15 2013 -0400 @@ -0,0 +1,87 @@ +#!/usr/bin/env python + +import os +import sys +import getopt + +from pyRepet.launcher.programLauncher import programLauncher +from commons.tools.ChangeSequenceHeaders import ChangeSequenceHeaders + + +def help(): + print + print "usage: ",sys.argv[0],"[ options ]" + print "options:" + print " -h: this help" + print " -i: name of the input file (aligned fasta)" + print " -c: clean" + print " -v: verbose (default=0)" + print + + +def main(): + + inFileName = "" + clean = False + verbose = 0 + try: + opts,args=getopt.getopt(sys.argv[1:],"hi:cv:") + except getopt.GetoptError, err: + print str(err) + help(); sys.exit(1) + for o,a in opts: + if o == "-h": + help(); sys.exit(0) + elif o == "-i": + inFileName = a + elif o == "-c": + clean = True + elif o == "-v": + verbose = int(a) + if inFileName == "": + print "ERROR: missing compulsory options" + help(); sys.exit(1) + + if verbose > 0: + print "START %s" % (sys.argv[0].split("/")[-1]) + sys.stdout.flush() + + csh = ChangeSequenceHeaders() + csh.setInputFile( inFileName ) + csh.setFormat( "fasta" ) + csh.setStep( 1 ) + csh.setPrefix( "seq" ) + csh.setLinkFile( inFileName+".shortHlink" ) + csh.setOutputFile( inFileName+".shortH" ) + csh.run() + + pL = programLauncher( inFileName+".shortH" ) + + pL.launchSreformat( outFormat="phylip", outFileName=inFileName+".shortH.phylip", verbose=verbose ) + + pL.reset( inFileName+".shortH.phylip" ) + + pL.launchPhyML( verbose=verbose ) + + csh.setInputFile( inFileName+".shortH.phylip_phyml_tree.txt" ) + csh.setFormat( "newick" ) + csh.setStep( 2 ) + csh.setLinkFile( inFileName+".shortHlink" ) + csh.setOutputFile( inFileName+"_phyml.newick" ) + csh.run() + + if clean: + for f in [ inFileName+".shortH", inFileName+".shortHlink", inFileName+".shortH.phylip", + inFileName+".shortH.phylip_phyml_lk.txt", inFileName+".shortH.phylip_phyml_tree.txt" ]: + os.remove( f ) + os.system( "mv %s.shortH.phylip_phyml_stat.txt %s_phyml.txt" % ( inFileName, inFileName ) ) + + if verbose > 0: + print "END %s" % (sys.argv[0].split("/")[-1]) + sys.stdout.flush() + + return 0 + + +if __name__ == "__main__": + main()