package Locus;

##########################################################
#                                                        #
# dictyBase Extension of Locus                           #
#                                                        #
##########################################################

use Locus_base;

BEGIN { %Locus:: = %Locus_base:: }

#
#  added this search string which returns a url encoded "OR" list of
#  the locus name and all of its aliases see dictyBase extension
#  GeneInfoUserPage subroutine pubmedSearch
#


sub quote {
   my $string = shift;

  #--------------------------
  # quote if string is more than one word
  #--------------------------
   $string = qq /"$string"/ if ($string =~ m/\s/);

   return $string;
}


sub searchString {
    my ($self) = @_;

    my $string;

    my $aliasArray = $self->locusAliasArrayRef;

    foreach my $alias (@{$aliasArray}) {
       my $aliasName = ${$alias}[1];
       $string .= "+OR+".quote($aliasName);
    }

    $string = quote($self->locus_name).$string;
    return $string;
}


####################################################################
sub publicCuratorNoteInfoArrayRef {
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT CN.curator_note_no, CN.note, CN.is_public
        FROM   $schema.curator_note CN, $schema.locus_cn LCN
        WHERE  CN.curator_note_no = LCN.curator_note_no
        AND    LCN.locus_no = ?
        AND    CN.is_public = 'Y'
    ");
    $sth->execute($self->locus_no);
    my $arrayRef = $sth->fetchall_arrayref();
    $sth->finish;
    return $arrayRef;
}
#
# we at dictyBase were'nt ready to get rid of this
#
###################################################################
 sub sacchdb_phenotype {
###################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT sacchdb_phenotype
        FROM   $schema.sacchdb_phenotype
        WHERE  locus_no = ?
    ");
    $sth->execute($self->locus_no);
    my $sachdbPheno;
    while(my ($pheno) = $sth->fetchrow()) {
        if ($sachdbPheno) { $sachdbPheno .= "; "; }
        $sachdbPheno .= $pheno;
    }
    $sth->finish;
    return $sachdbPheno;
 }

#
# took out gene reservation table
#
#######################################################################
sub geneReservationInfo {
#######################################################################
    my($self) = @_;

}


#######################################################################
sub phenotypeInfoArrayRef {
#######################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->{'_dbh'}->prepare("
        SELECT cvt.cvterm_id, cvt.name, LP.phenotype_type, LP.sentence
        FROM   CGM_CHADO.cvterm cvt, $schema.locus_pheno LP
        WHERE  cvt.cvterm_id = LP.phenotype_no
        AND    LP.locus_no = ?
    ");
    $sth->execute($self->locus_no);
    my $locusPhenoArrayRef = $sth->fetchall_arrayref();
    $sth->finish;
    return $locusPhenoArrayRef;
}



1;