#!/usr/bin/perl
package sdevGeneInfoCurationPage;

#######################################################################
##### Author :	Shuai Weng
##### Date   :  August 2000
##### Description : This package contains all necessary methods for dictyBase
#####               curators to curate Gene Info in oracle database. 
#####              
#######################################################################
use strict;
use DBI;
use CGI qw/:all :html3/;
use CGI::Carp qw(fatalsToBrowser);

use lib "/usr/local/dicty/www_dictybase/db/lib/dictyBase/Objects";
use Reference;
use Locus_gene_info;
use Feat_gene_info;
use GeneInfo;
use Ypd_protein_info;
use Ref_unlink;
use Delete_log;
use Ref_bad;
use Feature;
use Locus;

use lib "/usr/local/dicty/www_dictybase/db/lib/common";
use Login qw (ConnectToDatabase);
use TextUtil qw (DeleteUnwantedChar);

use lib "/usr/local/dicty/www_dictybase/db/lib/dictyBase";
use dictyBaseCentralMod qw(:formatPage :getInfo);
use FormatdictyBase qw (PrintPageTop Divider75);


#######################################################################
#################### global variables #################################
#######################################################################
my $dbh;
my $dblink; 
my $configUrl;

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

	$self = {};
	bless $self;

      	$self->{'_database'} = $args{'database'};
	$self->{'_help'}     = defined($args{'help'}) ? 
	                       $args{'help'} : "geneinfo.html";
	$self->{'_title'}    = defined($args{'title'}) ? 
	                       $args{'title'} : "Gene Info Curation Page";
	$self->{'_user'}     = defined($args{'user'}) ? $args{'user'} : "";
	$self->{'_feat'}     = defined($args{'feat'}) ? $args{'feat'} : "";
	$self->{'_type'}     = defined($args{'type'}) ? $args{'type'} : "";
	$dbh = &ConnectToDatabase($self->database);
    	return $self;
}

sub help { $_[0]->{_help} }
sub database { $_[0]->{_database} }
sub title { $_[0]->{_title} }
sub user { $_[0]->{_user} }

######################################################################
sub DESTROY {   ############ destructor ##############################
######################################################################
    	if (defined $dbh) {
		$dbh->disconnect;
    	}
}

######################################################################
sub start{
######################################################################

    	my ($self) = @_;
	$configUrl = ConfigURLdictyBase->new;	
	$dblink = $configUrl->dblink($self->database);
	if (!$self->user) {
	    print "location: ", $configUrl->dictyBaseCGIRoot, "$dblink/curatorLogin\n";
	    print "Content-type: text/html\n\n";
	    exit;
	}
	my ($dbuser, $dbpasswd) = &getUsernamePassword(uc($self->user), 
						       $self->database);
	if (!$dbuser || !$dbpasswd) {
	    print "location: ", $configUrl->dictyBaseCGIRoot, "$dblink/curatorLogin\n";
	    print "Content-type: text/html\n\n";
	    exit;
	}

	my $feat = $self->{'_feat'};
	&DeleteUnwantedChar(\$feat);
	$self->{'_feat'} = $feat;

	if (param('submit') =~ /Add Loci/i) {
	    $dbh->disconnect;
	    $dbh = &ConnectToDatabase($self->database, $dbuser, $dbpasswd);
	    $self->addLoci;
	}
	elsif (param('commit')) {
	    $dbh->disconnect;
	    $dbh = &ConnectToDatabase($self->database, $dbuser, $dbpasswd);
	    $self->commitInfo;
	}
	elsif (param('paperList')) {
	    $self->displayPaperList;
	}	
	elsif (param('refNo')) {
	    $self->displayAnnotation;
	}
	elsif (param('type')) {
	    $self->checkQuery;
	    $self->displayMainList;
	}
        else {
	    $self->printEntryForm;
        }
}

#######################################################################
sub printEntryForm {
#######################################################################
        my ($self) = shift;

	&printStartPage($self->database, $self->title, $self->help);

	my %typeLabels = ('Locus'=>'Locus or locus_no',
			  'Feature'=>'Feature or feature_no');
	my @typeValues = qw/Locus Feature/;
	my $defaultType = 'Locus';

        ##########################
	print 
	    startform,
	    b("This form is for dictyBase curators to curate gene info in oracle database"),p,
	    table(Tr(td(b(font({-size=>"+1"}, 'Enter ')),
			popup_menu(-name=>'type',
				   -"values"=>\@typeValues,
				   -default=>$defaultType,
				   -labels=>\%typeLabels
				   ), b(": ").      
			textfield(-name=>'feat', -size=>30)).
		     td(hidden('user', $self->user),
			submit('Submit','Submit'), " ",
			reset))).
	    endform;
	&printEndPage;
}

#######################################################################
sub displaySharedAnnotation {
#######################################################################
    my ($self) = shift;
    my $title = "Annotation for Locus and Feature";
    &printStartPage($self->database, $title, $self->help);

    my $refNo = param('refNo');
    my ($locusArrayRef, $featureArrayRef);
    my $refObj = Reference->new(dbh=>$dbh,
				reference_no=>$refNo);
    if (param('locusNo')) {
	$locusArrayRef = $refObj->locusList;
    }
    elsif (param('featNo')) {
	$featureArrayRef = $refObj->featureList;
    }
    else {
	$locusArrayRef = $refObj->locusList;
	$featureArrayRef = $refObj->featureList;
    }
    print center(h2("reference_no = $refNo")).p;
    my $list;
    foreach my $rowRef (@$locusArrayRef) {
	my ($locusNm) = @$rowRef;
	$list .= li(a({-href=>$configUrl->dictyBaseCGIRoot."gene_page.pl?gene_name=$locusNm", 
		       -target=>'anotherWin'}, $locusNm));
    }
    foreach my $rowRef (@$featureArrayRef) {
	my ($featNm) = @$rowRef;
	$list .= li(a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/locus.pl?featureName=$featNm", 
		       -target=>'anotherWin'}, $featNm));
    }
    print ul($list);
    print 
          "<div align=center>\n",
          "<form>\n",
          "<input type=button value=\"    Close    \" onClick=\"self.close()\">\n",
          "</form>";
    
    &printEndPage;
}

