#!/usr/bin/perl
package Alias;

#####################################################################
# Author : Shuai Weng
# Date   : July 2001
#
# Usage:
#
#   use Alias;
#
#   ### You may use one of the following syntaxes to
#   ### instantiate a new Alias object.
#
#   my $aliasObj = Alias->new(dbh=>$dbh,
#                             alias_name=>$aliasName,
#                             alias_type=>$aliasType);
#
#   my $aliasObj = Alias->new(dbh=>$dbh,
#                             alias_no=>$aliasNo);
#
#   ### You can use an accessor for any valid column
#   ### in the Alias table. For example:
#   my $alias_name = $aliasObj->alias_name;
#   my $alias_no = $aliasObj->alias_no;
#
#   See documentation for detail.
#
#   http:///usr/local/dicty/www_dictybase/db/lib/html/dictyBase/programmer/Alias.html
#
#####################################################################
use strict;
use DBI;
use vars qw (@ISA %allowedConstructors);
use dictyBase_Table;
@ISA = qw (dictyBase_Table); # base class

# Class Globals

# put column names in the hash below, that are able to uniquely
# specify a row in the table

%allowedConstructors = ('alias_name:alias_type'=>undef,
                        alias_no=>undef);


####################################################################
sub GetAliasTypeBYaliasNm {
####################################################################
    my($self, %args) = @_;

    my $dbh = $args{'dbh'} || die "You have to pass the database handle to 'GetAliasTypeBYaliasNm' method.";
    my $aliasNm = $args{'alias_name'} || die "You have to pass the alias_name to 'GetAliasTypeBYaliasNm' method.";

    my $schema = $self->schema;

    my $sth = $dbh->prepare("
        SELECT alias_type
        FROM   $schema.alias
        WHERE  upper(Alias_name) = ?
    ");
    $sth->execute(uc($aliasNm));

    my $aliasTypes;

    while(my($type) = $sth->fetchrow()) {

        if ($aliasTypes) { $aliasTypes .= ":"; }

        $aliasTypes .= $type;

    }
    $sth->finish;

    return $aliasTypes;

}

####################################################################
sub getLocusNoList {
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
       SELECT locus_no
       FROM   $schema.locus_alias
       WHERE  alias_no = ?
    ");
    $sth->execute($self->alias_no);
    my $locusNoList;
    while(my ($locusNo) = $sth->fetchrow()) {
        if ($locusNoList) { $locusNoList .= ":"; }
        $locusNoList .= $locusNo;
    }
    $sth->finish();
    return $locusNoList;
}

####################################################################
sub getLoci {
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
       SELECT L.locus_name
       FROM   $schema.locus_alias LA, $schema.locus L
       WHERE  LA.alias_no = ?
       AND    L.locus_no = LA.locus_no
    ");
    $sth->execute($self->alias_no);
    my $loci;
    while(my ($locusNm) = $sth->fetchrow()) {
        if ($loci) { $loci .= ":"; }
        $loci .= $locusNm;
    }
    $sth->finish();
    return $loci;
}

####################################################################
sub getAliasType {
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
       SELECT A.alias_type
       FROM   $schema.alias A
       WHERE  A.alias_no = ?
    ");
    $sth->execute($self->alias_no);
    my $types;
    while(my ($type) = $sth->fetchrow()) {
        if ($types) { $types .= ":"; }
        $types .= $type;
    }
    $sth->finish();
    return $types;
}


####################################################################
sub DESTROY{
####################################################################
# nothing needs to be done

}


####################################################################
1; #################################################################
####################################################################


=pod

=head1 Name

Alias.pm


=head1 Description

This perl object (Alias.pm) acts as container for Alias info associated with a alias_no or alias_name in oracle database. Once an object has been instantiated, several methods are available to retrieve the
attributes of the object.


=head1 Instantiating a New Alias Object

To instantiate a new Alias object, you may use following syntax:

my $aliasObj = Alias->new(dbh=>$dbh, $colNm=>$value);

where $colNm is either alias_no or alias_name, and $dbh is a valid database handle to either dictyBase or SDEV. $value must be a valid value for the column that was provided, otherwise the script will die, with an appropriate error message.


Syntax example :

my $aliasObj = Alias->new(dbh=>$dbh, alias_no=>$aliasNo);

my $aliasObj = Alias->new(dbh=>$dbh, alias_name=>$aliasName, alias_type=>$aliasType);


=head1 Accessor Methods


All accessor methods take the form of :

my $column_value = $obj->column_name, eg:

my $aliasName = $aliasObj->alias_name;


etc. You can use an accessor for any valid column in the Alias table.

See valid columns in alias table:

http:///usr/local/dicty/www_dictybase/db/lib/cgi-bin/dictyBase/tableSpecifications?table=ALIAS

=head1 GetAliasTypeBYaliasNm method

Usage:

my $aliasTypeList = $aliasObj->GetAliasTypeBYaliasNm;

This method will return a colon (':') delimited alias_type for the specified
alias_name.

=head1 getLocusNoList method

Usage:

my $locusNoList = $aliasObj->getLocusNoList;

This method will return a colon (':') delimited locus_no for the specified
alias.


=head1 getLoci method

Usage:

my $loci = $aliasObj->getLoci;

This method will return a colon (':') delimited locus_name for the specified
alias.

=head1 getAliasType method

Usage:

my $aliasType = $aliasObj->getAliasType;

This method will return a colon (':') delimited alias_type for the specified
alias_no.


=head1 getRow method

Usage:

my $row = $obj->getRow;

This method returns a tab-delimited row from Alias table.

=head1 Insert, update and delete Methods

You can also use 'Insert' class method and 'update' and 'delete'
instance methods for inserting new row into database, updating and
deleting info for a specified row.

See dictyBase_Table documentation for usage details :

Update : http:///usr/local/dicty/www_dictybase/db/lib/staff/dictyBase/programmer/dictyBase_Table.html#Update_Method

Insert : http:///usr/local/dicty/www_dictybase/db/lib/staff/dictyBase/programmer/dictyBase_Table.html#Insert_Method

Delete : http:///usr/local/dicty/www_dictybase/db/lib/staff/dictyBase/programmer/dictyBase_Table.html#Delete_Method

=head1 Author

Shuai Weng

shuai@genome.stanford.edu

=cut










