#
# Perl Module for GeneFeaturePair
#
# Cared for by Tim Hubbard <th@sanger.ac.uk>
#
# Copyright Genome Research Limited (1997). Please see information on licensing in LICENSE

package GeneFeaturePair;

use vars qw($AUTOLOAD @ISA @EXPORT_OK);
use Exporter;
use Carp;
use strict;
use GeneFeature;

#
# Place functions/variables you want to *export*, ie be visible from the caller package into @EXPORT_OK
#

@EXPORT_OK = qw();

#
# @ISA has our inheritance.
#

@ISA = ( 'Exporter' );


my %fields = (
	      gf1 => undef, 
	      gf2  => undef,
	      e5 => undef,
	      e3 => undef,
);

sub new {
    my $ref = shift;
    my $class = ref($ref) || $ref;
    
    my $self = {
	'_permitted' => \%fields,
	%fields, };

    bless $self, $class;
    return $self;
}

#
# Autoload up my field name set/get
#
sub AUTOLOAD {
    my $self = shift;
    my $type = ref($self) || carp "Ok, $self is not an object of mine!";
    my $name = $AUTOLOAD;

    # don't propagate DESTROY messages...

    $name =~ /::DESTROY/ && return;

    $name =~ s/.*://; #get only the bit we want
    unless (exists $self->{'_permitted'}->{$name} ) {
	carp "In type $type, can't access $name - probably passed a wrong variable into Sequence  ";
    }
    if (@_) {
	return $self->{$name} = shift;
    } else {
	return $self->{$name}
    }
}

#
# Method to build GeneFeaturePair object from command line arguments
#

sub new_from_commandline {
    my $self;
    $self = new GeneFeaturePair;

    $self->gf1(shift);
    $self->gf2(shift);
    $self->e5(shift);
    $self->e3(shift);
    
    return $self;
}

#
# Method to return a formatted output of a GeneFeaturePair object to a filehandle
#

sub dump {
    my $self = shift;
    my $file = shift;
    my $tab = shift;
#    print "in GeneFeaturePair.pm::dump\n";
    
    if( !defined $file ){
	$file = \*STDOUT;
    }

    print $file $self->dump_string($tab)."\n";

}

#
# Method to return a formatted output of a GeneFeaturePair object to a string
#

sub dump_string {
    my $self = shift;
    my $tab = shift;
#    print "in GeneFeaturePair.pm::dump_string\n";

    my $string;
    my ($gf1,$gf2);

    $gf1=$self->gf1;
    $gf2=$self->gf2;
#    print "$gf1 $gf2\n";
    $string=$gf1->dump_string($tab);
    if($tab){
	$string.="\t";
    }else{
	$string.=" ";
    }
    $string.=$gf2->dump_string($tab);
    if($tab){
	$string.=sprintf("\t%d\t%d",
			 $self->e5(),
			 $self->e3());
    }else{
	$string.=sprintf(" %d %d",
			 $self->e5(),
			 $self->e3());
    }
    $string;
}

#
# Method to get ref to other GeneFeature listed in a GeneFeaturePair object
#

sub other {
    my $self = shift;
    my $gf = shift;
    if($self->gf1 == $gf){
	$self->gf2;
    }else{
	$self->gf1;
    }
}


1;  # says use was ok
__END__

=head1 NAME

GeneFeaturePair

=head1 DESCRIPTION

Description for B<GeneFeaturePair>

=head1 AUTHOR

B<Tim Hubbard> Email th@sanger.ac.uk

=head1 Functions

=over 5

=item new_from_comandline

Method to build GeneFeaturePair object from command line arguments

=item dump

Method to return a formatted output of a GeneFeaturePair object to a
filehandle

=item dump_string

Method to return a formatted output of a GeneFeaturePair object to a
string

=item other

No current documentation
