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 
15 /********************** Raw Data Struct ************************************/
16 
17 /* symbols used for F2 data preparation and storage */
18 #define PARENTAL_TYPE_A           'A'
19 #define PARENTAL_TYPE_B           'B'
20 #define TYPE_NOT_A                'C'
21 #define TYPE_NOT_B                'D'
22 #define HYBRID_TYPE_H             'H'
23 #define MISSING_DATA              '-'
24 
25 /* Definition for f2 raw data storage. */
26 typedef struct {
27     int         num_indivs;
28     int         cross_type;              /* F2_INTERCROSS or F2_BACKCROSS */
29     real        **allelic_distribution;  /* [loci][4: AA,AB,BA,BB] */
30     char        **allele;                /* [loci][indivs] */
31 }       F2_RAW;
32 
33 typedef struct {
34     char        filename[PATH_LENGTH+1]; /* raw data file */
35     int         filenumber;       	 /* for concurrency checks */
36     int         data_type;        	 /* defined above */
37     int 	num_markers;
38     char        **locus_name;     	 /* [loci][MAX_NAME_LEN] */
39     union {
40 #ifdef HAVE_CEPH
41     	CEPH_RAW      	ceph;             /* definition in ceph.h?? */
42 #endif
43     	F2_RAW   	f2;
44     } data;
45 } RAW_DATA;
46 
47 extern RAW_DATA raw;
48 
49 /****************************************************************************/
50 
51 
52 /* Guts of things used only inside converge_to_map. Much of this is for the
53    old_ctm implementation of F2 etc will be obsoleted by HMM... */
54 
55 #define RIGHT 		1
56 #define LEFT		0
57 #define NEGATIVE        1
58 #define POSITIVE        0
59 
60 typedef real   RECVECTOR[2];
61 typedef real   RECARRAY[2][2];
62 typedef char   CONV_HIST;
63 typedef int    (*PFI)();   /* pointer to function returning an integer */
64 typedef int    (*PFB)();   /* pointer to function returning a bool(int) */
65 
66 /* Locus structure for converge_to_map() down.  Used to store
67    the markers that converge_to_map() is being used on. */
68 typedef struct {
69     int         size;
70     int         *Entry;
71 } LOCUS;
72 
73 #ifdef HAVE_CEPH
74 /*****************************************************************************
75                        COOKED CEPH-DATA
76 *****************************************************************************/
77 
78 /* Processed data storage for phase known */
79 typedef struct {
80     int         num_markers;
81     int         num_families;
82     FLDB        **fldb;      /* as in CEPH_RAW, KNOWN data needs */
83 }       KNOWN_COMMUNITY;             /* no preprocessing */
84 
85 /* Processed data for phase unknown program */
86 typedef struct {
87     event_vector event[2];      /* [event] */
88     real prob[2];     	/* [side] */
89     real ap_prob;      	/* a priori probability */
90 } INHER_VECTOR;
91 
92 typedef struct {
93     int eff_locus[2];		/* effective parental locus */
94     int non_informative;	/* true iff non-inf for both parents */
95     long index;			/* size of dist */
96     INHER_VECTOR *dist;		/* probability distribution */
97 } INHER_STR;
98 
99 typedef struct {
100     INHER_STR *genes;
101     int kids;		        /* number of kids in family */
102 } FAMILY;
103 
104 typedef struct {
105     FAMILY *family;
106     int num_fams;	        /* number of families */
107 } UNKNOWN_COMMUNITY;
108 
109 /* Definitions used in the count_recs() procedures */
110 #define LOCUS_AT_INFINITY -1
111 #define TWO_TO_MAX_KIDS 32768
112 
113 typedef struct {
114     long size;
115     int eff_locus;
116     event_vector Entry[TWO_TO_MAX_KIDS];
117 } PREV_LOCUS;
118 
119 #endif
120 
121 
122 /*****************************************************************************
123 			COOKED F2 TYPE DATA
124 *****************************************************************************/
125 
126 #define NEUTER                      0
127 #define APRIORI                     2
128 
129 /* Definition for processed backcross data storage. */
130 /* As with phase known data, backcross data needs no preprocessing. */
131 typedef struct {
132     int         num_markers;
133     int         num_indivs;
134     char        **allele;         /* [loci][indivs], as in F2_RAW */
135 }       BACKX_GENERATION;
136 
137 /* Processed intercross data storage. */
138 typedef struct {
139     int 	index;
140     bool     non_informative;
141     int         event[4];        /* event: AA,AB,BA,BB */
142     real      prob_dist[3][4]; /* [apriori,left,right][event: AA,AB,BA,BB] */
143 }		F2_INHER_STR;
144 
145 typedef real PROB_DIST[3][4];  /* as in F2_INHER_STR */
146 
147 typedef struct {
148     int             number_indivs;
149     F2_INHER_STR    **data;
150 }                   F2_GENERATION;
151 
152 
153 /* processed data structure - created in the various init_for_em procedures */
154 typedef union {
155 #ifdef HAVE_CEPH
156     KNOWN_COMMUNITY	*known;        /* in ceph.h */
157     UNKNOWN_COMMUNITY	*unknown;      /* in ceph.h */
158 #endif
159     F2_GENERATION	*f2;           /* in f2.h */
160     BACKX_GENERATION    *backcross;    /* in f2.h */
161 }	PROCESSED_DATA;
162 
163 
164 /* Functions */
165 /*in ctm.c */
166 void converge_to_map();  /* arg: MAP; calls map making functions and returns
167 			    the converged map (alters: rec_frac, log-like) */
168 /* in multipt.c */
169 void allocate_recs();    /* These procedures are called by converge_to_map */
170 void allocate_temps();   /* and assist in the map making. */
171 void free_memory_temps();
172 void no_history();
173 bool norm_conv_rule();
174 bool norm_inner_conv_rule();
175 bool inner_converge_instantly();
176 bool converge_instantly();
177 void norm_make_new_map();
178 
179 /* map making procedures (separated by data type) */
180 /* in interx.c */
181 void f2_init_for_em();
182 void f2_count_recs();
183 void f2_free_memory_from_em();
184 /* the following are also in interx.c but are used by other functions */
185 int symbol_value();
186 int changes();
187 real f2_prob(), f3_prob();
188 real power();
189 
190 /* in known.c */
191 void known_init_for_em();
192 void known_count_recs();
193 void known_free_memory_from_em();
194 
195 /* in backx.c */
196 void backcross_init_for_em();
197 void backcross_count_recs();
198 void backcross_free_memory_from_em();
199 
200 /* in unk_init.c */
201 void unk_init_for_em();
202 void unk_free_memory_from_em();
203 /*in unk_cnt.c */
204 void unk_count_recs();
205 
206 /* in new_count.c */
207 void new_unk_init_for_em();
208 void new_unk_free_memory_from_em();
209 void new_unk_count_recs();
210 
211 
212 /* Constant definitions useful in converge_to_map() and
213    lower map making procedures. */
214 #define NUM_CONV_RULES 1
215 #define NORMAL_CONVERGENCE 0
216 #define NUM_INNER_CONV_RULES 1
217 #define NORM_INNER_CONVERGENCE 0
218 
219 #define UNINFORM	-1             /* Defs for marker types */
220 #define INFORM		0              /*   and zygosity.  	*/
221 #define HETERO		INFORM
222 #define HOMO		UNINFORM
223 #define EITHER		4
224 #define FIRSTHETERO	2
225 
226 #define REC 		1
227 #define NOREC 		0
228 #define for_recs(r)	for(r=REC;r>=NOREC;r--)
229 
230 #define SMALLRECOMBS    0.00001
231 #define BIGRECOMBS      0.50
232 
233 
234