@@ -308,40 +308,40 @@ void increment(char base, uint32_t *A, uint32_t *C, uint32_t *T, uint32_t *G) {
308
308
309
309
void * twobitBasesWorker (TwoBit * tb , uint32_t tid , uint32_t start , uint32_t end , int fraction ) {
310
310
void * out ;
311
- uint32_t sz = end - start , pos = 0 ;
312
- uint32_t A = 0 , C = 0 , T = 0 , G = 0 , len = end - start ;
313
- uint32_t maskIdx = -1 , maskStart = -1 , maskEnd = -1 ;
314
- uint32_t blockStart , offset ;
315
- uint8_t byte , base ;
316
- int rv = 0 ;
311
+ uint32_t A = 0 , C = 0 , T = 0 , G = 0 , len = end - start , i = 0 ;
312
+ uint32_t blockStart , blockEnd , offset ;
313
+ char * s = NULL ;
317
314
318
315
if (fraction ) {
319
316
out = malloc (4 * sizeof (double ));
320
317
} else {
321
318
out = malloc (4 * sizeof (uint32_t ));
322
319
}
323
320
if (!out ) return NULL ;
324
-
325
- getMask (tb , tid , start , end , & maskIdx , & maskStart , & maskEnd );
326
-
327
- //There are 4 bases/byte
328
- blockStart = start /4 ;
329
- offset = start % 4 ;
330
-
331
- if (twobitSeek (tb , tb -> idx -> offset [tid ] + blockStart ) != 0 ) goto error ;
332
- while (pos < sz ) {
333
- //Iterate over the 4 (or less) bases in each byte
334
- if (twobitRead (& byte , 1 , 1 , tb ) != 1 ) goto error ;
335
- for (; offset < 4 ; offset ++ ) {
336
- rv = cycle (tb , tid , start , end , & pos , & maskIdx , & maskStart , & maskEnd , & blockStart , & offset );
337
- if (rv == -1 ) goto error ;
338
- if (rv == 1 ) break ;
339
- base = byte2base (byte , offset );
340
- increment (base , & A , & C , & T , & G );
341
- if (++ pos >= sz ) break ;
321
+ s = constructSequence (tb , tid , start , end );
322
+ if (!s ) goto error ;
323
+
324
+ for (i = 0 ; i < len ; i ++ ) {
325
+ switch (s [i ]) {
326
+ case 'A' :
327
+ case 'a' :
328
+ A ++ ;
329
+ break ;
330
+ case 'C' :
331
+ case 'c' :
332
+ C ++ ;
333
+ break ;
334
+ case 'G' :
335
+ case 'g' :
336
+ G ++ ;
337
+ break ;
338
+ case 'T' :
339
+ case 't' :
340
+ T ++ ;
341
+ break ;
342
342
}
343
- if (rv != 1 ) offset = 0 ;
344
343
}
344
+ free (s );
345
345
346
346
if (fraction ) {
347
347
((double * ) out )[0 ] = ((double ) A )/((double ) len );
@@ -359,6 +359,7 @@ void *twobitBasesWorker(TwoBit *tb, uint32_t tid, uint32_t start, uint32_t end,
359
359
360
360
error :
361
361
free (out );
362
+ if (s ) free (s );
362
363
return NULL ;
363
364
}
364
365
0 commit comments