Imported Upstream version 0.12.7
[bowtie.git] / search_1mm_phase1.c
1 /*
2  * This is a fragment, included from multiple places in ebwt_search.cpp.
3  * It implements the logic of the first phase of the 1-mismatch search
4  * routine.  It is implemented as a code fragment so that it can be
5  * reused in both the half-index-in-memory and full-index-in-memory
6  * situations.
7  */
8 {
9         bt.setEbwt(&ebwtFw);
10         bt.setReportExacts(true);
11
12         if(plen < 2) {
13                 cerr << "Error: Reads must be at least 2 characters long in 1-mismatch mode" << endl;
14                 throw 1;
15         }
16
17         if(!nofw) {
18                 // First, try exact hits for the forward-oriented read
19                 params.setFw(true);
20                 bt.setQuery(patsrc->bufa());
21                 bt.setOffs(0, 0, s, s, s, s);
22                 if(bt.backtrack()) {
23                         DONEMASK_SET(patid);
24                         continue;
25                 }
26         }
27
28         if(!norc) {
29                 params.setFw(false);
30
31                 // Next, try exact hits for the reverse-complement read
32                 bt.setQuery(patsrc->bufa());
33                 bt.setOffs(0, 0, s, s, s, s);
34                 if(bt.backtrack()) {
35                         DONEMASK_SET(patid);
36                         continue;
37                 }
38         }
39
40         if(sink->finishedWithStratum(0)) { // no more exact hits are possible
41                 // the sink tells us we needn't try 1-mismatch alignments
42                 DONEMASK_SET(patid);
43                 continue;
44         }
45         bt.setReportExacts(false);
46
47         if(!norc) {
48                 // Next, try hits with one mismatch on the 3' end for the reverse-complement read
49                 bt.setQuery(patsrc->bufa());
50                 bt.setOffs(0, 0, s5, s, s, s); // 1 mismatch allowed in 3' half
51                 if(bt.backtrack()) {
52                         DONEMASK_SET(patid);
53                         continue;
54                 }
55         }
56
57         if(!nofw) {
58                 params.setFw(true);
59                 // Next, try hits with one mismatch on the 3' end for the reverse-complement read
60                 bt.setQuery(patsrc->bufa());
61                 bt.setOffs(0, 0, s5, s, s, s); // 1 mismatch allowed in 3' half
62                 if(bt.backtrack()) {
63                         DONEMASK_SET(patid);
64                         continue;
65                 }
66         }
67 }