########################################################################
sub displayMainList {
########################################################################
    my ($self) = shift;
    my ($title, $featNm, $featNo, $locusNm, $locusNo, 
	$curated, $notYet);
    if ($self->{'_locusNm'}) {
	$locusNm = $self->{'_locusNm'};
	$locusNo = $self->{'_locusNo'};
	$title = $self->title." for ".$locusNm;
	my $locusObj = Locus->new(dbh=>$dbh,
				  locus_name=>$locusNm);
	$curated = $locusObj->curatedRefNum;
	$notYet = $locusObj->notYetCuratedRefNum;
    }
    else {
	$featNm = $self->{'_featNm'};
	$featNo = $self->{'_featNo'};
	$title = $self->title." for ".$featNm;
	my $featObj = Feature->new(dbh=>$dbh,
				   feature_name=>$featNm);
	$curated = $featObj->curatedRefNum;
	$notYet = $featObj->notYetCuratedRefNum;
    }
    &printStartPage($self->database, $title, $self->help);  

    ###########
    my $ypdPaperNum;
    my $ypdObj = Ypd_protein_info->new(dbh=>$dbh,
				       dictyBaseid=>$self->{'_dictyBaseid'});
    if ($ypdObj) { $ypdPaperNum = $ypdObj->ypdPaperNum; }
    ###########
					    
    my ($name, $pass, $type);
    if ($locusNo) {
	$type = "Locus";
	$name = $locusNm;
	$pass = "locusNo=$locusNo";
    }
    else {
	$type= "Feature";
	$name = $featNm;
	$pass = "featNo=$featNo";
    }
    if ($curated) { ### the number of the curated papers	
        print p, b("$curated ".a({-href=>url."?user=".$self->user."&$pass&paperList=Curated"}, "Curated PubMed References for $name")),br;
	
    }
    if ($notYet) { ### the number of the not_yet_curated papers
       	print p, b("$notYet ".a({-href=>url."?user=".$self->user."&$pass&paperList=NotYet"}, "New PubMed References Not Yet Curated for $name")), br;       
    }
    if ($ypdPaperNum) {
	print p, b("$ypdPaperNum ".a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/YPD/ypdref_todo.pl?user=".$self->user."&type=$type&item=$name"}, "YPD papers for $name")), br;
    }

    if (!$curated && !$notYet) {
	print p, b("No PubMed Reference for $name at the moment.");
    }
    print p;
    &printEndPage;
}

########################################################################
sub displayPaperList {
########################################################################
    my ($self) = shift;
    my ($title, $featNm, $featNo, $locusNm, $locusNo, $name, $linkNm);
    if (param('featNo')) {
	$featNo = param('featNo');
	my $featObj = Feature->new(dbh=>$dbh,
				   feature_no=>$featNo);
	$featNm = $featObj->feature_name;
	$name = $featNm;
	$linkNm = "featNo=$featNo";
	$title = $self->title." for ".$featNm;
    }
    else {
	$locusNo = param('locusNo');
	my $locusObj = Locus->new(dbh=>$dbh,
			       locus_no=>$locusNo);
	$locusNm = $locusObj->locus_name;
	$name = $locusNm;
	$linkNm = "locusNo=$locusNo";
	$title = $self->title." for ".$locusNm;
    }
    $self->printStartPage4PaperList($self->database, $title, $self->help);
    my $giObject = GeneInfo->new(dbh=>$dbh,
				 locus=>$name);    
    my $arrayref;
    if (param('paperList') =~ /NotYet/i) {
	$arrayref = $giObject->notYetCuratedRef;
	print h3("Annotation : New PubMed References Not Yet Curated for a $name");
    }
    else {
	$arrayref = $giObject->curatedRef;
	print h3("Annotation : Curated PubMed References for $name");
    }
    
    print "<BLOCKQUOTE>";
    foreach my $row (@$arrayref) {
	my ($refNo, $citation, $year) = @$row;
	print "<P class=\"bib\">";
	print a({-href=>url."?user=".$self->user."&refNo=$refNo&$linkNm"}, $citation);
    }
    print p;
    &printEndPage;
}

########################################################################
sub displayAnnotation {
########################################################################
    my ($self) = @_;
    my ($title, $name);
    if (param('shared')) {
	$self->displaySharedAnnotation;
	exit;
    }
    elsif (param('featNo')) {
	my $featObj = Feature->new(dbh=>$dbh,
				   feature_no=>param('featNo'));
	$name = $featObj->feature_name;
	$title = $self->title." for ".$name;
	$self->populateTopicBYrefNoFeatNo(param('refNo'), 
					  param('featNo'));
    }
    elsif(param('locusNo')) {
	my $locusObj = Locus->new(dbh=>$dbh,
				  locus_no=>param('locusNo'));
	$name = $locusObj->locus_name;
	$title = $self->title." for ".$name;
	$self->populateTopicBYrefNoLocusNo(param('refNo'),
					   param('locusNo'));
    }   
    $self->printStartPage4annotation($self->database, $title, $self->help);

    $self->printTopText;

    print startform;
    print
	hidden('user', $self->user),
	hidden('refNo', param('refNo'));
    if (param('featNo')) {
	print
	    hidden('featNm', "$name"),
	    hidden('featNo', param('featNo'));
    }
    else {
	print 
	    hidden('locusNm', "$name"),
	    hidden('locusNo', param('locusNo'));
    }
    my $refObj = Reference->new(dbh=>$dbh,
				reference_no=>param('refNo'));  
    print table({-width=>"100%",
		 -border=>'0',
		 -cellspacing=>'0',
		 -cellpadding=>'2'},
		Tr(td({-width=>'50%', -valign=>'top'},
		      $self->topLeftCell($name, param('refNo'), $refObj)).
		   td({-width=>'50%', -valign=>'top'},
		      $self->topRightCell)).
		Tr(td({-width=>'400', -valign=>'top'},
		      $self->citationAbstract(param('refNo'), $refObj)).
		   td({-width=>'500', -valign=>'top'},
		      $self->mainInfo($name, param('refNo'), $refObj))));

    &printEndPage;
}

########################################################################
sub addLoci {
########################################################################
    my ($self) = @_;
    my $addedLoci = param('addedLoci');
    if (!$addedLoci) {
	$self->err_report("You have to provide locus name(s) before press the ".b("Add Loci & Curate")." button. Please go back, try again.");
        exit;
    }
    &printStartPage($self->database, $self->title, $self->help);

    ###### add each locus into locus_gene_info table, then pop up a small
    ###### window, display message ("the following loci have been added 
    ###### into locus_gene_info table, Click on each locus_name to curate it
    ###### then pass refNo and locusNo to the this program. 
    my $refNo = param('refNo');
  
    &DeleteUnwantedChar(\$addedLoci);
    $addedLoci =~ s/[,;:]/ /g;
    $addedLoci =~ s/\|/ /g;
    $addedLoci =~ s/ +/ /g;
    
    my @loci = split(/ /, $addedLoci);
    my @insertedLoci;
    foreach my $locus (@loci) {
	my $locusObj = Locus->new(dbh=>$dbh,
				  locus_name=>$locus);
	if (!$locusObj) {
	    my $featObj = Feature->new(dbh=>$dbh,
				       feature_name=>$locus);
	    if (!$featObj) {
		print "The locus_name or feature_name you entered (", font({-color=>'red'}, $locus), ") is not found in database",p;
		next;
	    }
	    $self->insertFeatGeneInfo($refNo, $featObj->feature_no);
	    next;
        }
	$self->insertLocusGeneInfo($refNo, $locusObj->locus_no);
    }
    &printEndPage;
}


########################################################################
sub commitInfo {
########################################################################
    my ($self) = shift;
    
    my ($title, $type, $locusORfeatNo);
    if (param('locusNm')){
	$title = $self->title." for ".param('locusNm');
	$locusORfeatNo = param('locusNo');
	$type = "locus";
	$self->populateTopicBYrefNoLocusNo(param('refNo'), 
					   $locusORfeatNo);
    }
    else {
	$title = $self->title." for ".param('featNm');
	$locusORfeatNo = param('featNo');
	$type = "feature";
	$self->populateTopicBYrefNoFeatNo(param('refNo'), 
					  $locusORfeatNo);
    }
    &printStartPage($self->database, $title, $self->help);
    ######################
    my $refNo = param('refNo');
    my $paperDelCB = param('paperDelCB');
    my $deleteLog = param('deletePaperLog');
    my $user = $self->user;
    if ($paperDelCB =~ /on/i) {
	$self->deletePaper($refNo, $deleteLog);
    }
    else {
	my $paperUnlinkCB = param('paperUnlinkCB');
	my $paperUnlinkCB4genes = param('paperUnlinkCB4genes');
	my $unlinkLoci = param('unlinkLocusNm');
	my $found = 0;
	if ($paperUnlinkCB =~ /on/i || 
	    ($paperUnlinkCB4genes =~ /on/i && $unlinkLoci)) {
	    $unlinkLoci =~ s/[\t\n\f\r ]+//g;
	    if ($paperUnlinkCB =~ /on/i) {
		if (param('locusNm')) {
		    if (!$unlinkLoci) {
			$unlinkLoci = param('locusNm');
		    }
		    else {
			$unlinkLoci = param('locusNm')."|".$unlinkLoci;
		    }
		}
		else {
		    if (!$unlinkLoci) {
			$unlinkLoci = param('featNm');
		    }
		    else {
			$unlinkLoci = param('featNm')."|".$unlinkLoci;
		    }
		}
	    }
	    my @loci = split(/\|/, $unlinkLoci);
	    my %unlinkItem;
	    my $refObj = Reference->new(dbh=>$dbh,
					reference_no=>$refNo);
	    my $pubmed = $refObj->pubmed;
	    foreach my $locus (@loci) {
		if ($unlinkItem{"\U$locus"}) { next;}
		$unlinkItem{"\U$locus"}++;
		my $locusObj = Locus->new(dbh=>$dbh,
					  locus_name=>$locus);
		if (!$locusObj) {
		    my $featObj = Feature->new(dbh=>$dbh,
					       feature_name=>$locus);
		    if (!$featObj) {
			print "The locus_name or feature_name you entered (", font({-color=>'red'}, $locus), ") is not found in database.", p; 
			next;
		    }
		    if ($featObj->feature_no == $locusORfeatNo) { $found++; }
		    $self->deleteFeatGeneInfo($refNo, $featObj->feature_no);
       		    $self->insertRefUnlink($pubmed, "FEATURE", 
			    $featObj->feature_no, $refNo);
		    next;
		}
		if ($locusObj->locus_no == $locusORfeatNo) { $found++;}
		$self->deleteLocusGeneInfo($refNo, $locusObj->locus_no);
		$self->insertRefUnlink($pubmed, "LOCUS", 
			    $locusObj->locus_no, $refNo);
	    }
	}
	if ($found == 0) {
	    my @currentVal;
	    my @dbVal;
	    $self->populateVal(\@currentVal, \@dbVal);
	    for (my $i = 0; $i <= $#dbVal; $i++) { 
		if ($currentVal[$i] && !$dbVal[$i]) {
		    if ($type =~ /locus/i) {
			$self->insertLocusGeneInfo($refNo, $locusORfeatNo, $currentVal[$i]);
		    }
		    else {
			$self->insertFeatGeneInfo($refNo, $locusORfeatNo, $currentVal[$i]);
		    }
		}
		elsif (!$currentVal[$i] && $dbVal[$i]) {
		    if ($type =~ /locus/i) {
			$self->deleteLocusGeneInfo($refNo, $locusORfeatNo, $dbVal[$i]);
		    }
		    else {
			$self->deleteFeatGeneInfo($refNo, $locusORfeatNo, $dbVal[$i]);
		    }
		}
	    }
	    ############## update locus and feature list
	    my $locuslist = param('locuslist');
	    &DeleteUnwantedChar(\$locuslist);
	    $locuslist =~ s/ *\| */\|/g;
	    my @locuslist = split(/\|/, $locuslist);
	    my $featlist = param('featlist');
	    &DeleteUnwantedChar(\$featlist);
	    $featlist =~ s/ *\| */\|/g;
	    my @featlist = split(/\|/, $featlist);	
	    ### locuslist
	    foreach my $locusNm (@locuslist) {
		my $locusObj = Locus->new(dbh=>$dbh,
					  locus_name=>$locusNm);
		if (!$locusObj) {
		    print "The locus_name you entered (", font({-color=>'red'}, $locusNm), ") is not found in database.", p;
		    next;
		}
		for (my $i = 0; $i <= $#currentVal; $i++) {
		    if ($currentVal[$i]) {
			$self->insertLocusGeneInfo($refNo, 
						   $locusObj->locus_no, 
						   $currentVal[$i]);
		    }
		}
	    }
	    ### featlist
	    foreach my $featNm (@featlist) {
		my $featObj = Feature->new(dbh=>$dbh,
					   feature_name=>$featNm);
		if (!$featObj) {
		    print "The feature_name you entered (", font({-color=>'red'}, $featNm), ") is not found in database.", p;
		    next;
		}
		for (my $i = 0; $i <= $#currentVal; $i++) {
		    if ($currentVal[$i]) {
			$self->insertFeatGeneInfo($refNo, 
						  $featObj->feature_no, 
						  $currentVal[$i]);
		    }
		}
	    }
	}
    }
    if ($type =~ /locus/i) {
	my $locusNm = param('locusNm');
	print p, b("View locus ".a({-href=>$configUrl->dictyBaseCGIRoot."gene_page.pl?gene_name=$locusNm", -target=>'infowin'}, $locusNm));
	print p. b("Return to ".a({-href=>url."?user=$user&type=locus&feat=$locusNm"}, "PubMed References List")), br;  
    }
    elsif ($type =~ /feature/i) {
	my $featNm = param('featNm');
	print p, b("View feature ".a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/locus.pl?featureName=$featNm", -target=>'infowin'}, $featNm));
	print p, b("Return to ".a({-href=>url."?user=$user&type=feature&feat=$featNm"}, "PubMed References List")), br;  
    }
    &returnToCuratorCentral($self->user, $configUrl->dictyBaseCGIRoot."$dblink/curatorLogin");
    
    ##################
    &printEndPage;
    ##################      
}

########################################################################
sub checkQuery {
########################################################################
    my ($self) = shift;
    if (!$self->{'_feat'}) {
	$self->err_report("You have to enter locus or feature name or number before press the Submit button. Please go back and try again.");           
    }
    if ($self->{'_type'} =~ /Feature/i) {
	my $featObj;
	if ($self->{'_feat'} =~ /^[0-9]+$/) {
	    $self->{'_featNo'} = $self->{'_feat'};
	    $featObj = Feature->new(dbh=>$dbh,
				    feature_no=>$self->{'_featNo'});
	    if (!$featObj) {
		$self->err_report("The feature_no you entered ($self->{'_featNo'}) is not found in database. Please go back, change the input and try again.");               
	    }
	    $self->{'_featNm'} = $featObj->feature_name;
	}
	else {
	    $featObj = Feature->new(dbh=>$dbh,
				    feature_name=>$self->{'_feat'});
	    if (!$featObj) {
		$self->err_report("The feature_name you entered ($self->{'_feat'}) is not found in database. Please go back, change the input and try again.");               
	    }
	    $self->{'_featNm'} = $featObj->feature_name;
	    $self->{'_featNo'} = $featObj->feature_no;
	    $self->{'_dictyBaseid'} = $featObj->dictyBaseid;
	}
	$self->{'_locusNm'} = $featObj->locus_name;
        $self->{'_locusNo'} = $featObj->locus_no;
	$self->{'_dictyBaseid'} = $featObj->dictyBaseid;
    }
    else {
	my $locusObj;
	if ($self->{'_feat'} =~ /^[0-9]+$/) {
	    $self->{'_locusNo'} = $self->{'_feat'};
	    $locusObj = Locus->new(dbh=>$dbh,
				   locus_no=>$self->{'_locusNo'});
	    if (!$locusObj) {
		$self->err_report("The locus_no you entered ($self->{'_locusNo'}) is not found in database. Please go back, change the input and try again.");               
	    }
	    $self->{'_locusNm'} = $locusObj->locus_name;
	}
	else {
	    $locusObj = Locus->new(dbh=>$dbh,
				   locus_name=>$self->{'_feat'});	    
	    if (!$locusObj) {
		$self->err_report("The locus_name you entered ($self->{'_feat'}) is not found in database. Please go back, change the input and try again.");
       	    }
	    $self->{'_locusNm'} = $locusObj->locus_name;
	    $self->{'_locusNo'} = $locusObj->locus_no;
	}
	$self->{'_dictyBaseid'} = $locusObj->dictyBaseidList;
	$self->{'_dictyBaseid'} =~ s/^([^\|]+)/$1/;
    }
}

########################################################################
sub populateVal {
########################################################################
    my ($self, $currentValRef, $dbValRef) = @_;
    push(@$currentValRef, param('mutpheCB') ? param('mutpheCB'):""); 
    push(@$currentValRef, param('geneticInterCB') ? param('geneticInterCB'):""); 
    push(@$currentValRef, param('funproCB') ? param('funproCB'):"");
    push(@$currentValRef, param('celllocCB') ? param('celllocCB'):"");
    push(@$currentValRef, param('regulationOfCB') ? param('regulationOfCB'):"");
    push(@$currentValRef, param('regulatoryRoleCB') ? param('regulatoryRoleCB'):"");
    push(@$currentValRef, param('cellcycleCB') ? param('cellcycleCB'):"");
    push(@$currentValRef, param('strainsCB') ? param('strainsCB'):"");
    push(@$currentValRef, param('aliasCB') ? param('aliasCB'):"");
    push(@$currentValRef, param('techCB') ? param('techCB'):"");
    push(@$currentValRef, param('otherCB') ? param('otherCB'):"");
    push(@$currentValRef, param('reviewCB') ? param('reviewCB'):"");
    push(@$currentValRef, param('archiveCB') ? param('archiveCB'):"");
    push(@$currentValRef, param('selectedCB') ? param('selectedCB'):"");
    push(@$currentValRef, param('genomeCB') ? param('genomeCB'):"");
    push(@$currentValRef, param('dnaseqCB') ? param('dnaseqCB'):"");
    push(@$currentValRef, param('mappingCB') ? param('mappingCB'):"");
    push(@$currentValRef, param('rnalevelCB') ? param('rnalevelCB'):"");
    push(@$currentValRef, param('transcripCB') ? param('transcripCB'):"");
    push(@$currentValRef, param('translationCB') ? param('translationCB'):"");
    push(@$currentValRef, param('proteinseqCB') ? param('proteinseqCB'):"");
    push(@$currentValRef, param('proteinphysCB') ? param('proteinphysCB'):"");
    push(@$currentValRef, param('proteinstructCB') ? param('proteinstructCB'):"");
    push(@$currentValRef, param('proteinprocessCB') ? param('proteinprocessCB'):"");
    push(@$currentValRef, param('proteinproteinCB') ? param('proteinproteinCB'):"");
    push(@$currentValRef, param('nucleicCB') ? param('nucleicCB'):"");
    push(@$currentValRef, param('substCB') ? param('substCB'):"");
    push(@$currentValRef, param('fungalCB') ? param('fungalCB'):"");
    push(@$currentValRef, param('nonfungalCB') ? param('nonfungalCB'):"");
    push(@$currentValRef, param('diseaseCB') ? param('diseaseCB'):"");
    

    @$dbValRef = ($self->{'_mutphe'},
		  $self->{'_geneticInter'},
		  $self->{'_funpro'},
		  $self->{'_cellloc'},
		  $self->{'_regulationOf'},
		  $self->{'_regulatoryRole'},
		  $self->{'_cellcycle'},
		  $self->{'_strains'},
		  $self->{'_alias'},
		  $self->{'_tech'},
		  $self->{'_other'},
		  $self->{'_review'},
		  $self->{'_archive'},
		  $self->{'_selected'},
		  $self->{'_genome'},
		  $self->{'_dnaseq'},
		  $self->{'_mapping'},
		  $self->{'_rnalevel'},
		  $self->{'_transcrip'},
		  $self->{'_translation'},
		  $self->{'_proteinseq'},
		  $self->{'_proteinphys'},
		  $self->{'_proteinstruct'},
		  $self->{'_proteinprocess'},
		  $self->{'_proteinprotein'},
		  $self->{'_nucleic'},
		  $self->{'_subst'},
		  $self->{'_fungal'},
		  $self->{'_nonfungal'},
		  $self->{'_disease'}
    );
    
}

########################################################################
sub deletePaper {
########################################################################
    my ($self, $refNo, $log) = @_;
    my $refObj = Reference->new(dbh=>$dbh,
				reference_no=>$refNo);
    my $deletedRow;
    if ($log) { $deletedRow = $refObj->getRow; }
    my $pubmed = $refObj->pubmed;
    eval { $refObj->delete; };
    if ($@) {
	print "An error occurred when deleting reference entry for reference_no = $refNo.", br, $@, p;
	$dbh->rollback;
    }
    else {

	print "The reference entry for reference_no = $refNo has been deleted from reference table.", p;
	$dbh->commit;

	if ($log) {

	    my $dlog = Delete_log->new(dbh=>$dbh,
				tab_name=>'REFERENCE',
				deleted_row=>$deletedRow);
   
	    $dlog->updateDescription($log);

	    eval { $dlog->enterUpdates($self->user); };

	    if ($@) {
		print "An error occurred when updating delete_log:$@", br;
		$dbh->rollback;
	    }
	    else {
		print "The delete log has been inserted into delete_log table.", p;
		$dbh->commit;
	    }
	}
	if ($pubmed) {
	    eval {
		Ref_bad->Insert(dbh=>$dbh,
				binds=>{pubmed=>$pubmed});
	    };
	    if ($@) {
		print "An error occurred when inserting pubmed = $pubmed into ref_bad table:$@", br;
		$dbh->rollback;
	    }
	    else {
		print "The bad pubmed ($pubmed) has been inserted into ref_bad table.", br;
		$dbh->commit;
            }
        }
    }
}

########################################################################
sub deleteLocusGeneInfo {
########################################################################
    my ($self, $refNo, $locusNo, $topic) = @_;
    if ($topic) {
	my $giObj = Locus_gene_info->new(dbh=>$dbh,
					 reference_no=>$refNo,
					 locus_no=>$locusNo,
					 literature_topic=>$topic);
	if ($giObj) { eval { $giObj->delete; }; }
    }
    else {
	eval { 
	    Locus_gene_info->DeleteEntryBYrefNoLocusNo(dbh=>$dbh,
						       reference_no=>$refNo,
						       locus_no=>$locusNo);
	};    
    }
    if ($@) {
	print "Error occurred when ", $topic? "deleting locus_no = $locusNo, reference_no = $refNo and and literature_topic = '$topic' from locus_gene_info table." : "unlinking locus_no = $locusNo from reference_no = $refNo.", br, $@, p;
	$dbh->rollback;
    }
    else {
	print "The entry for locus_no = $locusNo, reference_no = $refNo ", $topic? "and literature_topic = '$topic'" : "", " has been deleted from locus_gene_info table.", p;
	$dbh->commit;
    }
}

########################################################################
sub deleteFeatGeneInfo {
########################################################################
    my ($self, $refNo, $featNo, $topic) = @_;
    if ($topic) {
	my $giObj = Feat_gene_info->new(dbh=>$dbh,
					reference_no=>$refNo,
					feature_no=>$featNo,
					literature_topic=>$topic);
	if ($giObj) { eval { $giObj->delete; }; }
    }
    else {
	eval { 
	    Feat_gene_info->DeleteEntryBYrefNoFeatNo(dbh=>$dbh,
						     reference_no=>$refNo,
						     feature_no=>$featNo);
	};    
    }
    if ($@) {
	print "Error occurred when deleting feature_no = $featNo, reference_no = $refNo", $topic ? " and literature_topic = '$topic'" : "", " entry from feat_gene_info table.", br, $@, p;
	$dbh->rollback;
    }
    else {
	print "The entry for feature_no = $featNo, reference_no = $refNo", $topic ? " and literature_topic = '$topic'" : "", " has been deleted from feat_gene_info table.", p;
	$dbh->commit;
    }
}

########################################################################
sub insertRefUnlink {
########################################################################
    my ($self, $pubmed, $tabNm, $prikey, $refNo) = @_;
    eval {
	Ref_unlink->Insert(dbh=>$dbh,
			   literals=>{ref_unlink_no=>'CGM_DDB.runo_seq.nextval'},
			   binds=>{pubmed=>$pubmed,
			       tab_name=>$tabNm,
			       primary_key=>$prikey,
			       reference_no=>$refNo});
    };
    if ($@) {
	print "An error occurred when inserting new ref_unlink entry for pubmed = $pubmed, tab_name = '$tabNm', primary_key = '$prikey', and reference_no = $refNo into database:$@", br;
	$dbh->rollback;
    }
    else {
	print "The new ref_unlink entry for pubmed = $pubmed, tab_name = '$tabNm', primary_key = '$prikey', and reference_no = $refNo has been inserted into database.", br;
	$dbh->commit;
    }
}


########################################################################
sub insertLocusGeneInfo {
########################################################################
    my ($self, $refNo, $locusNo, $topic) = @_;
    if (!$topic) { $topic = "Not yet curated"; }
    else {
	my $giObj = Locus_gene_info->new(dbh=>$dbh,
					  reference_no=>$refNo,
					  locus_no=>$locusNo,
					  literature_topic=>'Not yet curated');
	if ($giObj) {
	    eval { $giObj->delete; };
	    if ($@) {
		print "An error occurred when deleting locus_gene_info entry for reference_no = $refNo, locus_no = $locusNo, and topic = 'Not yet curated':$@", br;
		$dbh->rollback;
	    }
	    else {
		print "The locus_gene_info entry for reference_no = $refNo, locus_no = $locusNo, and topic = 'Not yet curated' has been deleted from database.", br;
		$dbh->commit;
	    }
	}
    }

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

    if ($giObj) {

#	print "The locus_gene_info for reference_no=$refNo, locus_no=$locusNo, and literature_topic='$topic' is already in database.",br;

	return;

    }


    eval {
	Locus_gene_info->Insert(dbh=>$dbh,
				binds=>{reference_no=>$refNo,
				    locus_no=>$locusNo,
				    literature_topic=>$topic});
    };
    if ($@) {
	print "An error occurred when inserting new locus_gene_info entry for reference_no = $refNo, locus_no = $locusNo, and topic = '$topic' into database:$@", br;
	$dbh->rollback;
    }
    else {
	print "The new locus_gene_info entry for reference_no = $refNo, locus_no = $locusNo, and topic = '$topic' has been inserted into database.", br;
	$dbh->commit;
	if (!param('locusNo') || 
	    param('locusNo') != $locusNo) {
	    print a({-href=>url."?user=".$self->user."&refNo=$refNo&locusNo=$locusNo", -target=>'infowin'}, b("Curate this entry"));
        } 	
        print p;
    }

}

########################################################################
sub insertFeatGeneInfo {
########################################################################
    my ($self, $refNo, $featNo, $topic) = @_;
    if (!$topic) { $topic = "Not yet curated"; }
    else {
	my $giObj = Feat_gene_info->new(dbh=>$dbh,
					reference_no=>$refNo,
					feature_no=>$featNo,
					literature_topic=>'Not yet curated');
	if ($giObj) {
	    eval { $giObj->delete; };
	    if ($@) {
		print "An error occurred when deleting feat_gene_info entry for reference_no = $refNo, feature_no = $featNo, and topic = 'Not yet curated':$@", br;
		$dbh->rollback;
	    }
	    else {
		print "The feat_gene_info entry for reference_no = $refNo, feature_no = $featNo, and topic = 'Not yet curated' has been deleted from database.", br;
		$dbh->commit;
	    }
	}
    }

    my $giObj = Feat_gene_info->new(dbh=>$dbh,
				    reference_no=>$refNo,
				    feature_no=>$featNo,
				    literature_topic=>$topic);

    if ($giObj) {

#	print "The feat_gene_info for reference_no=$refNo, feature_no=$featNo, and literature_topic='$topic' is already in database.",br;

	return;

    }

    eval {
	Feat_gene_info->Insert(dbh=>$dbh,
				binds=>{reference_no=>$refNo,
				    feature_no=>$featNo,
				    literature_topic=>$topic});
    };
    if ($@) {
	print "An error occurred when inserting new feat_gene_info entry for reference_no = $refNo, feature_no = $featNo, and topic = '$topic' into database:$@", br;
	$dbh->rollback;
    }
    else {
	print "The new feat_gene_info entry for reference_no = $refNo, feature_no = $featNo, and topic = '$topic' has been inserted into database.", br;
	$dbh->commit;
	if (!param('featNo') || 
	    param('featNo') != $featNo) {
	    print a({-href=>url."?user=".$self->user."&refNo=$refNo&featNo=$featNo", -target=>'infowin'}, b("Curate this entry"));
        } 	
        print p;
    }
}


########################################################################
sub populateTopicBYrefNoFeatNo {
########################################################################
    my ($self, $refNo, $featNo) = @_;
    my $arrayRef = Feat_gene_info->GetTopicArrayRefBYrefNoFeatNo(
					  dbh=>$dbh,
					  reference_no=>$refNo,
					  feature_no=>$featNo);
    foreach my $rowRef (@$arrayRef) {
	my ($topic) = @$rowRef;
	$self->setTopic($topic);
    }
}


########################################################################
sub populateTopicBYrefNoLocusNo {
########################################################################
    my ($self, $refNo, $locusNo) = @_;
    my $arrayRef = Locus_gene_info->GetTopicArrayRefBYrefNoLocusNo(
					  dbh=>$dbh,
					  reference_no=>$refNo,
					  locus_no=>$locusNo);
    foreach my $rowRef (@$arrayRef) {
	my ($topic) = @$rowRef;
	$self->setTopic($topic);
    }
}


#######################################################################
sub setTopic {
#######################################################################
    my ($self, $topic) = @_;
        if ($topic =~ /^Mutants\/Phenotypes/i) {
	$self->{'_mutphe'} = $topic;
    }
    elsif ($topic =~ /^Genetic Interactions/i) {
	$self->{'_geneticInter'} = $topic;
    }
    elsif ($topic =~ /^Function\/Process/i) {
	$self->{'_funpro'} = $topic;
    }
    elsif ($topic =~ /^Cellular Location/i) {
	$self->{'_cellloc'} = $topic;
    }
    elsif ($topic =~ /^Regulation of/i) {
	$self->{'_regulationOf'} = $topic;
    }
    elsif ($topic =~ /^Regulatory Role/i) {
	$self->{'_regulatoryRole'} = $topic;
    }
    elsif ($topic =~ /^Cell Cycle Phase Involved/i) {
	$self->{'_cellcycle'} = $topic;
    }
    elsif ($topic =~ /^Strains\/Constructs/i) {
	$self->{'_strains'} = $topic;
    }
    elsif ($topic =~ /^Alias/i) {
	$self->{'_alias'} = $topic;
    }
    elsif ($topic =~ /^Techniques and Reagents/i) {
	$self->{'_tech'} = $topic;
    }
    elsif ($topic =~ /^Other Features/i) {
	$self->{'_other'} = $topic;
    }
    elsif ($topic =~ /^Reviews/i) {
	$self->{'_review'} = $topic;
    }
    elsif ($topic =~ /^Archived Literature/i) {
	$self->{'_archive'} = $topic;
    }
    elsif ($topic =~ /^Selected Review/i) {
	$self->{'_selected'} = $topic;
    }
    elsif ($topic =~ /^Genome-wide Analysis/i) {
	$self->{'_genome'} = $topic;
    }
    elsif ($topic =~ /^DNA\/RNA Sequence Features/i) {
	$self->{'_dnaseq'} = $topic;
    }
    elsif ($topic =~ /^Mapping/i) {
	$self->{'_mapping'} = $topic;
    }
    elsif ($topic =~ /^RNA Levels and Processing/i) {
	$self->{'_rnalevel'} = $topic;
    }
    elsif ($topic =~ /^Transcription/i) {
	$self->{'_transcrip'} = $topic;
    }
    elsif ($topic =~ /^Translational Regulation/i) {
	$self->{'_translation'} = $topic;
    }
    elsif ($topic =~ /^Protein Sequence Features/i) {
	$self->{'_proteinseq'} = $topic;
    }
    elsif ($topic =~ /^Protein Physical Properties/i) {
	$self->{'_proteinphys'} = $topic;
    }
    elsif ($topic =~ /^Protein\/Nucleic Acid Structure/i) {
	$self->{'_proteinstruct'} = $topic;
    }
    elsif ($topic =~ /^Protein Processing\/Regulation/i) {
	$self->{'_proteinprocess'} = $topic;
    }
    elsif ($topic =~ /^Protein-protein Interactions/i) {
	$self->{'_proteinprotein'} = $topic;
    }
    elsif ($topic =~ /^Protein-Nucleic Acid Interactions/i) {
	$self->{'_nucleic'} = $topic;
    }
    elsif ($topic =~ /^Substrates\/Ligands\/Cofactors/i) {
	$self->{'_subst'} = $topic;
    }
    elsif ($topic =~ /^Fungal Related Genes\/Proteins/i) {
	$self->{'_fungal'} = $topic;
    }
    elsif ($topic =~ /^Non-Fungal Related Genes\/Proteins/i) {
	$self->{'_nonfungal'} = $topic;
    }
    elsif ($topic =~ /^Disease Gene Related/i) {
	$self->{'_disease'} = $topic;
    }
}

########################################################################
########################################################################
sub printTopText {
########################################################################
    my ($self) = @_;
    my ($title, $featNm, $featNo, $locusNm, $locusNo, $curated, $notYet,
	$curatedParam, $notYetParam);
    if (param('locusNo')) {
	$locusNo = param('locusNo');
	my $locusObj = Locus->new(dbh=>$dbh,
				  locus_no=>$locusNo);
	$locusNm = $locusObj->locus_name;
	$curated = $locusObj->curatedRefNum;
	$notYet = $locusObj->notYetCuratedRefNum;
	$curatedParam 
	    = "user=".$self->user."&locusNo=$locusNo&paperList=curated";
	$notYetParam 
	    = "user=".$self->user."&locusNo=$locusNo&paperList=notYet";
	print p, "For the ".strong(a({-href=>$configUrl->dictyBaseCGIRoot."gene_page.pl?gene_name=$locusNm", -target=>"infowin"}, "locus $locusNm")." ");  
    }
    else {
	$featNo = param('featNo');
	my $featObj = Feature->new(dbh=>$dbh,
				   feature_no=>$featNo);
	$featNm = $featObj->feature_name;
	$curated = $featObj->curatedRefNum;
	$notYet = $featObj->notYetCuratedRefNum;
	$curatedParam
	    = "user=".$self->user."&featNo=$featNo&paperList=curated";
	$notYetParam
	    = "user=".$self->user."&featNo=$featNo&paperList=notYet";
	print p, "For the ".strong(a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/locus.pl?featureName=$featNm", -target=>"infowin"}, "feature $featNm")." ");
    }
    if (!$curated) { $curated = 0; }
    if (!$notYet) { $notYet = 0;}	 
    if ($curated && $notYet) {
	print "there are ".strong(a({-href=>url."?$curatedParam", -target=>"infowin"}, "$curated curated")." PubMed references")." and ".strong(a({-href=>url."?$notYetParam", -target=>"infowin"}, "$notYet new")." PubMed references")." not yet curated.";	
    }
    elsif ($curated) {
	print "there are ".strong(a({-href=>url."?$curatedParam",-target=>"infowin"}, "$curated curated")." PubMed references")." and ".strong("$notYet new PubMed references")." not yet curated.";	
    }
    else {
	print "there are ".strong("$curated curated PubMed references")." and ".strong(a({-href=>url."?$notYetParam",-target=>"infowin"}, "$notYet new")." PubMed references")." not yet curated.";	
    }
    print hr;
}

########################################################################
sub citationAbstract {
########################################################################
    my ($self, $refNo, $refObj) = @_;
    my $citation = $refObj->formatedCitation; 
    my $abstract = $refObj->abstract;
  
    $abstract =~ s/\///g;

    return $citation.br.font({-color=>"red"}, " (Reference_no = $refNo)").
	   blockquote($abstract);

}

########################################################################
sub mainInfo {
########################################################################
    my ($self, $name, $refNo, $refObject) = @_;
    my ($self, $name, $refNo, $refObject) = @_;
    my ($filterBy, $type, $No, $typeNm);
    if ($name =~ /^[Y[A-P][LR][0-9]{3}[WC]/i) {
	$filterBy = "FEAT_GENE_INFO";
	$type = "feature";
	$typeNm = "featNo";
	$No = param('featNo');
    }
    else {
	$filterBy = "LOCUS_GENE_INFO";
	$type = "locus";
	$typeNm = "locusNo";
	$No = param('locusNo');
    }
    my (@locuslist, @featlist);
    foreach my $rowRef (@{$refObject->locusArrayRef}) {
	my ($locusNm) = @$rowRef;
	push(@locuslist, $locusNm);
    }
    foreach my $rowRef (@{$refObject->featureArrayRef}) {
	my ($featNm) = @$rowRef;
	push(@featlist, $featNm);
    }
    my ($locuslist, $featlist);
    if (@locuslist > 4) {
        $locuslist = $locuslist[0]."|".$locuslist[1]."|".$locuslist[2]."|". 
		     $locuslist[3].br.
		     a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/curation/geneinfoCuration?user=".$self->user."&refNo=$refNo&$typeNm=$No&shared=1", 
			-target=>"infowin"}, 
		       "FULL LIST").br;
    }
    else {
	$locuslist = join("|", @locuslist); 
    }
    if (@featlist > 4) {
	$featlist = $featlist[0]."|".$featlist[1]."|".$featlist[2]."|". 
	            $featlist[2].br.
                    a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/curation/geneinfoCuration?user=".$self->user."&refNo=$refNo&$typeNm=$No&shared=1", 
			-target=>"infowin"}, 
		       "FULL LIST").br;
    }
    else {
	$featlist = join("|", @featlist);
    }
    my $locusText = "Enter locus names that will share all checked annotations upon submission; separate multiples by |  :";
    my $featText = "Enter feature names that will share all checked annotations upon submission; separate multiples by |  :";
    if ($locuslist) {
	$locusText .= br."This annotation shared by loci : ".font({color=>'red'}, $locuslist);
    }
    if ($featlist) {
	$featText .= br."This annotation shared by features : ".font({color=>'red'}, $featlist);
    }
    return 
    table({-width=>"100%",
	   -border=>'0',
	   -cellspacing=>'0',
	   -cellpadding=>'2'},
	Tr({-bgcolor=>"#a4abc2"},
	   th({-colspan=>'2'},
	      u(a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/reference/geneinfo.pl?locus=$name",
		   -target=>"infowin"},
		  "$name Gene Info")." Topics ").
	   font({-size=>'-1'},
		a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/curation/codeCuration?user=".$self->user."&colHeader=TAB_NAME&filterBy=$filterBy", 
		   -target=>"infowin"},
		  "(descriptions)")))).
	Tr({-bgcolor=>"#a4abc2"},
	   th(br."Genetics/Cell Biology").
	   th(br."Research Aids & Literature")).
	Tr(td($self->geneticSection($name, $type)).td($self->researchSection)).
	Tr({-bgcolor=>"#a4abc2"},
	   th("Nucleic Information").
	   th("Protein Information")).
	Tr(td($self->nucleicSection).td($self->proteinSection)).
	Tr({-bgcolor=>"#a4abc2"},
           th("Related Genes/Proteins")).
	Tr(td($self->relatedSection)).
	Tr(td(br)).
	Tr(td({-colspan=>'2'},
	      font({-size=>'-1'}, $locusText).
              textfield(-name=>'locuslist',
                        -value=>'',
                        -size=>'30'))).
	Tr(td({-colspan=>'2'},
	      font({-size=>'-1'}, $featText).
	      textfield(-name=>'featlist',
			-value=>'',
			-size=>'30'))).
	Tr(td({-colspan=>'2'},
              submit('commit', 'Submit').
	      reset.
	      hr({-size=>'2'}))).
	Tr(th({-bgcolor=>"#a4abc2"},
	      "$name Curation: ").
	   td({-align=>'left'},
	      a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/curation/${type}Curation?user=".$self->user."&type=$type&$type=$name", -target=>"infowin"},
		"\u$type").br.
	      a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/curation/goCuration?user=".$self->user."&type=$type&feat=$name", -target=>"infowin"},
		"Gene Ontology").br.
	      a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/curation/phenotypeCuration?user=".$self->user."&type=$type&feat=$name", -target=>"infowin"},
		  "Phenotype"))));
}


