-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadTrimmer.cpp
783 lines (665 loc) · 29.5 KB
/
ReadTrimmer.cpp
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
/*
Copyright (c) 2020 Ed Harry, Wellcome Sanger Institute
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#define PY_SSIZE_T_CLEAN
#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>
#include <Python.h>
#include "Header.h"
#pragma clang diagnostic push
#pragma GCC diagnostic ignored "-Wreserved-id-macro"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wcast-align"
#pragma GCC diagnostic ignored "-Wextra-semi-stmt"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wconditional-uninitialized"
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#pragma GCC diagnostic ignored "-Wpadded"
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#define STB_SPRINTF_IMPLEMENTATION
#include "stb_sprintf.h"
#pragma clang diagnostic pop
#define String_(x) #x
#define String(x) String_(x)
#define ErrorLine String(Error at line __LINE__)
#define TestForPythonError \
do \
{ \
if ((PyErr_Occurred())) \
{ \
PyErr_SetString(PyExc_Exception, ErrorLine); \
return(0); \
} \
} while (0)
global_variable
u08
Status_Marco_Expression_Sponge = 0;
global_variable
char
Message_Buffer[1024];
global_variable
s32
Error_Handle;
#define PrintError(message, ...) \
{ \
u32 halfSize = sizeof(Message_Buffer) >> 1; \
stbsp_snprintf(Message_Buffer, halfSize, message, ##__VA_ARGS__); \
u64 n = (u64)stbsp_snprintf(Message_Buffer + halfSize, halfSize, "%s\n", Message_Buffer); \
write(Error_Handle, Message_Buffer + halfSize, n); \
PyErr_SetString(PyExc_Exception, Message_Buffer + halfSize); \
} \
Status_Marco_Expression_Sponge = 0
global_variable
s32
Status_Handle;
#define PrintStatus(message, ...) \
{ \
u32 halfSize = sizeof(Message_Buffer) >> 1; \
stbsp_snprintf(Message_Buffer, halfSize, message, ##__VA_ARGS__); \
u64 n = (u64)stbsp_snprintf(Message_Buffer + halfSize, halfSize, "%s\n", Message_Buffer); \
write(Status_Handle, Message_Buffer + halfSize, n); \
} \
Status_Marco_Expression_Sponge = 0
global_variable
memory_arena
Working_Set;
struct
sequence
{
char *name;
u32 length;
u08 frontOverhang;
u08 endOverhang;
u08 frontOverhangIsFwd;
u08 endOverhangIsFwd;
sequence *next;
};
struct
sequence_hash_table_node
{
sequence *sequence;
sequence_hash_table_node *next;
};
struct
sequence_hash_table
{
sequence_hash_table_node **table;
u32 size;
u32 pad;
};
global_function
sequence_hash_table *
CreateSequenceHashTable(memory_arena *arena, u32 nEntries)
{
u32 size = NextPrime((u32)((f32)nEntries * 1.3f));
sequence_hash_table *table = PushStructP(arena, sequence_hash_table);
table->size = size;
table->table = PushArrayP(arena, sequence_hash_table_node *, size);
memset(table->table, 0, size * sizeof(sequence_hash_table_node *));
return(table);
}
global_function
void
AddSequenceToHashTable(memory_arena *arena, sequence_hash_table *table, sequence *sequence)
{
#define SequenceHashTableSeed 0xf20b503a1896576e
u32 name32[16];
PushStringIntoIntArray((u32 *)name32, ArrayCount(name32), (u08 *)sequence->name);
u32 hash = FastHash32(name32, sizeof(name32), SequenceHashTableSeed) % table->size;
sequence_hash_table_node *node = table->table[hash];
sequence_hash_table_node *prevNode = 0;
while (node)
{
prevNode = node;
node = node->next;
}
sequence_hash_table_node *newNode = PushStructP(arena, sequence_hash_table_node);
newNode->sequence = sequence;
newNode->next = 0;
(prevNode ? prevNode->next : table->table[hash]) = newNode;
}
global_function
sequence *
GetSequenceFromHashTable(sequence_hash_table *table, char *name, char nameTerm = '\t')
{
u32 name32[16];
PushStringIntoIntArray((u32 *)name32, ArrayCount(name32), (u08 *)name, (u08)nameTerm);
u32 hash = FastHash32(name32, sizeof(name32), SequenceHashTableSeed) % table->size;
sequence_hash_table_node *node = table->table[hash];
sequence_hash_table_node *prevNode = 0;
sequence *result = 0;
while (node)
{
prevNode = node;
sequence *test = node->sequence;
if (AreStringsEqual(name, nameTerm, test->name, '\0'))
{
result = test;
break;
}
node = node->next;
}
return(result);
}
struct
write_buffer
{
u08 *buffer;
u64 size;
};
global_function
write_buffer *
CreateWriteBuffer(memory_arena *arena, u64 bufferSize)
{
write_buffer *buffer = PushStructP(arena, write_buffer);
buffer->buffer = PushArrayP(arena, u08, bufferSize);
buffer->size = 0;
return(buffer);
}
global_variable
s32
Sam_Out;
global_variable
u08
Global_Write_Error_Flag = 0;
global_function
void
WriteFunction(void *in)
{
write_buffer *buffer = (write_buffer *)in;
if (write(Sam_Out, (const void *)buffer->buffer, buffer->size) != buffer->size)
{
PrintError("Error writing to output");
Global_Write_Error_Flag = 1;
}
}
struct
read_buffer
{
u08 *buffer;
u64 size;
};
struct
read_pool
{
thread_pool *pool;
s32 handle;
u32 bufferPtr;
read_buffer *buffers[2];
};
global_function
read_pool *
CreateReadPool(memory_arena *arena)
{
read_pool *pool = PushStructP(arena, read_pool);
pool->pool = ThreadPoolInit(arena, 1);
#define ReadBufferSize MegaByte(16)
pool->bufferPtr = 0;
pool->buffers[0] = PushStructP(arena, read_buffer);
pool->buffers[0]->buffer = PushArrayP(arena, u08, ReadBufferSize);
pool->buffers[0]->size = 0;
pool->buffers[1] = PushStructP(arena, read_buffer);
pool->buffers[1]->buffer = PushArrayP(arena, u08, ReadBufferSize);
pool->buffers[1]->size = 0;
return(pool);
}
global_function
void
FillReadBuffer(void *in)
{
read_pool *pool = (read_pool *)in;
read_buffer *buffer = pool->buffers[pool->bufferPtr];
buffer->size = (u64)read(pool->handle, buffer->buffer, ReadBufferSize);
}
global_function
read_buffer *
GetNextReadBuffer(read_pool *readPool)
{
FenceIn(ThreadPoolWait(readPool->pool));
read_buffer *buffer = readPool->buffers[readPool->bufferPtr];
readPool->bufferPtr = (readPool->bufferPtr + 1) & 1;
ThreadPoolAddTask(readPool->pool, FillReadBuffer, readPool);
return(buffer);
}
global_function
void
CloseReadPool(read_pool *pool)
{
ThreadPoolWait(pool->pool);
ThreadPoolDestroy(pool->pool);
}
global_function
PyObject *
Aligner_Main(PyObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *objParams;
static const char *kwlist[] = {"params", 0};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", (char **)kwlist, &objParams))
{
return(0);
}
PyObject *objSamInput, *objSamOutput, *objNThreads, *objInfo, *objError;
{
struct
inputParam
{
PyObject **obj;
char *name;
};
inputParam params[] = {
{
&objSamInput,
(char *)"samInput"
},
{
&objSamOutput,
(char *)"samOutput"
},
{
&objNThreads,
(char *)"nThreads"
},
{
&objInfo,
(char *)"info"
},
{
&objError,
(char *)"error"
}
};
ForLoop(ArrayCount(params))
{
inputParam *param = params + index;
PyObject *objName = Py_BuildValue("s", param->name);
*(param->obj) = PyObject_GetAttr(objParams, objName);
Py_DECREF(objName);
if (!(*(param->obj)))
{
PrintError("No param attribute \'%s\' found", param->name);
return(0);
}
}
}
s32 exitCode = EXIT_SUCCESS;
if ((Status_Handle = (s32)PyObject_AsFileDescriptor(objInfo)) < 0)
{
PyErr_SetString(PyExc_Exception, "Cannot open the info/status handle");
return(0);
}
if ((Error_Handle = (s32)PyObject_AsFileDescriptor(objError)) < 0)
{
PyErr_SetString(PyExc_Exception, "Cannot open the error handle");
return(0);
}
u32 nThreads = (u32)PyLong_AsUnsignedLong(objNThreads);
TestForPythonError;
Py_DECREF(objNThreads);
CreateMemoryArena(Working_Set, MegaByte(512));
thread_pool *writePool = ThreadPoolInit(&Working_Set, 1);
read_pool *readPool = CreateReadPool(&Working_Set);
s32 samIn;
if ((samIn = PyObject_AsFileDescriptor(objSamInput)) > 0)
{
readPool->handle = samIn;
if ((Sam_Out = PyObject_AsFileDescriptor(objSamOutput)) > 0)
{
Py_BEGIN_ALLOW_THREADS;
u08 samLine[KiloByte(16)];
u32 linePtr = 0;
u08 goodRead = 1;
write_buffer *writeBuffers[2];
writeBuffers[0] = CreateWriteBuffer(&Working_Set, ReadBufferSize);
writeBuffers[1] = CreateWriteBuffer(&Working_Set, ReadBufferSize);
u08 writeBufferFlip = 0;
write_buffer *currentWriteBuffer = writeBuffers[writeBufferFlip];
u08 headerMode = 1;
u64 numHeaderLines = 0;
u32 numSequences = 0;
sequence *sequences = 0;
sequence *tailSequence = 0;
sequence_hash_table *sequenceHashTable;
u64 totalRead = 0;
char printNBuffers[2][16] = {{0}};
u08 printNBufferPtr = 0;
read_buffer *readBuffer = GetNextReadBuffer(readPool);
do
{
readBuffer = GetNextReadBuffer(readPool);
for ( u64 bufferIndex = 0;
bufferIndex < readBuffer->size;
++bufferIndex )
{
u08 character = readBuffer->buffer[bufferIndex];
samLine[linePtr++] = character;
if (character == '\n')
{
if (headerMode && samLine[0] != '@')
{
sequenceHashTable = CreateSequenceHashTable(&Working_Set, numSequences);
PrintStatus("Created digestion fragment hash-table with capacity %u", sequenceHashTable->size);
TraverseLinkedList(sequences, sequence) AddSequenceToHashTable(&Working_Set, sequenceHashTable, node);
headerMode = 0;
PrintStatus("Inserted %u sequences into hash-table", numSequences);
}
if (headerMode && samLine[1] == 'S' && samLine[2] == 'Q')
{
++numHeaderLines;
u32 nameStart = 3;
while (!(samLine[nameStart] == '\t' && samLine[nameStart + 1] == 'S' && samLine[nameStart + 2] == 'N' && samLine[nameStart + 3] == ':')) ++nameStart;
nameStart += 4;
u08 *name = samLine + nameStart;
u32 nameLength = 1;
while (*name != '\t' && *name != '\n')
{
++name;
++nameLength;
}
name = PushArray(Working_Set, u08, nameLength);
ForLoop((nameLength - 1))
{
name[index] = samLine[nameStart + index];
}
name[nameLength - 1] = 0;
u08 *nameTmp = name + nameLength - 1;
u32 endLength = 0;
while (*(--nameTmp) != '_') ++endLength;
u32 end = StringToInt(name + nameLength - 2, endLength - 1);
u08 endOverhangIsFwd = name[nameLength - 2] == '+' ? 1 : 0;
u08 *nameTmpTmp = nameTmp;
u32 startLength = 0;
while (*(--nameTmpTmp) != '_') ++startLength;
u32 start = StringToInt(nameTmp - 1, startLength - 1);
u08 startOverhangIsFwd = nameTmp[-1] == '+' ? 1 : 0;
u32 lengthStart = 3;
while (!(samLine[lengthStart] == '\t' && samLine[lengthStart + 1] == 'L' && samLine[lengthStart + 2] == 'N' && samLine[lengthStart + 3] == ':')) ++lengthStart;
lengthStart += 4;
u08 *length = samLine + lengthStart;
u32 lengthLength = 0;
while (*length != '\t' && *length != '\n')
{
++length;
++lengthLength;
}
u32 seqLength = StringToInt(length, lengthLength);
sequence *newSequence = PushStruct(Working_Set, sequence);
newSequence->name = (char *)name;
newSequence->next = 0;
newSequence->length = seqLength;
newSequence->frontOverhang = (u08)start;
newSequence->endOverhang = (u08)end;
newSequence->frontOverhangIsFwd = startOverhangIsFwd;
newSequence->endOverhangIsFwd = endOverhangIsFwd;
++numSequences;
if (!sequences) sequences = newSequence;
else tailSequence->next = newSequence;
tailSequence = newSequence;
}
if (!headerMode)
{
u32 copyPtr = 0;
while (samLine[copyPtr++] != '\t') {} // read name
u32 flagsLength = 0;
while (samLine[copyPtr++] != '\t') ++flagsLength; // flags
u08 readIsRev = (StringToInt(samLine + copyPtr - 1, flagsLength) & 16) ? 1 : 0;
sequence *seq;
if ((seq = GetSequenceFromHashTable(sequenceHashTable, (char *)(samLine + copyPtr))))
{
while (samLine[copyPtr++] != '\t') {} // ref name
u32 posLen = 0;
while (samLine[copyPtr++] != '\t') ++posLen; // pos
u32 pos = StringToInt(samLine + copyPtr - 1, posLen);
if (pos)
{
pos -= 1;
while (samLine[copyPtr++] != '\t') {} // mapq
u32 startSamLength = copyPtr;
if (samLine[startSamLength] != '*')
{
u32 cigarLen = 0;
while (samLine[copyPtr++] != '\t') ++cigarLen; // cigar
u32 otherStart = copyPtr;
u32 otherLength = 2;
while (samLine[copyPtr++] != '\t') ++otherLength; // next read name
while (samLine[copyPtr++] != '\t') ++otherLength; // next pos
while (samLine[copyPtr++] != '\t') ++otherLength; // temp length
u32 seqStart = copyPtr;
u32 seqLength = 0;
while (samLine[copyPtr++] != '\t') ++seqLength; // seq
u32 qualStart = copyPtr;
while (samLine[copyPtr++] != '\t') {} // qual
u32 firstRefCigar = 0;
{
u08 *cigar = samLine + startSamLength;
u32 numLen = 0;
u08 cigOp;
while ((cigOp = *(cigar++)) != '\t')
{
u08 process = 1;
u08 ref = 0;
switch (cigOp)
{
case 'M':
case 'D':
case 'N':
case '=':
case 'X':
ref = 1;
case 'I':
case 'S':
case 'H':
case 'P':
break;
default:
++numLen;
process = 0;
}
if (ref) break;
if (process)
{
firstRefCigar += (numLen ? StringToInt(cigar - 1, numLen) : 1);
numLen = 0;
}
}
}
u32 frontOverhang = readIsRev == seq->frontOverhangIsFwd ? 0 : seq->frontOverhang;
u32 endOverhang = readIsRev == seq->endOverhangIsFwd ? 0 : seq->endOverhang;
u32 startOffset = firstRefCigar + frontOverhang;
startOffset = startOffset > pos ? startOffset - pos : 0;
pos = startOffset ? 0 : pos - frontOverhang;
u32 referenceLength = seq->length;
referenceLength = referenceLength > frontOverhang ? referenceLength - frontOverhang : 0;
referenceLength = referenceLength > endOverhang ? referenceLength - endOverhang : 0;
referenceLength = referenceLength > pos ? referenceLength - pos : 0;
u08 newSamLine[sizeof(samLine)];
u32 newLinePtr = (u32)stbsp_snprintf((char *)newSamLine, startSamLength + 1, "%s", samLine);
if (referenceLength)
{
u32 seqStartOffset = 0;
u32 seqEndOffset = 0;
{
u08 *cigar = samLine + startSamLength;
u32 numLen = 0;
u08 cigOp;
while ((cigOp = *(cigar++)) != '\t')
{
u08 process = 1;
u08 ref = 0;
u08 qu = 0;
switch (cigOp)
{
case 'I':
case 'S':
case 'M':
case '=':
case 'X':
qu = 1;
if (cigOp == 'I' || cigOp == 'S') break;
case 'D':
case 'N':
ref = 1;
case 'H':
case 'P':
break;
default:
++numLen;
process = 0;
}
if (process)
{
u32 n = numLen ? StringToInt(cigar - 1, numLen) : 1;
numLen = 0;
if (startOffset)
{
if (startOffset > n)
{
startOffset -= n;
if (qu) seqStartOffset += n;
n = 0;
}
else
{
if (qu) seqStartOffset += startOffset;
n -= startOffset;
startOffset = 0;
}
}
if (!startOffset)
{
if (referenceLength > n) referenceLength -= n;
else
{
if (qu) seqEndOffset += (n - referenceLength);
n = referenceLength;
referenceLength = 0;
}
if (n) newLinePtr += (u32)stbsp_snprintf((char *)newSamLine + newLinePtr, 6, "%u%c", n, cigOp);
}
}
}
}
newLinePtr += (u32)stbsp_snprintf((char *)newSamLine + newLinePtr, otherLength + 2, "\t%s", samLine + otherStart);
u32 totalOffset = seqStartOffset + seqEndOffset;
if (totalOffset < seqLength)
{
newLinePtr += (u32)stbsp_snprintf((char *)newSamLine + newLinePtr, seqLength - totalOffset + 2, "\t%s", samLine + seqStart + seqStartOffset);
newLinePtr += (u32)stbsp_snprintf((char *)newSamLine + newLinePtr, seqLength - totalOffset + 2, "\t%s", samLine + qualStart + seqStartOffset);
}
else
{
//newLinePtr += (u32)stbsp_snprintf((char *)newSamLine + newLinePtr, 5, "\t*\t*");
goodRead = 0;
}
}
else
{
//newLinePtr += (u32)stbsp_snprintf((char *)newSamLine + newLinePtr, 5, "\t*\t*");
goodRead = 0;
}
if (goodRead)
{
newLinePtr += (u32)stbsp_snprintf((char *)newSamLine + newLinePtr, linePtr - copyPtr + 2, "\t%s", samLine + copyPtr);
stbsp_snprintf((char *)samLine, newLinePtr + 1, "%s", newSamLine);
linePtr = newLinePtr;
}
}
}
}
}
if (goodRead)
{
if ((u64)linePtr > (ReadBufferSize - currentWriteBuffer->size))
{
if (Global_Write_Error_Flag)
{
exitCode = EXIT_FAILURE;
goto End;
}
FenceIn(ThreadPoolWait(writePool));
ThreadPoolAddTask(writePool, WriteFunction, currentWriteBuffer);
writeBufferFlip = (writeBufferFlip + 1) & 1;
currentWriteBuffer = writeBuffers[writeBufferFlip];
currentWriteBuffer->size = 0;
}
ForLoop(linePtr) currentWriteBuffer->buffer[currentWriteBuffer->size++] = samLine[index];
}
linePtr = 0;
goodRead = 1;
#define Log2_Print_Interval 14
if (!(++totalRead & ((1 << Log2_Print_Interval) - 1)))
{
u08 currPtr = printNBufferPtr;
u08 otherPtr = (currPtr + 1) & 1;
stbsp_snprintf(printNBuffers[currPtr], sizeof(printNBuffers[currPtr]), "%$" PRIu64, headerMode ? numHeaderLines : totalRead - numHeaderLines);
if (strcmp(printNBuffers[currPtr], printNBuffers[otherPtr]))
{
PrintStatus("%s %s processed", printNBuffers[currPtr], headerMode ? "header lines" : "reads");
}
printNBufferPtr = otherPtr;
}
}
}
} while (readBuffer->size);
ThreadPoolAddTask(writePool, WriteFunction, currentWriteBuffer);
ThreadPoolWait(writePool);
Py_END_ALLOW_THREADS;
}
else
{
PrintError("Could not open sam output");
exitCode = EXIT_FAILURE;
}
}
else
{
PrintError("Could not open sam input");
exitCode = EXIT_FAILURE;
}
End:
CloseReadPool(readPool);
ThreadPoolWait(writePool);
ThreadPoolDestroy(writePool);
FreeMemoryArena(Working_Set);
if (exitCode == EXIT_FAILURE || Global_Write_Error_Flag) return(0);
Py_RETURN_NONE;
}
#define ModuleName "_Aligner_Main"
#define ModuleDescription "HiLine alignment read trimmer"
global_variable
PyMethodDef
AlignerMethods[] =
{
{ModuleName, (PyCFunction) Aligner_Main, METH_VARARGS | METH_KEYWORDS, ModuleDescription},
{NULL, NULL, 0, NULL}
};
global_variable
struct
PyModuleDef
AlignerModule =
{
PyModuleDef_HEAD_INIT,
ModuleName,
ModuleDescription,
-1,
AlignerMethods
};
PyMODINIT_FUNC
PyInit__Aligner()
{
return(PyModule_Create(&AlignerModule));
}