41 lines
1.9 KiB
C++
41 lines
1.9 KiB
C++
#include <htslib/sam.h>
|
|
#include <spdlog/spdlog.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#include "sort_impl.h"
|
|
|
|
int ks_radixsort(size_t n, OneBam* buf, const sam_hdr_t* h, int tid) {
|
|
if (tid == 0) spdlog::info("sort in thread, {} {}", tid, n);
|
|
|
|
int curr = 0, ret = -1;
|
|
ssize_t i;
|
|
OneBam *buf_ar2[2], *bam_a, *bam_b;
|
|
uint64_t max_pos = 1;
|
|
uint32_t max_tid = 1, tid_bytes = 0, pos_bytes = 0, byte = 0;
|
|
uint32_t tid_shift_l, tid_shift_r;
|
|
int nref = sam_hdr_nref(h);
|
|
|
|
//if (tid == 0)
|
|
//spdlog::info("Before: {} {} {} {} {} {} {} {} {} {}", buf[0].pos, buf[1].pos, buf[2].pos, buf[3].pos, buf[4].pos, buf[5].pos, buf[6].pos,
|
|
//buf[7].pos, buf[8].pos, buf[9].pos);
|
|
// spdlog::info("name: {}", std::string(buf[0].qnameAddr, buf[0].qnameLen));
|
|
// spdlog::info("name addr: {}", (uint64_t)buf[0].qnameLen);
|
|
// std::sort(buf, buf + n, [](const OneBam& b1, const OneBam& b2) { return b1.pos < b2.pos; });
|
|
std::sort(buf, buf + n, [](const OneBam& b1, const OneBam& b2) {
|
|
int cmp = 0;
|
|
// strncmp((char*)(b1.blockThread->blockArr[b1.blockIdx].data + b1.offset + OneBam::QnameOffset),
|
|
// (char*)(b2.blockThread->blockArr[b2.blockIdx].data + b2.offset + OneBam::QnameOffset), std::min(b1.qnameLen, b2.qnameLen));
|
|
if (cmp == 0)
|
|
return b1.qnameLen < b2.qnameLen;
|
|
return cmp < 0;
|
|
});
|
|
if (tid == 0) {
|
|
//std::string s1 = (char*)(buf[0].blockThread->blockArr[buf[0].blockIdx].data + buf[0].offset + OneBam::QnameOffset);
|
|
//std::string s2 = (char*)(buf[1].blockThread->blockArr[buf[1].blockIdx].data + buf[1].offset + OneBam::QnameOffset);
|
|
//spdlog::info("After: {} {} {} {} {} {} {} {} {} {}", s1, s2, buf[2].pos, buf[3].pos, buf[4].pos, buf[5].pos, buf[6].pos, buf[7].pos,
|
|
//buf[8].pos, buf[9].pos);
|
|
}
|
|
|
|
return 0;
|
|
} |