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 /* qlow.h - declarations needed only deep within the bowls of QCTM */
15 
16 /* These locus and interval genotype codes are used in lots of places.
17    Do NOT change these definitions: if you do, all hell may break loose!
18    Here A means an A/A individual, B means B/B, H means A/B, and
19    I means B/A. For BACKCROSS, use A and H, not A and B for consistency
20    (in particular, so that count_recs and a few other things work).
21    The possible genotype encoding software in qraw.c presumes the
22    codes defined here! */
23 
24 #define MAX_LOCUS_GENOTYPES 3
25 #define A 0
26 #define H 1
27 #define B 2
28 #define I 3 /* not used */
29 
30 #define for_locus_genotypes(data_type,geno) \
31  for (geno=0; geno<(data_type==BACKCROSS ? 2:3); geno++)
32 
33 #define MAX_INTERVAL_GENOTYPES 9
34 #define AA 0
35 #define AH 1
36 #define HA 2
37 #define HH 3
38 #define AB 4
39 #define HB 5
40 #define BA 6
41 #define BB 7
42 #define BH 8
43 
44 #define for_interval_genotypes(data_type,geno) \
45  for (geno=0; geno<(data_type==BACKCROSS ? 4:9); geno++)
46 /**** used to be 3 for BACKCROSS - bug fix 6/7/90 ****/
47 
48 /* these are declared and set in qraw.c */
49 extern int *left_genotype, *right_genotype;
50     /* index with an interval genotype code => locus genotype code */
51 extern int **make_interval_genotype;
52     /* index with [left_genotype_code][right_genotype_code]=> interval code */
53 
54 typedef real INTERVAL_GENOTYPE_PROBS[16], LOCUS_GENOTYPE_PROBS[4];
55 typedef real GENO_PROBS[9][4];    /* 16 and 4 for indexing efficiency */
56 typedef int  INT_POSS_GENOTYPES[16];
57 
58 #define MAX_RECS        2
59 #define MAX_REC_FRAC	0.49995
60 #define MIN_REC_FRAC	0.00004
61 #define MAX_FRAC_OF_RF	0.99999
62 #define MAX_CM		998.5
63 #define MIN_CM		0.04
64 #define MAX_FRAC_OF_CM  0.99999
65 #define MAX_CHROM_LOC   100
66 
67 /*** This struct holds the data needed by QCTM ***/
68 
69 typedef struct {
70     int  num_intervals;
71     int  num_individuals;	/* < raw.n_indivs if some are missing pheno */
72     int  num_continuous_vars;
73     int  max_intervals;		/* max # this struct is allocated for */
74     int  max_individuals;
75     int  max_continuous_vars;
76     real *interval_len; 	/* [interval#] => length (a rec-frac really) */
77     INTERVAL_GENOTYPE_PROBS **genotype_prob;    /* [indiv#][int#][geno-code] */
78     real *phenotype; 		/* [individual#] */
79     real **cont_var;		/* [var#][individual#] */
80     int  **num_genotypes;	/* [individual#][interval#]=> #of poss genos */
81     INT_POSS_GENOTYPES **genotype; /* [individual#][interval#][genotype_num] */
82 } DATA;
83 
84 extern DATA *data; /* a global used by make_qtl_map() */
85 
86 /*** Functions in QDATA.C ***/
87 DATA *alloc_data();  /* args: int max_intervals, max_continuous_vars; */
88 void free_data();    /* args: DATA *ptr; */
89 
90 void prepare_data(); /* args: QTL_MAP *map; DATA *data; in qdata.c */
91 /* Prepare_data() uses the trait, left, right and num_intervals elements
92    of the map struct, along with the global raw struct, to side-effect an
93    existing data struct. */
94 
95 void initial_qctm_values(); /* args: DATA *data; QTL_MAP *map; in qdata.c */
96 /* map->fix_pos, ->fix_weight, ->fix_dominance, ->trait, ->left, and
97    ->right must be set, and prepare_data() must have been run on data;
98    map is side-effected. */
99 
100 /*** In QCTM.C ***/
101 void qtl_conv_to_map(); /* args: DATA *data; QTL_MAP *map; in qctm.c */
102 /* side-effects map */
103 
104 /* Those three routines do all the work needed to make QTL maps. */
105 
106 /* These are in qprint.c, and are called in the guts of QCTM */
107 void print_iteration();
108 void print_null_iteration();
109 void do_print_E_step();
110 
111 
112 /*** QCTM's state and global variables - declared and used in qctm.c, but
113      alloced in qdata.c ***/
114 
115 extern int max_intervals; /* this var is used all over the code */
116 extern int max_genotype_vars;
117 extern int max_interx_genotypes, max_backx_genotypes;
118 extern int **lookup_genotype;
119 extern real **lookup_coded_genotype;
120 
121 extern real **expected_genotype;
122 extern real **S_matrix, **S_inverse;
123 extern real **indiv_S_matrix;
124 extern real *int_like;
125 extern real *qctm_qtl_pos;
126 extern real *qctm_qtl_weight, *null_qtl_weight, *fix_qtl_weight;
127 extern real *temp_row;
128 extern GENO_PROBS *indiv_rec_like;
129 extern GENO_PROBS *expected_recs, *trans_prob;
130 extern INTERVAL_GENOTYPE_PROBS *rec_like;
131 extern char geno_chars[10],default_backcross_chars[10];
132 extern char default_intercross_chars[10];
133 
134 
135 /***** Stuff one needs to muck around with RAW data *****/
136 
137 typedef struct {
138         int data_type;  	/* valid data types are defined in qg.h */
139 	bool f3;
140 	char file[PATH_LENGTH+1];
141 	int filenumber;
142 	int n_loci, n_traits, max_traits;
143 	int n_indivs, name_len;
144 	int n_chroms;
145 	int *original_locus;   /* [qtl_locus_number] */
146 	int *chrom_start, *chrom_n_loci;
147 	char **locus;		/* [indvidual][locus#] => one char genotype */
148 	char **locus_name;	/* [locus#] => string */
149 	LOCUS_GENOTYPE_PROBS **left_cond_prob, **right_cond_prob;
150 	                        /* [indiv#][locus#][locus-geno-code] */
151 	real **trait;		/* [individual#][trait#] */
152 	char **trait_name;	/* [trait#] => string */
153 	char **trait_eqn;	/* [trait#] => string */
154 	real *map_dist;		/* [locus#] for dist to locus[locus#+1] */
155 } RAW;
156 /* FROB */
157 #define MAX_TRAITS(traits_in_file)(traits_in_file>10 ? 6*(traits_in_file) : 20)
158 #define MISSING_PHENO	-100000.0
159 
160 extern RAW raw;
161 
162 /*** Functions defined in QRAW.C ***/
163 void raw_init();             /* no args */
164 void read_data();            /* args FILE *fp; char *path; */
165 void read_olddata();         /* same args as read_data     */
166 void crunch_data();          /* no args; makes L&R cond_probs in raw struct */
167 bool data_loaded();          /* no args; return TRUE if data is loaded */
168 real map_length();           /* args: int left_locus, right_locus; */
169 real transition_prob();      /* args: int data_type, left, right; real theta;*/
170 real apriori_prob();         /* args: int data_type, geno; */
171 void indiv_interval_probs(); /* args: INTERVAL_GENOTYPE_PROBS *prob;
172 			        int index, indiv, left, right; real theta; */
173 void save_traitfile();       /* command call "store status" */
174 void free_raw();             /* no args; never been used! */
175 
176 
177 
178 /* Definitions from MAPMAKER needs for prep_dat */
179 typedef struct {
180     int         max_loci;
181     int         num_loci;
182     int         *locus;         /* [num_loci] (markers in the map) */
183     double      **rec_frac;     /* [intervals][M/F], recombination fractions */
184     int         unlink;         /* indicates interval (if any) held unlinked */
185     int         *fix_interval;  /* [intervals], intervals not converging */
186     int         sex_specific;
187     double      log_like;
188 }       MAP;
189 
190 extern MAP *raw_map;
191 
192 typedef struct {
193     int         max_maps;      /* used in allocation of structure */
194     int         max_loci;      /* used in allocation of structure */
195     MAP         **map_list;    /* list of max_maps pointers to MAPs */
196     MAP         *extra_map;    /* expendable map-for insertion and deletion */
197     int         num_maps;      /* number of maps in map_list (<= max_maps) */
198     double      threshold;     /* highest acceptable likelihood when sorting */
199     bool        sorted;        /* determines whether this is a sorted list */
200 } SAVED_LIST;
201 
202 extern SAVED_LIST *list;
203 
204 #define INTERCROSS_ALLELE_CHARS "ABCDH-"
205 #define NAME_LEN 10
206 #define TRAIT_EQN_LEN 250
207 #define UNSORTED 0
208 #define NONE_UNLINKED -1
209 
210 void create_status();
211 SAVED_LIST *allocate_map_list();
212 MAP *allocate_map();
213 void sort_last();
214 void free_map();
215 void free_map_list();
216 int symbol_value();
217 
218 #define PARENTAL_TYPE_A           'A'
219 #define PARENTAL_TYPE_B           'B'
220 #define TYPE_NOT_A                'C'
221 #define TYPE_NOT_B                'D'
222 #define HYBRID_TYPE_H             'H'
223 #define MISSING_DATA              '-'
224 
225 extern bool fix_weight_kludge; /* BIG KLUDGE for tweak-weight cmd */
226