Imported Debian patch 0.12.7-3
[bowtie.git] / aligner_0mm.h
1 /*
2  * aligner_0mm.h
3  */
4
5 #ifndef ALIGNER_0MM_H_
6 #define ALIGNER_0MM_H_
7
8 #include <utility>
9 #include <vector>
10 #include "aligner.h"
11 #include "hit.h"
12 #include "row_chaser.h"
13 #include "range_chaser.h"
14
15 /**
16  * Concrete factory class for constructing unpaired exact aligners.
17  */
18 class UnpairedExactAlignerV1Factory : public AlignerFactory {
19
20         typedef RangeSourceDriver<EbwtRangeSource> TRangeSrcDr;
21         typedef std::vector<TRangeSrcDr*> TRangeSrcDrPtrVec;
22         typedef CostAwareRangeSourceDriver<EbwtRangeSource> TCostAwareRangeSrcDr;
23
24 public:
25         UnpairedExactAlignerV1Factory(
26                         Ebwt<String<Dna> >& ebwtFw,
27                         Ebwt<String<Dna> >* ebwtBw,
28                         bool doFw,
29                         bool doRc,
30                         HitSink& sink,
31                         const HitSinkPerThreadFactory& sinkPtFactory,
32                         RangeCache* cacheFw,
33                         RangeCache* cacheBw,
34                         uint32_t cacheLimit,
35                         ChunkPool *pool,
36                         BitPairReference* refs,
37                         vector<String<Dna5> >& os,
38                         bool maqPenalty,
39                         bool qualOrder,
40                         bool strandFix,
41                         bool rangeMode,
42                         bool verbose,
43                         bool quiet,
44                         uint32_t seed) :
45                         ebwtFw_(ebwtFw),
46                         ebwtBw_(ebwtBw),
47                         doFw_(doFw), doRc_(doRc),
48                         sink_(sink),
49                         sinkPtFactory_(sinkPtFactory),
50                         cacheFw_(cacheFw),
51                         cacheBw_(cacheBw),
52                         cacheLimit_(cacheLimit),
53                         pool_(pool),
54                         refs_(refs),
55                         os_(os),
56                         maqPenalty_(maqPenalty),
57                         qualOrder_(qualOrder),
58                         strandFix_(strandFix),
59                         rangeMode_(rangeMode),
60                         verbose_(verbose),
61                         quiet_(quiet),
62                         seed_(seed)
63         {
64                 assert(ebwtFw.isInMemory());
65         }
66
67         /**
68          * Create a new UnpairedExactAlignerV1s.
69          */
70         virtual Aligner* create() const {
71                 HitSinkPerThread* sinkPt = sinkPtFactory_.create();
72                 EbwtSearchParams<String<Dna> >* params =
73                         new EbwtSearchParams<String<Dna> >(*sinkPt, os_, true, true);
74
75                 const int halfAndHalf = 0;
76                 const bool seeded = false;
77
78                 EbwtRangeSource *rFw = new EbwtRangeSource(
79                         &ebwtFw_, true,  0xffffffff, true, verbose_, quiet_, halfAndHalf, seeded, maqPenalty_, qualOrder_);
80                 EbwtRangeSource *rRc = new EbwtRangeSource(
81                         &ebwtFw_, false, 0xffffffff, true, verbose_, quiet_, halfAndHalf, seeded, maqPenalty_, qualOrder_);
82
83                 EbwtRangeSourceDriver * driverFw = new EbwtRangeSourceDriver(
84                         *params, rFw, true, false, maqPenalty_, qualOrder_, sink_, sinkPt,
85                         0,          // seedLen
86                         true,       // nudgeLeft (not applicable)
87                         PIN_TO_LEN, // whole alignment is unrevisitable
88                         PIN_TO_LEN, // "
89                         PIN_TO_LEN, // "
90                         PIN_TO_LEN, // "
91                         os_, verbose_, quiet_, true, pool_, NULL);
92                 EbwtRangeSourceDriver * driverRc = new EbwtRangeSourceDriver(
93                         *params, rRc, false, false, maqPenalty_, qualOrder_, sink_, sinkPt,
94                         0,          // seedLen
95                         true,       // nudgeLeft (not applicable)
96                         PIN_TO_LEN, // whole alignment is unrevisitable
97                         PIN_TO_LEN, // "
98                         PIN_TO_LEN, // "
99                         PIN_TO_LEN, // "
100                         os_, verbose_, quiet_, true, pool_, NULL);
101                 TRangeSrcDrPtrVec *drVec = new TRangeSrcDrPtrVec();
102                 if(doFw_) drVec->push_back(driverFw);
103                 if(doRc_) drVec->push_back(driverRc);
104                 TCostAwareRangeSrcDr* dr = new TCostAwareRangeSrcDr(strandFix_, drVec, verbose_, quiet_, false);
105                 delete drVec;
106
107                 // Set up a RangeChaser
108                 RangeChaser<String<Dna> > *rchase =
109                         new RangeChaser<String<Dna> >(cacheLimit_, cacheFw_, cacheBw_);
110
111                 return new UnpairedAlignerV2<EbwtRangeSource>(
112                         params, dr, rchase,
113                         sink_, sinkPtFactory_, sinkPt, os_, refs_,
114                         rangeMode_, verbose_, quiet_, INT_MAX, pool_, NULL, NULL);
115         }
116
117 private:
118         Ebwt<String<Dna> >& ebwtFw_;
119         Ebwt<String<Dna> >* ebwtBw_;
120         bool doFw_;
121         bool doRc_;
122         HitSink& sink_;
123         const HitSinkPerThreadFactory& sinkPtFactory_;
124         RangeCache *cacheFw_;
125         RangeCache *cacheBw_;
126         const uint32_t cacheLimit_;
127         ChunkPool *pool_;
128         BitPairReference* refs_;
129         vector<String<Dna5> >& os_;
130         bool maqPenalty_;
131         bool qualOrder_;
132         bool strandFix_;
133         bool rangeMode_;
134         bool verbose_;
135         bool quiet_;
136         uint32_t seed_;
137 };
138
139 /**
140  * Concrete factory class for constructing unpaired exact aligners.
141  */
142 class PairedExactAlignerV1Factory : public AlignerFactory {
143         typedef RangeSourceDriver<EbwtRangeSource> TRangeSrcDr;
144         typedef CostAwareRangeSourceDriver<EbwtRangeSource> TCostAwareRangeSrcDr;
145         typedef std::vector<TRangeSrcDr*> TRangeSrcDrPtrVec;
146 public:
147         PairedExactAlignerV1Factory(
148                         Ebwt<String<Dna> >& ebwtFw,
149                         Ebwt<String<Dna> >* ebwtBw,
150                         bool color,
151                         bool doFw,
152                         bool doRc,
153                         bool v1,
154                         HitSink& sink,
155                         const HitSinkPerThreadFactory& sinkPtFactory,
156                         bool mate1fw,
157                         bool mate2fw,
158                         uint32_t peInner,
159                         uint32_t peOuter,
160                         bool dontReconcile,
161                         uint32_t symCeil,
162                         uint32_t mixedThresh,
163                         uint32_t mixedAttemptLim,
164                         RangeCache* cacheFw,
165                         RangeCache* cacheBw,
166                         uint32_t cacheLimit,
167                         ChunkPool *pool,
168                         BitPairReference* refs,
169                         vector<String<Dna5> >& os,
170                         bool reportSe,
171                         bool maqPenalty,
172                         bool strandFix,
173                         bool qualOrder,
174                         bool rangeMode,
175                         bool verbose,
176                         bool quiet,
177                         uint32_t seed) :
178                         ebwtFw_(ebwtFw),
179                         color_(color),
180                         doFw_(doFw),
181                         doRc_(doRc),
182                         v1_(v1),
183                         sink_(sink),
184                         sinkPtFactory_(sinkPtFactory),
185                         mate1fw_(mate1fw),
186                         mate2fw_(mate2fw),
187                         peInner_(peInner),
188                         peOuter_(peOuter),
189                         dontReconcile_(dontReconcile),
190                         symCeil_(symCeil),
191                         mixedThresh_(mixedThresh),
192                         mixedAttemptLim_(mixedAttemptLim),
193                         cacheFw_(cacheFw),
194                         cacheBw_(cacheBw),
195                         cacheLimit_(cacheLimit),
196                         pool_(pool),
197                         refs_(refs), os_(os),
198                         reportSe_(reportSe),
199                         maqPenalty_(maqPenalty),
200                         qualOrder_(qualOrder),
201                         strandFix_(strandFix),
202                         rangeMode_(rangeMode),
203                         verbose_(verbose),
204                         quiet_(quiet),
205                         seed_(seed)
206         {
207                 assert(ebwtFw.isInMemory());
208         }
209
210         /**
211          * Create a new UnpairedExactAlignerV1s.
212          */
213         virtual Aligner* create() const {
214                 HitSinkPerThread* sinkPt = sinkPtFactory_.createMult(2);
215                 HitSinkPerThread* sinkPtSe1 = NULL, * sinkPtSe2 = NULL;
216                 EbwtSearchParams<String<Dna> >* params =
217                         new EbwtSearchParams<String<Dna> >(*sinkPt, os_, true, true);
218                 EbwtSearchParams<String<Dna> >* paramsSe1 = NULL, * paramsSe2 = NULL;
219                 if(reportSe_) {
220                         sinkPtSe1 = sinkPtFactory_.create();
221                         sinkPtSe2 = sinkPtFactory_.create();
222                         paramsSe1 =
223                                 new EbwtSearchParams<String<Dna> >(*sinkPtSe1, os_, true, true);
224                         paramsSe2 =
225                                 new EbwtSearchParams<String<Dna> >(*sinkPtSe2, os_, true, true);
226                 }
227
228                 const int halfAndHalf = 0;
229                 const bool seeded = false;
230
231                 bool do1Fw = true;
232                 bool do1Rc = true;
233                 bool do2Fw = true;
234                 bool do2Rc = true;
235                 if(!doFw_) {
236                         if(mate1fw_) do1Fw = false;
237                         else         do1Rc = false;
238                         if(mate2fw_) do2Fw = false;
239                         else         do2Rc = false;
240                 }
241                 if(!doRc_) {
242                         if(mate1fw_) do1Rc = false;
243                         else         do1Fw = false;
244                         if(mate2fw_) do2Rc = false;
245                         else         do2Fw = false;
246                 }
247
248                 EbwtRangeSource *r1Fw = NULL;
249                 EbwtRangeSource *r1Rc = NULL;
250                 TRangeSrcDr * driver1Fw = NULL;
251                 TRangeSrcDr * driver1Rc = NULL;
252                 EbwtRangeSource *r2Fw = NULL;
253                 EbwtRangeSource *r2Rc = NULL;
254                 TRangeSrcDr * driver2Fw = NULL;
255                 TRangeSrcDr * driver2Rc = NULL;
256                 if(do1Fw) {
257                         r1Fw = new EbwtRangeSource(
258                                 &ebwtFw_, true,  0xffffffff, true, verbose_, quiet_, halfAndHalf, seeded, maqPenalty_, qualOrder_);
259                         driver1Fw = new EbwtRangeSourceDriver(
260                                 *params, r1Fw, true, false, maqPenalty_, qualOrder_, sink_, sinkPt,
261                                 0,          // seedLen
262                                 true,       // nudgeLeft (not applicable)
263                                 PIN_TO_LEN, // whole alignment is unrevisitable
264                                 PIN_TO_LEN, // "
265                                 PIN_TO_LEN, // "
266                                 PIN_TO_LEN, // "
267                                 os_, verbose_, quiet_, true, pool_, NULL);
268                 }
269                 if(do2Fw) {
270                         r2Fw = new EbwtRangeSource(
271                                 &ebwtFw_, true,  0xffffffff, true, verbose_, quiet_, halfAndHalf, seeded, maqPenalty_, qualOrder_);
272                         driver2Fw = new EbwtRangeSourceDriver(
273                                 *params, r2Fw, true, false, maqPenalty_, qualOrder_, sink_, sinkPt,
274                                 0,          // seedLen
275                                 true,       // nudgeLeft (not applicable)
276                                 PIN_TO_LEN, // whole alignment is unrevisitable
277                                 PIN_TO_LEN, // "
278                                 PIN_TO_LEN, // "
279                                 PIN_TO_LEN, // "
280                                 os_, verbose_, quiet_, false, pool_, NULL);
281                 }
282                 if(do1Rc) {
283                         r1Rc = new EbwtRangeSource(
284                                 &ebwtFw_, false, 0xffffffff, true, verbose_, quiet_, halfAndHalf, seeded, maqPenalty_, qualOrder_);
285                         driver1Rc = new EbwtRangeSourceDriver(
286                                 *params, r1Rc, false, false, maqPenalty_, qualOrder_, sink_, sinkPt,
287                                 0,          // seedLen
288                                 true,       // nudgeLeft (not applicable)
289                                 PIN_TO_LEN, // whole alignment is unrevisitable
290                                 PIN_TO_LEN, // "
291                                 PIN_TO_LEN, // "
292                                 PIN_TO_LEN, // "
293                                 os_, verbose_, quiet_, true, pool_, NULL);
294                 }
295                 if(do2Rc) {
296                         r2Rc = new EbwtRangeSource(
297                                 &ebwtFw_, false, 0xffffffff, true, verbose_, quiet_, halfAndHalf, seeded, maqPenalty_, qualOrder_);
298                         driver2Rc = new EbwtRangeSourceDriver(
299                                 *params, r2Rc, false, false, maqPenalty_, qualOrder_, sink_, sinkPt,
300                                 0,          // seedLen
301                                 true,       // nudgeLeft (not applicable)
302                                 PIN_TO_LEN, // whole alignment is unrevisitable
303                                 PIN_TO_LEN, // "
304                                 PIN_TO_LEN, // "
305                                 PIN_TO_LEN, // "
306                                 os_, verbose_, quiet_, false, pool_, NULL);
307                 }
308
309                 RefAligner<String<Dna5> >* refAligner
310                         = new ExactRefAligner<String<Dna5> >(color_, verbose_, quiet_);
311
312                 // Set up a RangeChaser
313                 RangeChaser<String<Dna> > *rchase =
314                         new RangeChaser<String<Dna> >(cacheLimit_, cacheFw_, cacheBw_);
315
316                 if(v1_) {
317                         PairedBWAlignerV1<EbwtRangeSource>* al = new PairedBWAlignerV1<EbwtRangeSource>(
318                                 params,
319                                 driver1Fw == NULL ? (new StubRangeSourceDriver<EbwtRangeSource>()) : driver1Fw,
320                                 driver1Rc == NULL ? (new StubRangeSourceDriver<EbwtRangeSource>()) : driver1Rc,
321                                 driver2Fw == NULL ? (new StubRangeSourceDriver<EbwtRangeSource>()) : driver2Fw,
322                                 driver2Rc == NULL ? (new StubRangeSourceDriver<EbwtRangeSource>()) : driver2Rc,
323                                 refAligner,
324                                 rchase, sink_, sinkPtFactory_, sinkPt, mate1fw_, mate2fw_,
325                                 peInner_, peOuter_, dontReconcile_, symCeil_, mixedThresh_,
326                                 mixedAttemptLim_, refs_, rangeMode_, verbose_,
327                                 quiet_, INT_MAX, pool_, NULL);
328                         return al;
329                 } else {
330                         TRangeSrcDrPtrVec *drVec = new TRangeSrcDrPtrVec();
331                         if(driver1Fw != NULL) drVec->push_back(driver1Fw);
332                         if(driver1Rc != NULL) drVec->push_back(driver1Rc);
333                         if(driver2Fw != NULL) drVec->push_back(driver2Fw);
334                         if(driver2Rc != NULL) drVec->push_back(driver2Rc);
335                         PairedBWAlignerV2<EbwtRangeSource>* al = new PairedBWAlignerV2<EbwtRangeSource>(
336                                 params, paramsSe1, paramsSe2,
337                                 new TCostAwareRangeSrcDr(strandFix_, drVec, verbose_, quiet_, true),
338                                 refAligner,
339                                 rchase, sink_, sinkPtFactory_, sinkPt,
340                                 sinkPtSe1, sinkPtSe2, mate1fw_, mate2fw_,
341                                 peInner_, peOuter_,
342                                 mixedAttemptLim_, refs_, rangeMode_,
343                                 verbose_, quiet_, INT_MAX, pool_, NULL);
344                         delete drVec;
345                         return al;
346                 }
347         }
348
349 private:
350         Ebwt<String<Dna> >& ebwtFw_;
351         Ebwt<String<Dna> >* ebwtBw_;
352         bool color_;
353         bool doFw_;
354         bool doRc_;
355         bool v1_;
356         HitSink& sink_;
357         const HitSinkPerThreadFactory& sinkPtFactory_;
358         const bool mate1fw_;
359         const bool mate2fw_;
360         const uint32_t peInner_;
361         const uint32_t peOuter_;
362         const bool dontReconcile_;
363         const uint32_t symCeil_;
364         const uint32_t mixedThresh_;
365         const uint32_t mixedAttemptLim_;
366         RangeCache *cacheFw_;
367         RangeCache *cacheBw_;
368         const uint32_t cacheLimit_;
369         ChunkPool *pool_;
370         BitPairReference* refs_;
371         vector<String<Dna5> >& os_;
372         const bool reportSe_;
373         const bool maqPenalty_;
374         const bool qualOrder_;
375         const bool strandFix_;
376         const bool rangeMode_;
377         const bool verbose_;
378         const bool quiet_;
379         const uint32_t seed_;
380 };
381
382 #endif /* ALIGNER_0MM_H_ */