#!/usr/bin/perl

use IO::Socket;
use CGI qw(param);

@row_name =qw(Aful Mjan Mthe Phor Scer Cele Aaeo Syne Ecol Bsub Mtub
              Hinf Hpyl Mgen Mpne Bbur Tpal Ctra Cpne Rpro pair+number
              untrimmed+RMS trimmed+RMS seq.+identity P-value+(str.) P-value+(seq.)
              pair+number+(Domain+exclusive) untrimmed+RMS+(DE) trimmed+RMS+(DE)
              seq.+identity+(DE) P-value+(str.+DE) P-value+(seq.+DE) %+reference+genome
              level+transcriptome %+reference+transcriptome enrich+reference+transcriptome level+wild+type+(J) %+wild+type+(J)
              enrich+wild+type+(J) level+wild+type+(H) %+wild+type+(H) enrich+wild+type+(H) level+SAGE %+SAGE enrich+SAGE
              level+mating+type+a %+mating+type+a enrich+mating+type+a level+mating+type+alpha %+mating+type+alpha enrich+mating+type+alpha
              level+galactose %+galactose enrich+galactose level+heat+shock %+heat+shock enrich+heat+shock 
              CDC28 CDC15 alpha diauxic+shift sporulation heat+shock+(E.coli) development+(worm)
              size age pseudogene function enz Ala Cys Asp Glu Phe Gly His Ile Lys Leu
              Met Asn Pro Gln Arg Ser Thr Val Trp Tyr Ala100 Cys100 Asp100 Glu100 Phe100 Gly100 His100
              Ile100 Lys100 Leu100 Met100 Asn100 Pro100 Gln100 Arg100 Ser100 Thr100 Val100 Trp100 Tyr100
              pdball_inter pdba_inter pdbb_inter pdbab_inter pdball_intra pdba_intra pdbb_intra pdbab_intra
              pdball_all pdba_all pdbb_all pdbab_all 
              scerall_inter scera_inter scerb_inter scerab_inter scerall_intra scera_intra scerb_intra scerab_intra
              scerall_all scera_all scerb_all scerab_all 
              pdball_inter_ind pdba_inter_ind pdbb_inter_ind pdbab_inter_ind pdball_intra_ind pdba_intra_ind pdbb_intra_ind pdbab_intra_ind
              pdball_all_ind pdba_all_ind pdbb_all_ind pdbab_all_ind
              scerall_inter_ind scera_inter_ind scerb_inter_ind scerab_inter_ind scerall_intra_ind scera_intra_ind scerb_intra_ind scerab_intra_ind
              scerall_all_ind scera_all_ind scerb_all_ind scerab_all_ind
              AmaxRMS ARMSoverall Anhinges Akappa Adeltae Atranse Anresidue
              MmaxRMS MRMSoverall Mnhinges Mkappa Mdeltae Mtranse Mnresidue
              AmaxRMS_g ARMSoverall_g Anhinges_g Akappa_g Adeltae_g Atranse_g Anresidue_g
              MmaxRMS_g MRMSoverall_g Mnhinges_g Mkappa_g Mdeltae_g Mtranse_g Mnresidue_g
              9NaCl HHIG CyhR 67Calc YPD11C 75mMHU 01MMS 2EGTA YPD37C 20Ben 
              MethBl BCIP 10Ben 003SDS 46Hygr 12Calc YPGly CyhS 8Caff mode
);


