// Анализ белковых последовательностей


function helpmol()
{
	var hlp;
	hlp="/scripts/h01_18.html";
	window.open(hlp,'help', config='height=500,width=800,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,status=yes');
	self.name="main window"
}


function newImage(arg) {
   if (document.images) {
      rslt = new Image();
      rslt.src = arg;
      return rslt;
   }
}

function changeImage(pic, overpic) {
    if (document.images && (preloadFlag == true)) {
       document[pic].src = overpic;
    }
}

var preloadFlag = false;
function preloadImages() {
    frame = new Array();
    a = preloadImages.arguments;

    if (document.images) {
      for (i=0; i<a.length; i++) {
        if (a[i].indexOf("#")!=0) { frame[i] = newImage(a[i]); }
      }
      preloadFlag = true;
    }
}

count=new Array();
atoms=new Array("3511", "3511", "2311", "5911", "6111", "6111", "5911", "3512", "4712", "9911", "9912", "1121", "4513", "5713", "4622", "5822", "6731", "6121", "6141", "5711");
at=new Array();
at[0]=new Array();
at[1]=new Array();
at[2]=new Array();
at[3]=new Array();
at[4]=new Array();

for(j=0;j<5;j++)for(i=0;i<20;i++)at[j][i]=parseInt(atoms[i].charAt(j));
for(i=0;i<21;i++)at[4][i]=0;
at[4][1]=1;
at[4][6]=1;
at[1][4]=11;
at[1][5]=11;
at[1][11]=10;
at[1][17]=12;
at[1][18]=12;
at[0][11]=11;
prot="";
str="ACGVLIMSTFYWDENQHKRP";
function check(){
prot=document.input.link.value.toUpperCase();
l=prot.length;
prot2="";
for(i=0;i<l;i++)if(!(prot.charAt(i)==" "))prot2=prot2+prot.charAt(i);
prot=prot2;
l=prot.length;
document.input.leng.value=l;
if(l==0){result=-1}
else{
     result = -2; 
     for (i = 0; i < l; i++)
       {
          chr = prot.charAt(i);
          if (str.indexOf(chr,0)==-1)result = i;
      }     }         
return(result);}

function getnum(simb)
{return(str.indexOf(simb, 0));}
                                                            
function qpr(ph)
{
h=0;
 for(k=0; k<l;k++){
                          j=getnum(prot.charAt(k));
                     if (!(three[j]==-1))
                           {
                          ex=Math.exp(2.303*(ph-three[j]));
                          if(four[j]==0)h-=(ex/(ex+1));
                                        
                           else h+=(1/(1+ex));                        
                                                     
                           }
                   }                     
                       
   j=getnum(prot.charAt(0));
   ex=Math.exp(2.303*(ph-one[j]));
   h+=(1/(1+ex));                        
   j=getnum(prot.charAt(l-1));
   ex=Math.exp(2.303*(ph-two[j]));
   h-=(ex/(ex+1));
   return h; 
}



function openWin2(so, sost, sostpro, ipc, ph1, ma, mas, qmol, qqq, cis, nis, dis) {
myWin= open("", "displayWindow", 
    "width=400,height=300,status=no, toolbar=no, menubar=no, scrollbars=yes");
myWin.document.open();
myWin.document.write("<html><head><title>"+alt18_01+"</title></head><STYLE type='text/css'> .t1{color:#000000; font-size:16px;}");
myWin.document.write(".t2{color:#990000; font-size:22px; font-weight:bold; } .t3{color:#000000; font-size:14px; }</STYLE><body bgcolor='#E8EBD3'>");
myWin.document.write("<font class='t1'>"+alt18_02+" </font><font class='t2'>"+l+"</font><font class='t1'> "+alt18_03+"</font><br>");
myWin.document.write("<font class='t1'>"+alt18_04+"</font><font class='t2'>C<sub>"+count[0]+"</sub>H<sub>"+count[1]+"</sub>N<sub>"+count[2]+"</sub>O<sub>"+count[3]+"</sub>");
if(!(count[4]==0))myWin.document.write("S<sub>"+count[4]+"</sub>");
myWin.document.write("</font><br><br>");

if(ma){
      myWin.document.write("<font class='t1'> "+alt18_05+"</font>");
         myWin.document.write("<font class='t2'>"+mas+"</font><font class='t1'> Da</font>");
      if(cis||nis||dis){myWin.document.write("<br><font class='t3'> ( "+alt18_06);
                       if(cis)myWin.document.write(" <sup>13</sup>C ");
                       if(nis)myWin.document.write("<sup>15</sup>N ");
                       if(dis)myWin.document.write("D");
                       myWin.document.write(")<br></font>");                        
                       }
                    else {myWin.document.write("<br><font class='t3'> ("+alt18_07+")</font><br>");}
      myWin.document.write("<br>"); 
        }
if (ipc){
         myWin.document.write("<font class='t1'>"+alt18_08+"<b>pI = </b></font>");
         myWin.document.write("<font class='t2'>"+ph1+"</font><br>");
        }
if (qmol){
         myWin.document.write("<font class='t1'>"+alt18_09+document.input.ph.value+alt18_15+" </font>");
         myWin.document.write("<font class='t2'>"+qqq+"</font>");
        }


if(so){
         myWin.document.write("<br><br><font class='t1'>"+alt18_10+":</font><br>");
         myWin.document.write("<table width='100%' border=1 ><tr><td width='40%'><center><font class='t1'>"+alt18_11+"</font></center></td><td width='30%'><center><font class='t1'>"+alt18_12+"</font></center></td><td width='30%'><font class='t1'><center>%</center></font></td></tr>");
         for(i=0;i<20;i++)myWin.document.write("<tr><td><font class='t3'><center>"+str.charAt(i)+"</center></font></td><td><font class='t3'><center>"+sost[i]+"</center></font></td><td><font class='t3'><center>"+sostpro[i]+"</center></font></td></tr>");
         myWin.document.write("</table>");
      }

myWin.document.write("<BR><BR></BODY></html>");
myWin.document.close();
}  