########################################################################
sub geneticSection {
########################################################################
    my ($self, $name, $type) = @_;
    my $user = $self->user;
    my $urlRoot = $configUrl->dictyBaseCGIRoot;    
    return
	$self->topicCheckbox("mutpheCB", "Mutants/Phenotypes", $self->{'_mutphe'},  font({-size=>'-1'}, "Mutants/".a({-href=>$urlRoot."$dblink/curation/phenotypeCuration?user=$user&type=$type&feat=$name", -target=>"infowin"},"Phenotypes"))."&nbsp;".a({-href=>'javascript:checkboth()'},
 img({-src=>$configUrl->dictyBaseImages."both.gif", -width=>"30", -height=>"15", -border=>"0"}))).br.
	$self->topicCheckbox("geneticInterCB", "Genetic Interactions", $self->{'_geneticInter'}, font({-size=>'-1'}, " Genetic Interactions")).br.
	$self->topicCheckbox("funproCB", "Function/Process", $self->{'_funpro'}, font({-size=>'-1'}, " Function/Process &nbsp;&nbsp;".a({-href=>$urlRoot."$dblink/curation/goCuration?user=$user&type=$type&feat=$name", -target=>"infowin"}, "[GO]"))).br.
	$self->topicCheckbox("celllocCB", "Cellular Location", $self->{'_cellloc'}, font({-size=>'-1'}, " Cellular Location &nbsp;&nbsp;".a({-href=>$urlRoot."$dblink/curation/goCuration?user=$user&type=$type&feat=$name", -target=>"infowin"},"[GO]"))).br.
	$self->topicCheckbox("regulationOfCB", "Regulation of", $self->{'_regulationOf'}, font({-size=>'-1'}, " Regulation of")).br.
	$self->topicCheckbox("regulatoryRoleCB", "Regulatory Role", $self->{'_regulatoryRole'}, " Regulatory Role").br.
	$self->topicCheckbox("cellcycleCB", "Cell Cycle Phase Involved", $self->{'_cellcycle'}, font({-size=>'-1'}, " Cell Cycle Phase Involved"));

}


