#!/usr/bin/perl -w
#
# change the above line to match the location of perl on your system
#


use strict;

# EMBOSS farm file script
#
# Written by Simon Andrews
# simon.andrews@bbsrc.ac.uk
# Dec 2001
#
# This script allows you to set up a farm
# of EMBOSS databases which can be queried
# by a single instance of seqret.  The
# program must be accompanied by an entry
# in emboss.default which looks like this:
#
# DB name_of_database [
#       type: N (or P if we're dealing with proteins)
#       method: app
#       format: fasta
#       app: "/path/to/this/emboss_farm.script"
#       comment: "Whatever text you'd like to see in showdb" 
# ]
#

# First we need to set a few preferences
#
# What is the full path to seqret?
# If you are sure that seqret will always
# be somewhere in your path, then you can
# just leave this as 'seqret'.

my $seqret_path = 'seqret';


# Now we need to know the names of the
# databases you'd like included in the
# search.  These must be dabases which
# have already been indexed, and installed
# correctly into emboss.default.  Simply
# enter the database names between the
# brackets, separated by spaces.

my @databases = qw(dbase1 dbase2 dbase3);


##### End of bits which need to be edited #########

my ($reference) = @ARGV;

if ($reference =~ /:(.+)$/){
  $reference = $1;            
}

else {
  die "\n*** FARM ERROR *** Couldn't get accession after : from
$reference\n\n";
}


foreach my $database (@databases){

  my $sequence = `$seqret_path $database:$reference fasta::stdout 2>/dev/null`;

  if ($sequence){
        print $sequence;
        exit;
  }

}

warn "\n*** FARM ERROR *** Couldn't find $reference in any of '@databases'\n\n";