bwa_perf/util.cpp

56 lines
1.2 KiB
C++

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "util.h"
// base转成2bit值
int bval(char b)
{
if (b == 'A')
return 0;
if (b == 'C')
return 1;
if (b == 'G')
return 2;
if (b == 'T')
return 3;
return 4;
}
// 互补碱基值
int cbval(char b)
{
return 3 - bval(b);
}
double realtime(void)
{
struct timeval tp;
struct timezone tzp;
gettimeofday(&tp, &tzp);
return tp.tv_sec + tp.tv_usec * 1e-6;
}
// 打印故障信息,并终止程序
void _err_fatal_simple_core(const char *func, const char *msg)
{
fprintf(stderr, "[%s] %s Abort!\n", func, msg);
abort();
}
// 读取数据
bwtint_t fread_fix(FILE *fp, bwtint_t size, void *a)
{ /* Mac/Darwin has a bug when reading data longer than 2GB. This function fixes this issue by reading data in small chunks */
const int bufsize = 0x1000000; // 16M block
bwtint_t offset = 0;
while (size)
{
int x = bufsize < size ? bufsize : size;
if ((x = fread((uint8_t *)a + offset, 1, x, fp)) == 0)
break;
size -= x;
offset += x;
}
return offset;
}