@func_name = qw(G(aful) G(mjan) G(mthe) G(phor) G(scer) G(cele) G(aaeo) G(syne) G(ecol) G(bsub) G(mtub)
              G(hinf) G(hpyl) G(mgen) G(mpne) G(bbur) G(tpal) G(ctra) G(cpne) G(rpro)
              N(all) U(all) R(all) S(all) P(all) Q(all) 
              N(foldonly) U(foldonly) R(foldonly) S(foldonly) P(foldonly) Q(foldonly)
              C(refg) L(ref) C(ref) E(ref) L(vegsam) C(vegsam) E(vegsam) L(vegyou) C(vegyou) E(vegyou)
              L(sage) C(sage) E(sage) L(matea) C(matea) E(matea) L(gal) C(mateal) E(mateal) L(gal) C(gal) E(gal)
              L(heat) C(heat) E(heat) 
              F(cdc28) F(cdc15) F(alpha) F(diaux) F(spor) F(heatec) F(deve)
              X(size) X(age) X(pseu) X(func) X(enz)
              B(Ala|pdb40) B(Cys|pdb40) B(Asp|pdb40) B(Glu|pdb40) B(Phe|pdb40) 
              B(Gly|pdb40) B(His|pdb40) B(Ile|pdb40) B(Lys|pdb40) B(Leu|pdb40)
              B(Met|pdb40) B(Asn|pdb40) B(Pro|pdb40) B(Gln|pdb40) B(Arg|pdb40) 
              B(Ser|pdb40) B(Thr|pdb40) B(Val|pdb40) B(Trp|pdb40) B(Tyr|pdb40)
              B(Ala|pdb100) B(Cys|pdb100) B(Asp|pdb100) B(Glu|pdb100) B(Phe|pdb100) 
              B(Gly|pdb100) B(His|pdb100) B(Ile|pdb100) B(Lys|pdb100) B(Leu|pdb100)
              B(Met|pdb100) B(Asn|pdb100) B(Pro|pdb100) B(Gln|pdb100) B(Arg|pdb100) 
              B(Ser|pdb100) B(Thr|pdb100) B(Val|pdb100) B(Trp|pdb100) B(Tyr|pdb100)
              I(pdball|inter) I(pdba|inter) I(pdbb|inter) I(pdbab|inter)
              I(pdball|intra) I(pdba|intra) I(pdbb|intra) I(pdbab|intra)
              I(pdball|all) I(pdba|all) I(pdbb|all) I(pdbab|all)
              I(scerall|inter) I(scera|inter) I(scerb|inter) I(scerab|inter)
              I(scerall|intra) I(scera|intra) I(scerb|intra) I(scerab|intra)
              I(scerall|all) I(scera|all) I(scerb|all) I(scerab|all)
              J(pdball|inter) J(pdba|inter) J(pdbb|inter) J(pdbab|inter)
              J(pdball|intra) J(pdba|intra) J(pdbb|intra) J(pdbab|intra)
              J(pdball|all) J(pdba|all) J(pdbb|all) J(pdbab|all)
              J(scerall|inter) J(scera|inter) J(scerb|inter) J(scerab|inter)
              J(scerall|intra) J(scera|intra) J(scerb|intra) J(scerab|intra)
              J(scerall|all) J(scera|all) J(scerb|all) J(scerab|all)
              A(maxcadev|auto) A(rmsoverall|auto) A(nhinges|auto) A(kappa|auto) 
              A(deltae|auto) A(transe|auto) A(nresidue|auto)
              M(maxcadev|auto) M(rmsoverall|auto) M(nhinges|auto) M(kappa|auto) 
              M(deltae|auto) M(transe|auto) M(nresidue|auto)
              A(maxcadev|gold) A(rmsoverall|gold) A(nhinges|gold) A(kappa|gold)
              A(deltae|gold) A(transe|gold) A(nresidue|gold)
              M(maxcadev|gold) M(rmsoverall|gold) M(nhinges|gold) M(kappa|gold)
              M(deltae|gold) M(transe|gold) M(nresidue|gold)
              T(9NaCl) T(HHIG) T(CyhR) T(67Calc) T(YPD11C) T(75mMHU) T(01MMS) T(2EGTA) T(YPD37C) T(20Ben) 
              T(MethBl) T(BCIP) T(10Ben) T(003SDS) T(46Hygr) T(12Calc) T(YPGly) T(CyhS) T(8Caff)
              O(mode)
);



@colors = qw(fde3e3 fde5e3 fde8e3 fdebe3 fdeee3 fdf4e3 fdf7e3 fdfce3 
             fafde3 f7fde3 fdfde3 effde3 ecfde3 e7fde3 e3fde3 e3fde6 
             e3fdea e3fdf1 e3fdf5 e3fdfa);

@imgs = qw(50 70 100 120);

open(LOGFILE,">>./compare.log") || die "cannot open log file!\n";
$date = `date` ;
$date =~ s/\n//g ;
$ENV{'REMOTE_HOST'} = gethostbyaddr(inet_aton($ENV{'REMOTE_ADDR'}), AF_INET) or $ENV{'REMOTE_ADDR'};
print LOGFILE "$date \| $ENV{'REMOTE_HOST'} \| $ENV{'REMOTE_ADDR'} \| $ENV{'HTTP_USER_AGENT'}\n";
close(LOGFILE);


