-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcnv.c
85 lines (65 loc) · 1.98 KB
/
cnv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "cnv.h"
double get_depth_region(short *depths, int start, int end){
if( end <start){ return get_depth_region(depths,end,start);}
double sum = 0;
int i;
for( i = floor(start/MOLECULE_BIN_SIZE);i<ceil(end/MOLECULE_BIN_SIZE);i++){
sum+=depths[i];
}
return sum / ceil((1.0*end-start)/MOLECULE_BIN_SIZE);
}
double get_depth_deviation(short *depths, int start, int end){
if( end <start){ return get_depth_deviation(depths,end,start);}
double mean = get_depth_region(depths,start,end);
int i;
double sum = 0;
for(i= floor(start/MOLECULE_BIN_SIZE);i<ceil(end/MOLECULE_BIN_SIZE);i++){
sum+=((depths[i]-mean) * (depths[i]-mean));
}
return sqrt(sum/ceil((1.0*end-start)/MOLECULE_BIN_SIZE));
}
int cmp_short(const void *a, const void *b){
short aa = *(short *) a;
short bb = *(short *) b;
return aa - bb;
}
double make_global_molecule_mean(short *depths, sonic *snc, int chr){
long bin_count = snc->chromosome_lengths[chr] / MOLECULE_BIN_SIZE;
double sum = 0;
int i;
for(i=0;i<bin_count;i++){
sum+= depths[i];
}
return sum/bin_count;
}
double make_global_molecule_std_dev(short *depths, sonic *snc, int chr, double mean){
double sum = 0;
long bin_count = snc->chromosome_lengths[chr] / MOLECULE_BIN_SIZE;
int i;
sum = 0;
for( i=0;i<bin_count;i++){
if(depths[i] < mean / 4){
continue;
}else if( depths[i] > mean * 4){
continue;
}
sum+=(depths[i]-mean)*(depths[i]-mean);
}
double std_dev = sqrt((double)sum/bin_count);
return std_dev;
}
short *make_molecule_depth_array(vector_t *regions, sonic *snc, int chr){
long bin_count = 1+snc->chromosome_lengths[chr] / MOLECULE_BIN_SIZE;
short *depths = malloc(sizeof(short) * bin_count);
int i, j;
for( i=0;i<bin_count;i++){
depths[i] = 0;
}
for( i=0;i<regions->size;i++){
interval_10X *molecule = vector_get(regions,i);
for( j=molecule->start;j<molecule->end;j+=MOLECULE_BIN_SIZE){
depths[j/MOLECULE_BIN_SIZE]++;
}
}
return depths;
}