/* @source embiep.c ** ** Acid/base routines ** Copyright (c) 1999 Alan Bleasby ** ** This program is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License ** as published by the Free Software Foundation; either version 2 ** of the License, or (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ******************************************************************************/ #include "emboss.h" #include #include #include #include #define PKFILE "Epk.dat" /* @func embIeppKNew ***************************************************** ** ** Create a pK array and read the data ** ** @return [double*] pK data ******************************************************************************/ double* embIeppKNew(void) { double *pK = NULL; AJCNEW(pK,EMBIEPSIZE); embIepPkRead(pK); /* read pK's */ return pK; } /* @func embIeppKDel ***************************************************** ** ** Delete a pK array and read the data ** ** @param [w] pK [double *] pKs ** ** @return [void] ******************************************************************************/ void embIeppKDel(double *pK) { AJFREE(pK); return; } /* @func embIepPhToHconc ***************************************************** ** ** Convert pH to hydrogen ion concontration ** ** @param [r] pH [double] pH ** ** @return [double] hydrogen ion concentrration ******************************************************************************/ double embIepPhToHconc(double pH) { return pow(10.0,-pH); } /* @func embIepPhFromHconc **************************************************** ** ** Convert hydrogen ion concontration to pH ** ** @param [r] H [double] H ** ** @return [double] pH ******************************************************************************/ double embIepPhFromHconc(double H) { return -log10(H); } /* @func embIepPkToK ********************************************************* ** ** Convert pK to dissociation constant ** ** @param [r] pK [double] pK ** ** @return [double] dissociation constant ******************************************************************************/ double embIepPkToK(double pK) { return pow(10.0,-pK); } /* @func embIepPkFromK ******************************************************** ** ** Convert dissociation constant to pK ** ** @param [r] K [double] K ** ** @return [double] pK ******************************************************************************/ double embIepPkFromK(double K) { return -log10(K); } /* @func embIepPkRead ******************************************************** ** ** Read the pK values from Epk.dat ** ** @param [w] pK [double*] pK ** ** @return [void] ******************************************************************************/ void embIepPkRead(double *pK) { AjPFile inf = NULL; AjPStr line; const char *p; double amino = 8.6; double carboxyl = 3.6; char ch; ajint i; inf = ajDatafileNewInNameC(PKFILE); if(!inf) ajFatal("%s file not found",PKFILE); for(i=0;i D:%d N:%d\n", c[1], j, c[1]-j); c[1] = 0; } if(c[25]) /* Z = E or Q use Dayhoff freq */ { j = (int) (0.5 + ((float)c[25]) * 6.0 / 9.9); c[4] += j; c[16] += c[25] - j; ajDebug("embIepCompC Z:%d => E:%d Q:%d\n", c[25], j, c[25]-j); c[25] = 0; } c[EMBIEPAMINO] = amino; c[EMBIEPCARBOXYL] = carboxyl; if (sscount > 0) { if(c[EMBIEPCYSTEINE] < 2*sscount) { ajWarn("embIepCompC %d disulphides but only %d cysteines\n", sscount, c[EMBIEPCYSTEINE]+2*sscount); c[EMBIEPCYSTEINE] = 0; } else { c[EMBIEPCYSTEINE] -= 2*sscount; } } if (modlysine > 0) { if(c[EMBIEPLYSINE] < modlysine) { ajWarn("embIepCompC %d modified lysines but only %d lysines\n", sscount, c[EMBIEPLYSINE]); c[EMBIEPLYSINE] = 0; } else { c[EMBIEPLYSINE] -= modlysine; } } return; } /* @func embIepCompS ********************************************************** ** ** Calculate the amino acid composition of a protein sequence ** ** @param [r] str [const AjPStr] protein sequence ** @param [r] amino [ajint] number of amino termini ** @param [r] carboxyl [ajint] number of carboxyl termini ** @param [r] sscount [ajint] number of disulphide bridges ** @param [r] modlysine [ajint] number of modified lysines ** @param [w] c [ajint *] amino acid composition ** ** @return [void] ******************************************************************************/ void embIepCompS(const AjPStr str, ajint amino, ajint carboxyl, ajint sscount, ajint modlysine, ajint *c) { embIepCompC(ajStrGetPtr(str), amino, carboxyl, sscount, modlysine, c); return; } /* @obsolete embIepComp ** @replace embIepCompC (1,2,3/1,2,0,0,3) */ __deprecated void embIepComp(const char *s, ajint amino, ajint carboxyl, ajint *c) { embIepCompC(s, amino, carboxyl, 0, 0, c); return; } /* @func embIepCalcK ********************************************************* ** ** Calculate the dissociation constants ** Amino acids for which there is no entry in Epk.dat have K set to 0.0 ** ** @param [w] K [double *] dissociation constants ** @param [w] pK [double *] pK values ** ** @return [void] ******************************************************************************/ void embIepCalcK(double *K, double *pK) { ajint i; for(i=0;i0.0 && bot>0.0) || (top<0.0 && bot<0.0)) return 0.0; while(bph-tph>0.0001) { mid = ((bph-tph) / 2.0) + tph; H = embIepPhToHconc(mid); embIepGetProto(K,c,op,H,pro); charge = embIepGetCharge(c,pro,&sum); if(charge>0.0) { tph = mid; continue; } if(charge<0.0) { bph = mid; continue; } else return mid; } return tph; } /* @func embIepIepC *********************************************************** ** ** Calculate the pH nearest the IEP. ** ** @param [r] s [const char *] sequence ** @param [r] amino [ajint] number of N-termini ** @param [r] carboxyl [ajint] number of C-termini ** @param [r] sscount [ajint] number of disulphide bridges ** @param [r] modlysine [ajint] number of modified lysines ** @param [w] pK [double *] pK values ** @param [w] iep [double *] IEP ** @param [r] termini [AjBool] use termini ** ** @return [AjBool] True if IEP exists ******************************************************************************/ AjBool embIepIepC(const char *s, ajint amino, ajint carboxyl, ajint sscount, ajint modlysine, double *pK, double *iep, AjBool termini) { ajint *c = NULL; ajint *op = NULL; double *K = NULL; double *pro = NULL; *iep = 0.0; AJCNEW(c, EMBIEPSIZE); AJCNEW(op, EMBIEPSIZE); AJCNEW(K, EMBIEPSIZE); AJCNEW(pro, EMBIEPSIZE); embIepCalcK(K,pK); /* Convert to dissoc consts */ /* Get sequence composition */ embIepCompC(s,amino,carboxyl,sscount, modlysine,c); if(!termini) c[EMBIEPAMINO] = c[EMBIEPCARBOXYL] = 0; *iep = embIepPhConverge(c,K,op,pro); AJFREE(pro); AJFREE(K); AJFREE(op); AJFREE(c); if(!*iep) return ajFalse; return ajTrue; } /* @func embIepIepS *********************************************************** ** ** Calculate the pH nearest the IEP. ** ** @param [r] str [const AjPStr] sequence ** @param [r] amino [ajint] number of N-termini ** @param [r] carboxyl [ajint] number of C-termini ** @param [r] sscount [ajint] number of disulphide bridges ** @param [r] modlysine [ajint] number of modified lysines ** @param [w] pK [double *] pK values ** @param [w] iep [double *] IEP ** @param [r] termini [AjBool] use termini ** ** @return [AjBool] True if IEP exists ******************************************************************************/ AjBool embIepIepS(const AjPStr str, ajint amino, ajint carboxyl, ajint sscount, ajint modlysine, double *pK, double *iep, AjBool termini) { return embIepIepC(ajStrGetPtr(str), amino, carboxyl, sscount, modlysine, pK, iep, termini); } /* @obsolete embIepIEP ** @replace embIepIepC (1,2,3,4/1,2,0,0,3,4) */ __deprecated AjBool embIepIEP(const char *s, ajint amino, ajint carboxyl, double *pK, double *iep, AjBool termini) { return embIepIepC(s, amino, carboxyl, 0, 0, pK, iep, termini); }