@@ -431,7 +431,8 @@ get_full_and_partial_ops(const uint32_t *cig_in, const uint32_t in_ops,
431
431
* output of "A-" is "-T", and the output of "C-" is "-G", and so
432
432
* forth. The user must handle this case separately.
433
433
*/
434
- const uint8_t byte_revcom_table[] = {
434
+ const uint8_t byte_revcomp_table[] = {
435
+ // clang-format off
435
436
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 8 , 136 ,
436
437
72 , 0 , 40 , 0 , 0 , 0 , 24 , 0 , 0 , 0 , 0 , 0 , 0 , 248 , 4 , 132 , 68 , 0 ,
437
438
36 , 0 , 0 , 0 , 20 , 0 , 0 , 0 , 0 , 0 , 0 , 244 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -446,29 +447,31 @@ const uint8_t byte_revcom_table[] = {
446
447
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
447
448
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
448
449
0 , 0 , 0 , 0 , 0 , 0 , 15 , 143 , 79 , 0 , 47 , 0 , 0 , 0 , 31 , 0 , 0 , 0 ,
449
- 0 , 0 , 0 , 255 };
450
+ 0 , 0 , 0 , 255
451
+ // clang-format on
452
+ };
450
453
451
454
static inline void
452
- revcom_byte_then_reverse (unsigned char *a, unsigned char *b) {
453
- unsigned char *p1, *p2;
454
- for (p1 = a, p2 = b - 1 ; p2 > p1; ++p1, --p2) {
455
- *p1 = byte_revcom_table [*p1];
456
- *p2 = byte_revcom_table [*p2];
455
+ revcomp_byte_then_reverse (unsigned char *const a, unsigned char *const b) {
456
+ unsigned char *p1{a} , *p2{b} ;
457
+ for (p2 -= 1 ; p2 > p1; ++p1, --p2) {
458
+ *p1 = byte_revcomp_table [*p1];
459
+ *p2 = byte_revcomp_table [*p2];
457
460
*p1 ^= *p2;
458
461
*p2 ^= *p1;
459
462
*p1 ^= *p2;
460
463
}
461
464
if (p1 == p2)
462
- *p1 = byte_revcom_table [*p1];
465
+ *p1 = byte_revcomp_table [*p1];
463
466
}
464
467
465
468
static inline void
466
- revcomp_seq_by_byte (bam1_t *aln) {
469
+ revcomp_seq_by_byte (bam1_t *const aln) {
467
470
const size_t l_qseq = get_l_qseq (aln);
468
471
auto seq = bam_get_seq (aln);
469
- const size_t num_bytes = ceil (l_qseq / 2.0 );
472
+ const size_t num_bytes = (l_qseq + 1 ) / 2 ; // integer ceil / 2
470
473
auto seq_end = seq + num_bytes;
471
- revcom_byte_then_reverse (seq, seq_end);
474
+ revcomp_byte_then_reverse (seq, seq_end);
472
475
if (l_qseq % 2 == 1 ) { // for odd-length sequences
473
476
for (size_t i = 0 ; i < num_bytes - 1 ; i++) {
474
477
// swap 4-bit chunks within consecutive bytes like this:
@@ -486,7 +489,7 @@ revcomp_seq_by_byte(bam1_t *aln) {
486
489
// has been set to ceil((a_used_len + b_seq_len) / 2.0) where
487
490
// a_used_len = c_seq_len - b_seq_len
488
491
static inline void
489
- merge_by_byte (const bam1_t * a, const bam1_t * b, bam1_t *c) {
492
+ merge_by_byte (bam1_t const * const a, bam1_t const * const b, bam1_t *const c) {
490
493
// ADS: (todo) need some functions for int_ceil and is_odd
491
494
const size_t b_seq_len = get_l_qseq (b);
492
495
const size_t c_seq_len = get_l_qseq (c);
@@ -496,8 +499,8 @@ merge_by_byte(const bam1_t *a, const bam1_t *b, bam1_t *c) {
496
499
const bool is_b_odd = b_seq_len % 2 == 1 ;
497
500
const bool is_c_odd = c_seq_len % 2 == 1 ;
498
501
499
- const size_t a_num_bytes = ceil (a_used_len / 2.0 );
500
- const size_t b_num_bytes = ceil (b_seq_len / 2.0 );
502
+ const size_t a_num_bytes = (a_used_len + 1 ) / 2 ; // integer ceil / 2
503
+ const size_t b_num_bytes = (b_seq_len + 1 ) / 2 ; // integer ceil / 2
501
504
502
505
const size_t b_offset = is_a_odd && is_b_odd;
503
506
@@ -511,25 +514,25 @@ merge_by_byte(const bam1_t *a, const bam1_t *b, bam1_t *c) {
511
514
// or [ aa aa aa a- ]
512
515
c_seq[a_num_bytes - 1 ] &= 0xf0 ;
513
516
c_seq[a_num_bytes - 1 ] |=
514
- is_b_odd ? byte_revcom_table [b_seq[b_num_bytes - 1 ]]
515
- : byte_revcom_table [b_seq[b_num_bytes - 1 ]] >> 4 ;
517
+ is_b_odd ? byte_revcomp_table [b_seq[b_num_bytes - 1 ]]
518
+ : byte_revcomp_table [b_seq[b_num_bytes - 1 ]] >> 4 ;
516
519
}
517
520
if (is_c_odd) {
518
521
// c_seq looks like either [ aa aa aa aa ]
519
522
// or [ aa aa aa ab ]
520
523
for (size_t i = 0 ; i < b_num_bytes - 1 ; i++) {
521
524
c_seq[a_num_bytes + i] =
522
- (byte_revcom_table [b_seq[b_num_bytes - i - 1 ]] << 4 ) |
523
- (byte_revcom_table [b_seq[b_num_bytes - i - 2 ]] >> 4 );
525
+ (byte_revcomp_table [b_seq[b_num_bytes - i - 1 ]] << 4 ) |
526
+ (byte_revcomp_table [b_seq[b_num_bytes - i - 2 ]] >> 4 );
524
527
}
525
- c_seq[a_num_bytes + b_num_bytes - 1 ] = byte_revcom_table [b_seq[0 ]] << 4 ;
528
+ c_seq[a_num_bytes + b_num_bytes - 1 ] = byte_revcomp_table [b_seq[0 ]] << 4 ;
526
529
// Here, c_seq is either [ aa aa aa aa bb bb bb b- ] (a even; b odd)
527
530
// or [ aa aa aa ab bb bb bb b- ] (a odd; b odd)
528
531
}
529
532
else {
530
533
for (size_t i = 0 ; i < b_num_bytes - b_offset; i++) {
531
534
c_seq[a_num_bytes + i] =
532
- byte_revcom_table [b_seq[b_num_bytes - i - 1 - b_offset]];
535
+ byte_revcomp_table [b_seq[b_num_bytes - i - 1 - b_offset]];
533
536
}
534
537
// Here, c_seq is either [ aa aa aa aa bb bb bb bb ] (a even and b even)
535
538
// or [ aa aa aa ab bb bb bb ] (a odd and b odd)
@@ -554,16 +557,15 @@ flip_conversion(bam_rec &aln) {
554
557
flip_conversion (aln.b );
555
558
}
556
559
557
- // static inline bool
558
- // are_mates(const bam1_t *one, const bam1_t *two) {
559
- // return one->core.mtid == two->core.tid && one->core.mpos == two->core.pos
560
- // &&
561
- // (one->core.flag & BAM_FREVERSE) != (one->core.flag & BAM_FREVERSE);
562
- // // below is a consistency check and should not be necessary
563
- // /* &&
564
- // two->core.mtid == one->core.tid &&
565
- // two->core.mpos == one->core.pos; */
566
- // }
560
+ [[maybe_unused]] static inline bool
561
+ are_mates (const bam1_t *one, const bam1_t *two) {
562
+ return one->core .mtid == two->core .tid && one->core .mpos == two->core .pos &&
563
+ (one->core .flag & BAM_FREVERSE) != (one->core .flag & BAM_FREVERSE);
564
+ // below is a consistency check and should not be necessary
565
+ /* &&
566
+ two->core.mtid == one->core.tid &&
567
+ two->core.mpos == one->core.pos; */
568
+ }
567
569
568
570
static inline int
569
571
truncate_overlap (const bam1_t *a, const uint32_t overlap, bam1_t *c) {
@@ -830,7 +832,7 @@ keep_better_end(const bam_rec &a, const bam_rec &b, bam_rec &c) {
830
832
// ADS: will move to using this function once it is written
831
833
static inline void
832
834
standardize_format (const string &input_format, bam1_t *aln) {
833
- int err_code = 0 ;
835
+ int err_code{} ;
834
836
835
837
if (input_format == " abismal" || input_format == " walt" )
836
838
return ;
@@ -977,7 +979,7 @@ to_string(const bam_header &hdr, const bam_rec &aln) {
977
979
kstring_t ks = {0 , 0 , nullptr };
978
980
int ret = sam_format1 (hdr.h , aln.b , &ks);
979
981
if (ret < 0 ) {
980
- runtime_error (" Can't format record: " + to_string (hdr, aln));
982
+ throw runtime_error (" Can't format record: " + to_string (hdr, aln));
981
983
}
982
984
if (ks.s != nullptr )
983
985
free (ks.s );
0 commit comments