Debian Codegraph @

atac-driver/gapShifter/extractUnmapped.C

raw symbols SCIP
1 // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/gapShifter/extractUnmapped.C`/
2 // Copyright (c) 2006 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 "atac.H"cxx . . $ `<file>/atac-driver/libatac/atac.H`/
25
26
27
28 //
29 // Tested to work on ../../atac/B36LCvsHUREF6A/B36LCvsHUREF6A.gapsFixed.atac
30 //
31
32
33
34 // Reads a set of matches and outputs two sequence files containing sequence that
35 // is not matched.
36
37
38 void
39 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(FILE *output,
40 seqInCorecxx . . $ seqInCore# *S,
41 uint32cxx . . $ uint32# beg,
42 uint32cxx . . $ uint32# end,
43 uint32cxx . . $ uint32# extend,
44 atacMatchcxx . . $ atacMatch# *l,
45 atacMatchcxx . . $ atacMatch# *r) {
46 char *s = S->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).();
47
48
49 // Skip any N's starting where we are currently
50 //
51 while ((beg < end) &&
52 (toUpper[(int)s[beg]] == 'N'))
53 beg++;
54
55 while ((beg < end) &&
56 (toUpper[(int)s[end-1]] == 'N'))
57 end--;
58
59 if (beg >= end)
60 return;
61
62 // Extend the ends up to 'extend' positions, as long as we don't
63 // hit a gap.
64 //
65 for (uint32cxx . . $ uint32# x=0; ((x < extend) &&
66 (beg > 0) &&
67 (toUpper[(int)s[beg-1]] != 'N')); x++)
68 beg--;
69
70 for (uint32cxx . . $ uint32# x=0; ((x < extend) &&
71 (end < S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).()) &&
72 (toUpper[(int)s[end]] != 'N')); x++)
73 end++;
74
75 // Just make sure we're still in bounds!
76 if (end > S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).())
77 end = S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).();
78
79 // Over the whole sequence
80 //
81 while (beg < end) {
82
83 // Skip any N's starting where we are currently
84 //
85 while ((beg < end) &&
86 (toUpper[(int)s[beg]] == 'N'))
87 beg++;
88
89 // Move our current up to here
90 uint32cxx . . $ uint32# cur = beg;
91
92 // If we're at the end of the sequence, this block doesn't
93 // exist; it's solid N.
94 //
95 if (beg < end) {
96
97 // Move cur up to the next N
98 //
99 while ((cur < end) &&
100 (toUpper[(int)s[cur]] != 'N'))
101 cur++;
102
103 // And output whatever this block is
104 //
105 fprintf(output, "%s extracted from iid "uint32FMTcxx . . $ `libutil/util.h:65:10`!" pos "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" between match %s(%s) and %s(%s)\n",
106 S->headercxx . . $ seqInCore#header(e7e5aa338b9d5147).(), S->getIIDcxx . . $ seqInCore#getIID(ddd8539a2fcdd4ce).(), beg, cur,
107 (l) ? l->matchuidcxx . . $ atacMatch#matchuid. : "none",
108 (l) ? l->parentuidcxx . . $ atacMatch#parentuid. : "none",
109 (r) ? r->matchuidcxx . . $ atacMatch#matchuid. : "none",
110 (r) ? r->parentuidcxx . . $ atacMatch#parentuid. : "none");
111
112 fwrite(S->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + beg, sizeof(char), cur-beg, output);
113 fprintf(output, "\n");
114
115 }
116
117 // Move to the next block.
118 beg = cur;
119 }
120 }
121
122
123
124
125
126 // COPIED from libatac/matchList.C, but need to dereference the atacMatch again.
127 //
128 static
129 int
130 sort1_cxx . . $ sort1_(9148c8c3ff42c9d8).(const void *a, const void *b) {
131 const atacMatchcxx . . $ atacMatch# *A = *(const atacMatchcxx . . $ atacMatch# * const *)a;
132 const atacMatchcxx . . $ atacMatch# *B = *(const atacMatchcxx . . $ atacMatch# * const *)b;
133
134 if (A->iid1cxx . . $ atacMatch#iid1. < B->iid1cxx . . $ atacMatch#iid1.) return(-1);
135 if (A->iid1cxx . . $ atacMatch#iid1. > B->iid1cxx . . $ atacMatch#iid1.) return(1);
136 if (A->pos1cxx . . $ atacMatch#pos1. < B->pos1cxx . . $ atacMatch#pos1.) return(-1);
137 if (A->pos1cxx . . $ atacMatch#pos1. > B->pos1cxx . . $ atacMatch#pos1.) return(1);
138 if (A->len1cxx . . $ atacMatch#len1. > B->len1cxx . . $ atacMatch#len1.) return(-1);
139 if (A->len1cxx . . $ atacMatch#len1. < B->len1cxx . . $ atacMatch#len1.) return(1);
140 if (A->iid2cxx . . $ atacMatch#iid2. < B->iid2cxx . . $ atacMatch#iid2.) return(-1);
141 if (A->iid2cxx . . $ atacMatch#iid2. > B->iid2cxx . . $ atacMatch#iid2.) return(1);
142 if (A->pos2cxx . . $ atacMatch#pos2. < B->pos2cxx . . $ atacMatch#pos2.) return(-1);
143 if (A->pos2cxx . . $ atacMatch#pos2. > B->pos2cxx . . $ atacMatch#pos2.) return(1);
144 if (A->len2cxx . . $ atacMatch#len2. > B->len2cxx . . $ atacMatch#len2.) return(-1);
145 if (A->len2cxx . . $ atacMatch#len2. < B->len2cxx . . $ atacMatch#len2.) return(1);
146 return(0);
147 }
148
149 static
150 int
151 sort2_cxx . . $ sort2_(9148c8c3ff42c9d8).(const void *a, const void *b) {
152 const atacMatchcxx . . $ atacMatch# *A = *(const atacMatchcxx . . $ atacMatch# * const *)a;
153 const atacMatchcxx . . $ atacMatch# *B = *(const atacMatchcxx . . $ atacMatch# * const *)b;
154
155 if (A->iid2cxx . . $ atacMatch#iid2. < B->iid2cxx . . $ atacMatch#iid2.) return(-1);
156 if (A->iid2cxx . . $ atacMatch#iid2. > B->iid2cxx . . $ atacMatch#iid2.) return(1);
157 if (A->pos2cxx . . $ atacMatch#pos2. < B->pos2cxx . . $ atacMatch#pos2.) return(-1);
158 if (A->pos2cxx . . $ atacMatch#pos2. > B->pos2cxx . . $ atacMatch#pos2.) return(1);
159 if (A->len2cxx . . $ atacMatch#len2. > B->len2cxx . . $ atacMatch#len2.) return(-1);
160 if (A->len2cxx . . $ atacMatch#len2. < B->len2cxx . . $ atacMatch#len2.) return(1);
161 if (A->iid1cxx . . $ atacMatch#iid1. < B->iid1cxx . . $ atacMatch#iid1.) return(-1);
162 if (A->iid1cxx . . $ atacMatch#iid1. > B->iid1cxx . . $ atacMatch#iid1.) return(1);
163 if (A->pos1cxx . . $ atacMatch#pos1. < B->pos1cxx . . $ atacMatch#pos1.) return(-1);
164 if (A->pos1cxx . . $ atacMatch#pos1. > B->pos1cxx . . $ atacMatch#pos1.) return(1);
165 if (A->len1cxx . . $ atacMatch#len1. > B->len1cxx . . $ atacMatch#len1.) return(-1);
166 if (A->len1cxx . . $ atacMatch#len1. < B->len1cxx . . $ atacMatch#len1.) return(1);
167
168 return(0);
169 }
170
171
172
173 // New method, uses an intervalList to find the unmapped regions for
174 // each sequence.
175 //
176 class extractMatchListcxx . . $ extractMatchList# {
177
178 public:
179 extractMatchListcxx . . $ extractMatchList#extractMatchList(49f6e7a06ebc5aa8).() {
180 matchesLencxx . . $ extractMatchList#matchesLen. = 0;
181 matchesMaxcxx . . $ extractMatchList#matchesMax. = 16;
182 matchescxx . . $ extractMatchList#matches. = new atacMatchcxx . . $ atacMatch# * [matchesMaxcxx . . $ extractMatchList#matchesMax.];
183 };
184 ~cxx . . $ extractMatchList#`~extractMatchList`(ced63f7c635d850d).extractMatchListcxx . . $ extractMatchList#() {
185 delete [] matchescxx . . $ extractMatchList#matches.;
186 };
187
188 atacMatchcxx . . $ atacMatch# *operatorcxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).[](uint32cxx . . $ uint32# idx) {
189 return(matchescxx . . $ extractMatchList#matches.[idx]);
190 };
191
192 uint32cxx . . $ uint32# lencxx . . $ extractMatchList#len(db52760e79bf9054).(void) {
193 return(matchesLencxx . . $ extractMatchList#matchesLen.);
194 };
195
196 void addcxx . . $ extractMatchList#add(84d849da2700a03).(atacMatchcxx . . $ atacMatch# *m) {
197 if (matchesLencxx . . $ extractMatchList#matchesLen. >= matchesMaxcxx . . $ extractMatchList#matchesMax.) {
198 matchesMaxcxx . . $ extractMatchList#matchesMax. *= 2;
199 atacMatchcxx . . $ atacMatch# **M = new atacMatchcxx . . $ atacMatch# * [matchesMaxcxx . . $ extractMatchList#matchesMax.];
200 memcpy(M, matchescxx . . $ extractMatchList#matches., sizeof(atacMatchcxx . . $ atacMatch# *) * matchesLencxx . . $ extractMatchList#matchesLen.);
201 delete [] matchescxx . . $ extractMatchList#matches.;
202 matchescxx . . $ extractMatchList#matches. = M;
203 }
204 matchescxx . . $ extractMatchList#matches.[matchesLencxx . . $ extractMatchList#matchesLen.++] = m;
205 };
206
207 void sort1cxx . . $ extractMatchList#sort1(49f6e7a06ebc5aa8).(void) {
208 qsortcxx . . $ qsort(ebb60b13a65e77d7).(matchescxx . . $ extractMatchList#matches., matchesLencxx . . $ extractMatchList#matchesLen., sizeof(atacMatchcxx . . $ atacMatch#*), sort1_cxx . . $ sort1_(9148c8c3ff42c9d8).);
209 };
210 void sort2cxx . . $ extractMatchList#sort2(49f6e7a06ebc5aa8).(void) {
211 qsortcxx . . $ qsort(ebb60b13a65e77d7).(matchescxx . . $ extractMatchList#matches., matchesLencxx . . $ extractMatchList#matchesLen., sizeof(atacMatchcxx . . $ atacMatch#*), sort2_cxx . . $ sort2_(9148c8c3ff42c9d8).);
212 };
213
214 private:
215 atacMatchcxx . . $ atacMatch# **matchescxx . . $ extractMatchList#matches.;
216 uint32cxx . . $ uint32# matchesLencxx . . $ extractMatchList#matchesLen.;
217 uint32cxx . . $ uint32# matchesMaxcxx . . $ extractMatchList#matchesMax.;
218 };
219
220
221
222
223 void
224 extractUnmappedcxx . . $ extractUnmapped(2f7eb2669ea79946).(seqCachecxx . . $ seqCache# *A, seqCachecxx . . $ seqCache# *B,
225 FILE *Aoutput, FILE *Boutput,
226 uint32cxx . . $ uint32# extend,
227 atacFilecxx . . $ atacFile# &AF,
228 atacMatchListcxx . . $ atacMatchList# &ML) {
229 uint32cxx . . $ uint32# numSeqsA = AF.fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).()->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).();
230 uint32cxx . . $ uint32# numSeqsB = AF.fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).()->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).();
231
232 extractMatchListcxx . . $ extractMatchList# *coveredA = new extractMatchListcxx . . $ extractMatchList# [numSeqsA];
233 extractMatchListcxx . . $ extractMatchList# *coveredB = new extractMatchListcxx . . $ extractMatchList# [numSeqsB];
234
235 // Populate the intervals with the mapping
236 //
237 for (uint32cxx . . $ uint32# x=0; x<ML.numMatchescxx . . $ atacMatchList#numMatches(db52760e79bf9054).(); x++) {
238 atacMatchcxx . . $ atacMatch# *m = ML[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).x];
239
240 coveredA[m->iid1cxx . . $ atacMatch#iid1.].addcxx . . $ extractMatchList#add(84d849da2700a03).(m);
241 coveredB[m->iid2cxx . . $ atacMatch#iid2.].addcxx . . $ extractMatchList#add(84d849da2700a03).(m);
242 }
243
244 // Sort the intervals, manually invert the interval -- remembering
245 // what matches are where.
246 //
247 for (uint32cxx . . $ uint32# seq=0; seq<numSeqsA; seq++) {
248 coveredA[seq].sort1cxx . . $ extractMatchList#sort1(49f6e7a06ebc5aa8).();
249
250 //ML.fastaA()->find(seq);
251 //seqInCore *S = ML.fastaA()->getSequenceInCore();
252
253 seqInCorecxx . . $ seqInCore# *S = A->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(seq);
254
255 if (coveredA[seq].lencxx . . $ extractMatchList#len(db52760e79bf9054).() == 0) {
256 // Hey! This sequence has NO matches at all!
257 //
258 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(Aoutput,
259 S,
260 0,
261 AF.fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).()->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(seq),
262 extend,
263 0L, 0L);
264 } else {
265 if (0 < coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).0]->pos1cxx . . $ atacMatch#pos1.) {
266 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(Aoutput,
267 S,
268 0,
269 coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).0]->pos1cxx . . $ atacMatch#pos1.,
270 extend,
271 0L, coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).0]);
272 }
273
274 for (uint32cxx . . $ uint32# i=1; i<coveredA[seq].lencxx . . $ extractMatchList#len(db52760e79bf9054).(); i++) {
275 if (coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1]->pos1cxx . . $ atacMatch#pos1. + coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1]->len1cxx . . $ atacMatch#len1. < coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i]->pos1cxx . . $ atacMatch#pos1.) {
276 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(Aoutput,
277 S,
278 coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1]->pos1cxx . . $ atacMatch#pos1. + coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1]->len1cxx . . $ atacMatch#len1.,
279 coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i]->pos1cxx . . $ atacMatch#pos1.,
280 extend,
281 coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1], coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i]);
282 }
283 }
284
285 uint32cxx . . $ uint32# last = coveredA[seq].lencxx . . $ extractMatchList#len(db52760e79bf9054).()-1;
286 if (coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).last]->pos1cxx . . $ atacMatch#pos1.) {
287 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(Aoutput,
288 S,
289 coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).last]->pos1cxx . . $ atacMatch#pos1. + coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).last]->len1cxx . . $ atacMatch#len1.,
290 AF.fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).()->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(seq),
291 extend,
292 coveredA[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).0], 0L);
293 }
294 }
295 }
296
297
298
299 // DUPLICATION OF THE ABOVE! (Replace 1 with 2, A with B)
300
301
302 // Sort the intervals, manually invert the interval -- remembering
303 // what matches are where.
304 //
305 for (uint32cxx . . $ uint32# seq=0; seq<numSeqsB; seq++) {
306 coveredB[seq].sort2cxx . . $ extractMatchList#sort2(49f6e7a06ebc5aa8).();
307
308 seqInCorecxx . . $ seqInCore# *S = B->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(seq);
309
310 if (coveredB[seq].lencxx . . $ extractMatchList#len(db52760e79bf9054).() == 0) {
311 // Hey! This sequence has NO matches at all!
312 //
313 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(Boutput,
314 S,
315 0,
316 AF.fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).()->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(seq),
317 extend,
318 0L, 0L);
319 } else {
320 if (0 < coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).0]->pos2cxx . . $ atacMatch#pos2.) {
321 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(Boutput,
322 S,
323 0,
324 coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).0]->pos2cxx . . $ atacMatch#pos2.,
325 extend,
326 0L, coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).0]);
327 }
328
329 for (uint32cxx . . $ uint32# i=1; i<coveredB[seq].lencxx . . $ extractMatchList#len(db52760e79bf9054).(); i++) {
330 if (coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1]->pos2cxx . . $ atacMatch#pos2. + coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1]->len2cxx . . $ atacMatch#len2. < coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i]->pos2cxx . . $ atacMatch#pos2.) {
331 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(Boutput,
332 S,
333 coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1]->pos2cxx . . $ atacMatch#pos2. + coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1]->len2cxx . . $ atacMatch#len2.,
334 coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i]->pos2cxx . . $ atacMatch#pos2.,
335 extend,
336 coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i-1], coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).i]);
337 }
338 }
339
340 uint32cxx . . $ uint32# last = coveredB[seq].lencxx . . $ extractMatchList#len(db52760e79bf9054).()-1;
341 if (coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).last]->pos2cxx . . $ atacMatch#pos2.) {
342 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(Boutput,
343 S,
344 coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).last]->pos2cxx . . $ atacMatch#pos2. + coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).last]->len2cxx . . $ atacMatch#len2.,
345 AF.fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).()->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(seq),
346 extend,
347 coveredB[seq][cxx . . $ extractMatchList#`operator[]`(4b949e4d42dbfd78).0], 0L);
348 }
349 }
350 }
351
352
353
354
355
356
357
358
359
360 }
361
362
363 void
364 extractUnmappedRunscxx . . $ extractUnmappedRuns(cbdd3c2201bfceae).(seqCachecxx . . $ seqCache# *A, seqCachecxx . . $ seqCache# *B,
365 FILE *ARoutput, FILE *BRoutput,
366 uint32cxx . . $ uint32# extend,
367 atacMatchListcxx . . $ atacMatchList# &ML) {
368 seqInCorecxx . . $ seqInCore# *S1 = 0L;
369 seqInCorecxx . . $ seqInCore# *S2 = 0L;
370
371 atacMatchOrdercxx . . $ atacMatchOrder# MOcxx . . $ atacMatchOrder#atacMatchOrder(f3ef1525738b52af).(ML);
372 MO.sortAcxx . . $ atacMatchOrder#sortA(b4d55b1286ff73e8).();
373
374 for (uint32cxx . . $ uint32# i=1; i<MO.numMatchescxx . . $ atacMatchOrder#numMatches(db52760e79bf9054).(); i++) {
375 atacMatchcxx . . $ atacMatch# *l = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1];
376 atacMatchcxx . . $ atacMatch# *r = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i];
377
378 if (l->iid1cxx . . $ atacMatch#iid1. != r->iid1cxx . . $ atacMatch#iid1.)
379 continue;
380 if (l->iid2cxx . . $ atacMatch#iid2. != r->iid2cxx . . $ atacMatch#iid2.)
381 continue;
382
383 // Extract from (l->pos1 + l->len1) to (r->pos1), if it's longer than 20bp
384
385 bool lengthOK = true;
386 if (l->pos1cxx . . $ atacMatch#pos1. + l->len1cxx . . $ atacMatch#len1. + 20 >= r->pos1cxx . . $ atacMatch#pos1.)
387 lengthOK = false;
388 if ((l->fwd2cxx . . $ atacMatch#fwd2. == true) && (l->pos2cxx . . $ atacMatch#pos2. + l->len2cxx . . $ atacMatch#len2. + 20 >= r->pos2cxx . . $ atacMatch#pos2.))
389 lengthOK = false;
390 if ((l->fwd2cxx . . $ atacMatch#fwd2. == false) && (r->pos2cxx . . $ atacMatch#pos2. + r->len2cxx . . $ atacMatch#len2. + 20 >= l->pos2cxx . . $ atacMatch#pos2.))
391 lengthOK = false;
392
393 // Extract if our two matches are in the same run.
394 //
395 if ((lengthOK) &&
396 (strcmp(l->parentuidcxx . . $ atacMatch#parentuid., r->parentuidcxx . . $ atacMatch#parentuid.) == 0)) {
397
398 #if 0
399 if (l->iid1 != S1->getIID()) {
400 delete S1;
401 W1->find(l->iid1);
402 S1 = W1->getSequenceInCore();
403 }
404
405 if (l->iid2 != S2->getIID()) {
406 delete S2;
407 W2->find(l->iid2);
408 S2 = W2->getSequenceInCore();
409 }
410 #else
411 S1 = A->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(l->iid1cxx . . $ atacMatch#iid1.);
412 S2 = B->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(l->iid2cxx . . $ atacMatch#iid2.);
413 #endif
414
415 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(ARoutput,
416 S1,
417 l->pos1cxx . . $ atacMatch#pos1. + l->len1cxx . . $ atacMatch#len1.,
418 r->pos1cxx . . $ atacMatch#pos1.,
419 extend,
420 l, r);
421
422 // Need to deal with reverse matches here! In run matches
423 // should be the same orientation, but we'll still check.
424 //
425 if (l->fwd2cxx . . $ atacMatch#fwd2. != r->fwd2cxx . . $ atacMatch#fwd2.) {
426 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WOAH! Matches of different orientation in a run?!?\n");
427 exitcxx . . $ exit(44ed87f96534fad7).(1);
428 }
429
430 if (l->fwd2cxx . . $ atacMatch#fwd2.) {
431 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(BRoutput,
432 S2,
433 l->pos2cxx . . $ atacMatch#pos2. + l->len2cxx . . $ atacMatch#len2.,
434 r->pos2cxx . . $ atacMatch#pos2.,
435 extend,
436 l, r);
437 } else {
438 writeGaplessSequencecxx . . $ writeGaplessSequence(e30efb18d99e7b4b).(BRoutput,
439 S2,
440 r->pos2cxx . . $ atacMatch#pos2. + r->len2cxx . . $ atacMatch#len2.,
441 l->pos2cxx . . $ atacMatch#pos2.,
442 extend,
443 l, r);
444 }
445 }
446 }
447 }
448
449
450
451
452
453
454
455
456 void
457 usagecxx . . $ usage(fda57c8427c60377).(char *name) {
458 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [-OP output.fasta] [-t trfile] -m matches\n", name);
459 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " OP\n");
460 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -a extract all unmapped sequence in A\n");
461 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -b extract all unmapped sequence in B\n");
462 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -ar extract within run unmapped sequence in A\n");
463 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -br extract within run unmapped sequence in B\n");
464 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " BOTH -ar and -br need to be specified!\n");
465 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n");
466 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -t mask out tandem repeats listed in trfile\n");
467 }
468
469 FILE *
470 openOutputFilecxx . . $ openOutputFile(102d3a3004848b86).(char *name) {
471 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
472 FILE *R = fopen(name, "w");
473 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
474 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to open '%s': %s\n", name, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1);
475 return(R);
476 }
477
478 int
479 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) {
480 char *matchesFile = 0L;
481 FILE *Aoutput = 0L;
482 FILE *Boutput = 0L;
483 FILE *ARoutput = 0L;
484 FILE *BRoutput = 0L;
485 uint32cxx . . $ uint32# extend = 0;
486 char *trFile = 0L;
487
488 int arg=1;
489 while (arg < argc) {
490 if (strcmp(argv[arg], "-m") == 0) {
491 matchesFile = argv[++arg];
492 } else if (strcmp(argv[arg], "-a") == 0) {
493 Aoutput = openOutputFilecxx . . $ openOutputFile(102d3a3004848b86).(argv[++arg]);
494 } else if (strcmp(argv[arg], "-b") == 0) {
495 Boutput = openOutputFilecxx . . $ openOutputFile(102d3a3004848b86).(argv[++arg]);
496 } else if (strcmp(argv[arg], "-ar") == 0) {
497 ARoutput = openOutputFilecxx . . $ openOutputFile(102d3a3004848b86).(argv[++arg]);
498 } else if (strcmp(argv[arg], "-br") == 0) {
499 BRoutput = openOutputFilecxx . . $ openOutputFile(102d3a3004848b86).(argv[++arg]);
500 } else if (strcmp(argv[arg], "-e") == 0) {
501 extend = strtouint32cxx . . $ `libutil/util.h:82:10`!(argv[++arg], 0L);
502 } else if (strcmp(argv[arg], "-t") == 0) {
503 trFile = argv[++arg];
504 } else {
505 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
506 exitcxx . . $ exit(44ed87f96534fad7).(1);
507 }
508 arg++;
509 }
510
511 if (matchesFile == 0L)
512 usagecxx . . $ usage(fda57c8427c60377).(argv[0]), exitcxx . . $ exit(44ed87f96534fad7).(1);
513
514 atacFilecxx . . $ atacFile# AFcxx . . $ atacFile#atacFile(85c52e162fed56f9).(matchesFile);
515 atacMatchListcxx . . $ atacMatchList# &ML = *AF.matchescxx . . $ atacFile#matches(33e88ebc28d05bce).();
516
517 // Build caches for both sequences, then modify that sequence to
518 // mask out tandem repeats.
519 //
520 seqCachecxx . . $ seqCache# *A = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileAcxx . . $ atacFileBase#assemblyFileA(41208ce6ca65dd58).(), 0, true);
521 seqCachecxx . . $ seqCache# *B = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileBcxx . . $ atacFileBase#assemblyFileB(41208ce6ca65dd58).(), 0, true);
522
523 A->loadAllSequencescxx . . $ seqCache#loadAllSequences(49f6e7a06ebc5aa8).();
524 B->loadAllSequencescxx . . $ seqCache#loadAllSequences(49f6e7a06ebc5aa8).();
525
526 if (trFile) {
527 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! =0;
528 FILE *F = fopen(trFile, "r");
529 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
530 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error opening '%s': %s\n", trFile, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
531
532 char L[1024] = { 0 };
533 splitToWordscxx . . $ splitToWords# Wcxx . . $ splitToWords#splitToWords(fda57c8427c60377).(L);
534
535 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Masking repeats in '%s'\n", trFile);
536
537 uint32cxx . . $ uint32# statidx = 0;
538 uint32cxx . . $ uint32# stats[2] = { 0 };
539
540 while (!feof(F)) {
541 fgets(L, 1024, F);
542 W.splitcxx . . $ splitToWords#split(fda57c8427c60377).(L);
543
544 char source = W[cxx . . $ splitToWords#`operator[]`(f109d7e0a0ca42b3).0][0];
545 uint32cxx . . $ uint32# iid = strtouint32cxx . . $ `libutil/util.h:82:10`!(W[1], 0L);
546 uint32cxx . . $ uint32# pos = strtouint32cxx . . $ `libutil/util.h:82:10`!(W[2], 0L);
547 uint32cxx . . $ uint32# len = strtouint32cxx . . $ `libutil/util.h:82:10`!(W[3], 0L);
548 bool fwd = (W[cxx . . $ splitToWords#`operator[]`(f109d7e0a0ca42b3).4][0] != '-');
549
550 seqInCorecxx . . $ seqInCore# *S = 0L;
551 char *s = 0L;
552
553 if (source == 'B') {
554 S = A->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(iid);
555 s = A->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(iid)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).();
556 statidx = 0;
557 } else if (source == 'H') {
558 S = B->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(iid);
559 s = B->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(iid)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).();
560 statidx = 1;
561 } else {
562 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Unknown source '%c'\n", source);
563 exitcxx . . $ exit(44ed87f96534fad7).(1);
564 }
565
566 //fprintf(stderr, "Masking %c "uint32FMTW(8)" from "uint32FMTW(9)" to "uint32FMTW(9)" on strand %c\r",
567 // source, iid, pos, pos+len, (fwd) ? 'f' : 'r');
568
569 if (fwd) {
570 s += pos;
571 } else {
572 s += S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).() - pos - len;
573 }
574
575 for (uint32cxx . . $ uint32# i=0; i<len; i++) {
576 if (toUpper[(int)s[i]] != 'N')
577 stats[statidx]++;
578 s[i] = 'N';
579 }
580 }
581 fclose(F);
582
583 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Done masking. "uint32FMTcxx . . $ `libutil/util.h:65:10`!" in A, "uint32FMTcxx . . $ `libutil/util.h:65:10`!" in B.\n", stats[0], stats[1]);
584 }
585
586
587 if (Aoutput && Boutput) {
588 extractUnmappedcxx . . $ extractUnmapped(2f7eb2669ea79946).(A, B, Aoutput, Boutput, extend, AF, ML);
589 fclose(Aoutput);
590 fclose(Boutput);
591 }
592
593 if (ARoutput && BRoutput) {
594 extractUnmappedRunscxx . . $ extractUnmappedRuns(cbdd3c2201bfceae).(A, B, ARoutput, BRoutput, extend, ML);
595 fclose(ARoutput);
596 fclose(BRoutput);
597 }
598
599 return(0);
600 }