#!/usr/bin/perl
package Locus_gene_info;

#####################################################################
# Author : Shuai Weng
# Date   : July 2001
# 
# See documentation for the usage details. 
#    
# http:///usr/local/dicty/www_dictybase/db/lib/html/dictyBase/programmer/Locus_gene_info.html
#
#####################################################################

use strict;
use DBI;
use Carp;
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 = ('locus_no:reference_no:literature_topic'=>undef);


####################################################################
sub GetTopicArrayRefBYrefNoLocusNo {
####################################################################
    my ($self, %args) = @_;
    my $dbh = $args{'dbh'} || die "A database handle must be passed to 'GetTopicArrayRefBYrefNoLocusNo' method";
    my $schema = $self->schema;
    my $sth = $dbh->prepare("
         SELECT literature_topic
         FROM   $schema.locus_gene_info
         WHERE  reference_no = ?
         AND    locus_no = ?
    ");
    $sth->execute($args{'reference_no'}, $args{'locus_no'});   
    my $arrayRef = $sth->fetchall_arrayref();
    $sth->finish;
    return $arrayRef;
}

####################################################################
sub GetRefNoBYlocusNo {
####################################################################
    my ($self, %args) = @_;
    my $dbh = $args{'dbh'} || die "A database handle must be passed to 'GetRefNoBYlocusNo' method";
    my $schema = $self->schema;
    my $sth = $dbh->prepare("
        SELECT unique reference_no
        FROM   $schema.locus_gene_info
        WHERE  locus_no = ? 
    ");
    $sth->execute($args{'locus_no'});   
    my $refNoList;
    while(my ($refNo) = $sth->fetchrow()) {
	$refNoList .= ":".$refNo;
    }
    $refNoList =~ s/^\://;
    $sth->finish;
    return $refNoList;
}

####################################################################
sub DeleteEntryBYrefNoLocusNo {
####################################################################
    my ($self, %args) = @_;
    my $dbh = $args{'dbh'} || die "A database handle must be passed to 'DeleteEntryBYrefNoLocusNo' method";
    my $schema = $self->schema;
    my $sth = $dbh->prepare("
        DELETE from $schema.locus_gene_info
        WHERE  reference_no = ?
        AND    locus_no = ?
    ");
    $sth->execute($args{'reference_no'}, $args{'locus_no'});
    $sth->finish;
}

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

}


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

=pod

=head1 Name

Locus_gene_info.pm

=head1 Description

This perl object (Locus_gene_info.pm) acts as container for Locus_gene_info info in oracle database. Once an object has been instantiated, several methods are available to retrieve the attributes of the object. 


=head1 Instantiating a New Locus_gene_info Object

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

my $Obj = Locus_gene_info->new(dbh=>$dbh,
			       locus_no=>$locusNo,
			       reference_no=>$refNo,
			       literature_topic=>$topic);


where $dbh is a valid database handle to either dictyBase or SDEV. All passed in values must be valid values for the columns that were provided, otherwise the script will die, with an appropriate error message.
 

=head1 getRow Method

Usage:

my $row = $Obj->getRow;

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

=head1 GetTopicArrayRefBYrefNoLocusNo Method

Usage :

my $arrayRef = Locus_gene_info->GetTopicArrayRefBYrefNoLocusNo(dbh=>$dbh,
						      locus_no=>$locusNo,
						      reference_no=>$refNo);


foreach my $rowRef (@$arrayRef) {

    my ($topic) = @$rowRef;

    ######

}     

This method returns literature_topics associated with the specified locus_no amd reference_no.


=head1 DeleteEntryBYrefNoLocusNo Method


eval {

    Locus_gene_info->DeleteEntryBYrefNoLocusN(dbh=>$dbh,
					      locus_no=>$locusNo,
					      reference_no=>$refNo);


};


This method will delete locus_gene_info entries associated with specified locus_no and reference_no.

=head1 Insert and delete Methods

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

See dictyBase_Table documentation for usage details :

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