########################################################################
sub researchSection {
########################################################################
    my ($self) = @_;
    return 
	$self->topicCheckbox("strainsCB", "Strains/Constructs", $self->{'_strains'}, font({-size=>'-1'}," Strains/Constructs")).br.
	$self->topicCheckbox("aliasCB", "Alias", $self->{'_alias'}, font({-size=>'-1'}," Alias")).br.
	$self->topicCheckbox("techCB", "Techniques and Reagents", $self->{'_tech'},
 font({-size=>'-1'}," Techniques and Reagents")).br.
        $self->topicCheckbox("otherCB", "Other Features", $self->{'_other'}, font({-size=>'-1'}," Other Features")).br.
        $self->topicCheckbox("reviewCB", "Reviews", $self->{'_review'}, font({-size=>'-1'}," Reviews")).br.
	$self->topicCheckbox("archiveCB", "Archived Literature", $self->{'_archive'}, font({-size=>'-1'}, " Archived Literature")).br.
	$self->topicCheckbox("selectedCB", "Selected Review", $self->{'_selected'}, font({-size=>'-1'}," Selected Review")).br.
	$self->topicCheckbox("genomeCB", "Genome-wide Analysis", $self->{'_genome'}, font({-size=>'-1'}," Genome-wide Analysis"));

}


