#!/usr/bin/perl
package printFeatureMod_base;

# Author:           Shuai Weng                                     
# Date:             June 2000  
# Description:      This package contains 'display' modules for 
#                   locus and feature curation pages.
#
##################           RCS INFORMATION          ################
# $Author: emj466 $
# $Date: 2006/10/25 18:29:11 $
# $Header: /projects/dicty/build/source_files/db/lib/site_name/curation/printFeatureMod_base.pm,v 1.1 2006/10/25 18:29:11 emj466 Exp $
# $Log: printFeatureMod_base.pm,v $
# Revision 1.1  2006/10/25 18:29:11  emj466
# new build directory
#
# Revision 1.1.1.2  2003/08/18 22:50:40  emj466
# no message
#
# Revision 1.1.1.1  2003/08/15 20:18:40  emj466
# initial load of dicty/build
#
# Revision 1.11  2003/06/26 19:36:07  anand
# added method to draw text field for aliases and name_description
#
# Revision 1.1  2003/06/03 22:04:21  anand
# Initial revision
#
# Revision 1.10  2002/11/27 18:40:44  kara
# made changes so that chromosome and coords cannot be edited using this
# interface (but new features and their chr and coord can be inserted).
#
# Revision 1.9  2002/11/27 01:54:44  kara
# added comments where the subroutine needs to be updated.
#
# $Revision: 1.1 $
# $Source: /projects/dicty/build/source_files/db/lib/site_name/curation/printFeatureMod_base.pm,v $
# $State: Exp $
# $Locker:  $
######################################################################
use strict;
use DBI;
use CGI qw/:standard :html3/;
use lib "/usr/local/dicty/www_dictybase/db/lib/dictyBase/Objects";
use ConfigURLdictyBase;
use Exporter();
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

$VERSION = 1.00;
@ISA = qw( Exporter );

%EXPORT_TAGS = ( 
    printInfo => [qw/printSubTitle printAssigndictyBaseidBox printDeleteFeatureBox printDeleteLocusBox printDeleteAliasBox printUpdateFeatureBox printUpdateLocusBox printUpdateAliasBox printUpdateUniformAliasBox printUpdateNonUniformAliasBox printUpdateProteinNameAliasBox printFeatureTypes printFeaturePosInfo printGeneticPosition printFeatureDesc printPhenoType printCuratorNote printGeneReservationInfo printAddContact printNameDesc printLocusDesc printGeneProduct/]
);


Exporter::export_ok_tags('printInfo');

#######################################################################
sub printSubTitle {
#######################################################################
    my ($subTitle) = @_;
    print table(Tr(td({-width=>'100%',
		       -bgcolor=>'#b7d8e4'},
		      b($subTitle))));
}

#######################################################################
sub printAssigndictyBaseidBox {
#######################################################################
    print table(Tr(td({-align=>'left'},
		      checkbox(-name=>'assigndictyBaseidCB',
			       -label=>'').
		      b(font({-color=>'red'}, 
				" If you don't want to associate it with a feature, please check this box to assign a new dictyBaseid for this locus")))));

}

#######################################################################
sub printDeleteFeatureBox {
#######################################################################
    print table(Tr(td({-align=>'left'},
		      font({-size=>'-1'},
			   checkbox(-name=>'featDelCB',
				    -label=>'').
			   "Delete this feature from the database")).
		   td(font({-size=>'-1'},
			   " delete log comments ").
		      textfield('featDelLog', '', '50'))));
}

#######################################################################
sub printDeleteLocusBox {
#######################################################################
    my ($locus) = @_;
    my $row = checkbox(-name=>'locusDelCB',
		       -label=>'');
    if ($locus) {
        $row .= "Delete locus $locus from the database";
    }
    else {
	$row .= "Delete this locus from the database";
    }
    print table(Tr(td({-align=>'left'},
		      font({-size=>'-1'},
			   $row)).
		      td(font({-size=>'-1'},
			      " delete log comments ").
			 textfield('locusDelLog', '', '50'))));
}