print_HTMLhead();
$total_rows = 205;

for($i=0; $i<$total_rows; $i++){
  $namet = $row_name[$i];
  $namet =~ tr/+/ /;
  $tt = param("$namet");
  if(length($tt) != 0){
     $rowstring = $rowstring . $i . ",";
     }
  }

$tt = param("selectedrows");
if(length($tt) >0){
   $rowstring = $tt;
   }

$rankby = param("rankby");
if(length($rankby) == 0 ){
   $rankby = 0;
   }

$updown = param("updown");
if(length($updown) == 0 ){
   $updown = "down";
   }

$range = param("range");
if(length($range) == 0 ){
   $range = "30";
   }

$imgsize = param("imgsize");
if(length($imgsize) == 0){
   $imgsize = 70;
   }

$fold_sfam = param("fold_sfam");
if(length($fold_sfam) == 0){
   $fold_sfam = "Fold";
   }

$value_rank = param("value_rank");
if(length($value_rank) == 0){
   $value_rank = "Value";
   }


$tc= substr($rowstring, -1, 1);
if($tc eq ","){ chop($rowstring);}

chomp($rowstring);
(@num) = split(/,/,$rowstring);
$num_row = @num;

if($num_row == 0){
  print "<h2>Please select at least one quantity to rank</h2>";
  print "<a href=\"./index.html\">back</a>";
  print "</body></html>";
  exit ;
}


for($i=0; $i<$num_row; $i++){
  $max[$i] = -9999;
  $min[$i] = 9999;
  $ave[$i] = 0;
  $hit[$i] = 0;
  $nonzero[$i] = 0;
  }

if($fold_sfam eq "Fold"){
  if($value_rank eq "Value"){
     open(RAW_DATA, "table_fold.txt");
     }
   else{
     open(RAW_DATA, "table_fold_rank.txt");
     }

  }else{
    if($value_rank eq "Value"){
     open(RAW_DATA, "table_sfam.txt");
     }
    else{
     open(RAW_DATA, "table_sfam_rank.txt");
     }
    }

$k = 0;
while($buffer = <RAW_DATA>){
   chomp($buffer);
   ($scopid, @occu)=split(/,/, $buffer);
   $bigstring = $scopid;
   for($i=0; $i<$num_row; $i++){
     if($occu[$num[$i]] ne "." &&
        $occu[$num[$i]] ne "-" &&
        $occu[$num[$i]] != 0 ){ 

        if($occu[$num[$i]] >$max[$i]){
          $max[$i] = $occu[$num[$i]];
          }
        if($occu[$num[$i]] <$min[$i]){
          $min[$i] = $occu[$num[$i]];
          }
        if($occu[$num[$i]] > 0){
          $nonzero[$i]++;
          }
        $hit[$i]++;
        $ave[$i]+=$occu[$num[$i]];
        }
     $bigstring = join(",", $bigstring, $occu[$num[$i]]);
     }
   $rowo{$scopid} = $bigstring;
   $rankrow{$scopid} = $occu[$num[$rankby]];
   $k++;
   } 

close(RAW_DATA);


for($i=0; $i<$num_row; $i++){
      $ave[$i] = $ave[$i]/$hit[$i];
      $step[$i] = ($max[$i] - $min[$i])/20.;
      }


print "<FONT FACE=\"sans-serif,helvetica,arial\"><h1><a href=./index.html class=no_underline>Comparer</a> for protein structure rankings</h1></FONT>";

print "<font size=-1><a href=\"/papers/partslist-nar\">Qian, J. et.al (2001) Nucleic Acids Research 29: 1750-64</a></font><br><br>";

print <<tableheader;
<TABLE CELLSPACING="1" BORDER="0" >
<tr bgcolor=#eeeeee>
<td COLSPAN=2 align="center">
tableheader

