#
# package Bio::EnsEMBL::Pipeline::Config::ExonerateTranscript
# 
# Cared for by EnsEMBL (ensembl-dev@ebi.ac.uk)
#
# Copyright GRL & EBI
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::EnsEMBL::Analysis::Config::AlignmentFilter

=head1 SYNOPSIS

use Bio::EnsEMBL::Analysis::Config::AlignmentFilter;

=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.

=head1 CONTACT

=cut


package Bio::EnsEMBL::Analysis::Config::AlignmentFilter;

use strict;
use vars qw( %Config );

# Hash containing config info
%Config = (
        # For both chains and nets, input ids are assumed to relate to
        # the QUERY genome, so consider this when filling in this 
        # configuration and also when creating your input ids

        # If filtering alignments in preparation for the WGA2Genes
        # procedure, it is important that the Net is constructed with
        # the low-coverage genome to annotate as the QUERY (and the 
        # reference genome as the TARGET). The chaining procedure is
        # symettrical, so the assignment of genomes to QUERY and TARGET
        # should not matter. However, it is most practical for the low-
        # coverage genome to act as QUERY for chaining as well, because
        # (i) the same set of input ids can be used for chaining and netting
        # (ii) the sequence regions will rarely be big enough to make
        # memory/speed considerations an issue. 

           CHAIN_CONFIG_BY_LOGIC => {
             DEFAULT => {
               # the locations of the query and target genomes dumped
               # in Jim Kent's NIB format. If not supplied, the code
               # will dump on the fly. However, for genomes with large
               # top level pieces (e.g. human), it is advisable to pre-dump
               # to a directory, the name of which should be supplied here
               QUERY_NIB_DIR  => '/dir/with/query/seq/nib-files',
               TARGET_NIB_DIR => '/dir/with/target/seq/nib-files',

               # compara type of the raw alignments. Usually 'BLASTZ_RAW'
               INPUT_METHOD_LINK_TYPE => '',
               # compara type of the output chains. Usually 'ALIGNMENT_CHAINS'
               OUTPUT_METHOD_LINK_TYPE => '',

               # compara database details. This database should contain 
               # the raw alignments. The processed alignments will also
               # be written here
               COMPARA_DB => {
                 -dbname => '',
                 -host   => '',
                 -user   => '',
                 -pass   => '',
                 -port   => '',
               },

               # query core database details
               QUERY_CORE_DB => {
                 -dbname => '',
                 -user   => '',
                 -host   => '',
                 -port   => '',
               },

               # target core database details
               TARGET_CORE_DB => {
                 -dbname => '',
                 -user   => '',
                 -host   => '',
                 -port   => '',
               },

               # leave these alone
               MAX_GAP => 50,
               MIN_CHAIN_SCORE => 1000,

             },

           },            

           NET_CONFIG_BY_LOGIC => {
             DEFAULT => {

               # proper species names (e.g. Homo sapiens) of query 
               # and target. If running in preparation for the WGA2Genes
               # procedure, the query should be the genome you wish to 
               # annotate and the target should be the genome you will
               # be drawing annotation from
               QUERY_SPECIES  => '',
               TARGET_SPECIES => '',

               # this will match the OUTPUT_METHOD_LINK_TYPE for chains
               # above (usually 'ALIGNMENT_CHAINS')
               INPUT_METHOD_LINK_TYPE => '',

               # compara type for the result net alignments
               OUTPUT_METHOD_LINK_TYPE => 'BLASTZ_NET',

               # compara database details. This database should contain 
               # the alignment chains. The processed alignments will also
               # be written here
               COMPARA_DB => {
                 -dbname => '',
                 -host   => '',
                 -user   => '',
                 -pass   => '',
                 -port   => '',                 
               },

               # ignore these
               MAX_GAP => 50,
               MIN_CHAIN_SCORE => 2000,

               # Five basic ways of calculating the Net are supported:
               # STANDARD : uses Jim Kent's chainNet
               # SYNTENIC : uses Jim Kent's netSynteny/netFilter (attempted
               #   pseudogene filtering)
               # SIMPLE_LOW : in-built perl implementation which rejects 
               #   lower-scoring chains if they have block overlap in the
               #   query with a higher scoring chain, and furthermore
               #   if the lower-scoring chain cannot be "separated" from
               #   the higher-scoring chains without splitting contigs
               # SIMPLE_HIGH: in-built perl implementation which rejects
               #   lower-scoring chains if their extent overlaps with the
               #   extent of a higher scoring chain, and furthermore if
               #   the lower-scoring chain cannot be "separated" from
               #   the higher-scoring chains without splitting contigs

               METHOD => '',

             },
           );

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";
	}
    }
}

1;
