<!--

//scripts for the Protein Extinction Coefficient tool

function Calculate(form) {
	thePept = new Pept(form.PeptBox.value);
	form.PeptBox.value = thePept.Sequence;
	form.mwBox.value = thePept.MW();
	form.ExCoBox.value = thePept.ExCo();
	
	form.lBox.value = thePept.Sequence.length;
	
	form.alaBox.value = thePept.CountA();
	form.asxBox.value = thePept.CountB();
	form.cysBox.value = thePept.CountC();
	form.aspBox.value = thePept.CountD();
	form.gluBox.value = thePept.CountE();
	form.pheBox.value = thePept.CountF();
	
	form.glyBox.value = thePept.CountG();
	form.hisBox.value = thePept.CountH();
	form.ileBox.value = thePept.CountI();
	form.lysBox.value = thePept.CountK();
	form.leuBox.value = thePept.CountL();
	form.metBox.value = thePept.CountM();
	
	form.asnBox.value = thePept.CountN();
	form.proBox.value = thePept.CountP();
	form.glnBox.value = thePept.CountQ();
	form.argBox.value = thePept.CountR();
	form.serBox.value = thePept.CountS();
	form.theBox.value = thePept.CountT();
	
	form.valBox.value = thePept.CountV();
	form.trpBox.value = thePept.CountW();
	form.tyrBox.value = thePept.CountY();
	form.glxBox.value = thePept.CountZ();

	form.CytoBox.value = thePept.CytoExCo();

	document.ProtCalc.threeletterbox.value=thePept.ConvertCode(form.PeptBox.value);
	document.ProtCalc.items.value=MakeItemsList(form.PeptBox.value);

}




function Pept(theString)
{
	theString = theString.toUpperCase()
	this.Sequence = RemoveNonRes(theString)
	this.aCount = CountChar(theString,"A")
	this.bCount = CountChar(theString,"B")
	this.cCount = CountChar(theString,"C")
	this.dCount = CountChar(theString,"D")
	this.eCount = CountChar(theString,"E")
	this.fCount = CountChar(theString,"F")
	this.gCount = CountChar(theString,"G")
	this.hCount = CountChar(theString,"H")
	this.iCount = CountChar(theString,"I")
	this.kCount = CountChar(theString,"K")
	this.lCount = CountChar(theString,"L")
	this.mCount = CountChar(theString,"M")
	this.nCount = CountChar(theString,"N")
	this.pCount = CountChar(theString,"P")
	this.qCount = CountChar(theString,"Q")
	this.rCount = CountChar(theString,"R")
	this.sCount = CountChar(theString,"S")
	this.tCount = CountChar(theString,"T")
	this.vCount = CountChar(theString,"V")
	this.wCount = CountChar(theString,"W")
	this.yCount = CountChar(theString,"Y")
	this.zCount = CountChar(theString,"Z")
	this.MW = MW
	this.ExCo = ExCo
	
	this.ConvertCode = ConvertCode
	this.ResTo = ResTo
	this.CountA = CountA
	this.CountB = CountB
	this.CountC = CountC
	this.CountD = CountD
	this.CountE = CountE
	this.CountF = CountF
	this.CountG = CountG
	this.CountH = CountH
	this.CountI = CountI
	this.CountK = CountK
	this.CountL = CountL
	this.CountM = CountM
	this.CountN = CountN
	this.CountP = CountP
	this.CountQ = CountQ
	this.CountR = CountR
	this.CountS = CountS
	this.CountT = CountT
	this.CountV = CountV
	this.CountW = CountW
	this.CountY = CountY
	this.CountZ = CountZ
	this.CytoExCo = CytoExCo
	
	

}

function AddRes(form, res){
	form.PeptBox.value += res
//	Calculate(form)
}




function MW()	//calculates molecular weight of peptide sequence after editing
{
	if (this.Sequence.length > 0) {
		return Math.round(71.1 * this.aCount + 
		156.2 * this.rCount + 
		114.1 * this.nCount + 
		115.1 * this.dCount + 
		103.1 * this.cCount + 
		128.1 * this.qCount + 
		129.1 * this.eCount + 
		57.1 * this.gCount + 
		137.1 * this.hCount + 
		113.1 * this.iCount + 
		113.1 * this.lCount + 
		128.2 * this.kCount + 
		131.2 * this.mCount + 
		147.2 * this.fCount + 
		97.1 * this.pCount + 
		87.1 * this.sCount + 
		101.1 * this.tCount + 
		186.2 * this.wCount + 
		163.2 * this.yCount + 
		99.1 * this.vCount + 
		132.61 * this.bCount + 
		146.64 * this.zCount + 18 )
	}
	else
	{
		return "0"
	}
}

/* ExCo funtion calculates the extinction coefficient of a denatured
protein in 6M guanidine/
HCl  at 280 nm based on the wok of Gill and von Hipple, Anal Biochem  (1989)*/


