#!/usr/bin/env python

import birchenv
import os
import os.path
import subprocess
import sys

# 15 Nov. 2004

# given a set of accessions, create a file
# containing the corresponding genbank entries
#
#  $1 file containing LOCUS names or ACCESSION numbers
#  $2 file to contain all of the GenBank entries

JOBID = os.getpid()

# Uses Leash.java

# Convert names or accessions into GI numbers
subprocess.call(["leash", "-mn", "SHoundFindAccList", "-mpf", sys.argv[1], "-of", "infile." + JOBID])

# Retrieve GenBank flatfiles
subprocess.call(["leash", "-mn", "SHoundGetGenBankffList", "-mpf", "infile." + JOBID, "-of", "genbank." + JOBID])

# SHoundGetGenBankffList omits '//' characters from the end
# of GenBank entries. Since these characters are required to
# indicate the end of an entry, SHound.fixGenBank.py adds them
# to the SHound output. When SHound is fixed, this script
# can be deleted.
subprocess.call(["python", os.path.join(birchenv.BIRCH, "script", "SHound.fixGenBank.py"), "genbank." + JOBID, sys.argv[2]])

os.remove("infile." + JOBID)
os.remove("genbank." + JOBID)
