Debian Codegraph @

atac-driver/matchExtender/matchExtender.C

raw symbols SCIP
1 // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/matchExtender/matchExtender.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 <vector>
24 #include <algorithm>
25 using namespace std;
26
27 #include "atac.H"cxx . . $ `<file>/atac-driver/libatac/atac.H`/
28 #include "match.H"cxx . . $ `<file>/atac-driver/matchExtender/match.H`/
29 #include "bio++.H"cxx . . $ `<file>/libbio/bio++.H`/
30 #include "seqCache.H"cxx . . $ `<file>/libseq/seqCache.H`/
31
32
33 uint32cxx . . $ uint32# minEndRunLencxx . . $ minEndRunLen. = 10; // -E /matchExtenderMinEndRunLen
34 uint32cxx . . $ uint32# maxMMBlockcxx . . $ maxMMBlock. = 3; // -B /matchExtenderMaxMMBlock
35 uint32cxx . . $ uint32# minBlockSepcxx . . $ minBlockSep. = 20; // -S /matchExtenderMinBlockSep
36 double minIdentitycxx . . $ minIdentity. = 0.95; // -I /matchExtenderMinIdentity
37 uint32cxx . . $ uint32# maxNbrSepcxx . . $ maxNbrSep. = 100; // -P /matchExtenderMaxNbrSep
38 uint32cxx . . $ uint32# maxNbrPathMMcxx . . $ maxNbrPathMM. = 5; // -D /matchExtenderMaxNbrPathMM
39
40
41 bool trim_to_pctcxx . . $ trim_to_pct(1c8cd03981c76a54).(vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *>& matches, uint32cxx . . $ uint32# midx, double pct);
42 void extend_match_backwardcxx . . $ extend_match_backward(d93cdad5b6b3ddbf).(vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *>& matches, uint32cxx . . $ uint32# midx, uint32cxx . . $ uint32# min_start_pos);
43 bool can_reach_nearby_matchcxx . . $ can_reach_nearby_match(4128224f31867dc7).(match_scxx . . $ match_s# *src, match_scxx . . $ match_s# *dest);
44 bool extend_match_forwardcxx . . $ extend_match_forward(ef06361883eeef5d).(vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *>& matches, uint32cxx . . $ uint32# midx, match_scxx . . $ match_s# *target);
45 uint32cxx . . $ uint32# extend_matches_on_diagonalcxx . . $ extend_matches_on_diagonal(d7a89b59e50aea78).(vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *>& matches, uint32cxx . . $ uint32# diag_start);
46
47
48 class MatchComparecxx . . $ MatchCompare# {
49 public:
50 int operatorcxx . . $ MatchCompare#`operator()`(af441a07cc1bc2f2).()(const match_scxx . . $ match_s# *m1, const match_scxx . . $ match_s# *m2) {
51 return(*m1 <cxx . . $ match_s#`operator<`(a0ef6c7694cfea08). *m2);
52 }
53 };
54
55
56
57 // Read matches until the iid differs. Leave the next match in inLine.
58 //
59 bool
60 readMatchescxx . . $ readMatches(c7b5d94326d7176d).(atacFileStreamMergecxx . . $ atacFileStreamMerge# &AF,
61 atacMatchcxx . . $ atacMatch# *&m,
62 seqCachecxx . . $ seqCache# *C1,
63 seqCachecxx . . $ seqCache# *C2,
64 vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *> &fwdMatches,
65 vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *> &revMatches) {
66
67 fwdMatches.clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
68 revMatches.clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
69
70 // If M is null, we're here for the first time, so get the next
71 // (first) match from the file. M is also null if we're at the end
72 // of the file, so if after getting a match (that's done at the end
73 // of this routine) we're still null, we're all done.
74 //
75 if (m == 0L)
76 m = AF.nextMatchcxx . . $ atacFileStreamMerge#nextMatch(7b3c5176a3224eae).('x');
77 if (m == 0L)
78 return(false);
79
80 uint32cxx . . $ uint32# iid1 = m->iid1cxx . . $ atacMatch#iid1.;
81 uint32cxx . . $ uint32# iid2 = m->iid2cxx . . $ atacMatch#iid2.;
82
83 seqInCorecxx . . $ seqInCore# *seq1 = C1->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(iid1);
84 seqInCorecxx . . $ seqInCore# *seq2 = C2->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(iid2);
85
86 while (m) {
87 if ((m->iid1cxx . . $ atacMatch#iid1. == iid1) && (m->iid2cxx . . $ atacMatch#iid2. == iid2)) {
88
89 if (m->fwd1cxx . . $ atacMatch#fwd1. == m->fwd2cxx . . $ atacMatch#fwd2.)
90 fwdMatches.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(new match_scxx . . $ match_s#(m->matchuidcxx . . $ atacMatch#matchuid.,
91 seq1, m->iid1cxx . . $ atacMatch#iid1., m->pos1cxx . . $ atacMatch#pos1., m->len1cxx . . $ atacMatch#len1., m->fwd1cxx . . $ atacMatch#fwd1.,
92 seq2, m->iid2cxx . . $ atacMatch#iid2., m->pos2cxx . . $ atacMatch#pos2., m->len2cxx . . $ atacMatch#len2., m->fwd2cxx . . $ atacMatch#fwd2.));
93 else
94 revMatches.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(new match_scxx . . $ match_s#(m->matchuidcxx . . $ atacMatch#matchuid.,
95 seq1, m->iid1cxx . . $ atacMatch#iid1., m->pos1cxx . . $ atacMatch#pos1., m->len1cxx . . $ atacMatch#len1., m->fwd1cxx . . $ atacMatch#fwd1.,
96 seq2, m->iid2cxx . . $ atacMatch#iid2., m->pos2cxx . . $ atacMatch#pos2., m->len2cxx . . $ atacMatch#len2., m->fwd2cxx . . $ atacMatch#fwd2.));
97 } else {
98 break;
99 }
100
101 m = AF.nextMatchcxx . . $ atacFileStreamMerge#nextMatch(7b3c5176a3224eae).('x');
102 }
103
104 if (fwdMatches.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() > 0)
105 sortcxx . . $ std/sort(4d3091562df4e52e).(fwdMatches.begincxx . . $ std/vector#begin(55a6de06420d4903).(), fwdMatches.endcxx . . $ std/vector#end(55a6de06420d4903).(), MatchComparecxx . . $ MatchCompare#());
106
107 if (revMatches.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() > 0)
108 sortcxx . . $ std/sort(4d3091562df4e52e).(revMatches.begincxx . . $ std/vector#begin(55a6de06420d4903).(), revMatches.endcxx . . $ std/vector#end(55a6de06420d4903).(), MatchComparecxx . . $ MatchCompare#());
109
110 return(true);
111 }
112
113
114
115
116 int
117 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) {
118 bool fail = false;
119
120 atacMatchcxx . . $ atacMatch# *m = 0L;
121 atacFileStreamMergecxx . . $ atacFileStreamMerge# AFcxx . . $ atacFileStreamMerge#atacFileStreamMerge(49f6e7a06ebc5aa8).;
122
123 int arg=1;
124 while (arg < argc) {
125 if (strcmp(argv[arg], "-e") == 0) {
126 minEndRunLencxx . . $ minEndRunLen. = strtouint32cxx . . $ `libutil/util.h:82:10`!(argv[++arg], 0L);
127 } else if (strcmp(argv[arg], "-b") == 0) {
128 maxMMBlockcxx . . $ maxMMBlock. = strtouint32cxx . . $ `libutil/util.h:82:10`!(argv[++arg], 0L);
129 } else if (strcmp(argv[arg], "-s") == 0) {
130 minBlockSepcxx . . $ minBlockSep. = strtouint32cxx . . $ `libutil/util.h:82:10`!(argv[++arg], 0L);
131 } else if (strcmp(argv[arg], "-i") == 0) {
132 minIdentitycxx . . $ minIdentity. = atofcxx . . $ atof(9b0361fcbc284e4f).(argv[++arg]);
133 } else if (strcmp(argv[arg], "-p") == 0) {
134 maxNbrSepcxx . . $ maxNbrSep. = strtouint32cxx . . $ `libutil/util.h:82:10`!(argv[++arg], 0L);
135 } else if (strcmp(argv[arg], "-d") == 0) {
136 maxNbrPathMMcxx . . $ maxNbrPathMM. = strtouint32cxx . . $ `libutil/util.h:82:10`!(argv[++arg], 0L);
137 } else {
138 //fprintf(stderr, "unknown option %s\n", argv[arg]);
139 //fail = true;
140 AF.addFilecxx . . $ atacFileStreamMerge#addFile(85c52e162fed56f9).(argv[arg]);
141 }
142
143 arg++;
144 }
145
146 if (fail) {
147 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [options] header.atac matches.atac ... > matches.atac\n", argv[0]);
148 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -e <int> matchExtenderMinEndRunLen, 10\n");
149 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -b <int> matchExtenderMaxMMBlock, 3\n");
150 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -s <int> matchExtenderMinBlockSep, 20\n");
151 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -i <float> matchExtenderMinIdentity, 0.95\n");
152 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -p <int> matchExtenderMaxNbrSep, 100\n");
153 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -d <int> matchExtenderMaxNbrPathMM, 5\n");
154 exitcxx . . $ exit(44ed87f96534fad7).(1);
155 }
156
157 AF.writeHeadercxx . . $ atacFileStreamMerge#writeHeader(8d4262d45fc644ab).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
158
159 seqCachecxx . . $ seqCache# *C1 = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileAcxx . . $ atacFileBase#assemblyFileA(41208ce6ca65dd58).(), 1, false);
160 seqCachecxx . . $ seqCache# *C2 = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileBcxx . . $ atacFileBase#assemblyFileB(41208ce6ca65dd58).(), 1, false);
161
162 C1->loadAllSequencescxx . . $ seqCache#loadAllSequences(49f6e7a06ebc5aa8).();
163
164 vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *> fwdMatchescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
165 vectorcxx . . $ std/vector#<match_scxx . . $ match_s# *> revMatchescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
166
167 while (readMatchescxx . . $ readMatches(c7b5d94326d7176d).(AF, m, C1, C2, fwdMatches, revMatches)) {
168
169 uint32cxx . . $ uint32# diag_start = 0;
170 while (diag_start < fwdMatches.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) {
171 //fprintf(stderr, "fwd: M u %s . %s %d %d 1 %s %d %d 1\n",
172 // fwdMatches[diag_start]->_matchId,
173 // fwdMatches[diag_start]->_id1, fwdMatches[diag_start]->_acc1->getRangeBegin(), fwdMatches[diag_start]->_acc1->getRangeLength(),
174 // fwdMatches[diag_start]->_id2, fwdMatches[diag_start]->_acc2->getRangeBegin(), fwdMatches[diag_start]->_acc2->getRangeLength());
175 diag_start = extend_matches_on_diagonalcxx . . $ extend_matches_on_diagonal(d7a89b59e50aea78).(fwdMatches, diag_start);
176 }
177
178 diag_start = 0;
179 while (diag_start < revMatches.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) {
180 //fprintf(stderr, "rev: M u %s . %s %d %d 1 %s %d %d 1\n",
181 // revMatches[diag_start]->_matchId,
182 // revMatches[diag_start]->_id1, revMatches[diag_start]->_acc1->getRangeBegin(), revMatches[diag_start]->_acc1->getRangeLength(),
183 // revMatches[diag_start]->_id2, revMatches[diag_start]->_acc2->getRangeBegin(), revMatches[diag_start]->_acc2->getRangeLength());
184 diag_start = extend_matches_on_diagonalcxx . . $ extend_matches_on_diagonal(d7a89b59e50aea78).(revMatches, diag_start);
185 }
186
187
188 // Dump and destroy all the matches
189 //
190 for (uint32cxx . . $ uint32# i=0; i<fwdMatches.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) {
191 if (!fwdMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->isDeletedcxx . . $ match_s#isDeleted(c9857a73d68e59ba).())
192 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "M u %s . %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1 %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1\n",
193 fwdMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_matchIdcxx . . $ match_s#_matchId.,
194 AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), fwdMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_iid1cxx . . $ match_s#_iid1., fwdMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_acc1cxx . . $ match_s#_acc1.->getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).(), fwdMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_acc1cxx . . $ match_s#_acc1.->getRangeLengthcxx . . $ FastAAccessor#getRangeLength(db52760e79bf9054).(),
195 AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), fwdMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_iid2cxx . . $ match_s#_iid2., fwdMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_acc2cxx . . $ match_s#_acc2.->getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).(), fwdMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_acc2cxx . . $ match_s#_acc2.->getRangeLengthcxx . . $ FastAAccessor#getRangeLength(db52760e79bf9054).());
196 delete fwdMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i];
197 }
198
199 for (uint32cxx . . $ uint32# i=0; i<revMatches.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) {
200 if (!revMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->isDeletedcxx . . $ match_s#isDeleted(c9857a73d68e59ba).())
201 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "M u %s . %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1 %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" -1\n",
202 revMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_matchIdcxx . . $ match_s#_matchId.,
203 AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), revMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_iid1cxx . . $ match_s#_iid1., revMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_acc1cxx . . $ match_s#_acc1.->getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).(), revMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_acc1cxx . . $ match_s#_acc1.->getRangeLengthcxx . . $ FastAAccessor#getRangeLength(db52760e79bf9054).(),
204 AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), revMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_iid2cxx . . $ match_s#_iid2., revMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_acc2cxx . . $ match_s#_acc2.->getRangeBegincxx . . $ FastAAccessor#getRangeBegin(db52760e79bf9054).(), revMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]->_acc2cxx . . $ match_s#_acc2.->getRangeLengthcxx . . $ FastAAccessor#getRangeLength(db52760e79bf9054).());
205 delete revMatches[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i];
206 }
207
208 fwdMatches.clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
209 revMatches.clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
210 }
211
212 delete C1;
213 delete C2;
214 }