########################################################################
sub nucleicSection {
########################################################################
    my ($self) = @_;
    return 
	$self->topicCheckbox("dnaseqCB", "DNA/RNA Sequence Features", $self->{'_dnaseq'}, font({-size=>'-1'}, " DNA/RNA Sequence Features")).br.
	$self->topicCheckbox("mappingCB", "Mapping", $self->{'_mapping'},font({-size=>'-1'}," Mapping")).br.
	$self->topicCheckbox("rnalevelCB", "RNA Levels and Processing", $self->{'_rnalevel'}, font({-size=>'-1'}," RNA Levels and Processing")).br.
        $self->topicCheckbox("transcripCB", "Transcription", $self->{'_transcrip'}, font({-size=>'-1'}," Transcription")).br.
        $self->topicCheckbox("translationCB", "Translational Regulation", $self->{'_translation'},font({-size=>'-1'}," Translational Regulation")).br.br.br;
}


############################################################################
sub proteinSection {
############################################################################
    my ($self) = @_;

    return 
	$self->topicCheckbox("proteinseqCB", "Protein Sequence Features", $self->{'_proteinseq'}, font({-size=>'-1'}," Protein Sequence Features")).br.
	$self->topicCheckbox("proteinphysCB", "Protein Physical Properties", $self->{'_proteinphys'}, font({-size=>'-1'}, " Protein Physical Properties")).br.
        $self->topicCheckbox("proteinstructCB", "Protein/Nucleic Acid Structure", $self->{'_proteinstruct'}, font({-size=>'-1'}, " Protein/Nucleic Acid Structure")).br.
        $self->topicCheckbox("proteinprocessCB", "Protein Processing/Regulation", $self->{'_proteinprocess'}, font({-size=>'-1'}, " Protein Processing/Regulation")).br.
        $self->topicCheckbox("proteinproteinCB", "Protein-protein Interactions", $self->{'_proteinprotein'}, font({-size=>'-1'}, " Protein-protein Interactions")).br.
        $self->topicCheckbox("nucleicCB", "Protein-Nucleic Acid Interactions", $self->{'_nucleic'}, font({-size=>'-1'}, " Protein-Nucleic Acid Interactions")).br.
        $self->topicCheckbox("substCB", "Substrates/Ligands/Cofactors", $self->{'_subst'}, font({-size=>'-1'}, " Substrates/Ligands/Cofactors"));
    
}

