#!/bin/tcsh

# This script attempts to bootstrap an HHBLITS search using jackhmmer

set jobid = $1
set bindir = $2
set tmpdir = $3
set db = $4
set cut = $5
set ext = $6
set jackhmmer = $7 #location of HMMER binaries
set hhdir = $8 #location of HH-sutie
set src = $9

cd $tmpdir

if ($status) then
   exit 1
endif

head -cut $jobid.tbl > $jobid_cut.tbl
$jackhmmer/easel/miniapps/esl-sfetch -f $db $jobid_cut.tbl > $jobid.fseqs

if ($status) then
   exit 1
endif

rm -r $jobid-mya3m
rm -r $jobid-mydb

cat $jobid.fasta >> $jobid.fseqs
mkdir -p $jobid-mya3m
mkdir -p $jobid-mydb

cd $jobid-mya3m

if ($status) then
   exit 1
endif

$bindir/fasta2a3msplit < $tmpdir/$jobid.fseqs > /dev/null

if ($status) then
   exit 1
endif

cd ..

if ($status) then
   exit 1
endif

perl $src/remove_a3m.pl $hhdir $jobid $ext

if ($status) then
   exit 1
endif

rm -rf $jobid-mya3m &
rm -rf $jobid-mydb &