Skip to content

Commit ec38c41

Browse files
replacing bam_set1 in truncate_overlap
1 parent f6873eb commit ec38c41

1 file changed

Lines changed: 29 additions & 25 deletions

File tree

src/utils/format-reads.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static int bam_set1_wrapper(bam1_t *bam,
210210
bam->l_data = (int)data_len;
211211
bam->core.pos = pos;
212212
bam->core.tid = tid;
213-
// bam->core.bin = bam_reg2bin(pos, pos + isize);
213+
// bam->core.bin = bam_reg2bin(pos, pos + rlen);
214214
bam->core.bin = hts_reg2bin(pos, pos + isize, 14, 5);
215215
// above taken from htslib/cram/cram_samtools.h
216216
bam->core.qual = mapq;
@@ -229,7 +229,7 @@ static int bam_set1_wrapper(bam1_t *bam,
229229
data_iter += l_qname + qname_nuls;
230230

231231
// std::copy_n(cigar, n_cigar * sizeof(uint32_t), data_iter);
232-
std::copy_n(cigar, n_cigar, reinterpret_cast<uint32_t*>(data_iter));
232+
std::copy_n(cigar, n_cigar, reinterpret_cast<uint32_t *>(data_iter));
233233
data_iter += n_cigar * sizeof(uint32_t);
234234

235235
// skipping sequece assignment
@@ -628,38 +628,42 @@ truncate_overlap(const bam1_t *a, const uint32_t overlap, bam1_t *c)
628628
/* after this point the cigar is set and should decide everything */
629629

630630
const uint32_t c_seq_len = bam_cigar2qlen(c_ops, c_cig);
631-
char *c_seq = (char *)calloc(c_seq_len + 1, sizeof(char));
632-
if (!c_seq)
633-
throw fr_expt("allocating sequence");
631+
// char *c_seq = (char *)calloc(c_seq_len + 1, sizeof(char));
632+
// if (!c_seq)
633+
// throw fr_expt("allocating sequence");
634634

635-
// copy the prefix of a into c; must be easier
636-
for (size_t i = 0; i < c_seq_len; ++i)
637-
c_seq[i] = seq_nt16_str[bam_seqi(bam_get_seq(a), i)];
635+
// // copy the prefix of a into c; must be easier
636+
// for (size_t i = 0; i < c_seq_len; ++i)
637+
// c_seq[i] = seq_nt16_str[bam_seqi(bam_get_seq(a), i)];
638638

639639
// get the template length
640640
const hts_pos_t isize = bam_cigar2rlen(c_ops, c_cig);
641641

642642
// flag only needs to worry about strand and single-end stuff
643643
const uint16_t flag = a->core.flag & (BAM_FREAD1 | BAM_FREAD2 | BAM_FREVERSE);
644644

645-
int ret = bam_set1(c,
646-
a->core.l_qname - (a->core.l_extranul + 1),
647-
bam_get_qname(a),
648-
flag, // flags (SR and revcomp info)
649-
a->core.tid,
650-
a->core.pos,
651-
a->core.qual,
652-
c_ops, // merged cigar ops
653-
c_cig, // merged cigar
654-
-1, // (no mate)
655-
-1, // (no mate)
656-
isize, // rlen from new cigar
657-
c_seq_len, // truncated seq length
658-
c_seq, // truncated sequence
659-
NULL, // no qual info
660-
8); // enough for the 2 tags?
645+
int ret = bam_set1_wrapper(c,
646+
a->core.l_qname - (a->core.l_extranul + 1),
647+
bam_get_qname(a),
648+
flag, // flags (SR and revcomp info)
649+
a->core.tid,
650+
a->core.pos,
651+
a->core.qual,
652+
c_ops, // merged cigar ops
653+
c_cig, // merged cigar
654+
-1, // (no mate)
655+
-1, // (no mate)
656+
isize, // rlen from new cigar
657+
c_seq_len, // truncated seq length
658+
// c_seq, // truncated sequence
659+
// NULL, // no qual info
660+
8); // enough for the 2 tags?
661661
free(c_cig);
662-
free(c_seq);
662+
// free(c_seq);
663+
auto c_seq = bam_get_seq(c);
664+
size_t num_bytes_to_copy = (c_seq_len + 1) / 2;
665+
std::copy_n(bam_get_seq(a), num_bytes_to_copy, c_seq);
666+
663667
if (ret < 0)
664668
throw fr_expt(ret, "bam_set1");
665669

0 commit comments

Comments
 (0)