#######################################################################
sub printDeleteAliasBox {
########################################################################
    my ($alias)= @_;
	my @aliases = split(/\|/, $alias);
	my $i = 0;
	foreach my $thisAlias(@aliases) {
	    $i++;
	    print hidden("alias$i", "$thisAlias");
	    print table(Tr(td({-align=>'left'},
			      font({-size=>'-1'},
				   checkbox(-name=>"aliasDelCB$i",
					    -label=>'').
				   "Delete alias $thisAlias from the database")).
			   td(font({-size=>'-1'},
				   " delete log comments ").
			      textfield("aliasDelLog$i", '', '50'))));
	}
}

########################################################################
sub printUpdateFeatureBox {
########################################################################
    my ($featName) = @_;
    print table(Tr(td({-align=>'left'},
		      font({-size=>'-1'},
			   "Feature name ").
		      textfield(-name=>'feature', 
				-value=>"$featName", 
				-size=>'10')).
		   td(font({-size=>'-1'},
			   " log comments ").
		      textfield('featUpdLog', '', '40'))));
}

########################################################################
sub printUpdateLocusBox {
########################################################################
    my ($locusNm) = @_;
    print table(Tr(td({-align=>'left'},
		      font({-size=>'-1'},
			   "Locus name ").
		      textfield(-name=>'locusNm', 
				-value=>"$locusNm", 
				-size=>'10')).
		   td(font({-size=>'-1'},
			   " log comments ").
		      textfield('locusUpdLog', '', '40'))));
}

########################################################################
sub printUpdateAliasBox {
########################################################################
    my ($alias) = @_;
    my $size = 10;
    if (length($alias) > 10) {
	$size = length($alias);
    }
    print table(Tr(td({-align=>'left'},
		      font({-size=>'-1'},
			   "alias.alias_name ").
		      textfield(-name=>'alias', 
				-value=>"$alias", 
				-size=>"$size").br.
		   font({-color=>'red'}, "separate names by '|'")).
		   td(font({-size=>'-1'},
			   " log comments ").
		      textfield('aliasUpdLog', '', '40'))));
}

########################################################################
sub printUpdateUniformAliasBox {
########################################################################
    my ($alias) = @_;
    my $size = 10;
    if (length($alias) > 10) {
	$size = length($alias);
    }
    print table(Tr(td({-align=>'left'},
		      font({-size=>'-1'},
			   "Uniform alias name ").
		      textfield(-name=>'uniform_alias', 
				-value=>"$alias", 
				-size=>"$size").br.
		   font({-color=>'red'}, "separate names by '|' ") . 
		   " Eg: PHM5|EPP1") .
		   td(font({-size=>'-1'},
			   " log comments ").
		      textfield('aliasUpdLog', '', '40'))));
}


########################################################################
sub printUpdateNonUniformAliasBox {
########################################################################
    my ($alias) = @_;
    my $size = 10;
    if (length($alias) > 10) {
	$size = length($alias);
    }
    print table(Tr(td({-align=>'left'},
		      font({-size=>'-1'},
			   "Non-uniform alias name ").
		      textfield(-name=>'non_uniform_alias', 
				-value=>"$alias", 
				-size=>"$size").br.
		   font({-color=>'red'}, "separate names by '|'") . 
		   " Eg: Endo-1|EndoPP1") .
		   td(font({-size=>'-1'},
			   " log comments ").
		      textfield('aliasUpdLog', '', '40'))));
}


########################################################################
sub printUpdateProteinNameAliasBox {
########################################################################
    my ($alias) = @_;
    my $size = 10;
    if (length($alias) > 10) {
	$size = length($alias);
    }
    print table(Tr(td({-align=>'left'},
		      font({-size=>'-1'},
			   "Protein name alias ").
		      textfield(-name=>'protein_name_alias', 
				-value=>"$alias", 
				-size=>"$size").br.
		   font({-color=>'red'}, "separate names by '|'") . 
		   " Eg: EndoPolyPase|EndoPolyPhosphatase") .
		   td(font({-size=>'-1'},
			   " log comments ").
		      textfield('aliasUpdLog', '', '40'))));
}

