File: FragsClumps.inl

package info (click to toggle)
yaha 0.1.83-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 117,148 kB
  • sloc: ansic: 3,816; cpp: 1,742; makefile: 44
file content (410 lines) | stat: -rw-r--r-- 10,640 bytes parent folder | download
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/* -*- Mode: C ; indent-tabs-mode: nil ; c-file-style: "stroustrup" ; column-number-mode: t -*-

    Project: YAHA, DNA alignment tool designed to find optimal split-read mappings on single-end queries.
    Author:  Greg Faust (gf4ea@virginia.edu)

    File:    FragsClumps.inl Contains inline functions for various operations on clumps and especially frags.

    License Information:

    Copyright 2009-2015 Gregory G. Faust

    Licensed under the MIT license (the "License");
    You may not use this file except in compliance with the License.
    You may obtain a copy of the License at http://opensource.org/licenses/MIT

*/

// We need this to allow this file to be included in both C and C++ code.

#ifdef __cplusplus
#define STATIC_DECL
#else
#define STATIC_DECL static
#endif

/////
//     Inlines for Fragments.
/////

/////
//     Start with basic getter/setters for implicit fields such as endRefOff
/////

// Make up for the fact that these values are not stored in the fragment structure.
STATIC_DECL inline int fragQueryLen (Fragment_t * frag)
{
    return 1 + ((int)frag->endQueryOff - (int)frag->startQueryOff);
}

// While forming fragments, we won't bother to keep both the query length and ref length.
// We don't need to, as they will both be the same.
// Later, we allow them to differ for some fragments as we build the final alignment.
// This routine let's us set the ref length to the query length before they can diverge.
STATIC_DECL inline void setRefLen (Fragment_t * frag)
{
    frag->refLen = fragQueryLen(frag);
}

STATIC_DECL inline SUINT fragRefLen (Fragment_t * frag)
{
    return frag->refLen;
}

STATIC_DECL inline ROFF fragEndRefOff (Fragment_t * frag)
{
    return frag->startRefOff + frag->refLen - 1 ;
}

STATIC_DECL inline void fragSetEndRefOff (Fragment_t * frag, ROFF refOff)
{
    frag->refLen = 1 + refOff - frag->startRefOff;
}

STATIC_DECL inline void fragSetSOs(Fragment_t * frag, QOFF qOff, ROFF rOff)
{
    frag->startQueryOff = qOff;
    frag->startRefOff = rOff;
}

STATIC_DECL inline void fragSetEOs(Fragment_t * frag, QOFF qOff)
{
    frag->endQueryOff = qOff;
    setRefLen(frag);
}

STATIC_DECL inline void addQLenToFront (Fragment_t * frag, int len)
{
    frag->startQueryOff -= len;
}

STATIC_DECL inline void addRLenToFront (Fragment_t * frag, int len)
{
    frag->startRefOff -= len;
    frag->refLen += len;
}

STATIC_DECL inline void addLenToFront (Fragment_t * frag, int len)
{
    addQLenToFront (frag, len);
    addRLenToFront (frag, len);
}

STATIC_DECL inline void addQLenToBack (Fragment_t * frag, int len)
{
    frag->endQueryOff += len;
}

STATIC_DECL inline void addRLenToBack (Fragment_t * frag, int len)
{
    frag->refLen += len;
}

STATIC_DECL inline void addLenToBack (Fragment_t * frag, int len)
{
    addQLenToBack (frag, len);
    addRLenToBack (frag, len);
}

STATIC_DECL inline void subLenFromFront(Fragment_t * frag, int len)
{
    frag->startQueryOff += len;
    frag->startRefOff += len;
    frag->refLen -= len;
}

STATIC_DECL inline void subLenFromBack(Fragment_t * frag, int len)
{
    frag->endQueryOff -= len;
    frag->refLen -= len;
}

STATIC_DECL inline ROFF fragDiag(Fragment_t * frag)
{
    return frag->startRefOff - frag->startQueryOff;
}

STATIC_DECL inline int UINTDiff(UINT uint1, UINT uint2)
{
    // Machinations to avoid unsigned subtraction wrap.
    return (uint1 >= uint2) ? (int)(uint1 - uint2) : -((int)(uint2 - uint1));
}

STATIC_DECL inline UINT absUINTDiff(UINT uint1, UINT uint2)
{
    // Machinations to avoid unsigned subtraction wrap.
    return (uint1 > uint2) ? (uint1 - uint2) : (uint2 - uint1);
}

