-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMICCT-ShortHandler.c
261 lines (229 loc) · 11 KB
/
MICCT-ShortHandler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//
// MICCT-ShortHandler.c
//
// mica
//
// Copyright (C) 2014, HKU
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
///////////////////////////////////////////////////////////////////////////////////////////////
#include "MICCT-ShortHandler.h"
__attribute__((target(mic)))
void MICSHProcessRead(HSP * hsp,
MICSRAArguments * readMicArgs, MICSRAArguments * mateMicArgs,
CPTSRAModel * cpPModels, CPTSRAModel * cpNModels,
PEInput * peAlgnmtInput, MICPEArguments * peArgs,
MICSRAArguments * readSeedMicArgs, MICSRAArguments * mateSeedMicArgs,
CPTSRAModel * cpPModels_seed, CPTSRAModel * cpNModels_seed,
MICPEArguments * peSeedArgs,
unsigned int * peSeedOutputPtr, MICSRAOccMetadata * peSeedMetaPtr,
PEDPSetting * pedpSetting, DPWorkMIC * dpWork,
unsigned int * outputPtr, uint8_t * outputBufferStatus, uint16_t * occCount,
MICDPOccurrence * dpOcc, unsigned dpOccCount, uint32_t * dpOccCountInc) {
int caseIdx = 0;
int stageCaseIdx = 0;
while (1) {
////////////////////////////////////////////
// READ
////////////////////////////////////////////
stageCaseIdx = caseIdx;
// Calling the model aligner
MICProcessStageDoubleStrand(readMicArgs,
&(cpPModels[readMicArgs->readLength]),
&(cpNModels[readMicArgs->readLength]),
&stageCaseIdx);
////////////////////////////////////////////
// MATE
////////////////////////////////////////////
stageCaseIdx = caseIdx;
// Calling the model aligner
MICProcessStageDoubleStrand(mateMicArgs,
&(cpPModels[mateMicArgs->readLength]),
&(cpNModels[mateMicArgs->readLength]),
&stageCaseIdx);
// Case that either of the leg alignment has been flooded
if ((*readMicArgs->outputStatus) != MIC_OUTPUT_STATUS_OPEN ||
(*mateMicArgs->outputStatus) != MIC_OUTPUT_STATUS_OPEN) {
break;
}
// All-best alignment
// This placed after the last step check because we want to carry out the last PE
// outside of this loop. The next call to the PE engine do not check the SRA occ count
// hence it will carry out singleEndAlignmentCopy.
if (peAlgnmtInput->OutputType == PE_REPORT_ALL_BEST) {
MICPEMappingInitialise(peArgs);
MICPEMappingOccurrences(peArgs);
if ( (*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_SKIPPED ||
(*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_UNHANDLE ||
(*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_CLOSED ||
(*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_PAIR ) {
break;
}
}
// Case that all the cases have been completed.
if (cpPModels[readMicArgs->readLength].cases[stageCaseIdx].type==SRA_CASE_TYPE_NOT_INITALISED) {
break;
}
caseIdx = stageCaseIdx + 1;
}
if ((*readMicArgs->outputStatus) == MIC_OUTPUT_STATUS_OPEN) {
(*readMicArgs->outputStatus) = MIC_OUTPUT_STATUS_COMPLETE;
}
if ((*mateMicArgs->outputStatus) == MIC_OUTPUT_STATUS_OPEN) {
(*mateMicArgs->outputStatus) = MIC_OUTPUT_STATUS_COMPLETE;
}
////////////////////////////////////////////
// Pairing
////////////////////////////////////////////
// This is where we will call the PE module.
// We need to carry out the following here
// 1. Check that the READ and MATE alignment
// count does not exceed a defined boundary
// 2. Pipe READ and MATE alignments into the
// PEMappingCore
// 3. Restrict the PEMappingCore to report only
// if the number of pair-end alignment is
// less than some defined boundary.
// 4. If orphan => Default DP. Symmetric
// 5. If still no PE result, seed and deep DP
// All-valid alignment
if (peAlgnmtInput->OutputType == PE_REPORT_ALL) {
MICPEMappingInitialise(peArgs);
MICPEMappingOccurrences(peArgs);
}
MICPEMappingComplete(peArgs);
////////////////////////////////////////////
// DP Engine
////////////////////////////////////////////
// skip if no vacancy
if ( dpOccCount+ MIC_DP_OUTPUT_MAX_ALIGNMENT > MIC_DP_OUTPUT_SIZE_PER_THREAD ) {
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_CLOSED;
(*occCount) = 0;
}
(*dpOccCountInc) = 0;
// Recovery DP - Only kick in when the DP is enabled
// aka Default DP
if ( (pedpSetting->SGAOrphanEnhancement) &&
((*outputBufferStatus)==MIC_PE_OUTPUT_STATUS_READ_NO_ALIGNMENT ||
(*outputBufferStatus)==MIC_PE_OUTPUT_STATUS_MATE_NO_ALIGNMENT ||
(*outputBufferStatus)==MIC_PE_OUTPUT_STATUS_BAD_PAIR )
) {
int defaultDPCount = MICDPOrphanAlignment(dpOcc + dpOccCount, dpWork, peArgs, hsp, pedpSetting->SGAOrphanTriggerTF);
#ifdef MIC_DP_DEBUG_PRINT_ALIGNMENT_FLOW
printf("[MICCT] Recovery DP is invoked. Returned %d\n",defaultDPCount);
#endif
if (defaultDPCount > 0){
if ((*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_READ_NO_ALIGNMENT){
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_DP_BASE_MATE;
} else if ((*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_MATE_NO_ALIGNMENT){
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_DP_BASE_READ;
} else if ((*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_BAD_PAIR){
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_DP_MIX_BASE;
}
(*dpOccCountInc) = defaultDPCount;
(*occCount) = defaultDPCount;
} else if (defaultDPCount == MIC_DP_STATUS_BREACH_LIMIT) {
// Too many DP results reported, requires CPU assistance
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_CLOSED;
(*occCount) = 0;
} else if (defaultDPCount == 0 || defaultDPCount == MIC_DP_STATUS_TOO_MANY_RESULT){
// processed but no result or too many result ... do nothing
//(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_CLOSED;
//(*occCount) = 0;
} else {
// unprocessed or error
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_CLOSED;
(*occCount) = 0;
}
}
// Seed DP - Only kick in when the DP is enabled
// aka Deep DP
if ( (pedpSetting->SGASeedEnhancement) &&
((*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_READ_NO_ALIGNMENT ||
(*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_MATE_NO_ALIGNMENT ||
(*outputBufferStatus) == MIC_PE_OUTPUT_STATUS_BOTH_NO_ALIGNMENT)
) {
int deepDPCount = MICDeepDP(peSeedArgs,
peSeedOutputPtr, peSeedMetaPtr,
readMicArgs, mateMicArgs,
readSeedMicArgs, mateSeedMicArgs,
cpPModels_seed, cpNModels_seed,
hsp,
dpWork,
pedpSetting->SGASeedLength,
pedpSetting->SGASeedLengthOverlap,
pedpSetting->SGAOrphanTriggerTF,
pedpSetting->SGAScoreTF,
pedpSetting->SGASeedOccLimitation,
dpOcc + dpOccCount);
#ifdef MIC_DP_DEBUG_PRINT_ALIGNMENT_FLOW
printf("[MICCT] Deep DP is invoked. Returned %d\n",deepDPCount);
#endif
if (deepDPCount > 0) {
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_DP_SEED;
(*dpOccCountInc) = deepDPCount;
(*occCount) = 1;
*outputPtr = deepDPCount;
} else if (deepDPCount == MIC_DP_STATUS_BREACH_LIMIT) {
// Too many DP results reported, requires CPU assistance
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_CLOSED;
(*occCount) = 0;
} else if (pedpSetting->SGASeedEnhancement_1) {
deepDPCount = MICDeepDP(peSeedArgs,
peSeedOutputPtr, peSeedMetaPtr,
readMicArgs, mateMicArgs,
readSeedMicArgs, mateSeedMicArgs,
cpPModels_seed, cpNModels_seed,
hsp,
dpWork,
pedpSetting->SGASeedLength_1,
pedpSetting->SGASeedLengthOverlap_1,
pedpSetting->SGAOrphanTriggerTF,
pedpSetting->SGAScoreTF,
pedpSetting->SGASeedOccLimitation_1,
dpOcc + dpOccCount);
#ifdef MIC_DP_DEBUG_PRINT_ALIGNMENT_FLOW
printf("[MICCT] Deep DP (Level-2) is invoked. Returned %d\n",deepDPCount);
#endif
if (deepDPCount > 0) {
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_DP_SEED;
(*dpOccCountInc) = deepDPCount;
(*occCount) = 1;
*outputPtr = deepDPCount;
} else if (deepDPCount == MIC_DP_STATUS_BREACH_LIMIT) {
// Too many DP results reported, requires CPU assistance
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_CLOSED;
(*occCount) = 0;
} else if (deepDPCount == 0 || deepDPCount == MIC_DP_STATUS_TOO_MANY_RESULT){
// processed but no result or too many result ... do nothing
//(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_SKIPPED;
//(*occCount) = 0;
} else {
// unprocessed or error
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_CLOSED;
(*occCount) = 0;
}
} else if (deepDPCount == 0 || deepDPCount == MIC_DP_STATUS_TOO_MANY_RESULT){
// processed but no result or too many result ... do nothing
//(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_SKIPPED;
//(*occCount) = 0;
} else {
// unprocessed or error
(*outputBufferStatus) = MIC_PE_OUTPUT_STATUS_CLOSED;
(*occCount) = 0;
}
}
}