########################################################################
sub printFeatureTypes {
########################################################################
    my($types) = @_;
    my @types = split(/\|/, $types);
    my ($default1, @default2);
    foreach my $type (@types) {
	if ($type =~ /(orf|rna|intron|transposon|cen|ltr|ars|snorna|snrna)/i) {
	    $default1 = $type;
	}
	else {
	    push(@default2, $type);
        }
    }
    
    print table(Tr(td("Choose one type:")).
		Tr(td(radio_group(-name=>'featuretype1',
				  -values=>['ORF','Transposon','rRNA','tRNA','Ty ORF','CEN','LTR','RNA','Intron','ARS','snoRNA','snRNA'],
				  -default=>"$default1"))).
		Tr(td("In addition, this feature is a:")).
		Tr(td(checkbox_group(-name=>'featuretype2',
				     -value=>['Questionable','Pseudogene','Mutant','Deleted', 'Merged'],
				     -default=>\@default2))));
}

########################################################################
sub printFeaturePosInfo {
########################################################################
    my ($chrnum, $beg, $end, $strand, $isPmap) = @_;
    my @chrValues;
    my $default = "chr".$chrnum;
    push(@chrValues, "-chr-");
    if ($chrnum == 17) { $default .= "\/Mito"; }
    for (my $i = 1; $i <= 17; $i++) {
	my $label = "chr$i";
	if ($i == 17) { $label .= "\/Mito"; }
	push(@chrValues, $label);
    }
    my @strandValues = ('-strand-', 'watson', 'crick');
    if ($strand =~ /^W/i) { $strand = "watson"; }
    elsif ($strand =~ /^C/i) { $strand = "crick"; }
    else { $strand = ""; }
    if ($isPmap !~ /^Y/i) { $isPmap = ""; }
    ## KD: if there are not values do this
    if ((!$chrnum) && (!$beg) && (!$end)) {
	print table(Tr(td({-align=>'left'},
		      popup_menu(-name=>'chr',
				 -value=>\@chrValues,
			         -default=>$default)).
		   td(font({-size=>'-1'},
			 "start_coord ").
		      textfield('beg', "$beg", '7')).
		   td(font({-size=>'-1'},
			 "stop_coord ").
		      textfield('end', "$end", '7')).
		   td({align=>'left'},
		      popup_menu(-name=>'strand',
				 -value=>\@strandValues,
				 -default=>$strand)).
		   td(font({-size=>'-1'},
		         "comments").
		      textfield('posInfoUpdLog', '', '40'))).
		Tr(td({-colspan=>'3'},
		      font({-size=>'-1'},
			   checkbox(-name=>'isOnPmap',
				    -checked=>$isPmap,
				    -label=>'').
			   " is on the physical map display"))));
    }
    ##KD: else just print values but do not make it editable
    else {
	print table(Tr(td({-align=>'left'}, "$default, ").
		   td(font({-size=>'-1'},
			 "start_coord = ").
		      "$beg, ").
		   td(font({-size=>'-1'},
			 "stop_coord = ").
		      "$end ").
		   td({align=>'left'},
		      popup_menu(-name=>'strand',
				 -value=>\@strandValues,
				 -default=>$strand)).
		   td(font({-size=>'-1'},
		         "comments").
		      textfield('posInfoUpdLog', '', '40'))).
		Tr(td({-colspan=>'3'},
		      font({-size=>'-1'},
			   checkbox(-name=>'isOnPmap',
				    -checked=>$isPmap,
				    -label=>'').
			   " is on the physical map display"))).
                Tr(td({-colspan=>'5'},
			   "To make a change to the coordinates or chromosome, 
                             use the Update Feature Sequence and Coords tool on 
                             Curator Central.")));
    }

}

########################################################################
sub printGeneticPosition {
########################################################################
    my($chrnum, $cm) = @_;

    my $default = "chr".$chrnum;
    if ($chrnum == 17) { $default .= "\/Mito"; }

    my @chrValues;
    push(@chrValues, "-chr-");
    for (my $i = 1; $i <= 17; $i++) {
	my $value = "chr$i";
	if ($i == 17) { $value .= "\/Mito"; }
	push(@chrValues, $value);
    }
    print table(Tr(td({-align=>'left'},
		      popup_menu(-name=>'chr',
			       -value=>\@chrValues,
			       -default=>$default)).
		   td("genetic_position ".
		      textfield('cm', "$cm", '10')).
		   td(" log comments ".
		      textfield('posUpdLog', '', '40'))));
}

########################################################################
sub printFeatureDesc {
########################################################################
    my ($desc) = @_;
    print table(Tr(td({-align=>'left'},
		      textfield('desc', "$desc", '40')).
		   td(font({-size=>'-1'},
			   "log comments").
		      textfield('descUpdLog', '', 40))));
}

########################################################################
sub printPhenoType {
########################################################################
    my($phenotype) = @_;
    print textarea(-name=>'phenotype',
		   -default=>"$phenotype",
		   -rows=>3,
		   -columns=>75);
    if ($phenotype) {
	print br,
	      table(Tr(td({-align=>'left'},
			  font({-size=>'-1'},
			       checkbox(-name=>'phenotypeDelCB',
					-label=>'').
			       "Delete phenotype from the database")).
		       td(font({-size=>'-1'},
			       " delete log comments ").
			  textfield('phenotypeDelLog', '', '50'))));
    }
}


########################################################################
sub printNameDesc {
########################################################################
    my($name_desc) = @_;
    print textarea(-name=>'name_desc',
		   -default=>"$name_desc",
		   -rows=>3,
		   -columns=>75), br,
          " log comments ",
          textfield('name_descUpdLog', '', '40'), br;
}

########################################################################
sub printLocusDesc {
########################################################################
    my($desc) = @_;
    print textarea(-name=>'desc',
		   -default=>"$desc",
		   -rows=>3,
		   -columns=>75), br,
          " log comments ",
          textfield('descUpdLog', '', '40'), br;
}

########################################################################
sub printGeneProduct {
########################################################################
    my($GPs) = @_;
    my @gpList = split(/\t/, $GPs);
    push(@gpList, "");
    my $configUrl = ConfigURLdictyBase->new;
    my $i;
    my $rows;
    foreach my $gp (@gpList) {
	$i++;
	print hidden("gp$i", "$gp");
	my $row;
	if (!$gp) {
	    $row = "Enter gene_product or gene_product_no ";
	}
	else {
	    my $thisGP = $gp;
	    $thisGP =~ s/ /+/g;
	    $row = "gene_product.gene_product ".a({-href=>$configUrl->dictyBaseCGIRoot."dictyBase/curation/dbSearch?queryStr=$thisGP&fill=1&type=gene_product",
						   -target=>"infowin"}, "SEARCH this gp");
	}
	$row .= textfield("NEWgp$i", "$gp", '40');
	$row = td($row);
        if ($gp) {
	    $row .= td(" log comments ".
		       textfield("gpUpdLog$i", '', '40'));
	}
	$rows .= Tr($row);
    }
    print table($rows);
    if ($GPs) {
	my $i;
	my $rows;
	foreach my $gp(@gpList) {
	    $i++;
	    if ($gp) {
		
		$rows .= Tr(td({-align=>'left'},
			       font({-size=>'-1'},
				    checkbox(-name=>"gpDelCB$i",
					-label=>'').
				    "Delete gene product ".font({-color=>'red'}, $gp)." from the database")).
			    td(font({-size=>'-1'},
				    " delete log comments ").
			       textfield("gpDelLog$i", '', '40')));
	    }
	}
	print table($rows);
    }
}

########################################################################
sub printCuratorNote {
########################################################################
        my ($dbh, $note, $isPublic) = @_;
	print textarea(-name=>'note',
		       -default=>"$note",
		       -rows=>3,
		       -columns=>75);
	print br, font({-size=>'-1'}, "If this note should be shared with another item in the DB, enter the table name(s) and primary key(s) (eg. Locus,10 Colleague,15)"), br;
	print textfield('idList', '', 30);
	print br, font({-size=>'-1'}, "Do you want the note to be public? "), br;
	if ($isPublic =~ /y/i) { $isPublic = "Yes"; }
	else { $isPublic = "No"; }

	print table(Tr(td(radio_group(-name=>'isPublic',			                                 -values=>['Yes','No'],
				      -default=>"$isPublic"))));
  
	if ($note) {
	    print br,
	      table(Tr(td({-align=>'left'},
			  font({-size=>'-1'},
			       checkbox(-name=>'noteDelCB',
					-label=>'').
			       "Delete curator note from the database")).
		       td(font({-size=>'-1'},
			       " delete log comments ").
			  textfield('noteDelLog', '', '50'))));
	}
    
}

########################################################################
sub printGeneReservationInfo {
########################################################################
    my ($geneReservationInfo, $collInfo) = @_;
    my @reservationInfo = split(/:/, $geneReservationInfo);
    my @headings = ("Reservation_no", "reservation_date", "expiration_date", 
                    "date_standardized", "is_standardized", "contacts");
    my $headerRow;
    for (my $i = 0; $i <= 5; $i++) {
	    $headerRow .= th({-width=>"15%",
			      -bgcolor=>"#a4abc2",
			      -align=>'left'},
			     font({-size=>'-1'}, $headings[$i]));
    }
    
    my $configUrl = ConfigURLdictyBase->new;
    my $contact;
    if ($collInfo) {
	my @collList = split(/\t/, $collInfo);
	foreach my $coll (@collList) {
	    my ($fullname, $colleagueNo) = split(/::/, $coll);
	    if ($contact) { $contact .= br; }
	    $contact .= a({-href=>$configUrl->dictyBaseCGIRoot."dictyBase/colleague/colleagueSearch?id=$colleagueNo&win=1",
			   -target=>"infowin"}, $fullname)." (coll_no=$colleagueNo)";
	}
    }
    push(@reservationInfo, $contact);
    my $row;
    for (my $i = 0; $i <= 5; $i++) {
	$row .= td({-width=>"15%",
		    -align=>'left'},
		   font({-size=>'-1'},
			$reservationInfo[$i]));
    }
    print table({-border=>'0',
		 -cellpadding=>'0',
		 -cellspacing=>'3',
		 -width=>"100%"},
		Tr($headerRow).
		Tr($row).
		Tr(td({-colspan=>'4'},
		      font({-size=>'-1'},
			   checkbox(-name=>'makeStdNmCB',
				    -checked=>'',
				    -label=>'').
			   "Make this the standard name"))));

    print table(Tr(td({-align=>'left'},
		      font({-size=>'-1'},
			   "Enter new expiration date (required format : 2001-08-15)").
		      textfield(-name=>'expirationDate', '', '10')).
		   td(font({-size=>'-1'}, "update log comments ").
		      textfield(-name=>'expirationUpdLog', '', '40'))));
}

###################################################################
sub printAddContact {
###################################################################
    my ($type) = @_;
    
    print "<table>";
    print "<tr>";
    my $text = "To add new colleague contact, enter colleague_no";
    if ($type) {
	$text = "To add colleague contact, enter colleague_no";
    }
    my $configUrl = ConfigURLdictyBase->new;
    print table(Tr(td({-colspan=>'2'},
		      font({-size=>'-1'},
			   $text).
		      textfield(-name=>'colleagueNo', '', '10').br.
		      font({-size=>'-1'},
			   a({-href=>$configUrl->dictyBaseCGIRoot."dictyBase/colleague/colleagueIdSearch",
			      -target=>"info"}, 
			     "Search for colleague_no by colleague last name")))));
}

########################################################################

########################################################################
1;  ##### Return it to the calling program
########################################################################






























