=head1 NAME

    Bio::EnsEMBL::Analysis::Config::Exonerate2Genes

=head1 SYNOPSIS

    use Bio::EnsEMBL::Analysis::Config::Exonerate2Genes;

=head1 DESCRIPTION

    It imports and sets a number of standard global variables into the
    calling package, which are used in many scripts in the human sequence
    analysis system. The variables are first declared using "use vars", so
    that it can be used when "use strict" is in use in the calling script.
    Without arguments all the standard variables are set, and with a list,
    only those variables whose names are provided are set. The module will
    die if a variable which doesn't appear in its C<%Exonerate> hash is
    asked to be set.

    Since The RunnableDB that this config controls can be used for
    inferring transcript structures from (different sets of) EST,
    cDNA and proteins, and several uses may be required in the same
    pipeline, this Config contains one primary config variable,
    EXONERATE_TRANSCRIPT_CONFIG. This is hash keyed off logic name,
    each entry of which is a hash containing the variable that affect
    the behaviour of the RunnableDB. When the RunnableDB instance is
    created, the correct entry is identified by logic name and value for a
    corresponding set of local variables are set.

=head1 LICENSE

    Copyright (c) 1999-2009 The European Bioinformatics Institute and
    Genome Research Limited.  All rights reserved.

    This software is distributed under a modified Apache license.
    For license details, please see

      http://www.ensembl.org/info/about/code_licence.html

=head1 CONTACT

    Please email comments or questions to the public Ensembl
    developers list at <ensembl-dev@ebi.ac.uk>.

    Questions may also be sent to the Ensembl help desk at
    <helpdesk@ensembl.org>.

=cut


package Bio::EnsEMBL::Analysis::Config::Exonerate2Genes;

use strict;
use vars qw( %Config );

# Hash containing config info
%Config = (
  EXONERATE_CONFIG_BY_LOGIC => {
      DEFAULT => {

        # The GENOMICSEQS can be a file (string, A.), a
        # directory with files (string, B.) or an anonymous
        # array containing the names of multiple directories
        # (array of strings, C.). In the latter case the order
        # of appearance will determine the usage of directories
        # and files; new versions should therefore be listed in
        # the first directory.
        #
        # format: A. '/your/soft/masked/genome.fa'
        #      or B. '/your/soft/masked/genomeDIR'
        #      or C. ['/your/soft/masked/genomeDIR_1', '/your/soft/masked/genomeDIR_2']
        GENOMICSEQS         => '/your/soft/masked/genome.fa',

        QUERYTYPE           => undef,
        QUERYSEQS           => undef,
        QUERYANNOTATION     => undef,
        IIDREGEXP           => undef,
        OUTDB               => undef,
        FILTER              => undef,
        COVERAGE_BY_ALIGNED => undef,
        OPTIONS             => undef,

        # Comment out or set to undef if non-reference regions (eg DR52
        # in human) should NOT be fetched, ie should be ignored:
        NONREF_REGIONS => 1,

        # If program not defined, will look in program_file of analysis
        # table. Or will take default 0.8.3 if neither is defined.
        PROGRAM => undef,    # /usr/local/ensembl/bin/exonerate
      },

      EST_logicname => {

        # GENOMICSEQS obtained from DEFAULT
        # IIDREGEXP not set; input ids are file names

        QUERYTYPE => 'dna',
        QUERYSEQS => '/directory/with/EST/chunks',

        # CHANGE! You can now either submit all db-connection parameters
        # for OUTDB (old method ) - or you can just supply a string. The string
        # must be assigned to a database-connection in Databases.pm
        OUTDB => "EXONERATE_DB",    # HASH-key out of Databases.pm

        FILTER => {
          OBJECT => 'Bio::EnsEMBL::Analysis::Tools::ExonerateTranscriptFilter',
          PARAMETERS => { -coverage                 => 90,
                          -percent_id               => 97,
                          -best_in_genome           => 1,
                          -reject_processed_pseudos => 1,
          },
        },

        COVERAGE_BY_ALIGNED => 1,
        OPTIONS             => "--model est2genome --forwardcoordinates FALSE "
          . "--softmasktarget TRUE --exhaustive FALSE --score 500 "
          . "--saturatethreshold 100 --dnahspthreshold 60 --dnawordlen 14",
      },

      CDNA_logic_name => {

        # GENOMICSEQS obtained from DEFAULT
        # IIDREGEXP not set; input ids are file names

        QUERYTYPE => 'dna',
        QUERYSEQS => '/directory/with/cdna/chunks',

        OUTDB => { -dbname => '',
                  -host   => '',
                  -port   => '',
                  -user   => '',
                  -pass   => '',
        },

        COVERAGE_BY_ALIGNED => 1,
        FILTER              => {
          OBJECT => 'Bio::EnsEMBL::Analysis::Tools::ExonerateTranscriptFilter',
          PARAMETERS => { -coverage                 => 90,
                          -percent_id               => 97,
                          -best_in_genome           => 1,
                          -reject_processed_pseudos => 1,
          },
        },

        OPTIONS => "--model est2genome --forwardcoordinates FALSE "
                . "--softmasktarget TRUE --exhaustive FALSE  --score 500 "
                . "--saturatethreshold 100 --dnahspthreshold 60 --dnawordlen 14",
      },

      Protein_logicname => {
        # GENOMICSEQS obtained from DEFAULT

        QUERYTYPE => 'protein',

        # QUERYSEQ can be a directory as well
        QUERYSEQS => '/file/containing/all/proteins.fa',

        # Input id is a chunk id and chunk total
        IIDREGEXP => '(\d+):(\d+)',

        OUTDB     => {
                  -dbname => '',
                  -host   => '',
                  -port   => '',
                  -user   => '',
                  -pass   => '',
        },

        # FILTER not set, so no filtering done
        COVERAGE_BY_ALIGNED => 0,

        OPTIONS => "--model protein2genome --forwardcoordinates FALSE "
                . "--softmasktarget TRUE --exhaustive FALSE  --bestn 1",
      },

      orthologue_recovery => {
              QUERYTYPE => 'protein',
              QUERYSEQS => "/path/to/where/you/want/your/seq/dumped/by/OrthologueAnalyis",
              IIDREGEXP => '(\d+):(\d+)',
              OUTDB     => {
                          -dbname => '',
                          -host   => '',
                          -port   => '3306',
                          -user   => '',
                          -pass   => '',
              },
              COVERAGE_BY_ALIGNED => 0,
              OPTIONS => "--model protein2genome --forwardcoordinates FALSE "
                        . " --softmasktarget TRUE --exhaustive FALSE  --bestn 1",
      },
    }
);

sub import {
  my ($callpack) = caller(0);    # Name of the calling package
  my $pack = shift;              # Need to move package off @_

  # Get list of variables supplied, or else everything
  my @vars = @_ ? @_ : keys(%Config);
  return unless @vars;

  # Predeclare global variables in calling package
  eval "package $callpack; use vars qw("
    . join( ' ', map { '$' . $_ } @vars ) . ")";
  die $@ if $@;

  foreach (@vars) {
    if ( defined $Config{$_} ) {
      no strict 'refs';
      # Exporter does a similar job to the following
      # statement, but for function names, not
      # scalar variables:
      *{"${callpack}::$_"} = \$Config{$_};
    } else {
      die "Error: Config: $_ not known\n";
    }
  }
} ## end sub import

1;
