#!/usr/bin/env python import birchenv import birchscript import os import os.path import shutil import subprocess import sys # For each name in INFILE, call a SeqHound method, and return # the result (a single line). Results are concatenated to # a single output file OUTFILE. # In a future release of seqhound (after 2.5) # SeqHound looks for a .shoundremrc # file in $HOME, and in the current directory # Until SeqHound comes up with a better way of finding # the .shoundremrc file, this script must be run by # any program using SeqHound # Make sure that the user has a ~.shoundremrc file #if [ ! -e ~/.shoundremrc ] \ # ln -s $SEQHOUND/shoundremrc ~/.shoundremrc #------------ SeqHound 2.5 ------------------------ # For now, we use 2.5, but we need to get around the # requirement that .shoundremrc must be present in every directory # in which seqhound will be run. The solution is to create a lock file # for every instance of leash. When a leash job terminates, # the lock file is removed. If no more lock files remain, # leash removes .shoundremrc. LOCK = "leash.lock." + os.getpid() h_lock = open (LOCK, "w") print >> h_lock, "This file is created when an instance of leash is running." print >> h_lock, "It should automatically be removed when leash terminates. " if not os.path.exists(".shoundremrc"): shutil.copyfile(os.path.join(birchenv.BIRCH, "java", "Leash", "shoundremrc"), os.path.join(os.getcwd(), ".shoundremrc")) h_INFILE = open(sys.argv[1], "r") h_OUTFILE = open(sys.argv[2], "w") TEMPFILE = "leash." + os.getpid() for name in h_INFILE: print name command = ["java", "-jar", os.path.join(birchenv.BIRCH, "java", "Leash", "Leash.jar"), "-mpi", name] command[5:] = sys.argv[3:] command[-1:] = [command[-1][0], "-of", TEMPFILE] subprocess.call(command) birchscript.cat_to(TEMPFILE, h_OUTFILE) h_OUTFILE.close() h_INFILE.close() os.remove(LOCK) os.remove(TEMPFILE) COUNT = 0 for file in os.listdir(os.getcwd()): if file.startswith("leash.lock"): COUNT += 1 if COUNT == 0: os.remove(".shoundremrc")