From ac93233f2f0fa6649ca225ac431d3b81aa4c5a3b Mon Sep 17 00:00:00 2001 From: Zhang Zhonghai Date: Wed, 7 Jan 2026 17:27:02 +0800 Subject: [PATCH] Fix a bug in indexing process --- .gitignore | 2 +- .vscode/launch.json | 12 ++++++------ Makefile | 2 +- bwa.h | 2 -- bwashm.c | 10 ---------- bwtindex.c | 12 ++++++++---- fastmap.c | 11 ++--------- 7 files changed, 18 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 7abd13b..2421f71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Prerequisites *.d -fastbwa +fastalign # Object files *.o diff --git a/.vscode/launch.json b/.vscode/launch.json index 0a30413..905ef22 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "preLaunchTask": "Build", "type": "cppdbg", "request": "launch", - "program": "${workspaceRoot}/fastbwa", + "program": "${workspaceRoot}/fastalign", "args": [ "mem", "-t", @@ -31,10 +31,10 @@ "preLaunchTask": "Build", "type": "cppdbg", "request": "launch", - "program": "${workspaceRoot}/fastbwa", + "program": "${workspaceRoot}/fastalign", "args": [ "index", - "~/data/reference/human_g1k_v37_decoy.fasta" + "./index/ref.fasta" ], "cwd": "${workspaceFolder}", // 当前工作路径:当前文件所在的工作空间 }, @@ -43,7 +43,7 @@ "preLaunchTask": "Build", "type": "cppdbg", "request": "launch", - "program": "${workspaceRoot}/fastbwa", + "program": "${workspaceRoot}/fastalign", "args": [ "buildkmer", "~/data/reference/human_g1k_v37_decoy.fasta.256.64.fmt", @@ -56,7 +56,7 @@ "preLaunchTask": "Build", "type": "cppdbg", "request": "launch", - "program": "${workspaceRoot}/fastbwa", + "program": "${workspaceRoot}/fastalign", "args": [ "shm", "-Z", @@ -69,7 +69,7 @@ "preLaunchTask": "Build", "type": "cppdbg", "request": "launch", - "program": "${workspaceRoot}/fastbwa", + "program": "${workspaceRoot}/fastalign", "args": [ "pac2bref", "~/data1/fmt_ref/human_g1k_v37_decoy.fasta" diff --git a/Makefile b/Makefile index 07b79b5..a13c7a8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC= gcc -CFLAGS= -g -Wall -Wno-unused-function -mavx2 -O2 +CFLAGS= -g -Wall -Wno-unused-function -mavx2 #-O2 WRAP_MALLOC=-DUSE_MALLOC_WRAPPERS SHOW_PERF= -DSHOW_PERF diff --git a/bwa.h b/bwa.h index 583423b..0059fa0 100644 --- a/bwa.h +++ b/bwa.h @@ -103,8 +103,6 @@ extern "C" { bwaidx_t *bwa_idx_load_from_shm(const char *hint); bwaidx_t *bwa_idx_load_from_disk(const char *hint, int which); bwaidx_t *bwa_fmtidx_load_from_shm(const char *hint); - bwaidx_t *bwa_ertidx_load_from_shm(const char *hint); - bwaidx_t *bwa_ertidx_load_from_disk(const char *hint); bwaidx_t *bwa_idx_load(const char *hint, int which); void bwa_idx_destroy(bwaidx_t *idx); int bwa_idx2mem(bwaidx_t *idx); diff --git a/bwashm.c b/bwashm.c index 2c350d9..4aa1a3b 100644 --- a/bwashm.c +++ b/bwashm.c @@ -386,16 +386,6 @@ int main_shm(int argc, char *argv[]) if (bwa_shm_test(shm_prefix) == 0) { #if 0 - bwaidx_t *idx; - if (useERT) - idx = bwa_ertidx_load_from_disk(argv[optind]); - else - idx = bwa_idx_load_from_disk(argv[optind], BWA_IDX_BNS | BWA_IDX_PAC | BWA_IDX_FMT); - if (bwa_shm_stage(idx, shm_prefix, useERT) < 0) { - fprintf(stderr, "[E::%s] failed to stage the index in shared memory\n", __func__); - ret = 1; - } - bwa_idx_destroy(idx); #else if (bwa_shm_stage_fmt(argv[optind]) < 0) { diff --git a/bwtindex.c b/bwtindex.c index 308b7b7..2670243 100644 --- a/bwtindex.c +++ b/bwtindex.c @@ -375,11 +375,13 @@ int bwa_idx_build(const char *fa, const char *prefix, int algo_type, int block_s { // nucleotide indexing gzFile fp = xzopen(fa, "r"); - t = clock(); + start_async_read(fp); + t = clock(); if (bwa_verbose >= 3) fprintf(stderr, "[bwa_index] Pack FASTA... "); l_pac = bns_fasta2bntseq(fp, prefix, 0); if (bwa_verbose >= 3) fprintf(stderr, "%.2f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC); - err_gzclose(fp); + stop_async_read(fp); + err_gzclose(fp); } if (algo_type == 0) algo_type = l_pac > 50000000? 2 : 3; // set the algorithm for generating BWT { @@ -409,11 +411,13 @@ int bwa_idx_build(const char *fa, const char *prefix, int algo_type, int block_s } { gzFile fp = xzopen(fa, "r"); - t = clock(); + start_async_read(fp); + t = clock(); if (bwa_verbose >= 3) fprintf(stderr, "[bwa_index] Pack forward-only FASTA... "); l_pac = bns_fasta2bntseq(fp, prefix, 1); if (bwa_verbose >= 3) fprintf(stderr, "%.2f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC); - err_gzclose(fp); + stop_async_read(fp); + err_gzclose(fp); } { bwt_t *bwt; diff --git a/fastmap.c b/fastmap.c index 46dc6c2..2185e2e 100644 --- a/fastmap.c +++ b/fastmap.c @@ -602,16 +602,9 @@ int main_mem(int argc, char *argv[]) PROF_END(gprof[G_PREPARE], prepare); PROF_START(idx); - if (useERT) aux.idx = bwa_ertidx_load_from_shm(argv[optind]); - else aux.idx = bwa_fmtidx_load_from_shm(argv[optind]); + aux.idx = bwa_fmtidx_load_from_shm(argv[optind]); if (aux.idx == 0) { - if (!useERT) { - if ((aux.idx = bwa_idx_load(argv[optind], BWA_IDX_BNS | BWA_IDX_PAC | BWA_IDX_FMT)) == 0) return 1; // FIXME: memory leak - } - else { - if ((aux.idx = bwa_ertidx_load_from_disk(argv[optind])) == 0) return 1; // FIXME: memory leak - } - + if ((aux.idx = bwa_idx_load(argv[optind], BWA_IDX_BNS | BWA_IDX_PAC | BWA_IDX_FMT)) == 0) return 1; // FIXME: memory leak } else if (bwa_verbose >= 3) fprintf(stderr, "[M::%s] load the bwa index from shared memory\n", __func__); if (ignore_alt)