annotate mrcanavar-0.34/gcnorm.c @ 0:86522a0b5f59 default tip

Uploaded source code for mrCaNaVaR
author calkan
date Tue, 21 Feb 2012 10:44:13 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
1 #include "gcnorm.h"
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
2
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
3 int norm_until_converges (enum WINDOWTYPE wt, float *gclookup, float *gclookup_x){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
4 float max;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
5 float max_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
6 float min;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
7 float min_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
8
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
9 float p_max;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
10 float p_max_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
11 float p_min;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
12 float p_min_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
13
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
14 int i, j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
15 float mean;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
16 float mean_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
17 float stdev;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
18 float stdev_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
19 int iter;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
20
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
21 float maxcut;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
22 float maxcut_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
23 float mincut;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
24 float mincut_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
25
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
26 iter = 1;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
27 calc_stat(wt, gclookup, gclookup_x, 0, &max, &max_x, &min, &min_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
28
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
29 switch(wt){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
30 case LW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
31 mean = LW_MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
32 mean_x = LW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
33 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
34 case SW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
35 mean = SW_MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
36 mean_x = SW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
37 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
38 case CW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
39 mean = CW_MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
40 mean_x = CW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
41 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
42 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
43
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
44
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
45 if (GENDER == AUTODETECT){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
46 if (VERBOSE)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
47 fprintf(stdout, "MEAN: %f\tMEAN_X: %f\n", mean, mean_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
48
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
49
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
50 if (mean_x / mean < 0.75){ // magical ratio
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
51 GENDER = MALE;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
52
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
53 if (VERBOSE)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
54 fprintf(stdout, "Autodetect Gender: Male\n");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
55
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
56 i = findChrom("chrX", "", -1);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
57
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
58
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
59 switch(wt){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
60
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
61 case CW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
62 for (j=0; j<chromosomes[i]->cw_cnt; j++)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
63 if (chromosomes[i]->cw[j].depth > (float) CW_MEAN_X * 2 || chromosomes[i]->cw[j].depth < (float) CW_MEAN_X / 10.0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
64 chromosomes[i]->cw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
65 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
66
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
67 case LW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
68 for (j=0; j<chromosomes[i]->lw_cnt; j++)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
69 if (chromosomes[i]->lw[j].depth > (float) LW_MEAN_X * 2 || chromosomes[i]->lw[j].depth < (float) LW_MEAN_X / 10.0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
70 chromosomes[i]->lw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
71 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
72
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
73 case SW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
74 for (j=0; j<chromosomes[i]->sw_cnt; j++)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
75 if (chromosomes[i]->sw[j].depth > (float) SW_MEAN_X * 2 || chromosomes[i]->sw[j].depth < (float) SW_MEAN_X / 10.0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
76 chromosomes[i]->sw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
77 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
78
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
79 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
80
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
81 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
82 else{
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
83 GENDER = FEMALE;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
84 if (VERBOSE)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
85 fprintf(stdout, "Autodetect Gender: Female\n");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
86 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
87 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
88
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
89 normalize(wt, gclookup, gclookup_x, &max, &max_x, &min, &min_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
90
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
91
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
92 do{
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
93
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
94 if (VERBOSE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
95 fprintf(stdout, "Control regions %s iteration %d ", (wt == LW ? "LW" : (wt == SW ? "SW" : "CW")), iter);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
96 fflush(stdout);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
97 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
98
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
99
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
100
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
101 p_min = min;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
102 p_max = max;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
103 p_min_x = min_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
104 p_max_x = max_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
105
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
106 calc_stat(wt, gclookup, gclookup_x, 1, &max, &max_x, &min, &min_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
107
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
108
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
109 switch(wt){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
110 case LW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
111 mean = LW_MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
112 stdev = LW_STD;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
113 mean_x = LW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
114 stdev_x = LW_STD_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
115 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
116 case SW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
117 mean = SW_MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
118 stdev = SW_STD;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
119 mean_x = SW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
120 stdev_x = SW_STD_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
121 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
122 case CW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
123 mean = CW_MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
124 stdev = CW_STD;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
125 mean_x = CW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
126 stdev_x = CW_STD_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
127 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
128 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
129
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
130
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
131 if (GENDER == FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
132 max_x = max;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
133 mean_x = mean;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
134 stdev_x = stdev;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
135 min_x = min;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
136 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
137
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
138
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
139 iter++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
140
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
141
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
142 maxcut = mean + 2.5 * stdev;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
143 mincut = mean - 2.5 * stdev;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
144 maxcut_x = mean_x + 2.5 * stdev_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
145 mincut_x = mean_x - 2.5 * stdev_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
146
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
147 if (GENDER != FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
148 maxcut_x = mean_x + 2 * stdev_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
149 mincut_x = mean_x - 2 * stdev_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
150 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
151
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
152 if (mincut < 0.0) mincut = mean / 10.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
153 if (mincut_x < 0.0) mincut_x = mean_x / 10.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
154
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
155 if (maxcut - mean > mean - mincut)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
156 maxcut = mean + (mean - mincut);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
157
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
158 if (GENDER != FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
159 if (maxcut_x - mean_x > mean_x - mincut_x)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
160 maxcut_x = mean_x + (mean_x - mincut_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
161 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
162
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
163
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
164 if (VERBOSE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
165 fprintf(stdout, "mean: %f\tstdev: %f\tmax: %f (cut: %f)\tmin: %f (cut: %f) \n", mean, stdev, max, maxcut, min, mincut);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
166 if (GENDER != FEMALE)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
167 fprintf(stdout, "mean_x: %f\tstdev_x: %f\tmax_x: %f (cut: %f)\tmin_x: %f (cut: %f)\n", mean_x, stdev_x, max_x, maxcut_x, min_x, mincut_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
168 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
169
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
170 if (p_min == min && p_max == max && p_min_x == min_x && p_max_x == max_x)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
171 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
172
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
173 } while (max >= maxcut || max_x >= maxcut_x || min <= mincut || min_x <= mincut_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
174
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
175
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
176 fprintf(stdout, "%s Normalization completed.\n", (wt == LW ? "LW" : (wt == SW ? "SW" : "CW")));
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
177
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
178 return 1;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
179 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
180
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
181
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
182 void normalize (enum WINDOWTYPE wt, float *gclookup, float *gclookup_x, float *max, float *max_x, float *min, float *min_x){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
183 int gc_index;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
184 float new_depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
185 int i, j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
186
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
187 float total, total_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
188 int win_cnt, win_cnt_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
189
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
190 total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
191 win_cnt = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
192 total_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
193 win_cnt_x = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
194
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
195
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
196 switch(wt){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
197 case LW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
198 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
199 for (j=0; j<chromosomes[i]->lw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
200 gc_index = chromosomes[i]->lw[j].gc * (float) GC_BIN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
201 if ((!strstr(chromosomes[i]->name, "chrX") && !strstr(chromosomes[i]->name, "chrY")) || GENDER == FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
202 if (MULTGC)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
203 new_depth = gclookup[i] * chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
204 else
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
205 new_depth = chromosomes[i]->lw[j].depth - (gclookup[gc_index] - LW_MEAN);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
206 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
207 else if ((strstr(chromosomes[i]->name, "chrX") || strstr(chromosomes[i]->name, "chrY")) && GENDER == MALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
208 if (MULTGC)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
209 new_depth = gclookup_x[i] * chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
210 else
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
211 new_depth = chromosomes[i]->lw[j].depth - (gclookup_x[gc_index] - LW_MEAN_X);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
212 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
213
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
214 if (new_depth < 0) new_depth = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
215
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
216 chromosomes[i]->lw[j].depth = new_depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
217 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
218 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
219 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
220
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
221 case SW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
222 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
223 for (j=0; j<chromosomes[i]->sw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
224 gc_index = chromosomes[i]->sw[j].gc * (float) GC_BIN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
225 if ((!strstr(chromosomes[i]->name, "chrX") && !strstr(chromosomes[i]->name, "chrY")) || GENDER == FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
226 if (MULTGC)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
227 new_depth = gclookup[i] * chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
228 else
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
229 new_depth = chromosomes[i]->sw[j].depth - (gclookup[gc_index] - SW_MEAN);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
230 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
231 else if ((strstr(chromosomes[i]->name, "chrX") || strstr(chromosomes[i]->name, "chrY")) && GENDER == MALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
232 if (MULTGC)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
233 new_depth = gclookup_x[i] * chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
234 else
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
235 new_depth = chromosomes[i]->sw[j].depth - (gclookup_x[gc_index] - SW_MEAN_X);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
236 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
237
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
238 if (new_depth < 0) new_depth = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
239 chromosomes[i]->sw[j].depth = new_depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
240 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
241 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
242 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
243
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
244 case CW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
245 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
246 for (j=0; j<chromosomes[i]->cw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
247 gc_index = chromosomes[i]->cw[j].gc * (float) GC_BIN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
248 if ((!strstr(chromosomes[i]->name, "chrX") && !strstr(chromosomes[i]->name, "chrY")) || GENDER == FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
249 if (MULTGC)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
250 new_depth = gclookup[i] * chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
251 else
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
252 new_depth = chromosomes[i]->cw[j].depth - (gclookup[gc_index] - CW_MEAN);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
253 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
254 else if ((strstr(chromosomes[i]->name, "chrX") || strstr(chromosomes[i]->name, "chrY")) && GENDER == MALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
255 if (MULTGC)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
256 new_depth = gclookup_x[i] * chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
257 else
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
258 new_depth = chromosomes[i]->cw[j].depth - (gclookup_x[gc_index] - CW_MEAN_X);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
259 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
260
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
261 if (new_depth < 0) new_depth = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
262
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
263 chromosomes[i]->cw[j].depth = new_depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
264 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
265 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
266 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
267 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
268
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
269
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
270
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
271 calc_stat(wt, gclookup, gclookup_x, 0, max, max_x, min, min_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
272
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
273 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
274
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
275
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
276 void calc_stat(enum WINDOWTYPE wt, float *gclookup, float *gclookup_x, char doClean, float *_max, float *_max_x, float *_min, float *_min_x){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
277 int i, j, k;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
278
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
279 float lw_var;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
280 float sw_var;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
281 float cw_var;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
282
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
283 float lw_total;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
284 float sw_total;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
285 float cw_total;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
286
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
287 float lw_var_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
288 float sw_var_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
289 float cw_var_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
290
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
291 float lw_total_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
292 float sw_total_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
293 float cw_total_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
294
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
295 int win_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
296 float max;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
297
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
298 int win_cnt_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
299 float max_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
300
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
301 float min;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
302 float min_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
303
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
304 int gc_index;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
305
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
306 float gc_total[GC_BIN]; // total depth by GC
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
307 int gc_wincount[GC_BIN]; // count of windows with the given GC content
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
308
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
309 float gc_total_x[GC_BIN]; // total depth by GC
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
310 int gc_wincount_x[GC_BIN]; // count of windows with the given GC content
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
311
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
312 float MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
313 float MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
314
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
315
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
316 float maxcut, mincut;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
317 float maxcut_x, mincut_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
318
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
319 lw_var = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
320 sw_var = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
321 cw_var = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
322
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
323 lw_total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
324 sw_total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
325 cw_total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
326
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
327 win_cnt = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
328
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
329 lw_var_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
330 sw_var_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
331 cw_var_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
332
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
333 lw_total_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
334 sw_total_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
335 cw_total_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
336
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
337 win_cnt_x = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
338
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
339 for (i=0; i<GC_BIN; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
340 gc_total[i] = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
341 gclookup[i] = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
342 gc_wincount[i] = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
343
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
344 gc_total_x[i] = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
345 gclookup_x[i] = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
346 gc_wincount_x[i] = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
347 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
348
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
349 max = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
350 max_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
351
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
352 min = FLT_MAX;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
353 min_x = FLT_MAX;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
354
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
355 /*
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
356
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
357 NOTE:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
358
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
359 As of November 11, 2010, only CW implementation is reliable.
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
360
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
361
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
362 */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
363
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
364 switch (wt){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
365 case LW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
366
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
367 if (doClean){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
368
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
369 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
370 for (j=0; j<chromosomes[i]->lw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
371
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
372 if (chromosomes[i]->lw[j].isControl == 1){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
373
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
374 /* AUTOSOMES -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
375 if (!strstr(chromosomes[i]->name, "chrX") || GENDER == FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
376
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
377 maxcut = LW_MEAN + 2.5 * LW_STD;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
378 mincut = LW_MEAN - 2.5 * LW_STD;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
379 if (mincut < LW_MEAN / 10.0) mincut = LW_MEAN / 10.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
380
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
381 if (maxcut - LW_MEAN > LW_MEAN - mincut)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
382 maxcut = LW_MEAN + (LW_MEAN - mincut);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
383
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
384 if (chromosomes[i]->lw[j].depth > maxcut || chromosomes[i]->lw[j].depth < mincut){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
385
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
386 /* Remove this window and its neighbors from controls */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
387 chromosomes[i]->lw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
388
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
389 k = j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
390
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
391 while (k > 0 && chromosomes[i]->lw[k-1].end >= chromosomes[i]->lw[j].start){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
392 chromosomes[i]->lw[--k].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
393 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
394
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
395 k = j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
396
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
397 while (k < chromosomes[i]->lw_cnt-1 && chromosomes[i]->lw[k+1].start <= chromosomes[i]->lw[j].end){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
398 chromosomes[i]->lw[++k].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
399 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
400
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
401 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
402
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
403 else{
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
404 lw_total += chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
405 win_cnt++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
406 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
407 } // if AUTOSOME
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
408
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
409
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
410 /* chrX -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
411 else if (strstr(chromosomes[i]->name, "chrX") && GENDER != FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
412
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
413 maxcut_x = LW_MEAN_X + 2 * LW_STD_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
414 mincut_x = LW_MEAN_X - 2 * LW_STD_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
415 if (mincut_x < LW_MEAN_X / 10.0) mincut_x = LW_MEAN_X / 10.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
416
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
417 if (chromosomes[i]->lw[j].depth > maxcut_x || chromosomes[i]->lw[j].depth < mincut_x){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
418
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
419 /* Remove this window and its neighbors from controls */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
420 chromosomes[i]->lw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
421
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
422 k = j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
423
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
424 while (k > 0 && chromosomes[i]->lw[k-1].end >= chromosomes[i]->lw[j].start){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
425 chromosomes[i]->lw[--k].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
426 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
427
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
428 k = j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
429
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
430 while (k < chromosomes[i]->lw_cnt-1 && chromosomes[i]->lw[k+1].start <= chromosomes[i]->lw[j].end){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
431 chromosomes[i]->lw[++k].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
432 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
433 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
434
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
435 else{
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
436 lw_total_x += chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
437 win_cnt_x++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
438 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
439 } // if chrX
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
440
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
441 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
442
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
443 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
444 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
445
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
446 LW_MEAN_X = lw_total_x / win_cnt_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
447 LW_MEAN = lw_total / win_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
448
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
449 } // do clean
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
450
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
451 lw_total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
452 win_cnt = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
453 lw_total_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
454 win_cnt_x = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
455
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
456 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
457 for (j=0; j<chromosomes[i]->lw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
458
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
459 if (chromosomes[i]->lw[j].isControl == 1){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
460
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
461 /* AUTOSOMES -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
462 if (!strstr(chromosomes[i]->name, "chrX") || GENDER==FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
463
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
464 lw_var += (LW_MEAN - chromosomes[i]->lw[j].depth) * (LW_MEAN - chromosomes[i]->lw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
465 win_cnt++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
466
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
467 lw_total += chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
468 gc_index = chromosomes[i]->lw[j].gc * GC_BIN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
469 gc_total[gc_index] += chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
470 gc_wincount[gc_index]++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
471
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
472 if (chromosomes[i]->lw[j].depth > max)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
473 max = chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
474 if (chromosomes[i]->lw[j].depth < min)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
475 min = chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
476
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
477 } // AUTOSOMES
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
478
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
479 /* chrX -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
480 else if (strstr(chromosomes[i]->name, "chrX") && GENDER != FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
481
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
482 lw_var_x += (LW_MEAN_X - chromosomes[i]->lw[j].depth) * (LW_MEAN_X - chromosomes[i]->lw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
483 win_cnt_x++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
484
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
485 lw_total_x += chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
486 gc_index = chromosomes[i]->lw[j].gc * GC_BIN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
487 gc_total_x[gc_index] += chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
488 gc_wincount_x[gc_index]++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
489
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
490 if (chromosomes[i]->lw[j].depth > max_x)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
491 max_x = chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
492 if (chromosomes[i]->lw[j].depth < min_x)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
493 min_x = chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
494
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
495 } // chrX
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
496
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
497
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
498 } // if control
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
499 } // outer for
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
500 } // if (!doClean)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
501
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
502 LW_MEAN_X = lw_total_x / win_cnt_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
503 LW_STD_X = sqrt(lw_var_x / win_cnt_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
504
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
505 LW_MEAN = lw_total / win_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
506 LW_STD = sqrt(lw_var / win_cnt);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
507
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
508 MEAN = LW_MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
509 MEAN_X = LW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
510
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
511 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
512
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
513 case SW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
514
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
515
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
516 if (doClean){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
517 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
518 for (j=0; j<chromosomes[i]->sw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
519
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
520 if (chromosomes[i]->sw[j].isControl == 1){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
521
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
522 /* AUTOSOMES -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
523 if (!strstr(chromosomes[i]->name, "chrX") || GENDER == FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
524
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
525 maxcut = SW_MEAN + 2.5 * SW_STD;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
526 mincut = SW_MEAN - 2.5 * SW_STD;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
527 if (mincut < SW_MEAN / 10.0) mincut = SW_MEAN / 10.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
528
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
529 if (maxcut - SW_MEAN > SW_MEAN - mincut)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
530 maxcut = SW_MEAN + (SW_MEAN - mincut);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
531
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
532 if (chromosomes[i]->sw[j].depth > maxcut || chromosomes[i]->sw[j].depth < mincut){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
533
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
534 /* Remove this window and its neighbors from controls */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
535 chromosomes[i]->sw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
536
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
537 k = j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
538
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
539 while (k > 0 && chromosomes[i]->sw[k-1].end >= chromosomes[i]->sw[j].start){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
540 chromosomes[i]->sw[--k].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
541 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
542
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
543 k = j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
544
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
545 while (k < chromosomes[i]->sw_cnt-1 && chromosomes[i]->sw[k+1].start <= chromosomes[i]->sw[j].end){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
546 chromosomes[i]->sw[++k].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
547 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
548
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
549 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
550
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
551 else{
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
552 sw_total += chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
553 win_cnt++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
554 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
555 } // if AUTOSOME
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
556
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
557
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
558 /* chrX -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
559 else if (strstr(chromosomes[i]->name, "chrX") && GENDER != FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
560
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
561 maxcut_x = SW_MEAN_X + 2 * SW_STD_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
562 mincut_x = SW_MEAN_X - 2 * SW_STD_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
563 if (mincut_x < SW_MEAN_X / 10.0) mincut_x = SW_MEAN_X / 10.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
564
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
565 if (chromosomes[i]->sw[j].depth > maxcut_x || chromosomes[i]->sw[j].depth < mincut_x){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
566
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
567 /* Remove this window and its neighbors from controls */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
568 chromosomes[i]->sw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
569
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
570 k = j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
571
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
572 while (k > 0 && chromosomes[i]->sw[k-1].end >= chromosomes[i]->sw[j].start){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
573 chromosomes[i]->sw[--k].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
574 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
575
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
576 k = j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
577
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
578 while (k < chromosomes[i]->sw_cnt-1 && chromosomes[i]->sw[k+1].start <= chromosomes[i]->sw[j].end){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
579 chromosomes[i]->sw[++k].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
580 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
581 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
582
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
583 else{
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
584 sw_total_x += chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
585 win_cnt_x++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
586 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
587 } // if chrX
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
588
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
589 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
590
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
591 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
592 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
593
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
594 SW_MEAN_X = sw_total_x / win_cnt_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
595 SW_MEAN = sw_total / win_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
596
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
597 } // do clean
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
598
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
599 sw_total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
600 win_cnt = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
601 sw_total_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
602 win_cnt_x = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
603
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
604 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
605 for (j=0; j<chromosomes[i]->sw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
606
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
607 if (chromosomes[i]->sw[j].isControl == 1){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
608
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
609 /* AUTOSOMES -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
610 if (!strstr(chromosomes[i]->name, "chrX") || GENDER==FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
611
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
612 sw_var += (SW_MEAN - chromosomes[i]->sw[j].depth) * (SW_MEAN - chromosomes[i]->sw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
613 win_cnt++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
614
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
615 sw_total += chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
616 gc_index = chromosomes[i]->sw[j].gc * GC_BIN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
617 gc_total[gc_index] += chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
618 gc_wincount[gc_index]++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
619
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
620 if (chromosomes[i]->sw[j].depth > max)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
621 max = chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
622 if (chromosomes[i]->sw[j].depth < min)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
623 min = chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
624
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
625 } // AUTOSOMES
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
626
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
627 /* chrX -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
628 else if (strstr(chromosomes[i]->name, "chrX") && GENDER != FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
629
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
630 sw_var_x += (SW_MEAN_X - chromosomes[i]->sw[j].depth) * (SW_MEAN_X - chromosomes[i]->sw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
631 win_cnt_x++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
632
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
633 sw_total_x += chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
634 gc_index = chromosomes[i]->sw[j].gc * GC_BIN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
635 gc_total_x[gc_index] += chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
636 gc_wincount_x[gc_index]++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
637
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
638 if (chromosomes[i]->sw[j].depth > max_x)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
639 max_x = chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
640 if (chromosomes[i]->sw[j].depth < min_x)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
641 min_x = chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
642
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
643 } // chrX
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
644
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
645
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
646 } // if control
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
647 } // outer for
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
648 } // if (!doClean)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
649
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
650 SW_MEAN_X = sw_total_x / win_cnt_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
651 SW_STD_X = sqrt(sw_var_x / win_cnt_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
652
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
653 SW_MEAN = sw_total / win_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
654 SW_STD = sqrt(sw_var / win_cnt);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
655
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
656 MEAN = SW_MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
657 MEAN_X = SW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
658
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
659
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
660 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
661
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
662 case CW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
663
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
664 if (doClean){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
665 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
666 for (j=0; j<chromosomes[i]->cw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
667
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
668
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
669 if (chromosomes[i]->cw[j].isControl == 1){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
670
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
671 /* AUTOSOMES -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
672 if (!strstr(chromosomes[i]->name, "chrX") || GENDER == FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
673
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
674 maxcut = CW_MEAN + 2.5 * CW_STD;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
675 mincut = CW_MEAN - 2.5 * CW_STD;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
676 if (mincut < CW_MEAN / 10.0) mincut = CW_MEAN / 10.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
677
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
678 if (maxcut - CW_MEAN > CW_MEAN - mincut)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
679 maxcut = CW_MEAN + (CW_MEAN - mincut);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
680
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
681 if (chromosomes[i]->cw[j].depth > maxcut || chromosomes[i]->cw[j].depth < mincut){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
682
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
683 /* Remove this window and its neighbors from controls */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
684 chromosomes[i]->cw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
685
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
686 if (j > 0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
687 chromosomes[i]->cw[j-1].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
688 if (j < chromosomes[i]->cw_cnt-1)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
689 chromosomes[i]->cw[j+1].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
690 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
691 else{
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
692 cw_total += chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
693 win_cnt++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
694 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
695 } // if AUTOSOME
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
696
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
697
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
698 /* chrX -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
699 else if (strstr(chromosomes[i]->name, "chrX") && GENDER != FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
700
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
701 maxcut_x = CW_MEAN_X + 2 * CW_STD_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
702 mincut_x = CW_MEAN_X - 2 * CW_STD_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
703 if (mincut_x < CW_MEAN_X / 10.0) mincut_x = CW_MEAN_X / 10.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
704
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
705 if (chromosomes[i]->cw[j].depth > maxcut_x || chromosomes[i]->cw[j].depth < mincut_x){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
706
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
707 /* Remove this window and its neighbors from controls */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
708 chromosomes[i]->cw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
709
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
710 if (j > 0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
711 chromosomes[i]->cw[j-1].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
712 if (j < chromosomes[i]->cw_cnt-1)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
713 chromosomes[i]->cw[j+1].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
714 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
715 else{
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
716 cw_total_x += chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
717 win_cnt_x++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
718 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
719 } // if chrX
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
720
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
721 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
722
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
723 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
724 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
725
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
726
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
727 CW_MEAN_X = cw_total_x / win_cnt_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
728
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
729 CW_MEAN = cw_total / win_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
730
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
731 } // do clean
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
732
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
733 cw_total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
734 win_cnt = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
735 cw_total_x = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
736 win_cnt_x = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
737
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
738 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
739 for (j=0; j<chromosomes[i]->cw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
740
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
741 if (chromosomes[i]->cw[j].isControl == 1){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
742
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
743 /* AUTOSOMES -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
744 if (!strstr(chromosomes[i]->name, "chrX") || GENDER==FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
745
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
746 cw_var += (CW_MEAN - chromosomes[i]->cw[j].depth) * (CW_MEAN - chromosomes[i]->cw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
747 win_cnt++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
748
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
749 cw_total += chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
750 gc_index = chromosomes[i]->cw[j].gc * GC_BIN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
751 gc_total[gc_index] += chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
752 gc_wincount[gc_index]++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
753
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
754 if (chromosomes[i]->cw[j].depth > max)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
755 max = chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
756 if (chromosomes[i]->cw[j].depth < min)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
757 min = chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
758
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
759 } // AUTOSOMES
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
760
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
761 /* chrX -- NOTE: chrY is NOT a control; it is prefiltered, no need to check for it here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
762 else if (strstr(chromosomes[i]->name, "chrX") && GENDER != FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
763
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
764 cw_var_x += (CW_MEAN_X - chromosomes[i]->cw[j].depth) * (CW_MEAN_X - chromosomes[i]->cw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
765 win_cnt_x++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
766
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
767 cw_total_x += chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
768 gc_index = chromosomes[i]->cw[j].gc * GC_BIN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
769 gc_total_x[gc_index] += chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
770 gc_wincount_x[gc_index]++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
771
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
772 if (chromosomes[i]->cw[j].depth > max_x)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
773 max_x = chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
774 if (chromosomes[i]->cw[j].depth < min_x)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
775 min_x = chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
776
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
777 } // chrX
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
778
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
779
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
780 } // if control
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
781 } // outer for
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
782 } // if (!doClean)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
783
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
784
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
785 CW_MEAN_X = cw_total_x / win_cnt_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
786 CW_STD_X = sqrt(cw_var_x / win_cnt_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
787
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
788 CW_MEAN = cw_total / win_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
789 CW_STD = sqrt(cw_var / win_cnt);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
790
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
791 MEAN = CW_MEAN;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
792 MEAN_X = CW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
793
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
794 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
795 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
796
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
797
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
798 /* calculate the gclookup table */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
799
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
800 for (i=0; i<GC_BIN; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
801
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
802 /* AUTOSOMES */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
803
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
804 if (gc_wincount[i] == 0 || gc_total[i] == 0){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
805 j=i-1;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
806
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
807 while (j >= 0 && gc_total[j] == 0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
808 j--;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
809
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
810 if (gc_total[j] == 0 || gc_wincount[j] == 0){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
811 j=i+1;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
812 while (j < GC_BIN && gc_total[j] == 0) j++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
813 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
814
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
815 gc_total[i] = gc_total[j];
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
816 gc_wincount[i] = gc_wincount[j];
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
817 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
818
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
819 if (gc_total[i] != 0.0){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
820 gclookup[i] = gc_total[i] / (float) gc_wincount[i];
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
821
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
822 if (MULTGC){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
823
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
824 /*
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
825 if (VERBOSE && i > 200)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
826 fprintf(stdout, "GC\%: %f\tlookup: %f\tnow: ", ((float)i / 10.0), gclookup[i]);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
827 */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
828
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
829 gclookup[i] = MEAN / gclookup[i];
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
830
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
831 /*
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
832 if (VERBOSE && i > 200)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
833 fprintf(stdout, "%f\n", gclookup[i]);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
834 */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
835
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
836 if (gclookup[i] > MAX_GC_CORR)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
837 gclookup[i] = MAX_GC_CORR;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
838 else if (gclookup[i] < MIN_GC_CORR)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
839 gclookup[i] = MIN_GC_CORR;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
840 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
841
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
842 /*
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
843 if (!MULTGC && VERBOSE && i > 200)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
844 fprintf(stdout, "GC\%: %f\tlookup: %f\n", ((float)i / 10.0), gclookup[i]);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
845 */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
846
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
847 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
848
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
849
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
850
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
851 /* chrX */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
852
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
853 if (GENDER != FEMALE){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
854
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
855 if (gc_wincount_x[i] == 0 || gc_total_x[i] == 0){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
856 j=i-1;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
857
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
858 while (j >= 0 && gc_total_x[j] == 0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
859 j--;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
860
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
861 if (gc_total_x[j] == 0 || gc_wincount_x[j] == 0){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
862 j=i+1;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
863 while (j < GC_BIN && gc_total_x[j] == 0) j++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
864 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
865
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
866 gc_total_x[i] = gc_total_x[j];
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
867 gc_wincount_x[i] = gc_wincount_x[j];
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
868 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
869
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
870 if (gc_total_x[i] != 0.0){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
871 gclookup_x[i] = gc_total_x[i] / (float) gc_wincount_x[i];
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
872
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
873 if (MULTGC){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
874 gclookup_x[i] = MEAN_X / gclookup_x[i];
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
875 if (gclookup_x[i] > MAX_GC_CORR)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
876 gclookup_x[i] = MAX_GC_CORR;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
877 else if (gclookup_x[i] < MIN_GC_CORR)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
878 gclookup_x[i] = MIN_GC_CORR;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
879 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
880
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
881 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
882
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
883 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
884
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
885
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
886 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
887
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
888
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
889 *_max = max;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
890 *_max_x = max_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
891
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
892 *_min = min;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
893 *_min_x = min_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
894
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
895
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
896 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
897
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
898
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
899
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
900
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
901