Hi, help me in debugging this function, it is giving me the same answer every time despite of different arguments. also please let me know if i need to add further more data into it.
ref=c("I=9.68", "L=9.60", "M=9.21", "F=9.13", "T=9.10", "W=9.39", "V=9.62", "A=9.69", "N=8.84", "Q=9.13", "G=9.60", "P=10.60", "S=9.15", "D=3.9", "E=4.7", "C=8.18", "Y=10.46", "H=6.04", "K=10.54", "R=12.48")
I=9.68
L=9.60
M=9.21
F=9.13
T=9.10
W=9.39
V=9.62
A=9.69
N=8.84
Q=9.13
G=9.60
P=10.60
S=9.15
D=3.9
E=4.7
C=8.18
Y=10.46
H=6.04
K=10.54
R=12.48
pi<-function(compound)
{
molecules=unlist(strsplit(compound,""))
DNum=0
ENum=0
CNum=0
YNum=0
HNum=0
KNum=0
RNum=0
for (i in molecules){
if (i == 'D')
DNum= DNum +1
if (i == 'E')
ENum= ENum +1
if (i == 'C')
CNum= CNum +1
if (i == 'Y')
YNum= YNum +1
if (i == 'H')
HNum= HNum +1
if (i == 'K')
KNum= KNum +1
if (i == 'R')
RNum= RNum +1
}
QN1=0
QN2=0
QN3=0
QN4=0
QN5=0
QP1=0
QP2=0
QP3=0
QP4=0
pH=0
test=1;
while(1){
QN1=-1/((1+(10)^(3.65-pH)))
QN2=-DNum/(1+((10)^(D-pH)))
QN3=-ENum/(1+((10)^(E-pH)))
QN4=-CNum/(1+((10)^(C-pH)))
QN5=-YNum/(1+((10)^(Y-pH)))
QP1=HNum/(1+((10)^(pH-H)))
QP2=1/(1+((10)^(pH-8.2)))
QP3=KNum/(1+((10)^(pH-K)))
QP4=RNum/(1+((10)^(pH-R)))
NQ=QN1+QN2+QN3+QN4+QN5+QP1+QP2+QP3+QP4
if(pH>=14)
print ("Something is wrong, pH is greater than 14")
break
if(NQ<=0)
print(NQ)
break
pH=pH+0.1
}
return(c("pI of a protein:"=pH))
}
And the result
pi("DECYHKR")
[1] 0
#> Error: <text>:61:3: unexpected '}'
#> 60: +
#> 61: + }
#> ^
Created on 2018-03-27 by the reprex package (v0.2.0).
This is the answer i am getting but the right answer should be 6.74 (according to Expasy(an online tool to calculate pI value of a protein))