Debian Codegraph @

sim4dbutils/plotIntronSize.C

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <errno.h>
6
7 #include "sim4reader.h"
8
9 //
10 // Outputs some statistics on the matches
11 //
12
13 #define HISTBIN (1000)
14 #define HISTMAX (300000000 / HISTBIN)
15
16 int
17 main(int argc, char ** argv) {
18 uint32 dumpSize = 0;
19 uint32 *hist;
20 FILE *all;
21 FILE *big;
22 int i, j;
23
24 if (isatty(fileno(stdin))) {
25 fprintf(stderr, "error: I cannot read polishes from the terminal!\n\n");
26 exit(1);
27 }
28
29 int arg = 1;
30 while (arg < argc) {
31 if (strncmp(argv[arg], "-dump", 2) == 0) {
32 dumpSize = atoi(argv[++arg]);
33 } else if (strncmp(argv[arg], "-all", 2) == 0) {
34 all = fopen(argv[++arg], "w");
35 if (all == 0L) {
36 fprintf(stderr, "Can't open '%s' for writing\n", argv[arg]);
37 exit(1);
38 }
39 } else if (strncmp(argv[arg], "-big", 2) == 0) {
40 big = fopen(argv[++arg], "w");
41 if (big == 0L) {
42 fprintf(stderr, "Can't open '%s' for writing\n", argv[arg]);
43 exit(1);
44 }
45 } else {
46 fprintf(stderr, "Unknown option: '%s'\n", argv[arg]);
47 }
48
49 arg++;
50 }
51
52 if (all || big) {
53 hist = new uint32 [HISTMAX];
54 memset(hist, 0, sizeof(uint32) * HISTMAX);
55 }
56
57 sim4polish *p = new sim4polish(stdin);
58 while (p->_numExons > 0) {
59 if (p->numExons > 1) {
60 int exA;
61 int exB;
62 int biggestIntron = 0;
63
64 for (exA=0, exB=1; exB < p->numExons; exA++, exB++) {
65 int dist = p->exons[exB].genFrom - p->exons[exA].genTo + 1;
66 if (dist > biggestIntron)
67 biggestIntron = dist;
68 if (all)
69 hist[dist / HISTBIN]++;
70 }
71
72 if (big)
73 hist[biggestIntron / HISTBIN]++;
74
75 //fprintf(stdout, "%d\n", biggestIntron);
76
77 if ((dumpSize > 0) && (biggestIntron > dumpSize))
78 printPolish(stdout, p);
79 }
80
81 destroyPolish(p);
82 }
83
84
85 if (all) {
86 for (j=HISTMAX-1; hist[j]==0 && j>=0; j--)
87 ;
88 for (i=0; i<j; i++)
89 fprintf(all, "%d\n", hist[i]);
90 fclose(all);
91 }
92
93 if (big) {
94 for (j=HISTMAX-1; hist[j]==0 && j>=0; j--)
95 ;
96 for (i=0; i<j; i++)
97 fprintf(big, "%d\n", hist[i]);
98 fclose(big);
99 }
100
101 delete [] hist;
102
103 return(0);
104 }