#!@@_perl_root_@@/bin/perl.exe
package Gene_product;

##########################################################
#                                                        #
# dictyBase Extension of Gene_product                          #
#                                                        #
##########################################################

use Gene_product_base;

BEGIN { %Gene_product:: = %Gene_product_base:: }

#
# only look in v_notdeleted_locus
#
# simple substitution of v_notdeleted_locus for locus
#

#######################################################################
sub getLocusArrayRef {
#######################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT G.FEATURE_ID, G.name
        FROM   $ENV{'CHADO_USER'}.v_GENE_FEATURES g, $schema.locus_gp LGP
        WHERE  LGP.gene_product_no = ?
        AND    G.FEATURE_ID = LGP.locus_no
        ORDER BY upper(G.name)
    ");
    $sth->execute($self->gene_product_no);
    my $arrayRef = $sth->fetchall_arrayref();
    $sth->finish;
    return $arrayRef;
}

#
# only look in v_notdeleted_locus
#
# added inner join to v_notdeleted_locus
#
####################################################################
sub getLocusNoList {
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT lgp.locus_no
        FROM   $schema.locus_gp lgp
  INNER JOIN   $ENV{'CHADO_USER'}.v_GENE_FEATURES G
          ON   G.FEATURE_ID = lgp.locus_no
        WHERE  lgp.gene_product_no = ?
    ");
    $sth->execute($self->gene_product_no);
    my $locusNoList;
    while( my($locusNo) = $sth->fetchrow()) {
        if ($locusNoList) { $locusNoList .= ":"; }
        $locusNoList .= $locusNo;
    }
    $sth->finish();
    return $locusNoList;
}

#
# only look in v_notdeleted_locus
#
# simple substitution of v_notdeleted_locus for locus
#

####################################################################
sub GetORFGeneArrayRefBYgeneProduct {
####################################################################
    my ($self, %args) = @_;
    my $dbh = $args{'dbh'} || die "A database handle must be passed to 'GetORFGeneArrayRefBYgeneProduct' method.";
    my $schema = $self->schema;
    my $sth = $dbh->prepare("
        SELECT F.feature_name, G.name, GP.gene_product
        FROM   $schema.feature F, $ENV{'CHADO_USER'}.v_GENE_FEATURES G,
               $schema.gene_product GP, $schema.locus_gp LGP
        WHERE  upper(GP.gene_product) like ?
        AND    GP.gene_product_no = LGP.gene_product_no
        AND    LGP.locus_no = G.FEATURE_ID
        AND    G.FEATURE_ID = F.locus_no
    ");
    $sth->execute(uc($args{'gene_product'}));
    my $arrayRef = $sth->fetchall_arrayref();
    $sth->finish;
    return $arrayRef;
}

1;