if($range eq "all"){
print "<a href=\"./compare.cgi?value_rank=$value_rank&fold_sfam=$fold_sfam&selectedrows=$rowstring&range=30&rankby=$rankby&updown=$updown&imgsize=$imgsize\" CLASS=\"no_underline\">[First 30 records]</a>[Entire table]<br>";
}
else{
print "[First 30 records]<a href=\"./compare.cgi?value_rank=$value_rank&fold_sfam=$fold_sfam&selectedrows=$rowstring&range=all&rankby=$rankby&updown=$updown&imgsize=$imgsize\" CLASS=\"no_underline\">[Entire table]</a><br>";
}

if($value_rank eq "Value"){
#  if($updown eq "down"){
#    $tmpupdown = "up";
#    }
#  else{
#    $tmpupdown = "down";
#    }
  print "[Display values]<a href=\"./compare.cgi?value_rank=Rank&fold_sfam=$fold_sfam&selectedrows=$rowstring&range=$range&rankby=$rankby&updown=$updown&imgsize=$imgsize\" CLASS=\"no_underline\">[Display ranks]</a><br>";
  }
else{
  print "<a href=\"./compare.cgi?value_rank=Value&fold_sfam=$fold_sfam&selectedrows=$rowstring&range=$range&rankby=$rankby&updown=$updown&imgsize=$imgsize\" CLASS=\"no_underline\">[Display values]</a>[Display ranks]<br>";
  }


print "<b>Image size: </b>";
for($i = 0; $i<4; $i++){
  $is = $imgs[$i];
  if($imgsize == $is){
    print "[$is]";
    }
  else{
    print "<a href=\"./compare.cgi?value_rank=$value_rank&fold_sfam=$fold_sfam&selectedrows=$rowstring&range=$range&rankby=$rankby&updown=$updown&imgsize=$is\" CLASS=\"no_underline\">[$is]</a>";
    }
  }

for($j=0; $j<$num_row; $j++){
    $name = longer_name($num[$j]);
    $main_f = substr($func_name[$num[$j]], 0, 1);
    $ll = length($func_name[$num[$j]]);
    $ll = $ll - 3;
    $para_f = substr($func_name[$num[$j]], 2, $ll);
    (@ps) = split(/\|/, $para_f);
    $pn = @ps;
    if($j == $rankby){
      if($pn == 1){
       print "<td border width=80 align=\"center\"><b><FONT FACE=\"sans-serif,helvetica,arial\" size=-1><a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet001.html#$main_f\" target=main_w>$main_f</a>(<a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet002.html#$para_f\" target=para_w>$para_f</a>)<br>$name</font></b></td>";
       }
       else{
        print "<td border width=80 align=\"center\"><b><FONT FACE=\"sans-serif,helvetica,arial\" size=-1><a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet001.html#$main_f\" target=main_w>$main_f</a>(<a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet002.html#$ps[0]\" target=para_w>$ps[0]</a>, <a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet002.html#$ps[1]\" target=para_w>$ps[1]</a>)<br>$name</font></b></td>";

        }
       }else{
        if($pn == 1){
         print "<td border width=80 align=\"center\"><FONT FACE=\"sans-serif,helvetica,arial\" size=-1><a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet001.html#$main_f\" target=main_w>$main_f</a>(<a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet002.html#$para_f\" target=para_w>$para_f</a>)<br>$name</font></td>";

          }
         else{
          print "<td border width=80 align=\"center\"><FONT FACE=\"sans-serif,helvetica,arial\" size=-1><a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet001.html#$main_f\" target=main_w>$main_f</a>(<a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet002.html#$ps[0]\" target=para_w>$ps[0]</a>,<a href=\"http://bioinfo.mbb.yale.edu/align/help/sheet002.html#$ps[1]\" target=para_w>$ps[1]</a>)<br>$name</font></td>";
        }
        }
    }
print "</tr>";

print "<tr><td COLSPAN=2 align=\"center\">Max in column";
for($j=0; $j<$num_row; $j++){
    if($j == $rankby){
      print "<td align=\"center\"><b>$max[$j]</b></td>";
      }
    else{
      print "<td align=\"center\">$max[$j]</td>";
      }
    }
print "</tr>";
print "<tr bgcolor=#edf6f3><td COLSPAN=2 align=\"center\">Min in column";
for($j=0; $j<$num_row; $j++){
    if($j == $rankby){
      print "<td align=\"center\"><b>$min[$j]</b></td>";
      }
    else{
      print "<td align=\"center\">$min[$j]</td>";
      }
    }
