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

##########################################################
#                                                        #
# dictyBase Extension ofProteinPage                      #
#                                                        #
##########################################################

use ProteinPage_base;

BEGIN { %ProteinPage:: = %ProteinPage_base:: }


#
#   changed link for Retrieve Protein Sequence to explicitly use feature name instead of $Locus
#
#      my $proseqUrl = $configUrl->dictyBaseCGIRoot."$db/getSeq?seq=".$self->featNm."&flankl=0&flankr=0&map=p3map";
#
#
#   this change seems heavy handed: to change one line, have to override this whole
#    method   
#      COULD CHANGE GETSEQ.PM TO BE ABLE TO RESOLVE LOCUS NAME INSTEAD OF THIS CHANGE
#
########################################################################
sub ProteinPage {
########################################################################
# This method prints out a protein page for a given query

    my ($self) = @_;

    $self->getIDs;

    #If the locus have no feature, no protein info
    if (!($self->featNm)) {

        my $message = "Your search for \'".font({-color=>'red'},$self->query)."\' did not return any hits. Wild cards were prepended and appended to your query.";
        $self->{'_query'} = '*'.$self->query.'*';
        $self->{'_append'} = $message;

        $self->wildCardSearch;

        $self->DESTROY;
    }

    my @data = $self->getData;

    #put ',' in long integer
    my $mw = $self->formatNumber($data[0]);
    my $prlen = $self->formatNumber($data[2]);

    my $showNm = $self->locusNm.'/'.$self->featNm;

    if (!$self->locusNm) {

        $showNm = $self->featNm;
    }

    my $title = "$showNm Protein Page";

    my $Locus = $self->locusNm || $self->featNm;

    my $locus_url = $configUrl->dictyBaseCGIRoot ."gene_page.pl?gene_name=$Locus";
    my $locus_info = a({-href=>$locus_url},$Locus." Locus Page");

    my $proseqUrl = $configUrl->dictyBaseCGIRoot."$db/getSeq?dictyBaseid=".$self->dictyBaseid."&sequence_type=Protein";

    my $proseqInfo = a({-href=>$proseqUrl}, "Retrieve Protein Sequence");


#    my $redNm = lc($Locus).'p';

    my $redNm = $Locus;
#    my $first = substr( $redNm, 0, 1);   
#    substr( $redNm, 0, 1) = uc($first);

    #for those ORF without a gene name
    if (!$self->locusNm) {

        $redNm = uc($Locus);    
    }

    #construct  rows for the structure and comparison resources
    my @rightRows = $self->formRightRows($redNm);

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

    my $aaUrl = $configUrl->dictyBaseCGIRoot."$db/protein/aa.pl?locus=".$self->locusNm."&feat=".$self->featNm;
 
    # Here's the javascript code that we include in the document.
    my $javascript =  "
      <SCRIPT language=\"JavaScript\"> 
      <!--
         if (document.layers)
            isNS = true
         else
            isNS = false
         if (document.all)
            isIE = true
         else
            isIE = false
         if (isNS)
            var gBorder = 20; //Minimum image border to avoid scrollbars in NS
         else
            var gBorder = 55; //Minimum image border to avoid scrollbars in IE 
         
         function newwindow() { 
            window.open('$aaUrl','Composition','toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=no,resizable=yes,width=200,height=680,screenX=0,screenY=40,top=40,left=450'); 
         } 

         function switchAddress(list ){	
	    location.href = list.options[list.selectedIndex].value;
         }
      //--> 
      </SCRIPT> "
    ;
   
    print $javascript;

    print center(
        table({-border=>0,-width=>'100%', -cellpadding=>3, -cellspacing=>2, -align=>'center'},

            Tr(
                td({-align=>'right', -colspan=>2},
                    table( {-border=>0, -cellpadding=>2, -cellspacing=>4},
                        Tr(
                            td({-bgcolor=>'#b7d8e4',-align=>'center'},
                                font({-size=>3},$locus_info))
                        )
                    )
                )
            ),

            Tr(
                td({-align=>'center', -colspan=>2},    
                    table( {-border=>0, -width=>'100%', -cellpadding=>2, -cellspacing=>4},
                        Tr(
			    th({-align=>'left'}, 
                                font({-size=>"+1", -color=>'red'}, $redNm ).
			        font({-size=>"+1"}, ' PROTEIN INFORMATION')
                            ),
                            th({-align=>'right'}, 
                                font({-size=>'+1', -color=>'red'}, $redNm ).
			        font({-size=>'+1'},' STRUCTURE AND COMPARISON RESOURCES')
                            )
                          
                        )
                    ) 
                )
            ) #Tr
    ));

    #the table of sequence calculation and pulldown menus.
    print center(
        table({-border=>0,-width=>'95%', -cellpadding=>3, -cellspacing=>2, -align=>'center'},

            Tr(
                td({-align=>'left', -valign=>'top', -rowspan=>'10'},
                
                    table({-border=>2, -width=>325, -cellpadding=>3, -cellspacing=>0},
			Tr({-bgcolor=>"869FB6"},

			    td({-align=>'center', -colspan=>2},
                                b('Protein Sequence Calculations').
                                br.
                                font({-size=>"-1"}, 'from Predicted Full length Translation')                               
                            )
                        ),

			Tr({-align=>'center'}, 
			   th({-bgcolor=>'#d8d8d8'}, 'N-term'),
                           td($data[3])
                        ),

                        Tr({-align=>'center'}, 
			   th({-bgcolor=>'#d8d8d8'}, 'C-term'),
                           td($data[4])
                        ),
     
                        Tr({-align=>'center'}, 
			   th({-bgcolor=>'#d8d8d8'}, 'Length(aa)'),
                           td($prlen)
                        ),

                        Tr({-align=>'center'}, 
			   th({-bgcolor=>'#d8d8d8'}, 'MW(Da)'),
                           td($mw)
                        ),
   
#                        Tr({-align=>'center'}, 
#			   th({-bgcolor=>'#d8d8d8'}, 'pI'),
#                           td($data[1])
#                        ),

                        Tr({-align=>'center'},
                           th({-colspan=>2}, font({-size=>'-1'},a({-href=>"javascript:newwindow()"},'Amino Acid Composition (full length)')))
                        ),

                        Tr({-align=>'center'},
                           th({-colspan=>2}, font({-size=>'-1'},$proseqInfo))
                        ) 
                        
                    ), p, #table contain the seq calculation table

#                    table({-border=>2, -width=>325, -cellpadding=>3, -cellspacing=>0},
#			Tr({-bgcolor=>"869FB6"},
#			    td({-align=>'center', -colspan=>2},
#                                b('Transcript Translation Calculations')
#                            )
#                        ),
#
#                        Tr({-align=>'right'}, 
#			   th({-bgcolor=>'#d8d8d8'}, 'Codon Bias'),
#                           td($data[5]."&nbsp"."&nbsp")
#                        ),
#
#                        Tr({-align=>'right'}, 
#			   th({-bgcolor=>'#d8d8d8'}, 'Codon Adaptation Index'),
#                           td($data[6]."&nbsp"."&nbsp")
#                        ),
#
#                        Tr({-align=>'right'}, 
#			   th({-bgcolor=>'#d8d8d8'}, 'Frequency of Optimal Codons'),
#                           td($data[7]."&nbsp"."&nbsp")
#                        ),
#
#                        Tr({-align=>'right'}, 
#			   th({-bgcolor=>'#d8d8d8'}, 'Hydropathicity of Protein'),
#                           td($data[8]."&nbsp"."&nbsp")
#                        ),
#
#                        Tr({-align=>'right'}, 
#			   th({-bgcolor=>'#d8d8d8'}, 'Aromaticity Score'),
#                           td($data[9]."&nbsp"."&nbsp")
#                        )
#                    ) #table for codon usage
               
                ), #td on the left

	        td({-bgcolor=>'#d8d8d8'},

                    table({-border=>0, -width=>'80%', -align=>'center'},
 
                        [@rightRows]
                    )

                )  #td contain structure and comparison resources

            ) #Tr Info and Structure
        ) 
    );

    &printEndPage;
}



