#!/usr/bin/env python3 import birchscript import os import os.path import shutil import subprocess import sys #Version February 10, 2021 # Launch viewers for phylogenetic tree data or send output to files # For use by programs that generate tree output eg. bldna, blprotein, blmarker etc. # #Synopsis: bltreeoutput.py [-e|-d|-f] outtree outfile outname #Convert arguments to variables WHATTODO = str(sys.argv[1]) OUTTREE = str(sys.argv[2]) OUTFILE = str(sys.argv[3]) OUTNAME = str(sys.argv[4]) JOBID = str(os.getpid()) BIRCH = os.getenv("BIRCH") # Note that the second argument to birchscript.Cleanrun is a list of files to delete after the # command is executed. For the -e and -d options, OUTTREE is read by more than one command. # Therefore, the delete list is empty until the last command that reads OUTTREE. if WHATTODO == '-e': # output to tree editor birchscript.Cleanrun([["chooseviewer.py", OUTFILE]], [OUTFILE], True) birchscript.Cleanrun([['archaeopteryx', OUTTREE]], [], True) birchscript.Cleanrun([["chooseviewer.py", OUTTREE]], [], True) birchscript.Cleanrun([['python3', os.path.join(BIRCH, 'script', 'tree2flat.py'), OUTTREE, JOBID + '.flat'], ['bltree', JOBID + '.flat']], [OUTTREE, JOBID + '.flat'], True) if os.path.exists(OUTTREE + '.alltrees'): birchscript.Cleanrun([['python3', os.path.join(BIRCH, 'script', 'tree2flat.py'), OUTTREE + '.alltrees', JOBID + '.alltrees.flat'], ['bltree', JOBID + '.alltrees.flat']], [JOBID + '.alltrees.flat'], True) birchscript.Cleanrun([["chooseviewer.py", OUTTREE + '.alltrees']], [OUTTREE + '.alltrees'], True) elif WHATTODO == '-d': # output to the Phylip drawtree program birchscript.Cleanrun([['python3', os.path.join(BIRCH, 'script', 'tree2flat.py'), OUTTREE, JOBID + '.flat']], [], True) birchscript.Cleanrun([["chooseviewer.py", OUTFILE]], [OUTFILE], True) p= subprocess.Popen(['python3', os.path.join(BIRCH, 'script', 'drawtree.py'), OUTTREE, 'yes', 'f', '0', '360', 'IE', '360', 'reg', os.path.join(BIRCH, 'dat', 'Phylip', 'font1'), '0.333', 'l', JOBID + '.ps']) p.wait() birchscript.Cleanrun([["chooseviewer.py", JOBID + '.ps']], [JOBID + '.ps'], True) birchscript.Cleanrun([['bltree', JOBID + '.flat']], [], True) birchscript.Cleanrun([["chooseviewer.py", OUTTREE]], [OUTTREE, JOBID + '.flat'], True) if os.path.exists(OUTTREE + '.alltrees'): birchscript.Cleanrun([['python3', os.path.join(BIRCH, 'script', 'tree2flat.py'), OUTTREE + '.alltrees', JOBID + '.alltrees.flat'], ['bltree', JOBID + '.alltrees.flat']], [JOBID + '.alltrees.flat'], True) birchscript.Cleanrun([["chooseviewer.py", OUTTREE + '.alltrees']], [OUTTREE + '.alltrees'], True) elif WHATTODO == '-f': #output to files shutil.move(OUTFILE, OUTNAME + '.outfile') shutil.move(OUTTREE, OUTNAME + '.treefile') if os.path.exists(OUTTREE + '.alltrees'): shutil.move(OUTTREE + '.alltrees', OUTNAME + '.alltrees.treefile')