print "</tr>";
print "<tr><td COLSPAN=2 align=\"center\">Average";
for($j=0; $j<$num_row; $j++){
    if($j == $rankby){
      printf "<td align=\"center\"><b>%4.1f</b></td>", $ave[$j];
      }
    else{
      printf "<td align=\"center\">%4.1f</td>", $ave[$j];
      }
    }
print "<tr bgcolor=#edf6f3><td COLSPAN=2 align=\"center\">Non zero hits";
for($j=0; $j<$num_row; $j++){
    if($j == $rankby){
      print "<td align=\"center\"><b>$nonzero[$j]</b></td>";
      }
    else{
      print "<td align=\"center\">$nonzero[$j]</td>";
      }
    }
print "</tr>";

if($fold_sfam eq "Fold"){
     print "<tr bgcolor=#eeeeee><td COLSPAN=2 ROWSPAN=2 align=\"center\"><b>Ranked folds <font size=-1>(click on arrows to re-rank)</font></b></td>";
    }
else{
    print "<tr bgcolor=#eeeeee><td COLSPAN=2 ROWSPAN=2 align=\"center\"><b>Ranked superfamilies <font size=-1>(click on arrows to re-rank)</font></b></td>";
    }

for($j=0; $j<$num_row; $j++){

  if($updown eq "up" &&
     $rankby == $j){
     print "<td align=center><IMG BORDER=\"0\" SRC=\"./uparrow2.gif\"></td>";
     }
   else{
     print "<TD align=center><A HREF=\"compare.cgi?value_rank=$value_rank&fold_sfam=$fold_sfam&selectedrows=$rowstring&updown=up&rankby=$j&range=$range&imgsize=$imgsize\">";
     print "<IMG BORDER=\"0\" SRC=\"./uparrow.gif\"></A></td>";
     }

 }
 print "</form></tr>";

print "<tr bgcolor=#eeeeee>";
for($j=0; $j<$num_row; $j++){

    if($updown eq "down" &&
       $rankby == $j){
       print "<td align=center><IMG BORDER=\"0\" SRC=\"./downarrow2.gif\"></td>";
       }
     else{
       print "<TD align=center><A HREF=\"compare.cgi?value_rank=$value_rank&fold_sfam=$fold_sfam&selectedrows=$rowstring&updown=down&rankby=$j&range=$range&imgsize=$imgsize\">";
       print "<IMG BORDER=\"0\" SRC=\"./downarrow.gif\"></A></td>";
       }
    }
 print "</tr>";

if($fold_sfam eq "Fold"){
  dbmopen(%folddescription, "./folddesc", undef);
  }else{
    dbmopen(%folddescription, "./sfamdesc", undef);
    }

$i = 0;

if($range eq "30"){
   $endline = 30;
   }
else{
   $endline = 800;
   }

