Debian Codegraph @

sim4dbutils/depthOfPolishes.C

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5
6 #include "sim4.H"
7
8 // ./genomics/sim4dbutils/depthOfPolishes -v < runA.1.ms12.filtered.sim4db > depth-out
9 // plot [112000:113000][] "depth-out" using 2 with lines
10
11 int
12 main(int argc, char **argv) {
13 uint32 genomeLength = 0;
14 uint32 seqIdx = 0;
15
16 int arg = 1;
17 while (arg < argc) {
18 if (strncmp(argv[arg], "-l", 2) == 0) {
19 genomeLength = strtouint32(argv[++arg], 0L);
20
21 } else if (strncmp(argv[arg], "-s", 2) == 0) {
22 seqIdx = strtouint32(argv[++arg], 0L);
23
24 } else {
25 fprintf(stderr, "Unknown arg '%s'\n", argv[arg]);
26 }
27 arg++;
28 }
29
30 intervalList<uint64> IL;
31
32 sim4polishReader *R = new sim4polishReader("-");
33 sim4polish *p = 0L;
34
35 while (R->nextAlignment(p)) {
36 uint32 beg = p->_exons[0]._genFrom - 1;
37 uint32 end = p->_exons[p->_numExons-1]._genTo;
38
39 if (p->_genID != seqIdx)
40 continue;
41
42 if (end > genomeLength)
43 genomeLength = end;
44
45 IL.add(beg, end-beg);
46 }
47
48 intervalList<uint64> ID(IL);
49
50 // The extra 1000 here is so we can be lazy in the
51 // output section when computing averages.
52 //
53 uint32 *DD = new uint32 [genomeLength + 1000];
54 for (uint32 i=0; i<genomeLength + 1000; i++)
55 DD[i] = 0;
56
57 for (uint32 i=0; i<ID.numberOfIntervals(); i++) {
58 uint32 l = ID.lo(i);
59 uint32 h = ID.hi(i);
60 uint32 d = ID.count(i);
61
62 while (l < h) {
63 DD[l] = d;
64 l++;
65 }
66 }
67
68 // This stolen to leaff.C for %GC computation
69
70 uint32 ave3 = 0;
71 uint32 ave5 = 0;
72 uint32 ave11 = 0;
73 uint32 ave51 = 0;
74 uint32 ave101 = 0;
75 uint32 ave201 = 0;
76 uint32 ave501 = 0;
77 uint32 ave1001 = 0;
78 uint32 ave2001 = 0;
79
80 // Preload the averages
81 ave3 += DD[0];
82 ave5 += DD[0] + DD[1];
83
84 for (uint32 i=0; i<5; i++) ave11 += DD[i];
85 for (uint32 i=0; i<25; i++) ave51 += DD[i];
86 for (uint32 i=0; i<50; i++) ave101 += DD[i];
87 for (uint32 i=0; i<100; i++) ave201 += DD[i];
88 for (uint32 i=0; i<250; i++) ave501 += DD[i];
89 for (uint32 i=0; i<500; i++) ave1001 += DD[i];
90 for (uint32 i=0; i<1000; i++) ave2001 += DD[i];
91
92 for (uint32 i=0; i<genomeLength; i++) {
93 ave3 += DD[i+1] - ((i > 1) ? DD[i-2] : 0);
94 ave5 += DD[i+2] - ((i > 2) ? DD[i-3] : 0);
95 ave11 += DD[i+5] - ((i > 5) ? DD[i-6] : 0);
96 ave51 += DD[i+25] - ((i > 25) ? DD[i-25] : 0);
97 ave101 += DD[i+50] - ((i > 50) ? DD[i-51] : 0);
98 ave201 += DD[i+100] - ((i > 100) ? DD[i-101] : 0);
99 ave501 += DD[i+250] - ((i > 250) ? DD[i-251] : 0);
100 ave1001 += DD[i+500] - ((i > 500) ? DD[i-501] : 0);
101 ave2001 += DD[i+1000] - ((i > 1000) ? DD[i-1001] : 0);
102
103 fprintf(stdout, uint32FMT"\t"uint32FMT"\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",
104 i,
105 DD[i],
106 ave3 / (double)((i >= 1) ? 3 - ((i < genomeLength - 1) ? 0 : i + 2 - genomeLength) : i+2),
107 ave5 / (double)((i >= 2) ? 5 - ((i < genomeLength - 2) ? 0 : i + 3 - genomeLength) : i+3),
108 ave11 / (double)((i >= 5) ? 11 - ((i < genomeLength - 4) ? 0 : i + 5 - genomeLength) : i+6),
109 ave51 / (double)((i >= 25) ? 51 - ((i < genomeLength - 24) ? 0 : i + 25 - genomeLength) : i+26),
110 ave101 / (double)((i >= 50) ? 101 - ((i < genomeLength - 49) ? 0 : i + 50 - genomeLength) : i+51),
111 ave201 / (double)((i >= 100) ? 201 - ((i < genomeLength - 99) ? 0 : i + 100 - genomeLength) : i+101),
112 ave501 / (double)((i >= 250) ? 501 - ((i < genomeLength - 249) ? 0 : i + 250 - genomeLength) : i+251),
113 ave1001 / (double)((i >= 500) ? 1001 - ((i < genomeLength - 499) ? 0 : i + 500 - genomeLength) : i+501),
114 ave2001 / (double)((i >= 1000) ? 2001 - ((i < genomeLength - 999) ? 0 : i + 1000 - genomeLength) : i+1001));
115 }
116
117 return(0);
118 }