function CountA() {
	return this.aCount;
}
function CountB() {
	return this.bCount;
}
function CountC() {
	return this.cCount;
}
function CountD() {
	return this.dCount;
}
function CountE() {
	return this.eCount;
}
function CountF() {
	return this.fCount;
}
function CountG() {
	return this.gCount;
}
function CountH() {
	return this.hCount;
}
function CountI() {
	return this.iCount;
}
function CountK() {
	return this.kCount;
}
function CountL() {
	return this.lCount;
}
function CountM() {
	return this.mCount;
}
function CountN() {
	return this.nCount;
}
function CountP() {
	return this.pCount;
}
function CountQ() {
	return this.qCount;
}
function CountR() {
	return this.rCount;
}
function CountS() {
	return this.sCount;
}
function CountT() {
	return this.tCount;
}
function CountV() {
	return this.vCount;
}
function CountW() {
	return this.wCount;
}
function CountY() {
	return this.yCount;
}
function CountZ() {
	return this.zCount;
}

function ExCo()
{
	if (this.cCount || this.yCount|| this.wCount) {
		return Math.round((125 * this.cCount)/2 + 1490 * this.yCount +
5500 *  this.wCount)
	}
	else{
		alert('This method of calculation is based on the assumption that the peptide specified contains at least one Tryptophan, Tyrosine, or Cysteine residue.')	}
}

function CytoExCo() {
			return Math.round(1490 * this.yCount +
5500 *  this.wCount)

}

	






function RemoveNonRes(theString) {
	var returnString = "";
	for ( var i = 0; i < theString.length; i++) {
		if (IsRes(theString.charAt(i))) {
			returnString += theString.charAt(i);
		}
	}
	return returnString
}

function CountChar(theString,theChar) {
	var returnValue = 0;
	for ( var i = 0; i < theString.length; i++) {
		if (theString.charAt(i) == theChar) {
			returnValue ++;
		}
	}
	return returnValue
}

function DoCheck(PeptBox) {
	PeptBox.value = CheckRes(PeptBox.value)
}

function CheckRes(theString) {
	var returnString = "";
	var cnt = 0;
	var rcnt = 0;
	theString = theString.toUpperCase()
	for ( var i = 0; i < theString.length; i++) {
		if (IsRes(theString.charAt(i))) {
			returnString += theString.charAt(i)
		}
	}
	theString=returnString
	returnString=""
	for ( var i = 0; i < theString.length; i++) {
		if (cnt>2) {
			returnString += " "
			cnt=0
		}
		cnt++
		if (rcnt>20) {
			returnString += "\r\n"
			rcnt=0
		}
		rcnt++
		returnString += theString.charAt(i)
	}
	return returnString
}

function IsRes(theRes) {
 if ((theRes == "A") ||
	(theRes == "B") ||
	(theRes == "C") ||
	(theRes == "D") ||
	(theRes == "E") ||
	(theRes == "F") ||
	(theRes == "G") ||
	(theRes == "H") ||
	(theRes == "I") ||
	(theRes == "K") ||
	(theRes == "L") ||
	(theRes == "M") ||
	(theRes == "N") ||
	(theRes == "P") ||
	(theRes == "Q") ||
	(theRes == "R") ||
	(theRes == "S") ||
	(theRes == "T") ||
	(theRes == "V") ||
	(theRes == "W") ||
	(theRes == "Y") ||
	(theRes == "Z") ) {
		return 1
	}
	return 0  //put in alert box
}

function ConvertCode(data) {
	if (data.length<1)
		return "";
	var returnstring=ResTo(data.charAt(0));
	for (var i=1; i<data.length;i++) {
		returnstring+=" - "+ResTo(data.charAt(i));
	}
    return returnstring;
}



function ResTo(theRes) {
	if (theRes == "A") return "Ala";
	if (theRes == "B") return "Asx";
	if (theRes == "C") return "Cys";
	if (theRes == "D") return "Asp";
	if (theRes == "E") return "Glu";
	if (theRes == "F") return "Phe";
	if (theRes == "G") return "Gly";
	if (theRes == "H") return "His";
	if (theRes == "I") return "Ile";
	if (theRes == "K") return "Lys";
	if (theRes == "L") return "Leu";
	if (theRes == "M") return "Met";
	if (theRes == "N") return "Asn";
	if (theRes == "P") return "Pro";
	if (theRes == "Q") return "Gln";
	if (theRes == "R") return "Arg";
	if (theRes == "S") return "Ser";
	if (theRes == "T") return "Thr";
	if (theRes == "V") return "Val";
	if (theRes == "W") return "Trp";
	if (theRes == "Y") return "Tyr";
	if (theRes == "Z") return "Glx";
	return "???";
}

















function Disallow(form) {
	form.PeptBox.focus()
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//-->