if(($updown eq "down" && $value_rank eq "Value")||
   ($updown eq "up" && $value_rank eq "Rank")){
 foreach $scopid (reverse (sort {$rankrow{$a} <=> $rankrow{$b};} keys %rankrow)){

     if($rankrow{$scopid} ne "." &&
     $rankrow{$scopid} ne "-" &&
     $rankrow{$scopid} != 0){


    ($scopid, @occu)=split(/,/, $rowo{$scopid});

  $fold_des = $folddescription{$scopid};
  ($scopnum, $class, $des)=split(/\|/, $fold_des);
  if($fold_sfam eq "Fold"){
     ($d1, $d2, $d3) = split(/\./, $scopnum);
     }
  else{
     ($d1, $d2, $d3, $d4) = split(/\./, $scopnum);
     }
  $d2 = digit1($d2);
  $d3 = digit1($d3);
  $scopnum = $d2 . "." . $d3;
  if($fold_sfam eq "Superfamily"){
     $d4 = digit1($d4);
     $scopnum = $d2 . "." . $d3 . "." . $d4;
     } 

  chomp($des);
  $tt = $i - int($i/2)*2;
  if($tt == 0){
     print "<tr bgcolor=#edf6f3>";
     }
   else{
     print "<tr>";
     }
  print "<td border width=100>$des<br><a href=\"http://bioinfo.mbb.yale.edu/foldreport.cgi?id=$scopid\" CLASS=\"no_underline\">$scopid</a>:<font size=-2>$scopnum (1.39)</a>   $class</font></td>";
  $pdbid = substr($scopid, 1, 4);
  $imgname=$pdbid . "x" . $imgsize . "c.jpg";
  print "<td align=\"center\"><img src=./pictures/$imgname></td>";
  for($j=0; $j<$num_row; $j++){
     if($occu[$j] eq "." ||
        $occu[$j] eq "-"){
        $cn = 0;
        }else{
           $cn = int ($occu[$j] - $min[$j])/$step[$j] ;
           if($cn ==20){ $cn--;}
           }
     if($j == $rankby){
       print "<td bgcolor=\"#$colors[19-$cn]\" align=\"center\"><b><font size=+2>$occu[$j]</font></b></td>";
       }else{
        print "<td bgcolor=\"#$colors[19-$cn]\" align=\"center\"><font size=+2>$occu[$j]</font></td>";
        }
     }
  print "</tr>";
  $i++;
  if($i == $endline) {last ;}
  }
   }
}
else{
  foreach $scopid (sort {$rankrow{$a} <=> $rankrow{$b};} keys %rankrow){

  if($rankrow{$scopid} ne "." &&
     $rankrow{$scopid} ne "-" &&
     $rankrow{$scopid} != 0){

  ($scopid, @occu)=split(/,/, $rowo{$scopid});

  $fold_des = $folddescription{$scopid};
  ($scopnum, $class, $des)=split(/\|/, $fold_des);

  if($fold_sfam eq "Fold"){
     ($d1, $d2, $d3) = split(/\./, $scopnum);
     }
  else{
     ($d1, $d2, $d3, $d4) = split(/\./, $scopnum);
     }
  $d2 = digit1($d2);
  $d3 = digit1($d3);
  $scopnum = $d2 . "." . $d3;
  if($fold_sfam eq "Superfamily"){
     $d4 = digit1($d4);
     $scopnum = $d2 . "." . $d3 . "." . $d4;
     }

  chomp($des);
  $tt = $i - int($i/2)*2;
  if($tt == 0){
     print "<tr bgcolor=#edf6f3>";
     }
   else{
     print "<tr>";
     }
  print "<td border width=100>$des<br><a href=\"http://bioinfo.mbb.yale.edu/foldreport.cgi?id=$scopid\" CLASS=\"no_underline\">$scopid</a>:<font size=-2>$scopnum (1.39)</a>   $class</font></td>";

  $pdbid = substr($scopid, 1, 4);
  $imgname=$pdbid . "x" . $imgsize . "c.jpg";
  print "<td align=\"center\"><img src=./pictures/$imgname></td>";
  for($j=0; $j<$num_row; $j++){
     if($occu[$j] eq "." ||
        $occu[$j] eq "-"){
        $cn = 0;
        }else{
           $cn = int ($occu[$j] - $min[$j])/$step[$j] ;
           if($cn ==20){ $cn--;}
           }
     if($j == $rankby){
       print "<td bgcolor=\"#$colors[19-$cn]\" align=\"center\"><b><font size=+2>$occu[$j]</font></b></td>";
       }else{
        print "<td bgcolor=\"#$colors[19-$cn]\" align=\"center\"><font size=+2>$occu[$j]</font></td>";
        }
     }
  print "</tr>";
  $i++;
  if($i == $endline) {last ;}
  }

   }
}


print "</table>";

dbmclose(%folds);

print <<end;
<br><br><font size=-1>The images of protein structures were taken from <a href="http://www.rcsb.org">www.rcsb.org</a></font><br>

<font size=-1>The classification of folds is from <a href="http://scop.mrc-lmb.cam.ac.uk/scop">SCOP </a>version 1.39</font><br><br>

<font size=-1>Questions, comments, and suggestions <a href="mailto:qian\@csb.yale.edu">qian\@csb.yale.edu</a></font><br><br>

</body></html>
end