function ok(){

res = check();

if (res==-2) calc(prot); else {
        if (res==-1) alert(alt18_13);
        else alert(alt18_14+(res+1));
       }

}

function calc(input){

one=new Array(9.6, 8.33, 9.6, 9.72, 9.6, 9.76, 9.21, 9.15, 10.43, 9.24, 9.11, 9.39, 9.82, 9.67, 8.8, 9.13, 9.17, 8.95, 9.04, 10.6);
two=new Array(2.43, 1.71, 2.34, 2.29, 2.36, 2.32, 2.28, 2.21, 2.63, 2.58, 2.2, 1.22, 2.09, 2.19, 2.02, 2.17, 1.82, 2.18, 2.17, 2);
three=new Array()
for(i=0;i<20;i++)three[i]=-1;
three[1]=10.3;
three[10]=10.1;
three[12]=3.86;
three[13]=4.25;
three[16]=6.0;
three[17]=10.5;
three[18]=12.48;

four=new Array()
for(i=1;i<21;i++)four[i]=-1;
four[1]=0;
four[10]=0;
four[12]=0;
four[13]=0;
four[16]=1;
four[17]=1;
four[18]=1;

mass=new Array(89.1, 121.2, 75.1, 117.1, 131.2, 131.2, 149.2, 105.1, 119.1, 165.2, 181.2, 204.2, 133.1, 147.1, 132.1, 146.1, 155.2, 164.2, 174.2, 115.1);


myWin= open("", "displayWindow", 
    "width=400,height=300,status=no, toolbar=no, menubar=no, scrollbars=yes");
  
so=document.input.sostav.checked;
sost=new Array()
for(i=0;i<20;i++)sost[i]=0;
sostpro=new Array()
for(i=0;i<20;i++)sostpro[i]=0;
if(so){
         //считаем состав  
         for(k=0; k<l;k++){
                          j=getnum(input.charAt(k));
                          sost[j]++;
                          //alert(" j="+j+" k="+k);
                          }
         for(i=0;i<20;i++)sostpro[i]=Math.ceil(sost[i]*10000/l)/100;
      }

//MR

for(i=0;i<5;i++)count[i]=0;
ma=document.input.mr.checked;
for(e=0;e<l;e++){
                    j=getnum(prot.charAt(e));
                    for(y=0;y<5;y++)count[y]+=at[y][j];  
                 }
count[1]+=2;
count[3]+=1;
if(ma){
        cis=document.input.C13.checked;
        nis=document.input.N15.checked;
        dis=document.input.D.checked;
        mas=count[4]*32.06+count[3]*15.999;  
        if(cis)mas+=count[0]*13;else mas+=count[0]*12.011;
        if(nis)mas+=count[2]*15;else mas+=count[2]*14.0067;
        if(dis)mas+=2*count[1]; else mas+=count[1]*1.0079;
        mas=Math.ceil(mas*100)/100;
       }

ipc=document.input.ip.checked;
if(ipc){
left=0;
right=14;
cent=0;
while(Math.abs(qpr(cent))>0.0000005)
      {
       cent=(left+right)/2;
       if(qpr(cent)>0)left=cent;
       else right=cent;
      }
cent=Math.ceil(cent*100)/100;
}


qmol=document.input.q.checked;
qqq=qpr(parseFloat(document.input.ph.value));
qqq=Math.ceil(qqq*1000)/1000;
openWin2(so, sost, sostpro, ipc, cent, ma, mas, qmol, qqq, cis, nis, dis);
}