// These are just synonyms for the above.
// As diagonals are of type ROFF.
STATIC_DECL inline int diagDiff(ROFF diag1, ROFF diag2)
{
    return UINTDiff(diag1, diag2);
}

STATIC_DECL inline UINT absDiagDiff(ROFF diag1, ROFF diag2)
{
    return absUINTDiff(diag1, diag2);
}

/////
//     Various ways of calculating gaps and overlaps between two fragments.
/////

// These are macros instead of inlines because we need them for different data types.
// In C++ we would just have these be overloaded inlines.
// TODO  In future, if QOFF is ever implemented, these unsigned casts will no longer be needed.
#define calcGap(lowOffset, highOffset) ((highOffset > lowOffset) ? ((unsigned)(highOffset - lowOffset) - 1) : 0)
#define calcOverlap(lowOffset, highOffset) ((lowOffset >= highOffset) ? ((unsigned)(lowOffset - highOffset) + 1) : 0)

STATIC_DECL inline int calcMaxOverlap (Fragment_t * frag1, Fragment_t * frag2)
{
    return MAX(calcOverlap(frag1->endQueryOff, frag2->startQueryOff), calcOverlap(fragEndRefOff(frag1), frag2->startRefOff));
}

STATIC_DECL inline int calcQueryGap (Fragment_t * frag1, Fragment_t * frag2)
{
    return calcGap(frag1->endQueryOff, frag2->startQueryOff);
}

STATIC_DECL inline int calcRefGap (Fragment_t * frag1, Fragment_t * frag2)
{
    return calcGap(fragEndRefOff(frag1), frag2->startRefOff);
}

STATIC_DECL inline int calcMinGap (Fragment_t * frag1, Fragment_t * frag2)
{
    return MIN(calcQueryGap(frag1, frag2), calcRefGap(frag1, frag2));
}

STATIC_DECL inline int calcMaxGap (Fragment_t * frag1, Fragment_t * frag2)
{
    return MAX(calcQueryGap(frag1, frag2), calcRefGap(frag1, frag2));
}

/////
//     Inlines related to scoring.
/////

STATIC_DECL inline int calcGapCost(int len, AlignmentArgs_t * AAs)
{
    return (len > 0) ? -(AAs->GOCost + len * AAs->GECost) : 0;
}

// The match count for frags is now always the length.
STATIC_DECL inline int fragMatchCount(Fragment_t * frag)
{
    return frag->refLen;
}

/////
//     Inlines for Super Fragments.
/////

STATIC_DECL inline Fragment_t   * getFragPtr(SFragment_t * SFrag)
{
    return &(SFrag->frag);
}

STATIC_DECL inline EditOpList_t * getEOLPtr(SFragment_t * SFrag)
{
    return &(SFrag->EOList);
}

STATIC_DECL inline BOOL SFragmentListIsEmpty(SFragmentList_t * list)
{
    return (list->head == NULL);
}

/////
//     Inlines for Clumps.
/////

STATIC_DECL inline EditOpList_t * EOLPtr(Clump_t * clump)
{
    return &(clump->EOList);
}

STATIC_DECL inline SFragmentList_t * SFragListPtr(Clump_t * clump)
{
    return &(clump->SFragList);
}

// The status flags for clumps.
#define clumpReversed 0x01  // Indicates clump is aligned to inverse (3' to 5') strand.
#define clumpFormed   0x02  // Is this currently in use?
#define clumpAligned  0x04  // Indicates clump has been aligned.  This implies it will have a single SFrag with an edit op list.
#define clumpScored   0x08  // Indicates clump has successfully been scored.  This implies it has survived splitting and threshold tests.
#define clumpSplit    0x10  // Indicates clump was involved in a split during scoring.
#define clumpPrimary  0x20  // Indicates clump was in set of primary clumps spanning the query.

STATIC_DECL inline BOOL isReversed(Clump_t * clump)
{
    return ((clump->status & clumpReversed) != 0);
}

STATIC_DECL inline BOOL isFormed(Clump_t * clump)
{
    return ((clump->status & clumpFormed) != 0);
}

STATIC_DECL inline BOOL isAligned(Clump_t * clump)
{
    return ((clump->status & clumpAligned) != 0);
}

STATIC_DECL inline BOOL isScored(Clump_t * clump)
{
    return ((clump->status & clumpScored) != 0);
}