#
#
# dictyBase took out much of the options in the right hand menu
#
#
########################################################################
sub formRightRows {
########################################################################

    my ($self, $redNm) = @_; 

    my @row;

    my $dictyBase = dictyBaseObject->new(database=>$self->database , dictyBaseid=>$self->dictyBaseid);

    #have to initialize first to get URL.
    $dictyBase->_initURLs;

    #structure and motifs
    my $pdb = $dictyBase->pdbInfo;

    my $motif = $dictyBase->motifInfo;

    my @StrVal;

    push (@StrVal, $pdb) if $pdb;
    push (@StrVal, $motif) if $motif;

    my %Str = ($pdb => 'PDB Homolog Structures',
               $motif => 'Motifs');

#    push(@row, Tr(td(
#            start_form.
#                li(b("Structure and Motifs")).$seperator.
#                    popup_menu(-name=>'prot',
#                               -values=>\@StrVal,
#                               -labels=>\%Str).
#                              button(-onClick=>'switchAddress(this.form.prot)',
#                                          -name=>'Go').
#                                              end_form
#
#    ))) if (@StrVal);


    push(@row, Tr(td('
There will be more features in the future
Check for updates!'
    )));


    #Secondary Structure Prediction
    my $secStrbaseURL = $configUrl->dictyBaseCGIRoot."$db/protein/secStructure?Feat=".$self->featNm."&Locus=".$redNm;

    my $heli = $secStrbaseURL."&Type=HW";

    my $pepplot = $secStrbaseURL."&Type=PP";

    my $pepStr = $secStrbaseURL."&Type=PS";

    my @SecVal = ($pepplot, $pepStr, $heli);

    my %Sec = ($heli => 'Helical Wheel',
               $pepplot => 'GCG: PepPlot',
               $pepStr => 'GCG: PepStruct');

#    push(@row, Tr(td(
#            start_form.
#                li(b("Secondary Structure Prediction")).$seperator.
#                    popup_menu(-name=>'sec',
#                               -values=>\@SecVal,
#                               -labels=>\%Sec).
#                              button(-onClick=>'switchAddress(this.form.sec)',
#                                          -name=>'Go').
#                                              end_form
#
#    )));

    #interaction
    my $grid = $dictyBase->grid;
    my $curagen = $dictyBase->curagen;

    my @intval;

    push (@intval, $grid) if $grid;
    push (@intval, $curagen) if $curagen;

    my %int = ($grid => "Interactions DB (GRID)",
               $curagen => "Two Hybrid (Portal PathCalling)");

#    push(@row, Tr(td(
#        start_form.
#            li(b("Interactions")).$seperator.
#                popup_menu(-name=>'inter',
#                           -values=>\@intval,
#                           -labels=>\%int).
#                               button(-onClick=>'switchAddress(this.form.inter)',
#                                      -name=>'Go').
#                                          end_form
#
#
#    )));

    #literature
    my $litGuide = $dictyBase->litGuide;

    my $pubMed = $dictyBase->pubMed;

    my @litval;

    push (@litval, $litGuide) if $litGuide;
    push (@litval, $pubMed) if $pubMed;

    my %lit = ($litGuide => "Literature Guide",
               $pubMed => "PubMed Search");

    push(@row, Tr(td(
        start_form.
            li(b("Literature")).$seperator.
                popup_menu(-name=>'lit',
                           -values=>\@litval,
                           -labels=>\%lit).
                               button(-onClick=>'switchAddress(this.form.lit)',
                                      -name=>'Go').
                                          end_form


    )));

    #Homologs
    my $candidaComp = $dictyBase->candidaComp;
    my $wormComp = $dictyBase->wormComp;
    my $mamComp = $dictyBase->mamComp;

    my @compVal;

    push (@compVal, $candidaComp) if $candidaComp;
    push (@compVal, $wormComp) if $wormComp;
    push (@compVal, $mamComp) if $mamComp;

    my %comparisons = (
                       $candidaComp=>"Candida homologs (CandidaDB)",
                       $mamComp=>"Mammalian Homologs",
                       $wormComp=>"Worm Homologs"
    );

#    push(@row, Tr(td(
#        start_form.
#                li(b("Comparison Resources")).$seperator.
#                    popup_menu(-name=>'comp',
#                               -values=>\@compVal,
#                               -labels=>\%comparisons).
#                              button(-onClick=>'switchAddress(this.form.comp)',
#                                          -name=>'Go').
#                                              end_form
#
#    )));

    return @row;
}




################################################################
1; # to keep the program executable
################################################################
