1 /************************************************************
2 * HMMER - Biological sequence analysis with profile HMMs
3 * Copyright (C) 1992-1999 Washington University School of Medicine
6 * This source code is distributed under the terms of the
7 * GNU General Public License. See the files COPYING and LICENSE
9 ************************************************************/
12 * RCS $Id: funcs.h,v 1.1.1.1 2005/03/22 08:34:07 cmzmasek Exp $
14 * Declarations of external functions in HMMER.
17 #ifndef FUNCSH_INCLUDED
18 #define FUNCSH_INCLUDED
26 * Configuration of global alphabet information
28 extern void DetermineAlphabet(char **rseqs, int nseq);
29 extern void SetAlphabet(int type);
30 extern int SymbolIndex(char sym);
31 extern char *DigitizeSequence(char *seq, int L);
32 extern char *DedigitizeSequence(char *dsq, int L);
33 extern void DigitizeAlignment(MSA *msa, char ***ret_dsqs);
34 extern void P7CountSymbol(float *counters, char sym, float wt);
35 extern void DefaultGeneticCode(int *aacode);
36 extern void DefaultCodonBias(float *codebias);
38 /* from core_algorithms.c
39 * Clean research/demonstration versions of basic algorithms.
41 extern struct dpmatrix_s *AllocPlan7Matrix(int rows, int M, int ***xmx,
42 int ***mmx, int ***imx, int ***dmx);
43 extern struct dpshadow_s *AllocShadowMatrix(int rows, int M, char ***xtb,
44 char ***mtb, char ***itb, char ***dtb);
45 extern void FreePlan7Matrix(struct dpmatrix_s *mx);
46 extern void FreeShadowMatrix(struct dpshadow_s *tb);
47 extern int P7ViterbiSize(int L, int M);
48 extern int P7SmallViterbiSize(int L, int M);
49 extern int P7WeeViterbiSize(int L, int M);
50 extern float P7Forward(char *dsq, int L, struct plan7_s *hmm,
51 struct dpmatrix_s **ret_mx);
52 extern float P7Viterbi(char *dsq, int L, struct plan7_s *hmm,
53 struct p7trace_s **ret_tr);
54 extern void P7ViterbiTrace(struct plan7_s *hmm, char *dsq, int L,
55 struct dpmatrix_s *mx, struct p7trace_s **ret_tr);
56 extern float P7SmallViterbi(char *dsq, int L, struct plan7_s *hmm, struct p7trace_s **ret_tr);
57 extern float P7ParsingViterbi(char *dsq, int L, struct plan7_s *hmm,
58 struct p7trace_s **ret_tr);
59 extern float P7WeeViterbi(char *dsq, int L, struct plan7_s *hmm,
60 struct p7trace_s **ret_tr);
61 extern float Plan7ESTViterbi(char *dsq, int L, struct plan7_s *hmm,
62 struct dpmatrix_s **ret_mx);
63 extern struct p7trace_s *P7ViterbiAlignAlignment(MSA *msa, struct plan7_s *hmm);
64 extern struct p7trace_s *ShadowTrace(struct dpshadow_s *tb, struct plan7_s *hmm, int L);
65 extern void PostprocessSignificantHit(struct tophit_s *ghit, struct tophit_s *dhit, struct p7trace_s *tr, struct plan7_s *hmm, char *dsq, int L, char *seqname, char *seqacc, char *seqdesc, int do_forward, float sc_override, int do_null2, struct threshold_s *thresh, int hmmpfam_mode);
69 * Debugging output of various sorts.
71 extern char *Statetype(char st);
72 extern char *AlphabetType2String(int type);
73 extern void P7PrintTrace(FILE *fp, struct p7trace_s *tr,
74 struct plan7_s *hmm, char *dsq);
75 extern void P7PrintPrior(FILE *fp, struct p7prior_s *pri);
76 extern int TraceCompare(struct p7trace_s *t1, struct p7trace_s *t2);
77 extern int TraceVerify(struct p7trace_s *tr, int M, int N);
81 * Ian Holmes' functions for displaying HMMER2 data structures, especially
82 * for posterior probabilities in alignments.
84 extern void DisplayPlan7Matrix(char *dsq, int L, struct plan7_s *hmm,
85 struct dpmatrix_s *mx);
86 extern void DisplayPlan7Posteriors(int L, struct plan7_s *hmm,
87 struct dpmatrix_s *forward, struct dpmatrix_s *backward,
88 struct p7trace_s *viterbi, struct p7trace_s *optacc);
89 extern void DisplayPlan7PostAlign(int L, struct plan7_s *hmm,
90 struct dpmatrix_s *forward, struct dpmatrix_s *backward,
91 struct p7trace_s **alignment, int A);
95 * Generation of sequences/traces from an HMM
97 extern void EmitSequence(struct plan7_s *hmm, char **ret_dsq, int *ret_L, struct p7trace_s **ret_tr);
98 extern void EmitConsensusSequence(struct plan7_s *hmm, char **ret_seq, char **ret_dsq, int *ret_L, struct p7trace_s **ret_tr);
99 extern void StateOccupancy(struct plan7_s *hmm, float **ret_mp, float **ret_ip, float **ret_dp);
103 * Interfaces between HMMER and other software packages
105 extern void WriteProfile(FILE *fp, struct plan7_s *hmm, int do_xsw);
109 * accumulation of scores
111 extern struct histogram_s *AllocHistogram(int min, int max, int lumpsize);
112 extern void FreeHistogram(struct histogram_s *h);
113 extern void UnfitHistogram(struct histogram_s *h);
114 extern void AddToHistogram(struct histogram_s *h, float sc);
115 extern void PrintASCIIHistogram(FILE *fp, struct histogram_s *h);
116 extern void PrintXMGRHistogram(FILE *fp, struct histogram_s *h);
117 extern void PrintXMGRDistribution(FILE *fp, struct histogram_s *h);
118 extern void PrintXMGRRegressionLine(FILE *fp, struct histogram_s *h);
119 extern void EVDBasicFit(struct histogram_s *h);
120 extern int ExtremeValueFitHistogram(struct histogram_s *h, int censor,
122 extern void ExtremeValueSetHistogram(struct histogram_s *h, float mu, float lambda,
123 float low, float high, int ndegrees);
124 extern int GaussianFitHistogram(struct histogram_s *h, float high_hint);
125 extern void GaussianSetHistogram(struct histogram_s *h, float mean, float sd);
126 extern double EVDDensity(float x, float mu, float lambda);
127 extern double EVDDistribution(float x, float mu, float lambda);
128 extern double ExtremeValueP (float x, float mu, float lambda);
129 extern double ExtremeValueP2(float x, float mu, float lambda, int N);
130 extern double ExtremeValueE (float x, float mu, float lambda, int N);
131 extern float EVDrandom(float mu, float lambda);
132 extern int EVDMaxLikelyFit(float *x, int *y, int n,
133 float *ret_mu, float *ret_lambda);
134 extern int EVDCensoredFit(float *x, int *y, int n, int z, float c,
135 float *ret_mu, float *ret_lambda);
136 extern void Lawless416(float *x, int *y, int n, float lambda,
137 float *ret_f, float *ret_df);
138 extern void Lawless422(float *x, int *y, int n, int z, float c,
139 float lambda, float *ret_f, float *ret_df);
142 * Input/output (saving/reading) of models
144 extern HMMFILE *HMMFileOpen(char *hmmfile, char *env);
145 extern int HMMFileRead(HMMFILE *hmmfp, struct plan7_s **ret_hmm);
146 extern void HMMFileClose(HMMFILE *hmmfp);
147 extern int HMMFileFormat(HMMFILE *hmmfp);
148 extern void HMMFileRewind(HMMFILE *hmmfp);
149 extern int HMMFilePositionByName(HMMFILE *hmmfp, char *name);
150 extern int HMMFilePositionByIndex(HMMFILE *hmmfp, int idx);
151 extern void WriteAscHMM(FILE *fp, struct plan7_s *hmm);
152 extern void WriteBinHMM(FILE *fp, struct plan7_s *hmm);
155 * Repetitive sequence masking.
157 extern int XNU(char *dsq, int len);
158 extern float TraceScoreCorrection(struct plan7_s *hmm, struct p7trace_s *tr, char *dsq);
161 * Much of this code deals with Dirichlet prior mathematics.
163 extern int Prob2Score(float p, float null);
164 extern float Score2Prob(int sc, float null);
165 extern float Scorify(int sc);
166 extern double PValue(struct plan7_s *hmm, float sc);
167 extern float LogSum(float p1, float p2);
168 extern int ILogsum(int p1, int p2);
169 extern void LogNorm(float *vec, int n);
170 extern float Logp_cvec(float *cvec, int n, float *alpha);
171 extern void SampleDirichlet(float *alpha, int n, float *p);
172 extern float SampleGamma(float alpha);
173 extern void SampleCountvector(float *p, int n, int c, float *cvec);
174 extern float P_PvecGivenDirichlet(float *p, int n, float *alpha);
177 * Miscellaneous functions with no home
179 extern char *Getword(FILE *fp, int type);
180 extern char *Getline(char *s, int n, FILE *fp);
181 extern int SetAutocuts(struct threshold_s *thresh, struct plan7_s *hmm);
183 /* from modelmakers.c
184 * Model construction algorithms
186 extern void P7Handmodelmaker(MSA *msa, char **dsq, struct plan7_s **ret_hmm,
187 struct p7trace_s ***ret_tr);
188 extern void P7Fastmodelmaker(MSA *msa, char **dsq,
189 float maxgap, struct plan7_s **ret_hmm,
190 struct p7trace_s ***ret_tr);
191 extern void P7Maxmodelmaker(MSA *msa, char **dsq,
192 float maxgap, struct p7prior_s *prior,
193 float *null, float null_p1, float mpri,
194 struct plan7_s **ret_hmm,
195 struct p7trace_s ***ret_tr);
198 * Plan7 HMM structure support
200 extern struct plan7_s *AllocPlan7(int M);
201 extern struct plan7_s *AllocPlan7Shell(void);
202 extern void AllocPlan7Body(struct plan7_s *hmm, int M);
203 extern void FreePlan7(struct plan7_s *hmm);
204 extern void ZeroPlan7(struct plan7_s *hmm);
205 extern void Plan7SetName(struct plan7_s *hmm, char *name);
206 extern void Plan7SetAccession(struct plan7_s *hmm, char *acc);
207 extern void Plan7SetDescription(struct plan7_s *hmm, char *desc);
208 extern void Plan7ComlogAppend(struct plan7_s *hmm, int argc, char **argv);
209 extern void Plan7SetCtime(struct plan7_s *hmm);
210 extern void Plan7SetNullModel(struct plan7_s *hmm, float null[MAXABET], float p1);
211 extern void P7Logoddsify(struct plan7_s *hmm, int viterbi_mode);
212 extern void Plan7Renormalize(struct plan7_s *hmm);
213 extern void Plan7RenormalizeExits(struct plan7_s *hmm);
214 extern void Plan7NakedConfig(struct plan7_s *hmm);
215 extern void Plan7GlobalConfig(struct plan7_s *hmm);
216 extern void Plan7LSConfig(struct plan7_s *hmm);
217 extern void Plan7SWConfig(struct plan7_s *hmm, float pentry, float pexit);
218 extern void Plan7FSConfig(struct plan7_s *hmm, float pentry, float pexit);
219 extern void PrintPlan7Stats(FILE *fp, struct plan7_s *hmm, char **dsq,
220 int nseq, struct p7trace_s **tr);
221 extern int DegenerateSymbolScore(float *p, float *null, int ambig);
222 extern void Plan9toPlan7(struct plan9_s *hmm, struct plan7_s **ret_plan7);
226 * Backwards compatibility for the Plan 9 data structures of HMMER 1.x
228 extern struct plan9_s *P9AllocHMM(int M);
229 extern void P9ZeroHMM(struct plan9_s *hmm);
230 extern int P9FreeHMM(struct plan9_s *hmm);
231 extern void P9Renormalize(struct plan9_s *hmm);
232 extern void P9DefaultNullModel(float *null);
236 * Functions for working with posterior probabilities within alignments
238 extern float P7OptimalAccuracy(char *dsq, int L, struct plan7_s *hmm, struct p7trace_s **ret_tr);
239 extern float P7Backward(char *dsq, int L, struct plan7_s *hmm, struct dpmatrix_s **ret_mx);
240 extern void P7EmitterPosterior(int L, struct plan7_s *hmm, struct dpmatrix_s *forward,
241 struct dpmatrix_s *backward, struct dpmatrix_s *mx);
242 extern float P7FillOptimalAccuracy(int L, int M, struct dpmatrix_s *posterior,
243 struct dpmatrix_s *mx, struct p7trace_s **ret_tr);
244 extern void P7OptimalAccuracyTrace(int L, int M, struct dpmatrix_s *posterior,
245 struct dpmatrix_s *mx, struct p7trace_s **ret_tr);
246 extern char *PostalCode(int L, struct dpmatrix_s *mx, struct p7trace_s *tr);
251 extern struct p7prior_s *P7AllocPrior(void);
252 extern struct p7prior_s *P7LaplacePrior(void);
253 extern struct p7prior_s *P7DefaultPrior(void);
254 extern struct p7prior_s *P7ReadPrior(char *prifile);
255 extern void P7FreePrior(struct p7prior_s *pri);
256 extern void PAMPrior(char *pamfile, struct p7prior_s *pri, float pamwgt);
257 extern void P7DefaultNullModel(float *null, float *ret_p1);
258 extern void P7ReadNullModel(char *rndfile, float *null, float *ret_p1);
259 extern void P7PriorifyHMM(struct plan7_s *hmm, struct p7prior_s *pri);
260 extern void P7PriorifyTransitionVector(float *t, struct p7prior_s *prior,
261 float tq[MAXDCHLET]);
262 extern void P7PriorifyEmissionVector(float *vec, struct p7prior_s *pri,
263 int num, float eq[MAXDCHLET],
264 float e[MAXDCHLET][MAXABET],
270 * PVM Parallel Virtual Machine implementation
272 extern void PVMSpawnSlaves(char *slave, int **ret_tid, int *ret_nslaves);
273 extern void PVMConfirmSlaves(int *slave_tid, int nslaves);
274 extern void PVMCheckSlaves(int *slave_tid, int nslaves);
275 extern void PVMKillSlaves(int *slave_tid, int nslaves);
276 extern int PVMPackString(char *s);
277 extern char * PVMUnpackString(void);
278 extern int PVMPackTrace(struct p7trace_s *tr);
279 extern struct p7trace_s *PVMUnpackTrace(void);
280 extern int PVMPackHMM(struct plan7_s *hmm);
281 extern struct plan7_s * PVMUnpackHMM(void);
286 * POSIX threads implementation
288 extern int ThreadNumber(void);
289 #endif /*HMMER_THREADS*/
293 * Support for keeping/sorting top scoring hit/alignment lists
295 extern struct tophit_s *AllocTophits(int lumpsize);
296 extern void GrowTophits(struct tophit_s *h);
297 extern void FreeTophits(struct tophit_s *h);
298 extern struct fancyali_s *AllocFancyAli(void);
299 extern void FreeFancyAli(struct fancyali_s *ali);
300 extern void RegisterHit(struct tophit_s *h, double sortkey,
301 double pvalue, float score,
302 double motherp, float mothersc,
303 char *name, char *acc, char *desc,
304 int sqfrom, int sqto, int sqlen,
305 int hmmfrom, int hmmto, int hmmlen,
306 int domidx, int ndom,
307 struct fancyali_s *ali);
308 extern void GetRankedHit(struct tophit_s *h, int rank,
309 double *r_pvalue, float *r_score,
310 double *r_motherp, float *r_mothersc,
311 char **r_name, char **r_acc, char **r_desc,
312 int *r_sqfrom, int *r_sqto, int *r_sqlen,
313 int *r_hmmfrom, int *r_hmmto, int *r_hmmlen,
314 int *r_domidx, int *r_ndom,
315 struct fancyali_s **r_ali);
316 extern int TophitsMaxName(struct tophit_s *h);
317 extern void FullSortTophits(struct tophit_s *h);
318 extern void TophitsReport(struct tophit_s *h, double E, int nseq);
321 * Support for traceback (state path) structure
323 extern void P7AllocTrace(int tlen, struct p7trace_s **ret_tr);
324 extern void P7ReallocTrace(struct p7trace_s *tr, int tlen);
325 extern void P7FreeTrace(struct p7trace_s *tr);
326 extern void TraceSet(struct p7trace_s *tr, int tpos, char type, int idx, int pos);
327 extern struct p7trace_s **MergeTraceArrays(struct p7trace_s **t1, int n1, struct p7trace_s **t2, int n2);
328 extern void P7ReverseTrace(struct p7trace_s *tr);
329 extern void P7TraceCount(struct plan7_s *hmm, char *dsq, float wt,
330 struct p7trace_s *tr);
331 extern float P7TraceScore(struct plan7_s *hmm, char *dsq, struct p7trace_s *tr);
332 extern MSA *P7Traces2Alignment(char **dsq, SQINFO *sqinfo, float *wgt,
334 struct p7trace_s **tr, int matchonly);
335 extern int TransitionScoreLookup(struct plan7_s *hmm, char st1,
336 int k1, char st2, int k2);
337 extern struct fancyali_s *CreateFancyAli(struct p7trace_s *tr, struct plan7_s *hmm,
338 char *dsq, char *name);
339 extern void PrintFancyAli(FILE *fp, struct fancyali_s *ali);
340 extern void TraceDecompose(struct p7trace_s *otr, struct p7trace_s ***ret_tr,
342 extern int TraceDomainNumber(struct p7trace_s *tr);
343 extern void TraceSimpleBounds(struct p7trace_s *tr, int *ret_i1, int *ret_i2,
344 int *ret_k1, int *ret_k2);
345 extern struct p7trace_s *MasterTraceFromMap(int *map, int M, int alen);
346 extern void ImposeMasterTrace(char **aseq, int nseq, struct p7trace_s *mtr,
347 struct p7trace_s ***ret_tr);
350 #endif /*FUNCSH_INCLUDED*/