Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
rocksort: fix sorting by read name, which had been broken in a previo…
Browse files Browse the repository at this point in the history
…us refactoring
  • Loading branch information
mlin committed Feb 27, 2014
1 parent b5b67cc commit e51afc2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bam_rocksort.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ static void nop_rocksdb_comparator_destructor(void *c) {
}

/* given a bam1_t, formulate the appropriate key for insertion into RocksDB */
static size_t formulate_key(const int sort_key, bam1_t *b, uint64_t seqno, char *keybuf, size_t *keybufsz) {
static size_t formulate_key(const int sort_key, bam1_t *b, uint64_t seqno, char **keybufp, size_t *keybufsz) {
char *keybuf = *keybufp;
size_t keylen = 0;
assert(*keybufsz >= 2*sizeof(uint64_t));
switch (sort_key) {
Expand Down Expand Up @@ -200,6 +201,7 @@ static size_t formulate_key(const int sort_key, bam1_t *b, uint64_t seqno, char
seqno >>= 8;
keylen++;
}
*keybufp = keybuf;
return keylen;
}

Expand Down Expand Up @@ -239,7 +241,7 @@ static int bam_to_rocksdb(bamFile fp, rocksdb_t *rdb, const int sort_key, unsign
/* for each BAM record */
while ((ret = bam_read1(fp,b)) >= 0) {
/* formulate key for insertion into RocksDB */
if (!(keylen = formulate_key(sort_key, b, ++(*count), key, &keybufsz))) {
if (!(keylen = formulate_key(sort_key, b, ++(*count), &key, &keybufsz))) {
ret = -4;
goto cleanup;
}
Expand Down
4 changes: 4 additions & 0 deletions test/rocksort/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ if [ "$result_sam_count" != "$expected_sam_count" ]; then
fi
./bamsorted "$sorted_bam"

echo "Sort by read name..."
time $samtools rocksort -n -l 1 -@ 2 -m 16M "$shuffled_bam" "${testdir}/samtools_rocksort_test_sorted"
sorted_bam="${testdir}/samtools_rocksort_test_sorted_by_name.bam"

# Clean up
rm -rf $testdir
echo "Test passed. Cleaned up $testdir"

0 comments on commit e51afc2

Please sign in to comment.