Debian Codegraph @

src/hmmband.h

raw symbols SCIP
1 /* hmmband.h
2 * Eric Nawrocki
3 * 12.16.05
4 * (many functions older than 12.16.05)
5 *
6 * Functions to support either CM Plan 9 (CP9) HMMs for band
7 * calculation. Includes functions for calc'ing posteriors.
8 *
9 * Note: Initially, plan 7 (P7) versions of most of these functions
10 * were implemented, but abandoned once it was clear CP9s were
11 * more appropriate for CMs. To see the original P7 funcs, see
12 * the end of the hmmband.c file.
13 */
14
15 #include <esl_config.h>
16 #include "config.h"
17
18 #include "easel.h"
19 #include "esl_msa.h"
20 #include "esl_stack.h"
21 #include "esl_stopwatch.h"
22
23 #include "structs.h" /* data structures, macros, #define's */
24
25 extern CP9Bands_t * AllocCP9Bands(CM_t *cm, CP9_t *hmm);
26 extern void FreeCP9Bands(CP9Bands_t *cp9bands);
27
28 extern double dbl_Score2Prob(int sc, float null);
29
30 /* CP9_seq2bands() takes a CM, sequence, and allocated CP9Bands_t structure and
31 * calculates the CP9Bands_t by calling many of the other functions below. */
32 extern void CP9_seq2bands(CM_t *cm, ESL_DSQ *dsq, int i0, int j0, CP9Bands_t *cp9b,
33 CP9_dpmatrix_t **ret_cp9_post, int debug_level);
34
35 /* CP9_seq2posteriors() takes a CM and sequence and runs Forward and Backward algorithms
36 * (or scanning Forward/Backward) and returns a CP9 posterior matrix. */
37 extern void CP9_seq2posteriors(CM_t *cm, ESL_DSQ *dsq, int i0, int j0, CP9_dpmatrix_t **ret_cp9_post,
38 int debug_level);
39
40 /* Functions for getting posterior probabilities from CP9 HMMs
41 * based on Ian Holmes' hmmer/src/postprob.c functions
42 * P7Forward() is in HMMER's core_algorithms.c
43 * and P7Backward() is in HMMER's postprob.c*/
44 extern float CP9ForwardOLD(ESL_DSQ *dsq, int i0, int j0, CP9_t *hmm,
45 struct cp9_dpmatrix_s **ret_mx);
46 extern float CP9ViterbiOLD(ESL_DSQ *dsq, int i0, int j0, CP9_t *hmm, struct cp9_dpmatrix_s *mx, struct cp9trace_s **ret_tr);
47 extern float CP9BackwardOLD(ESL_DSQ *dsq, int i0, int j0, CP9_t *hmm, struct cp9_dpmatrix_s **ret_mx);
48 extern void CP9Posterior(ESL_DSQ *dsq, int i0, int j0,
49 CP9_t *hmm,
50 struct cp9_dpmatrix_s *fmx,
51 struct cp9_dpmatrix_s *bmx,
52 struct cp9_dpmatrix_s *mx);
53 extern void CP9_ifill_post_sums(struct cp9_dpmatrix_s *post, CP9Bands_t *cp9, int i0, int j0);
54
55 /* Functions to determine HMM bands */
56 extern void CP9_hmm_band_bounds(int **post, int i0, int j0, int M, int *isum_pn, int *pn_min, int *pn_max, double p_thresh,
57 int state_type, int use_sums, int debug_level);
58
59 /* Function to go from HMM bands to i and j bands on a CM */
60 extern void hmm2ij_bands(CM_t *cm, CP9Map_t *cp9map, int i0, int j0, int *pn_min_m,
61 int *pn_max_m, int *pn_min_i, int *pn_max_i, int *pn_min_d,
62 int *pn_max_d, int *imin, int *imax, int *jmin, int *jmax,
63 int debug_level);
64
65 /* Helper functions for *_hmm2ij_bands() */
66 extern void hmm2ij_prestate_step0_initialize(int n, int *nss_max_imin, int *nss_min_jmax, int i0, int j0);
67 extern void hmm2ij_prestate_step1_set_node_inserts(int n, int *nis_imin, int *nis_imax,
68 int *nis_jmin, int *nis_jmax,
69 int *nss_imin, int *nss_imax,
70 int *nss_jmin, int *nss_jmax,
71 int *pn_min_i, int *pn_max_i,
72 CP9Map_t *cp9map);
73 extern void hmm2ij_prestate_step2_determine_safe(int n,
74 int nss_max_imin_np1, int nss_min_jmax_np1,
75 int nis_imin_n,
76 int nis_jmax_n,
77 int *safe_imax, int *safe_jmin);
78 extern void hmm2ij_prestate_step3_preset_node_splits(int n, int *nis_imin, int *nis_imax,
79 int *nis_jmin, int *nis_jmax,
80 int *nss_imin, int *nss_imax,
81 int *nss_jmin, int *nss_jmax,
82 int *pn_min_m, int *pn_max_m,
83 int *pn_min_d, int *pn_max_d,
84 CP9Map_t *cp9map);
85 extern void hmm2ij_split_state_step1_set_state_bands(int v, int n,
86 int tmp_imin, int tmp_imax,
87 int tmp_jmin, int tmp_jmax,
88 int *imin, int *imax, int *jmin, int *jmax,
89 int *nss_imin, int *nss_imax,
90 int *nss_jmin, int *nss_jmax);
91 extern void hmm2ij_insert_state_step1_set_state_bands(int v,
92 int tmp_imin, int tmp_imax,
93 int tmp_jmin, int tmp_jmax,
94 int *imin, int *imax, int *jmin, int *jmax);
95 extern void hmm2ij_state_step2_enforce_safe_trans(CM_t *cm, int v, int n, int *imax, int *jmin,
96 int *nss_imax, int *nss_jmin,
97 int safe_imax, int safe_jmin);
98 extern void hmm2ij_state_step3_enforce_state_delta(CM_t *cm, int v, int *jmin, int *jmax);
99 extern void hmm2ij_state_step4_update_safe_holders(int v, int n, int imin_v, int jmax_v, int *nss_max_imin,
100 int *nss_min_jmax);
101 extern void hmm2ij_state_step5_non_emitter_d0_hack(int v, int imax_v, int *jmin);
102
103 /* Debugging print functions */
104 extern void debug_print_hmm_bands(FILE *ofp, int L, CP9Bands_t *cp9b, double hmm_bandp, int debug_level);
105 extern void ij_banded_trace_info_dump(CM_t *cm, Parsetree_t *tr, int *imin, int *imax,
106 int *jmin, int *jmax, int debug_level);
107 extern void ijd_banded_trace_info_dump(CM_t *cm, Parsetree_t *tr, int *imin, int *imax,
108 int *jmin, int *jmax, int **hdmin, int **hdmax,
109 int debug_level);
110 extern void debug_check_CP9_FB(struct cp9_dpmatrix_s *fmx,
111 struct cp9_dpmatrix_s *bmx,
112 CP9_t *hmm, float sc, int i0, int j0,
113 ESL_DSQ *dsq);
114
115 /* Other misc. functions */
116 extern void relax_root_bands(int *imin, int *imax, int *jmin, int *jmax);