Debian Codegraph @

atac-driver/alignOverlap/overlap-stats.H

raw symbols SCIP
1 // This file is part of A2Amapper.
2 // Copyright (c) 2005 J. Craig Venter Institute
3 // Author: Brian Walenz
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received (LICENSE.txt) a copy of the GNU General Public
16 // License along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 #ifndef OVERLAP_STATS_H
20 #define OVERLAP_STATS_H
21
22 #include "overlap.H"
23
24 // Statistics and Histograms
25 //
26 // Index 1 is the assembly, 2 is the mapping. Stats count the
27 // number of bases covered, histograms are of the block sizes.
28 //
29 class histogram {
30 public:
31 histogram(uint32 max=65536) {
32 histMax = max;
33 hist = new uint32 [histMax];
34 sum = 0;
35
36 for (uint32 i=0; i<histMax; i++)
37 hist[i] = 0;
38 };
39 ~histogram() {
40 delete [] hist;
41 };
42
43 void update(uint32 length) {
44 sum += length;
45 hist[ ((length) > histMax) ? 0 : length ]++;
46 };
47
48 void operator+=(uint32 length) {
49 update(length);
50 };
51
52 uint32 getSum(void) {
53 return(sum);
54 };
55
56 void writeHistogram(char const *prefix, char const *label) {
57 char filename[1024];
58 sprintf(filename, "%s.%s", prefix, label);
59 errno = 0;
60 FILE *out = fopen(filename, "w");
61 if (errno)
62 fprintf(stderr, "Failed to open '%s': %s\n", filename, strerror(errno)), exit(1);
63 for (uint32 i=0; i<histMax; i++)
64 fprintf(out, uint32FMT" "uint32FMT"\n", i, hist[i]);
65 fclose(out);
66 };
67
68 private:
69 uint32 *hist;
70 uint32 histMax;
71 uint32 sum;
72 };
73
74 class overlapStats {
75 public:
76 histogram unmapped;
77 histogram map1unique;
78 histogram map2unique;
79 histogram different;
80 histogram wilddiff;
81 histogram same;
82 histogram inconsistent;
83
84 void writeHistogram(char const *prefix) {
85 unmapped.writeHistogram(prefix, "unmapped");
86 map1unique.writeHistogram(prefix, "map1unique");
87 map2unique.writeHistogram(prefix, "map2unique");
88 different.writeHistogram(prefix, "different");
89 wilddiff.writeHistogram(prefix, "wilddiff");
90 same.writeHistogram(prefix, "same");
91 inconsistent.writeHistogram(prefix, "inconsistent");
92 };
93 };
94
95
96 #endif // OVERLAP_STATS_H