Debian Codegraph @

atac-driver/alignOverlap/overlap-find.C

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 #include "overlap.H"
20
21 // Looks for 1's surrounded by U's
22 void
23 findIsolatedUnique(annoList *AL, uint32 ALlen) {
24 bool only1 = true;
25 uint32 sumA = 0, tA=0;
26 uint32 sumB = 0, tB=0;
27
28 for (uint32 i=1; i<ALlen; i++) {
29 if (AL[i].type == 'U') {
30 if (only1 && (!tA || !tB)) {
31 sumA += tA;
32 sumB += tB;
33 }
34 tA = 0;
35 tB = 0;
36 only1 = true;
37 } else if (AL[i].type != '1') {
38 only1 = false;
39 } else {
40 tA += AL[i].len2a;
41 tB += AL[i].len2b;
42 }
43 }
44
45 fprintf(stderr, "isolated Unique: map1: "uint32FMT" map2: "uint32FMT"\n", sumA, sumB);
46 }
47
48
49
50 uint32 encodeType(uint32 type) {
51 uint32 t = 9;
52 if (type == 'U') t = 0;
53 else if (type == '1') t = 1;
54 else if (type == 'Y') t = 2;
55 else if (type == 'N') t = 3;
56 else if (type == '?') t = 4;
57 else if (type == '!') t = 5;
58 if (t == 9)
59 fprintf(stderr, "got invalid type; "uint32FMT" -- %c\n", type, (char)type), exit(1);
60 return(t);
61 }
62
63
64
65 // Looks for 1's at the end of a Y, that have the same match id
66 void
67 findExtended(annoList *AL, uint32 ALlen) {
68
69 class stat_s {
70 public:
71 uint32 count;
72 uint32 len;
73
74 stat_s() {
75 count = 0;
76 len = 0;
77 };
78
79 stat_s &operator+=(uint32 x) {
80 count++;
81 len += x;
82 return(*this);
83 };
84 stat_s &operator+=(stat_s &x) {
85 count += x.count;
86 len += x.len;
87 return(*this);
88 };
89
90 void print(char const *msg) {
91 fprintf(stderr, "%s: "uint32FMT" len:"uint32FMT"\n", msg, count, len);
92 };
93 };
94
95 stat_s count1[6][6][2][2][2];
96 stat_s count2[6][6][2][2][2];
97
98 // Look forward for the next event:
99 // non-1
100 // the iid changed
101 //
102 // End is the match after the 1, beg is the match before the 1.
103 //
104 for (uint32 i=0; i<ALlen; i++) {
105 if (AL[i].type == '1') {
106 uint32 beg = i-1;
107 uint32 gap = i;
108 uint32 end = i;
109 uint32 len = 0;
110
111 if (AL[gap].iid2a) {
112 while ((AL[gap].iid2a == AL[end].iid2a) && (AL[end].type == '1')) {
113 len += AL[end].len1;
114 end++;
115 }
116 } else {
117 while ((AL[gap].iid2b == AL[end].iid2b) && (AL[end].type == '1')) {
118 len += AL[end].len1;
119 end++;
120 }
121 }
122
123 if (beg == gap)
124 fprintf(stderr, "beg == gap?\n"), exit(1);
125 if (gap == end)
126 fprintf(stderr, "end == gap?\n"), exit(1);
127
128 uint32 tbeg = encodeType(AL[beg].type);
129 uint32 tend = encodeType(AL[end].type);
130
131 bool mbeg, mend, moth;
132 if (AL[gap].iid2a) {
133 mbeg = (AL[beg].iid2a == AL[gap].iid2a);
134 mend = (AL[end].iid2a == AL[gap].iid2a);
135 moth = (AL[beg].iid2b == AL[end].iid2b);
136 count1[tbeg][tend][mbeg][mend][moth] += len;
137 } else {
138 mbeg = (AL[beg].iid2b == AL[gap].iid2b);
139 mend = (AL[end].iid2b == AL[gap].iid2b);
140 moth = (AL[beg].iid2a == AL[end].iid2a);
141 count2[tbeg][tend][mbeg][mend][moth] += len;
142 }
143 }
144 }
145
146
147 char label[6] = {'U', '1', 'Y', 'N', '?', '!'};
148
149 #define TYPE_U 0
150 #define TYPE_1 1
151 #define TYPE_Y 2
152 #define TYPE_N 3
153 #define TYPE_Q 4
154 #define TYPE_E 5
155
156 // If the other iid is the same, then these are all interesting cases
157 // Maybe not.
158 #if 0
159 stat_s oth_cnst_1;
160 stat_s oth_cnst_2;
161 stat_s oth_diff_1;
162 stat_s oth_diff_2;
163
164 for (uint32 i=0; i<6; i++)
165 for (uint32 j=0; j<6; j++)
166 for (uint32 k=0; k<2; k++)
167 for (uint32 l=0; l<2; l++) {
168 oth_cnst_1 += count1[i][j][k][l][1];
169 oth_cnst_2 += count2[i][j][k][l][1];
170 oth_diff_1 += count1[i][j][k][l][0];
171 oth_diff_2 += count2[i][j][k][l][0];
172 }
173 fprintf(stderr, "count1 other iid constant: "uint32FMT" len:"uint32FMT"\n", oth_cnst_1.count, oth_cnst_1.len);
174 fprintf(stderr, "count2 other iid constant: "uint32FMT" len:"uint32FMT"\n", oth_cnst_2.count, oth_cnst_2.len);
175 fprintf(stderr, "count1 other iid different: "uint32FMT" len:"uint32FMT"\n", oth_diff_1.count, oth_diff_1.len);
176 fprintf(stderr, "count2 other iid different: "uint32FMT" len:"uint32FMT"\n", oth_diff_2.count, oth_diff_2.len);
177 #endif
178
179 #if 0
180 for (uint32 tbeg=0; tbeg<6; tbeg++)
181 for (uint32 tend=0; tend<6; tend++)
182 for (uint32 mbeg=0; mbeg<2; mbeg++)
183 for (uint32 mend=0; mend<2; mend++)
184 for (uint32 moth=0; moth<2; moth++) {
185 }
186 #endif
187
188
189 // Look for things with an extra piece in the middle -- mbeg and mend
190 //
191 stat_s extraMid1[7];
192 stat_s extraMid2[7];
193
194 for (uint32 tbeg=0; tbeg<6; tbeg++)
195 for (uint32 tend=0; tend<6; tend++)
196 for (uint32 mbeg=0; mbeg<2; mbeg++)
197 for (uint32 mend=0; mend<2; mend++)
198 for (uint32 moth=0; moth<2; moth++) {
199 if (mbeg && mend) {
200 extraMid1[6] += count1[tbeg][tend][mbeg][mend][moth];
201 extraMid2[6] += count2[tbeg][tend][mbeg][mend][moth];
202
203 if (tbeg == tend) {
204 extraMid1[tbeg] += count1[tbeg][tend][mbeg][mend][moth];
205 extraMid2[tbeg] += count2[tbeg][tend][mbeg][mend][moth];
206 }
207 }
208 }
209
210 extraMid1[6].print("extra middle 1");
211 extraMid2[6].print("extra middle 2");
212 for (uint32 i=0; i<6; i++) {
213 char l[64];
214 sprintf(l, "extra middle 1 %c", label[i]);
215 extraMid1[i].print(l);
216 sprintf(l, "extra middle 2 %c", label[i]);
217 extraMid2[i].print(l);
218 }
219
220 // Look for true extensions
221 //
222 stat_s extY1;
223 stat_s extN1;
224 stat_s extY2;
225 stat_s extN2;
226
227 for (uint32 tbeg=0; tbeg<6; tbeg++)
228 for (uint32 tend=0; tend<6; tend++)
229 for (uint32 mbeg=0; mbeg<2; mbeg++)
230 for (uint32 mend=0; mend<2; mend++)
231 for (uint32 moth=0; moth<2; moth++) {
232 if (mbeg && !mend) {
233 if (tbeg == TYPE_Y) {
234 extY1 += count1[tbeg][tend][mbeg][mend][moth];
235 } else {
236 extN1 += count1[tbeg][tend][mbeg][mend][moth];
237 }
238 }
239 if (!mbeg && mend) {
240 if (tend == TYPE_Y) {
241 extY2 += count2[tbeg][tend][mbeg][mend][moth];
242 } else {
243 extN2 += count2[tbeg][tend][mbeg][mend][moth];
244 }
245 }
246 }
247 extY1.print("extension Y 1");
248 extN1.print("extension N 1");
249 extY2.print("extension Y 2");
250 extN2.print("extension N 2");
251
252
253 fprintf(stderr, "----------------------------------------\n");
254 fprintf(stderr, "BEGIN IID SAME, END IID SAME, OTHER IID SAME\n");
255 fprintf(stderr, "----------------------------------------\n");
256 fprintf(stderr, "END IID\n");
257 fprintf(stderr, "----------------------------------------\n");
258 fprintf(stderr, "OTHER IID\n");
259 }