annotate mrcanavar-0.34/callcnv.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 "callcnv.h"
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
2
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
3 void call_cnv(char *depthFile, char *out_prefix){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
4
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
5 int i, j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
6
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
7 float *gclookup;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
8 float *gclookup_x;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
9
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
10 char *fname;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
11 char logname[2 * MAX_STR];
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
12 FILE *log;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
13
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
14 if (GENOME_CONF == NULL)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
15 print_error("Select genome configuration file (input) through the -conf parameter.\n");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
16 if (depthFile == NULL)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
17 print_error("Select read depth output file through the -depth parameter.\n");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
18 if (out_prefix == NULL)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
19 print_error("Select output file prefix through the -o parameter.\n");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
20
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
21
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
22
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
23 loadRefConfig(GENOME_CONF);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
24
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
25 readDepth(depthFile);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
26
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
27
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
28 sprintf(logname, "%s.log", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
29 log = my_fopen(logname, "w", 0);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
30
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
31 /* trivial control removal */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
32
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
33
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
34 fprintf(stdout, "Control region cleanup...");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
35 fflush(stdout);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
36
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
37 /* add stdev calculation here */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
38
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
39
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
40 for (i=0; i<num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
41 for (j=0; j<chromosomes[i]->lw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
42 if (chromosomes[i]->lw[j].depth > (float) LW_MEAN * 2.0 || chromosomes[i]->lw[j].depth < (float) LW_MEAN / 10.0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
43 chromosomes[i]->lw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
44 if (strstr(chromosomes[i]->name, "random") || strstr(chromosomes[i]->name, "chrY") || strstr(chromosomes[i]->name, "hap") || strstr(chromosomes[i]->name, "chrUn"))
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
45 chromosomes[i]->lw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
46 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
47 for (j=0; j<chromosomes[i]->sw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
48 if (chromosomes[i]->sw[j].depth > (float) SW_MEAN * 2.0 || chromosomes[i]->sw[j].depth < (float) SW_MEAN / 10.0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
49 chromosomes[i]->sw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
50 if (strstr(chromosomes[i]->name, "random") || strstr(chromosomes[i]->name, "chrY") || strstr(chromosomes[i]->name, "hap") || strstr(chromosomes[i]->name, "chrUn"))
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
51 chromosomes[i]->sw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
52 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
53
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
54 for (j=0; j<chromosomes[i]->cw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
55 if (chromosomes[i]->cw[j].depth > (float) CW_MEAN * 2.0 || chromosomes[i]->cw[j].depth < (float) CW_MEAN / 10.0)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
56 chromosomes[i]->cw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
57 if (strstr(chromosomes[i]->name, "random") || strstr(chromosomes[i]->name, "chrY") || strstr(chromosomes[i]->name, "hap") || strstr(chromosomes[i]->name, "chrUn"))
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
58 chromosomes[i]->cw[j].isControl = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
59 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
60 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
61
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
62
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
63
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
64 fprintf(stdout, "\n");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
65
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
66 gclookup = (float *) malloc(sizeof(float) * GC_BIN);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
67 gclookup_x = (float *) malloc(sizeof(float) * GC_BIN);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
68
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
69 fprintf (log, "\nmrCaNaVaR version %s\nLast update: %s\n\n", VERSION, LAST_UPDATE);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
70 fprintf (log, "Calculating library %s\n", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
71 fprintf (log, "GC correction mode: %s\n", MULTGC == 1 ? "MULTIPLICATIVE" : "ADDITIVE");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
72
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
73 norm_until_converges(CW, gclookup, gclookup_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
74
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
75 fprintf (log, "\nAfter GC Correction:\n--------------------\n");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
76 fprintf (log, "Sample Gender: %s.\n", GENDER == MALE ? "Male" : "Female");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
77 fprintf (log, "CW Average Read Depth: %f, Standard Deviation: %f\n", CW_MEAN, CW_STD);
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 if (GENDER == MALE)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
81 fprintf (log, "CW Average chrX Read Depth: %f, Standard Deviation: %f\n", CW_MEAN_X, CW_STD_X);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
82
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
83 norm_until_converges(LW, gclookup, gclookup_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
84 fprintf (log, "LW Average Read Depth: %f, Standard Deviation: %f\n", LW_MEAN, LW_STD);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
85 if (GENDER == MALE)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
86 fprintf (log, "LW Average chrX Read Depth: %f, Standard Deviation: %f\n", LW_MEAN_X, LW_STD_X);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
87
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
88 norm_until_converges(SW, gclookup, gclookup_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
89 fprintf (log, "SW Average Read Depth: %f, Standard Deviation: %f\n", SW_MEAN, SW_STD);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
90 if (GENDER == MALE)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
91 fprintf (log, "SW Average chrX Read Depth: %f, Standard Deviation: %f\n", SW_MEAN_X, SW_STD_X);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
92
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
93
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
94 fprintf (stdout, "Writing normalized CW depth to: %s.cw_norm.bed.\n", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
95
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
96 fname = (char *) malloc(sizeof (char) * (strlen(out_prefix) + strlen(".cw_norm.bed") + 1));
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
97
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
98 sprintf (fname, "%s.cw_norm.bed", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
99 dump_text_windows(fname, CW);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
100
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
101 fprintf (stdout, "Writing normalized LW depth to: %s.lw_norm.bed.\n", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
102
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
103 sprintf (fname, "%s.lw_norm.bed", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
104 dump_text_windows(fname, LW);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
105
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
106 fprintf (stdout, "Writing normalized SW depth to: %s.sw_norm.bed.\n", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
107
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
108 sprintf (fname, "%s.sw_norm.bed", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
109 dump_text_windows(fname, SW);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
110
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
111 sprintf (fname, "%s.copynumber.bed", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
112 fprintf (stdout, "Writing copy numbers to: %s.copynumber.bed. \n", out_prefix);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
113 print_copy_numbers(fname);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
114
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
115 free(fname);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
116
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
117 free(gclookup);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
118 free(gclookup_x);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
119 fclose(log);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
120
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
121 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
122
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
123
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
124
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
125 void readDepth(char *depthFile){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
126
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
127 FILE *binDepth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
128 int i, j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
129 int retVal;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
130
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
131 float lw_total;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
132 float sw_total;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
133 float cw_total;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
134
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
135 int lw_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
136 int sw_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
137 int cw_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
138
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
139 int isMagicNum;
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 binDepth = my_fopen(depthFile, "r", 0);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
143
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
144 retVal = fread(&isMagicNum, sizeof(isMagicNum), 1, binDepth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
145
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
146 if (isMagicNum != magicNum)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
147 print_error("Read depth file seems to be invalid or corrupt.\n");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
148
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
149
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
150 lw_total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
151 sw_total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
152 cw_total = 0.0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
153
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
154 lw_cnt = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
155 sw_cnt = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
156 cw_cnt = 0;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
157
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
158 /* read LW */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
159
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
160 for (i = 0; i < num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
161 for (j = 0; j < chromosomes[i]->lw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
162 retVal = fread(&(chromosomes[i]->lw[j].depth), sizeof(chromosomes[i]->lw[j].depth), 1, binDepth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
163 lw_total += chromosomes[i]->lw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
164 chromosomes[i]->lw[j].isControl = 1;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
165 lw_cnt++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
166 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
167 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
168
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
169 /* read SW */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
170
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
171 for (i = 0; i < num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
172 for (j = 0; j < chromosomes[i]->sw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
173 retVal = fread(&(chromosomes[i]->sw[j].depth), sizeof(chromosomes[i]->sw[j].depth), 1, binDepth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
174 sw_total += chromosomes[i]->sw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
175 chromosomes[i]->sw[j].isControl = 1;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
176 sw_cnt++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
177 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
178 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
179
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
180 /* read CW */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
181
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
182 for (i = 0; i < num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
183 for (j = 0; j < chromosomes[i]->cw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
184 retVal = fread(&(chromosomes[i]->cw[j].depth), sizeof(chromosomes[i]->cw[j].depth), 1, binDepth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
185 cw_total += chromosomes[i]->cw[j].depth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
186 chromosomes[i]->cw[j].isControl = 1;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
187 cw_cnt++;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
188 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
189 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
190
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
191 LW_MEAN = lw_total / lw_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
192 SW_MEAN = sw_total / sw_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
193 CW_MEAN = cw_total / cw_cnt;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
194
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
195 fprintf(stdout, "[OK] depth file %s is loaded.\n", depthFile);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
196 if (VERBOSE)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
197 fprintf(stdout, "LW_MEAN: %f\tSW_MEAN: %f\tCW_MEAN:%f\n", LW_MEAN, SW_MEAN, CW_MEAN);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
198
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
199 fclose(binDepth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
200 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
201
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
202
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
203 void dump_text_windows(char *fname, enum WINDOWTYPE wt){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
204
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
205 FILE *txtDepth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
206 int i, j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
207
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
208 txtDepth = my_fopen(fname, "w", 0);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
209
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
210 fprintf(txtDepth, "#%s\t%s\t%s\t%s\t%s\t%s\n\n", "CHROM", "START", "END", "GC\%", "READ_DEPTH", "IS_CONTROL");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
211
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
212 switch (wt){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
213 case LW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
214 for (i = 0; i < num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
215 for (j = 0; j < chromosomes[i]->lw_cnt; j++)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
216 if (chromosomes[i]->lw[j].isControl == 1)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
217 fprintf(txtDepth, "%s\t%d\t%d\t%f\t%f\tY\n", chromosomes[i]->name, chromosomes[i]->lw[j].start, chromosomes[i]->lw[j].end, chromosomes[i]->lw[j].gc, chromosomes[i]->lw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
218 else
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
219 fprintf(txtDepth, "%s\t%d\t%d\t%f\t%f\tN\n", chromosomes[i]->name, chromosomes[i]->lw[j].start, chromosomes[i]->lw[j].end, chromosomes[i]->lw[j].gc, chromosomes[i]->lw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
220 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
221 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
222
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
223 case SW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
224 for (i = 0; i < num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
225 for (j = 0; j < chromosomes[i]->sw_cnt; j++)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
226 if (chromosomes[i]->sw[j].isControl == 1)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
227 fprintf(txtDepth, "%s\t%d\t%d\t%f\t%f\tY\n", chromosomes[i]->name, chromosomes[i]->sw[j].start, chromosomes[i]->sw[j].end, chromosomes[i]->sw[j].gc, 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 fprintf(txtDepth, "%s\t%d\t%d\t%f\t%f\tN\n", chromosomes[i]->name, chromosomes[i]->sw[j].start, chromosomes[i]->sw[j].end, chromosomes[i]->sw[j].gc, chromosomes[i]->sw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
230 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
231 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
232
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
233 case CW:
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
234 for (i = 0; i < num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
235 for (j = 0; j < chromosomes[i]->cw_cnt; j++)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
236 if (chromosomes[i]->cw[j].isControl == 1)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
237 fprintf(txtDepth, "%s\t%d\t%d\t%f\t%f\tY\n", chromosomes[i]->name, chromosomes[i]->cw[j].start, chromosomes[i]->cw[j].end, chromosomes[i]->cw[j].gc, chromosomes[i]->cw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
238 else
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
239 fprintf(txtDepth, "%s\t%d\t%d\t%f\t%f\tN\n", chromosomes[i]->name, chromosomes[i]->cw[j].start, chromosomes[i]->cw[j].end, chromosomes[i]->cw[j].gc, chromosomes[i]->cw[j].depth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
240 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
241 break;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
242 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
243
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
244 fclose(txtDepth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
245
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
246 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
247
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
248
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
249
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
250 void print_copy_numbers(char *fname){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
251 /* UNFINISHED */
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
252
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
253 FILE *txtDepth;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
254 int i, j;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
255 float copy_num;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
256
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
257 txtDepth = my_fopen(fname, "w", 0);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
258
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
259 fprintf(txtDepth, "#%s\t%s\t%s\t%s\t%s\n\n", "CHROM", "START", "END", "GC\%", "COPYNUMBER");
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
260
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
261 for (i = 0; i < num_chrom; i++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
262 for (j = 0; j < chromosomes[i]->cw_cnt; j++){
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
263 if (GENDER == FEMALE)
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
264 copy_num = (chromosomes[i]->cw[j].depth / CW_MEAN) * 2;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
265 else{
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
266 if (!strstr(chromosomes[i]->name, "chrX") && !strstr(chromosomes[i]->name, "chrY"))
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
267 copy_num = (chromosomes[i]->cw[j].depth / CW_MEAN) * 2;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
268 else
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
269 copy_num = chromosomes[i]->cw[j].depth / CW_MEAN_X;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
270 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
271
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
272 if (GENDER == FEMALE && (strstr(chromosomes[i]->name, "chrY")))
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
273 continue;
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
274
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
275 fprintf(txtDepth, "%s\t%d\t%d\t%f\t%f\n", chromosomes[i]->name, chromosomes[i]->cw[j].start, chromosomes[i]->cw[j].end, chromosomes[i]->cw[j].gc, copy_num);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
276 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
277 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
278
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
279
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
280 fclose(txtDepth);
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
281
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
282
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
283 }
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
284
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
285
86522a0b5f59 Uploaded source code for mrCaNaVaR
calkan
parents:
diff changeset
286