1 /******************************************************************************
2 
3   ####   #    #    ##    #####           #    #
4  #    #  ##  ##   #  #   #    #          #    #
5  #    #  # ## #  #    #  #    #          ######
6  #  # #  #    #  ######  #####    ###    #    #
7  #   #   #    #  #    #  #        ###    #    #
8   ### #  #    #  #    #  #        ###    #    #
9 
10 ******************************************************************************/
11 /* This file is part of MAPMAKER 3.0b, Copyright 1987-1992, Whitehead Institute
12    for Biomedical Research. All rights reserved. See READ.ME for license. */
13 
14 /***** qmap.h - Everything one needs to call QCTM should be in here. *****/
15 
16 /****************** CALLING CONVENTIONS FOR QCTM ******************
17 Before entry, QCTM requires that pos_tolerance, like_tolerance, and
18 mat_tolerance be set, and that qctm_alloc be run (which requires that
19 max_intervals and max_individuals be set). Data must be processed with
20 prepare_data() for each set of intervals to run through qctm.  In
21 addition, the map should be run through initial_qctm_values(). If
22 certain values in the data struct do not correspond to those in the
23 map (data->num_intervals and map->n_intervals, for example) then god
24 knows what will happen.
25 
26 In the map struct, qtl_weight, qtl_pos, mu, sigma_sq, null_mu, and
27 null_sigma_sq should be initialized, as should qtl_dominance if the
28 data is f2 intercross. Note that this can all be done by the canned
29 procedures provided. All of these variables, as well as var_explained,
30 chi_sq, null_log_like, abs_log_like, and log_like will be
31 side-effected!  Map->left and map->right are ignored, except in
32 print_iter (see print_iterations(), defined elsewhere).  Qtl_pos and
33 qtl_weight must be #intervals and #intervals+1 (IMPORTANT!) in length,
34 respectively.
35 
36 Throughout the qctm code, qtl_pos and qtl_weight are arrays, while mu
37 and sigma_sq, are simply pointers to single reals. QCTM may possibly
38 send messages CRASH, SINGMAT, or MATMULT, which indicate failure. In
39 this case, the QTL_MAP results are undefined. No memory is allocated
40 by qctm (for efficiency, all big things are static), and thus no
41 cleanup after these messages is required.
42 *********************************************************************/
43 
44 /* Pretty much everything that happens to data produced by qctm does
45    (and should) happen using the QTL_MAP struct... */
46 
47 /* Constraints for the intercross weight and dominance terms:
48    a * weight + b * dominance = c */
49 
50 typedef struct {
51     real backx_weight;  /* used for backx only, the rest are for interx only */
52     int interx_type;    /* defined immediately below */
53     real a, b, c;
54 } GENETICS;
55 #define FREE        0
56 #define DOMINANT    1
57 #define RECESSIVE   2
58 #define ADDITIVE    3
59 #define CONSTRAINED 4
60 #define FIXED       5
61 #define TEST_MODELS 6  /* TEST_MODELS is only allowed inside QTL_SEQUENCEs */
62 #define NUM_MODELS  4  /* 0-3 as FIXED and CONSTRAINED models don't count */
63 #define F3DOMINANT  7
64 #define F3RECESSIVE 8
65 
66 typedef struct {
67     int trait;
68     int num_intervals;
69     int num_continuous_vars;
70     int max_intervals;			/* max # allocated for */
71     int max_continuous_vars;
72     int *left, *right;			/* [interval#] => left & right loci */
73     real *interval_len; 		/* [interval#] => a rec frac */
74     real *qtl_pos;			/* [interval#] also is a r.f. */
75     real *fix_pos;	     	        /* [interval#] is DONT_FIX or a r.f. */
76     real *qtl_weight;			/* [interval#] */
77     real *qtl_dominance;                /* [interval#] only for intercross! */
78     int  *cont_var;			/* [cont_var#] => a valid trait# */
79     real *cont_var_weight; 		/* [cont_var#] */
80     real *fix_cont_var_weight; 		/* [cont_var#] */
81     GENETICS *constraint;               /* an array of #intervals structs */
82     real mu, sigma_sq, var_explained, chi_sq;
83     real null_mu, null_sigma_sq, null_log_like;
84     real log_like, no_data_like, abs_log_like;
85 } QTL_MAP;
86 
87 #define DONT_FIX   OBSCURE_REAL         /* use for fix_pos or fix_weight */
88 #define EPISTASIS_TERM -1 		/* special cont-var */
89 
90 /*** handy functions in QCTM.C ***/
91 
92 /*** things in QDATA.C ***/
93 bool qctm_globals_avail();
94 void alloc_qctm_globals();
95 void free_qctm_globals();
96 real model_prediction(); /* args: QTL_MAP *map; int indiv; */
97 
98 /*** things in QTOP.C ***/
99 QTL_MAP *alloc_qtl_map(); /* args: int n_intervals, n_continuous_vars; */
100 void free_qtl_map();
101 bool reset_map();
102 void really_reset_map();
103 int  add_interval();
104 void mapcpy();
105 void make_qtl_map(); /* args: QTL_MAP *map; sets map->trait the runs
106    prepare_data(), initial_qctm_values(), and qtl_conv_to_map() */
107 /* BAGGED THIS:
108 real qtl_map_like();  like make_qtl_map(), but it assume that the map->
109    weight, dominance, and cont_var_weight values have been set, and it
110    calls qtl_noconv_to_map(). The likelihood is returned AND map->log_like
111    is set to it. */
112 
113 void copy_genetics();
114 bool constrained(); /* args: GENETICS *genetics; */
115 
116 
117 /*** random things ***/
118 #define INF_LOCUS 	-1
119 #define NO_LOCUS 	-2
120 #define ANY_LOCUS 	-3
121 #define VERY_UNLIKELY	-1e30
122 /* #define NO_TRAIT	-1 */
123 
124 
125 
126