STATIC_DECL inline BOOL isSplit(Clump_t * clump)
{
    return ((clump->status & clumpSplit) != 0);
}

STATIC_DECL inline BOOL isPrimary(Clump_t * clump)
{
    return ((clump->status & clumpPrimary) != 0);
}

STATIC_DECL inline BOOL setReversed(Clump_t * clump, BOOL bit)
{
    if (bit)
        return clump->status |= clumpReversed;
    else
        return clump->status &= ~clumpReversed;
}

STATIC_DECL inline BOOL setFormed(Clump_t * clump, BOOL bit)
{
    if (bit)
        return clump->status |= clumpFormed;
    else
        return clump->status &= ~clumpFormed;
}

STATIC_DECL inline BOOL setAligned(Clump_t * clump, BOOL bit)
{
    if (bit)
        return clump->status |= clumpAligned;
    else
        return clump->status &= ~clumpAligned;
}

STATIC_DECL inline BOOL setScored(Clump_t * clump, BOOL bit)
{
    if (bit)
        return clump->status |= clumpScored;
    else
        return clump->status &= ~clumpScored;
}

STATIC_DECL inline BOOL setSplit(Clump_t * clump, BOOL bit)
{
    if (bit)
        return clump->status |= clumpSplit;
    else
        return clump->status &= ~clumpSplit;
}

STATIC_DECL inline BOOL setPrimary(Clump_t * clump, BOOL bit)
{
    if (bit)
        return clump->status |= clumpPrimary;
    else
        return clump->status &= ~clumpPrimary;
}

STATIC_DECL inline Fragment_t * clumpFirstFrag(Clump_t * clump)
{
    return getFragPtr(SFragListPtr(clump)->head);
}

STATIC_DECL inline Fragment_t * clumpLastFrag(Clump_t * clump)
{
    return getFragPtr(SFragListPtr(clump)->tail);
}

STATIC_DECL inline BOOL isEmpty(Clump_t * clump)
{
    return (SFragListPtr(clump)->head == NULL);
}

STATIC_DECL inline QOFF clumpSQO(Clump_t * clump)
{
    return (clumpFirstFrag(clump)->startQueryOff);
}

STATIC_DECL inline QOFF clumpEQO(Clump_t * clump)
{
    return (clumpLastFrag(clump)->endQueryOff);
}

STATIC_DECL inline ROFF clumpSRO(Clump_t * clump)
{
    return (clumpFirstFrag(clump)->startRefOff);
}

STATIC_DECL inline ROFF clumpERO(Clump_t * clump)
{
    return (fragEndRefOff(clumpLastFrag(clump)));
}

STATIC_DECL inline QOFF clumpPlusSQO(Clump_t * clump, QueryState_t * QS)
{
    if (isReversed(clump)) return (QS->queryLen - 1) - clumpEQO(clump);
    else return clumpSQO(clump);
}

STATIC_DECL inline QOFF clumpPlusEQO(Clump_t * clump, QueryState_t * QS)
{
    if (isReversed(clump)) return (QS->queryLen - 1) - clumpSQO(clump);
    else return clumpEQO(clump);
}

STATIC_DECL inline QOFF clumpQueryLen(Clump_t * clump)
{
    return 1 + clumpEQO(clump) - clumpSQO(clump);
}

STATIC_DECL inline QOFF clumpRefLen(Clump_t * clump)
{
    return 1 + clumpERO(clump) - clumpSRO(clump);
}

/////
//     Inline to push a clump onto a clump list.
/////
STATIC_DECL inline Clump_t * pushClump(Clump_t * clump, Clump_t * clumpList)
{
    clump->next = clumpList;
    return clump;
}

/////
//     Inlines for QueryState Accessors.
/////
//     Sneaking this in a file now inaptly named.
/////

STATIC_DECL inline char * getQueryBuf(QueryState_t * QS)
{
    return QS->queryBuf;
}

STATIC_DECL inline char * getQueryCodeBuf(QueryState_t * QS)
{
    return QS->queryCodeBuf;
}

STATIC_DECL inline char * getClumpQueryBuf(QueryState_t * QS, Clump_t * clump)
{
    return (isReversed(clump)) ? QS->reverseBuf : QS->forwardBuf;
}

STATIC_DECL inline char * getClumpQueryCodeBuf(QueryState_t * QS, Clump_t * clump)
{
    return (isReversed(clump)) ? QS->reverseCodeBuf : QS->forwardCodeBuf;
}