########################################################################
sub relatedSection {
########################################################################
    my ($self) = @_;
    return 
	$self->topicCheckbox("fungalCB", "Fungal Related Genes/Proteins", $self->{'_fungal'}, font({-size=>'-1'}, " Fungal Related Genes/Proteins")).br.
        $self->topicCheckbox("nonfungalCB", "Non-Fungal Related Genes/Proteins", $self->{'_nonfungal'}, font({-size=>'-1'}, " Non-Fungal Related Genes/Proteins")).br.
	$self->topicCheckbox("diseaseCB", "Disease Gene Related", $self->{'_disease'}, font({-size=>'-1'}," Disease Gene Related"));

}

########################################################################
sub topicCheckbox {
########################################################################
    my ($self, $CBname, $CBvalue, $checked, $text) = @_;
    return 
	checkbox(-name=>"$CBname",
		 -value=>"$CBvalue",
		 -checked=>"$checked",
		 -label=>'').
	font({-size=>'-1'}, $text);
}

########################################################################
sub topLeftCell {
########################################################################
    my ($self, $name, $refNo, $refObj) = @_;
    
    my @curatedLoci = $refObj->getCuratedLoci;
    my @curatedFeatures = $refObj->getCuratedFeatures;

    my @notYetLoci = $refObj->getNotYetLoci;
    my @notYetFeatures = $refObj->getNotYetFeatures;
    
    my @unlinkedLoci = $refObj->getUnlinkedLoci;
    my @unlinkedFeatures = $refObj->getUnlinkedFeatures;

    my ($curatedList, $notYetList, $unlinkedList);

    my $user = $self->user;
    foreach my $curated (@curatedLoci) {
	my ($locusNm, $locusNo) = split(/:/, $curated);
	$curatedList .= a({-href=>url."?user=$user&locusNo=$locusNo&refNo=$refNo", -target=>"infowin"}, $locusNm)."|"; 
    }
    foreach my $curated (@curatedFeatures) {
	my ($featNm, $featNo) = split(/:/, $curated);
	$curatedList .= a({-href=>url."?user=$user&featNo=$featNo&refNo=$refNo", -target=>"infowin"}, $featNm)."|"; 
    }
    if (!$curatedList) { $curatedList = "nothing yet";}
    else { $curatedList =~ s/\| *$//; }

    foreach my $notyet (@notYetLoci) {
	my ($locusNm, $locusNo) = split(/:/, $notyet);
	$notYetList .= a({-href=>url."?user=$user&locusNo=$locusNo&refNo=$refNo", -target=>"infowin"}, $locusNm); 
	my $locusObj = Locus->new(dbh=>$dbh,
				  locus_no=>$locusNo);
	if ($locusObj) {
	    my ($Rnum, $Rdate, $Edate, $Sdate, $isStd) = 
		split(/:/, $locusObj->geneReservationInfo);
	    if ($isStd =~ /^N/i) {
		$notYetList .= font({-color=>'red'}, "*");
	    }
	}
	$notYetList .= "|";
    }
    foreach my $notyet (@notYetFeatures) {
	my ($featNm, $featNo) = split(/:/, $notyet);
	$notYetList .= a({-href=>url."?user=$user&featNo=$featNo&refNo=$refNo", -target=>"infowin"}, $featNm)."|"; 
    }
    if (!$notYetList) { $notYetList = "nothing left";}
    else { $notYetList =~ s/\| *$//; }

    
    foreach my $unlinked (@unlinkedLoci) {

	my ($locusNm, $locusNo) = split(/:/, $unlinked);
	
	$unlinkedList .= a({-href=>url."?user=$user&locusNo=$locusNo&refNo=$refNo", -target=>"infowin"}, $locusNm)."|"; 
	
    }
    
    foreach my $unlinked (@unlinkedFeatures) {

	my ($featNm, $featNo) = split(/:/, $unlinked);
	$unlinkedList .= a({-href=>url."?user=$user&featNo=$featNo&refNo=$refNo", -target=>"infowin"}, $featNm)."|"; 

    }
    if (!$unlinkedList) { $unlinkedList = "nothing yet"; }
    else {  $unlinkedList =~ s/\| *$//; }

    return 
	table({-width=>'100%',
	       -border=>'0',
	       -cellspacing=>'0',
	       -cellpadding=>'2'},
	      Tr(th({-bgcolor=>"#a4abc2", width=>"50%"},
		    "Annotation Info : $name")).
	      Tr(td({-bgcolor=>"#CCFFCC"},
		    font({-size=>'-1'},
			 strong("Curated for : ").$curatedList))).
	      Tr(td({-bgcolor=>"#b7d8e4"},
		    font({-size=>'-1'},
			 strong("Not yet curated for : ").$notYetList).br.
		    textfield(-name=>'addedLoci',
			      -size=>15). " ".
		    submit(-name=>'submit',
			   -value=>'Add Loci & Curate'))).
	      Tr(td({-bgcolor=>"#CCFFFF"},
		    font({-size=>'-1'},
			 strong("Unlinked from : ").$unlinkedList))));
}

########################################################################
sub topRightCell {
########################################################################
    my ($self) = @_;
    
    return 
	table({-width=>'100%',
	       -border=>'0',
	       -cellspacing=>'0',
	       -cellpadding=>'2'},
	      Tr({-bgcolor=>"#a4abc2"},
		 (td({-align=>'left'},
		     font({-size=>'-1'},
			  checkbox(-name=>'paperDelCB',
				   -label=>'').
			  "Delete this paper from the database, thereby removing all of its associations in the database".br.
			  " delete log comments: ").
		     textfield(-name=>'deletePaperLog',
			       -size=>25,
			       -maxsize=>240)))).
	      Tr({-bgcolor=>"#a4abc2"},
		 (td({-align=>'left'},
		     font({-size=>'-1'},
			  checkbox(-name=>'paperUnlinkCB',
				   -label=>'').
			  "Unlink paper from current gene".br.
			  checkbox(-name=>'paperUnlinkCB4genes',
				   -label=>'').
			  "Unlink paper from additional gene(s) ").
		     textfield(-name=>'unlinkLocusNm',
			       -size=>14).br.
		     font({color=>'red', size=>'-1'}, " separate multiples by | ")
	       ))));

}

########################################################################
sub printStartPage4annotation {
########################################################################
    my ($self, $database, $title, $help) = @_;
    print header;
    ######################

my $JSCRIPT=<<END;

function checkboth() {
    if (document.giCuration.mutpheCB.checked == false) {
	document.giCuration.mutpheCB.checked = true;
	document.giCuration.strainsCB.checked = true;
    }
    else {
	document.giCuration.mutpheCB.checked = false;
	document.giCuration.strainsCB.checked = false;
    }
}

END
    #######################
    print start_html(-title=>"$title", -script=>$JSCRIPT);
    print "<body bgcolor='#FFFFFF'>\n";
    &PrintPageTop($database, $title, $help);	
}


########################################################################
sub printStartPage4PaperList {
########################################################################
    my ($self, $database, $title, $help) = @_;
    print header;
    ######################
my $STYLE=<<END;
P {} 
.bib { text-indent: -2em } 
END
    ######################
    print start_html(-title=>"$title", -style=>$STYLE);
    print "<body bgcolor='#FFFFFF'>\n";
    &PrintPageTop($database, $title, $help);	
}


########################################################################
sub printEndForm {
########################################################################
    my ($self, $Nm, $No) = @_;
    print
	hidden('user', "$self->user"),
	hidden('type', "$self->{'_type'}");
    if (param('type') =~ /feature/i) {
	print
	    hidden('featNm', "$Nm"),
	    hidden('featNo', "$No");
    }
    else {
	print 
	    hidden('locusNm', "$Nm"),
	    hidden('locusNo', "$No");
    }
    print
	submit('commit','Submit'), " ",
	endform;
}

########################################################################
sub err_report {
########################################################################
    my ($self, $err) = @_;
    
    &printStartPage($self->database, $self->title, $self->help);	
    print b($err);
    
    &printEndPage;
    $dbh->disconnect;
    exit;
}

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



















