Skip to content

Commit

Permalink
Fix issue arq5x#788 and add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
38 committed Nov 27, 2019
1 parent c9473fc commit 77f2374
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils/BamTools/include/BamAlignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ namespace BamTools {
bool SyncExtraData() const
{
#define BAM_DATA_OFFSET(what) ((size_t)(((uint8_t*)bam_get_##what(&_bam)) - ((uint8_t*)_bam.data)))
void* qname_buf = _ensure_data_chunk((bam1_t*)&_bam, BAM_DATA_OFFSET(qname), _bam.core.l_qname, Name.size());
void* qname_buf = _ensure_data_chunk((bam1_t*)&_bam, BAM_DATA_OFFSET(qname), _bam.core.l_qname, Name.size() + 1);
if(NULL == qname_buf) return false;
memcpy(qname_buf, Name.c_str(), Name.size());
((bam1_t*)&_bam)->core.l_qname = Name.size();
memcpy(qname_buf, Name.c_str(), Name.size() + 1);
((bam1_t*)&_bam)->core.l_qname = Name.size() + 1;

uint32_t* cigar_buf = (uint32_t*)_ensure_data_chunk((bam1_t*)&_bam, BAM_DATA_OFFSET(cigar), _bam.core.n_cigar * sizeof(uint32_t), sizeof(uint32_t) * CigarData.size());
if(NULL == cigar_buf) return false;
Expand Down
1 change: 1 addition & 0 deletions test/bedtobam/chrsize.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 3000
26 changes: 26 additions & 0 deletions test/bedtobam/test-bedtobam.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set -e;
BT=${BT-../../bin/bedtools}

FAILURES=0;

check()
{
if diff $1 $2; then
echo ok
else
FAILURES=$(expr $FAILURES + 1);
echo fail
fi
}

##################################################################
# Test one block without -split
##################################################################
echo -e " bedtobam.t1...\c"
echo \
"read_name 0 1 1001 255 1000M * 0 0 * *">exp
echo -e "1\t1000\t2000\tread_name\t255\t+" | $BT bedtobam -i - -g chrsize.tmp| samtools view > obs
check obs exp
rm obs exp

[[ $FAILURES -eq 0 ]] || exit 1;

0 comments on commit 77f2374

Please sign in to comment.