#!/usr/bin/env python import os import os.path import shutil import subprocess import sys #Version 6/23/98 # Run reticulate as a command #Synopsis: reticulate.csh infile title method outputtype fontsize outfile """ ensure that there are enough command line arguments to parse """ if len(sys.argv) < 7: print("Usage: reticulate.py INFILE TFILE METHOD OUTPUTTYPE FONTSIZE OUTFILE") exit(); #Convert arguments to variables INFILE = sys.argv[1] TFILE = sys.argv[2] METHOD = sys.argv[3] OUTPUTTYPE = sys.argv[4] FONTSIZE = sys.argv[5] OUTFILE = sys.argv[6] # Remember where we started STARTDIR = os.getcwd() IFN = os.path.splitext(str(INFILE))[0] # Make a temporary directory to run the program in TEMPDIR = 'reticulate.' + os.getpid() os.mkdir(TEMPDIR) shutil.copyfile(INFILE, os.path.join(TEMPDIR, 'infile.temp')) shutil.copyfile(TFILE, os.path.join(TEMPDIR, os.path.basename(TFILE))) os.chdir(TEMPDIR) # Determine whether sequence is protein or DNA # Only check for amino acid characters that are not also # used as DNA ambiguity codes. temphandle = open (INFILE, 'r') for line in temphandle: if not line.startswith('>'): string = line.upper() for char in string: if char == 'X': CONTAINSX = true elif char == 'N': CONTAINSN = true temphandle.close() #------ reticulate ----------------------- os.nice(10) p = subprocess.Popen(['reticulate'], stdin=subprocess.PIPE) os.nice(0) #----------------- generate keyboard input to send to program ----- p.stdin.write('infile.temp\n') # name of sequence file p.stdin.write('n\n') # init. gaps not marked in brackets if CONTAINSX: p.stdin.write('n\n') # X's are not unknowns if CONTAINSN: p.stdin.write('n\n') # N's are not unknowns temphandle = open (TFILE, 'r') p.stdin.write(temphandle.readline()) # title line temphandle.close() # Choose site polymorphism method if METHOD == 2: p.stdin.write('2\n') # As transversion sites (DNA/RNA only) elif METHOD == 3: p.stdin.write('3\n') # As sites with more than two characters else: # call this whether or not METHOD = 1 p.stdin.write('1\n') # Ignore these sites, use binary sites only p.stdin.write('y\n') # save informative sites to a file p.stdin.write(IFN + '\n') p.stdin.write('p\n') # print the output if OUTPUTTYPE == "eps": # Encapsulated Postscript OFN = IFN + '.eps' p.stdin.write('e\n') else: # Postscript OFN = IFN + '.ps' p.stdin.write('p\n') #echo IFN >> inputfile # name for window p.stdin.write(FONTSIZE + '\n') p.stdin.write(IFN + '\n') # base name for file p.stdin.write(" \n") # name for printout (blank) p.stdin.write('q\n') # quit p.stdin.close() p.wait() #----------- Return results to calling directory---------------- shutil.copyfile(OFN, os.path.join(STARTDIR, OUTFILE)) shutil.copyfile(IFN + '.sit', os.path.join(IFN + '.sit')) os.chdir(STARTDIR) shutil.rmtree(TEMPDIR)