sub print_HTMLhead()
{
print <<EndOfHTML0;
Content-type:text/html


<HTML>
<HEAD>
<TITLE> Rankings2 </title>
<STYLE TYPE="text/css"><!--
.sanserif {font-family:sans-serif,helvetica,arial}
.no_link {font-size:8pt;color:black;text-decoration:none;}
.no_underline {text-decoration:none}
--></STYLE>

</HEAD>
EndOfHTML0

my $hvar = `perl /web/align/header/header.cgi tree`; print "$hvar";


print "<blockquote>";

}

sub longer_name {
    my ($row) = @_;
    $name = $row_name[$row];
    $name =~ tr /+/ /;
    if($name eq "size"){
      $name = "average length of fold";
      }
    if($name eq "age"){
      $name = "year of fold determined";
      }
    if($name eq "pseudogene"){
      $name = "pseudogene complement of the ribbon worm";
      }
    if($name eq "function"){
      $name = "total number of functions associated with the fold";
      }
    if($name eq "enz"){
      $name = "number of enzymatic functions associated with the fold";
      }

    $name =~ s/\%/fold percentage in/;
    $name =~ s/enrich/fold enrichment in/;
    $name =~ s/level/expression level in/;

    if($name =~ /maxRMS/){
       $b = substr($name, 0, 1);
       if($b eq "M"){
          $name = "maximal Ca atom displacement between structures[Max.]";
          }
       else{
          $name = "maximal Ca atom displacement between structures[Ave.]";
          }
       }
    if($name =~ /nhinges/){
       $b = substr($name, 0, 1);
       if($b eq "M"){
          $name = "number of putative hinges found in fold [Max.]";
          }
       else{
          $name = "number of putative hinges found in fold [Ave.]";
          }
       }
    if($name =~ /RMSoverall/){
       $b = substr($name, 0, 1);
       if($b eq "M"){
           $name = "overall RMS between structures [Max.]";
          }
       else{
          $name = "overall RMS between structures [Ave.]";
          }
       }
    if($name =~ /deltae/){
       $b = substr($name, 0, 1);
       if($b eq "M"){
          $name = "energy difference between start and end states [Max.]";
          }
       else{
          $name = "energy difference between start and end states [Ave.]";
          }
       }
    if($name =~ /kappa/){
       $b = substr($name, 0, 1);
       if($b eq "M"){
          $name = "degree of rotation angle about hinge [Max.]";
          }
       else{
          $name = "degree of rotation angle about hinge [Ave.]";
          }
       }
    if($name =~ /transe/){
       $b = substr($name, 0, 1);
       if($b eq "M"){
          $name = "maximum energy difference [Max.]";
          }
       else{
          $name = "maximum energy difference [Ave.]";
          }
       }
    if($name =~ /nresidue/){
       $b = substr($name, 0, 1);
       if($b eq "M"){
          $name = "number of residues [Max.]";
          }
       else{
          $name = "number of residues [Ave.]";
          }
       }

    if($name =~ /all_inter/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction on different chains [pdb]";
          }
       else{
          $name = "interaction on different chains [yeast]";
          }
       }

    if($name =~ /a_inter/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction with alpha proteins on different chains [pdb]";
          }
       else{
          $name = "interaction with alpha proteins on different chains [yeast]";
          }
       }

    if($name =~ /ab_inter/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction with alpha-beta proteins on different chains [pdb]";
          }
       else{
          $name = "interaction with alpha-beta proteins on different chains [yeast]";
          }
       }
    elsif($name =~ /b_inter/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction with beta proteins on different chains [pdb]";
          }
       else{
          $name = "interaction with beta proteins on different chains [yeast]";
          }
       }

    if($name =~ /all_intra/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction on same chains [pdb]";
          }
       else{
          $name = "interaction on same chains [yeast]";
          }
       }

    if($name =~ /a_intra/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction with alpha proteins on same chains [pdb]";
          }
       else{
          $name = "interaction with alpha proteins on same chains [yeast]";
          }
       }

    if($name =~ /ab_intra/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction with alpha-beta proteins on same chains [pdb]";
          }
       else{
          $name = "interaction with alpha-beta proteins on same chains [yeast]";
          }
       }
    elsif($name =~ /b_intra/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction with beta proteins on same chains [pdb]";
          }
       else{
          $name = "interaction with beta proteins on same chains [yeast]";
           }   
       }

    if($name =~ /all_all/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction types [pdb]";
          }
       else{
          $name = "interaction types [yeast]";
          }
       }

    if($name =~ /a_all/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction with alpha proteins [pdb]";
          }
       else{
          $name = "interaction with alpha proteins [yeast]";
          }
       }

    if($name =~ /ab_all/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction with alpha-beta proteins [pdb]";
          }
       else{
          $name = "interaction with alpha-beta proteins [yeast]";
          }
       }
    elsif($name =~ /b_all/){
       $b = substr($name, 0, 3);
       if($b eq "pdb"){
          $name = "interaction with beta proteins [pdb]";
          }
       else{
          $name = "interaction with beta proteins [yeast]";
          }
       }


    if($name eq "Aful" || $name eq "Mjan" || $name eq "Mthe" ||$name eq "Phor" || $name eq "Scer" ||
       $name eq "Cele" || $name eq "Aaeo" || $name eq "Syne" ||$name eq "Ecol" || $name eq "Bsub" ||
       $name eq "Mtub" || $name eq "Hinf" || $name eq "Hpyl" ||$name eq "Mgen" || $name eq "Mpne" ||
       $name eq "Bbur" || $name eq "Tpal" || $name eq "Ctra" ||$name eq "Cpne" || $name eq "Rpro"){
       $name = "fold occurrence in " . $name;
       }
    if($name eq "CDC28" || $name eq "CDC15" || $name eq "alpha" ||
       $name eq "diauxic shift" || $name eq "sporulation" ||
       $name eq "heat shock (E.coli)" || $name eq "development (worm)"){
       $name = "fluctuation of expression levels in " . $name;
       }
    if($name eq "Ala" || $name eq "Cys" || $name eq "Asp" || $name eq "Glu" || $name eq "Phe" ||
       $name eq "Gly" || $name eq "His" || $name eq "Ile" || $name eq "Lys" || $name eq "Leu" ||
       $name eq "Met" || $name eq "Asn" || $name eq "Pro" || $name eq "Gln" || $name eq "Arg" ||
       $name eq "Ser" || $name eq "Thr" || $name eq "Val" || $name eq "Trp" || $name eq "Tyr"){
       $name = "composition percentage of " . $name . " for pdb40d";
       }
    if($name eq "Ala100" || $name eq "Cys100" || $name eq "Asp100" || $name eq "Glu100" || $name eq "Phe100" ||
       $name eq "Gly100" || $name eq "His100" || $name eq "Ile100" || $name eq "Lys100" || $name eq "Leu100" ||
       $name eq "Met100" || $name eq "Asn100" || $name eq "Pro100" || $name eq "Gln100" || $name eq "Arg100" ||
       $name eq "Ser100" || $name eq "Thr100" || $name eq "Val100" || $name eq "Trp100" || $name eq "Tyr100"){
       $name = substr($name, 0, 3);
       $name = "composition percentage of " . $name . " for pdb100d";
       }
    if($name eq "9NaCl" || $name eq "HHIG" || $name eq "CyhR" || $name eq "67Calc" ||
       $name eq "YPD11C" || $name eq  "75mMHU" || $name eq "01MMS" || $name eq "2EGTA" ||
       $name eq "YPD37C" || $name eq "20Ben" || $name eq "MethBl" || $name eq "BCIP" ||
       $name eq "10Ben" || $name eq "003SDS" || $name eq "46Hygr" || $name eq "12Calc" ||
       $name eq  "YPGly" || $name eq "CyhS" || $name eq "8Caff"){
       $name = "sensitivity of transposon at condition " . $name;
       }

    if($name eq "old-gen"){
       $name = "original yeast genome counts from NAR paper";
       }
    if($name eq "old-trans"){
       $name = "original yeast transcriptome counts from NAR paper";
       }

    if($name eq "mode"){
       $name = "mode concentration";
       }



    return $name;
}


sub digit1
{
  my($d1, $l, $d2, $d3);
  $d1 = $_[0];
  $l = substr($d1, 0, 1);
  if($l eq "0"){
    $d2 = substr($d1, 1);
    }
   else{ return $d1; }

  $l = substr($d2, 0, 1);
  if($l eq "0"){
    $d3 = substr($d2, 1);
    return $d3;
    }
  else{
    return $d2;
    }

} 
