Debian Codegraph @

atac-driver/mismatchCounter/mismatchCounter.C

raw symbols SCIP
1 // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/mismatchCounter/mismatchCounter.C`/
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 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22
23 #include "bio++.H"cxx . . $ `<file>/libbio/bio++.H`/
24 #include "seqCache.H"cxx . . $ `<file>/libseq/seqCache.H`/
25 #include "atac.H"cxx . . $ `<file>/atac-driver/libatac/atac.H`/
26
27 #define ANNOTATEcxx . . $ `atac-driver/mismatchCounter/mismatchCounter.C:27:9`!
28 #define EXTRAMATCHEScxx . . $ `atac-driver/mismatchCounter/mismatchCounter.C:28:9`!
29
30 // Generates a histogram of the exact match block sizes
31 // Counts to global number of mismatches
32 // Annotates each match with the number of mismatches
33 // Checks for identities outside matches
34
35
36 void
37 updateExactBlockHistogramcxx . . $ updateExactBlockHistogram(d89196f67e9c91e5).(uint32cxx . . $ uint32# *blockHistogram, uint32cxx . . $ uint32# blockMatches) {
38
39 if (blockMatches > 8 * 1024 * 1024)
40 blockHistogram[0]++;
41 else
42 blockHistogram[blockMatches]++;
43 }
44
45
46
47 int
48 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) {
49
50 int arg=1;
51 while (arg < argc) {
52 if (strcmp(argv[arg], "-h") == 0) {
53 // Generate a histogram of exact-match lengths
54 } else if (strcmp(argv[arg], "-a") == 0) {
55 // Annotate each match with the percent error, compute
56 // the global percent error.
57 } else if (strcmp(argv[arg], "-e") == 0) {
58 // Generate a histogram of the percent error in each match
59 } else if (strcmp(argv[arg], "-c") == 0) {
60 // Check the edges of each match to ensure there isn't a match
61 } else {
62 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [-h exact-match-histogram] [-a] [-e error-histogram] [-c]\n", argv[0]);
63 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -h: histogram of the length of the exact match blocks\n");
64 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -a: annotate each match with the percent error, write to stdout\n");
65 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -e: histogram of the error rate of each match\n");
66 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -c: check that the next base on each side is a mismatch\n");
67 exitcxx . . $ exit(44ed87f96534fad7).(1);
68 }
69 arg++;
70 }
71
72 uint32cxx . . $ uint32# globalSequence = 0;
73 uint32cxx . . $ uint32# globalMismatches = 0;
74 uint32cxx . . $ uint32# blockMatches = 0;
75 uint32cxx . . $ uint32# *blockHistogram = new uint32cxx . . $ uint32# [8 * 1024 * 1024];
76
77 for (uint32cxx . . $ uint32# x=0; x<8*1024*1024; x++)
78 blockHistogram[x] = 0;
79
80 atacFilecxx . . $ atacFile# AFcxx . . $ atacFile#atacFile(85c52e162fed56f9).("-");
81 atacMatchListcxx . . $ atacMatchList# &ML = *AF.matchescxx . . $ atacFile#matches(33e88ebc28d05bce).();
82
83 seqCachecxx . . $ seqCache# *C1 = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileAcxx . . $ atacFileBase#assemblyFileA(41208ce6ca65dd58).(), 1, false);
84 seqCachecxx . . $ seqCache# *C2 = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileAcxx . . $ atacFileBase#assemblyFileA(41208ce6ca65dd58).(), 1, false);
85
86 for (uint32cxx . . $ uint32# mi=0; mi<ML.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); mi++) {
87 atacMatchcxx . . $ atacMatch# *m = ML.getMatchcxx . . $ atacMatchList#getMatch(4b949e4d42dbfd78).(mi);
88
89 seqInCorecxx . . $ seqInCore# *S1 = C1->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid1cxx . . $ atacMatch#iid1.);
90 seqInCorecxx . . $ seqInCore# *S2 = C2->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid2cxx . . $ atacMatch#iid2.);
91
92 FastAAccessorcxx . . $ FastAAccessor# A1cxx . . $ FastAAccessor#FastAAccessor(15bbd9d839cdf78d).(S1, false);
93 FastAAccessorcxx . . $ FastAAccessor# A2cxx . . $ FastAAccessor#FastAAccessor(15bbd9d839cdf78d).(S2, (m->fwd1cxx . . $ atacMatch#fwd1. != m->fwd2cxx . . $ atacMatch#fwd2.));
94
95 A1.setRangecxx . . $ FastAAccessor#setRange(8e1b545ea3aecce3).(m->pos1cxx . . $ atacMatch#pos1., m->len1cxx . . $ atacMatch#len1.);
96 A2.setRangecxx . . $ FastAAccessor#setRange(8e1b545ea3aecce3).(m->pos2cxx . . $ atacMatch#pos2., m->len2cxx . . $ atacMatch#len2.);
97
98 uint32cxx . . $ uint32# localMismatches = 0;
99
100 #ifdef EXTRAMATCHEScxx . . $ `atac-driver/mismatchCounter/mismatchCounter.C:28:9`!
101 uint32cxx . . $ uint32# extraMatchesL = 0;
102 uint32cxx . . $ uint32# extraMatchesR = 0;
103
104 // Check for matches on either side of the region.
105
106 A1.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos1cxx . . $ atacMatch#pos1.);
107 A2.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos2cxx . . $ atacMatch#pos2.);
108 --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).A1;
109 --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).A2;
110 while (A1.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() &&
111 A2.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() &&
112 (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A1] != 0xff)&&
113 (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A2] != 0xff) &&
114 IUPACidentity[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A1][(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A2]) {
115 extraMatchesL++;
116 --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).A1;
117 --cxx . . $ FastAAccessor#operator--(ab00271b6674b0d4).A2;
118 }
119
120 A1.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos1cxx . . $ atacMatch#pos1. + m->len1cxx . . $ atacMatch#len1. - 1);
121 A2.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos2cxx . . $ atacMatch#pos2. + m->len2cxx . . $ atacMatch#len2. - 1);
122 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A1;
123 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A2;
124 while (A1.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() &&
125 A2.isValidcxx . . $ FastAAccessor#isValid(c9857a73d68e59ba).() &&
126 (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A1] != 0xff)&&
127 (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A2] != 0xff) &&
128 IUPACidentity[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A1][(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A2]) {
129 extraMatchesR++;
130 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A1;
131 ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A2;
132 }
133
134 // WARN if we found extra identities
135
136 #if 0
137 if (extraMatchesL + extraMatchesR > 0) {
138 A1.setPosition(m->pos1);
139 A2.setPosition(m->pos2);
140
141 chomp(inLine);
142 fprintf(stderr, "WARNING: found "uint32FMT" extra matches to the left and "uint32FMT" extra matches to the right in %s\n",
143 extraMatchesL, extraMatchesR, inLine);
144
145 #if 0
146 for (uint32 ii=0; ii<m->len1; ii++, ++A1)
147 fprintf(stdout, "%c", *A1);
148 fprintf(stdout, "\n");
149
150 for (uint32 ii=0; ii<m->len1; ii++, ++A2)
151 fprintf(stdout, "%c", *A2);
152 fprintf(stdout, "\n");
153 #endif
154 }
155 #endif
156
157 #endif // EXTRAMATCHES
158
159
160 A1.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos1cxx . . $ atacMatch#pos1.);
161 A2.setPositioncxx . . $ FastAAccessor#setPosition(dfa6e707f7696010).(m->pos2cxx . . $ atacMatch#pos2.);
162 for (uint32cxx . . $ uint32# ii=0; ii<m->len1cxx . . $ atacMatch#len1.; ii++, ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A1, ++cxx . . $ FastAAccessor#operator++(ab00271b6674b0d4).A2) {
163
164 // Count global matches / mismatches
165 //
166 globalSequence++;
167 if (!((letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A1] != 0xff) &&
168 (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A2] != 0xff) &&
169 IUPACidentity[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A1][(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A2])) {
170 globalMismatches++;
171 localMismatches++;
172 }
173
174 // Histogram of exact match block lengths
175 //
176 if ((letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A1] != 0xff) &&
177 (letterToBits[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A2] != 0xff) &&
178 IUPACidentity[(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A1][(int)*cxx . . $ FastAAccessor#`operator*`(1b8b762cbef9c2c9).A2]) {
179 blockMatches++;
180 } else {
181 updateExactBlockHistogramcxx . . $ updateExactBlockHistogram(d89196f67e9c91e5).(blockHistogram, blockMatches);
182 blockMatches = 0;
183 }
184 }
185
186 // Finish off stuff
187 //
188 updateExactBlockHistogramcxx . . $ updateExactBlockHistogram(d89196f67e9c91e5).(blockHistogram, blockMatches);
189 blockMatches = 0;
190
191 // If annotate, emit a new record.
192 }
193
194
195 // Report stuff
196 //
197 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "globalSequence = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", globalSequence);
198 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "globalMismatches = "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", globalMismatches);
199
200 #if 0
201 FILE *O = fopen("MismatchCounter.block.histogram.out", "w");
202 for (uint32 i=0; i<8 * 1024 * 1024; i++)
203 fprintf(O, uint32FMT" "uint32FMT"\n", i, blockHistogram[i]);
204 fclose(O);
205 #endif
206
207 return(0);
208 }