diff --git a/bwape.c b/bwape.c index e2c4c96..779670f 100644 --- a/bwape.c +++ b/bwape.c @@ -766,8 +766,11 @@ int bwa_sai2sam_pe(int argc, char *argv[]) { extern char *bwa_rg_line, *bwa_rg_id; extern int bwa_set_rg(const char *s); + extern char *bwa_infer_prefix(const char *hint); int c; pe_opt_t *popt; + char *prefix; + popt = bwa_init_pe_opt(); while ((c = getopt(argc, argv, "a:o:sPn:N:c:f:Ar:")) >= 0) { switch (c) { @@ -809,8 +812,13 @@ int bwa_sai2sam_pe(int argc, char *argv[]) fprintf(stderr, "\n"); return 1; } - bwa_sai2sam_pe_core(argv[optind], argv + optind + 1, argv + optind+3, popt); - free(bwa_rg_line); free(bwa_rg_id); + if ((prefix = bwa_infer_prefix(argv[optind])) == 0) { + fprintf(stderr, "[%s] fail to locate the index\n", __func__); + free(bwa_rg_line); free(bwa_rg_id); + return 0; + } + bwa_sai2sam_pe_core(prefix, argv + optind + 1, argv + optind+3, popt); + free(bwa_rg_line); free(bwa_rg_id); free(prefix); free(popt); return 0; } diff --git a/bwase.c b/bwase.c index f05fff9..e2754cd 100644 --- a/bwase.c +++ b/bwase.c @@ -650,7 +650,9 @@ void bwa_sai2sam_se_core(const char *prefix, const char *fn_sa, const char *fn_f int bwa_sai2sam_se(int argc, char *argv[]) { + extern char *bwa_infer_prefix(const char *hint); int c, n_occ = 3; + char *prefix; while ((c = getopt(argc, argv, "hn:f:r:")) >= 0) { switch (c) { case 'h': break; @@ -670,7 +672,12 @@ int bwa_sai2sam_se(int argc, char *argv[]) fprintf(stderr, "Usage: bwa samse [-n max_occ] [-f out.sam] [-r RG_line] \n"); return 1; } - bwa_sai2sam_se_core(argv[optind], argv[optind+1], argv[optind+2], n_occ); + if ((prefix = bwa_infer_prefix(argv[optind])) == 0) { + fprintf(stderr, "[%s] fail to locate the index\n", __func__); + free(bwa_rg_line); free(bwa_rg_id); + return 0; + } + bwa_sai2sam_se_core(prefix, argv[optind+1], argv[optind+2], n_occ); free(bwa_rg_line); free(bwa_rg_id); return 0; } diff --git a/bwtaln.c b/bwtaln.c index 18fa636..9db63c8 100644 --- a/bwtaln.c +++ b/bwtaln.c @@ -219,10 +219,35 @@ void bwa_aln_core(const char *prefix, const char *fn_fa, const gap_opt_t *opt) bwa_seq_close(ks); } +char *bwa_infer_prefix(const char *hint) +{ + char *prefix; + int l_hint; + FILE *fp; + l_hint = strlen(hint); + prefix = malloc(l_hint + 3 + 4 + 1); + strcpy(prefix, hint); + strcpy(prefix + l_hint, ".bwt"); + if ((fp = fopen(prefix, "rb")) != 0) { + prefix[l_hint] = 0; + return prefix; + } else { + strcpy(prefix + l_hint, ".64.bwt"); + if ((fp = fopen(prefix, "rb")) == 0) { + free(prefix); + return 0; + } else { + prefix[l_hint + 3] = 0; + return prefix; + } + } +} + int bwa_aln(int argc, char *argv[]) { int c, opte = -1; gap_opt_t *opt; + char *prefix; opt = gap_init_opt(); while ((c = getopt(argc, argv, "n:o:e:i:d:l:k:cLR:m:t:NM:O:E:q:f:b012IYB:")) >= 0) { @@ -303,8 +328,13 @@ int bwa_aln(int argc, char *argv[]) k = l; } } - bwa_aln_core(argv[optind], argv[optind+1], opt); - free(opt); + if ((prefix = bwa_infer_prefix(argv[optind])) == 0) { + fprintf(stderr, "[%s] fail to locate the index\n", __func__); + free(opt); + return 0; + } + bwa_aln_core(prefix, argv[optind+1], opt); + free(opt); free(prefix); return 0; } diff --git a/bwtindex.c b/bwtindex.c index a7b126e..eef3def 100644 --- a/bwtindex.c +++ b/bwtindex.c @@ -72,7 +72,11 @@ int bwa_index(int argc, char *argv[]) fprintf(stderr, " according to the length of the genome.\n\n"); return 1; } - if (prefix == 0) prefix = strdup(argv[optind]); + if (prefix == 0) { + prefix = malloc(strlen(argv[optind]) + 4); + strcpy(prefix, argv[optind]); + strcat(prefix, ".64"); + } str = (char*)calloc(strlen(prefix) + 10, 1); str2 = (char*)calloc(strlen(prefix) + 10, 1); str3 = (char*)calloc(strlen(prefix) + 10, 1); diff --git a/bwtsw2_main.c b/bwtsw2_main.c index ff5595a..dbd5d8d 100644 --- a/bwtsw2_main.c +++ b/bwtsw2_main.c @@ -9,9 +9,10 @@ int bwa_bwtsw2(int argc, char *argv[]) { + extern char *bwa_infer_prefix(const char *hint); bsw2opt_t *opt; bwt_t *target; - char buf[1024]; + char buf[1024], *prefix; bntseq_t *bns; int c; @@ -72,9 +73,13 @@ int bwa_bwtsw2(int argc, char *argv[]) opt->t *= opt->a; opt->coef *= opt->a; - strcpy(buf, argv[optind]); target = bwt_restore_bwt(strcat(buf, ".bwt")); - strcpy(buf, argv[optind]); bwt_restore_sa(strcat(buf, ".sa"), target); - bns = bns_restore(argv[optind]); + if ((prefix = bwa_infer_prefix(argv[optind])) == 0) { + fprintf(stderr, "[%s] fail to locate the index\n", __func__); + return 0; + } + strcpy(buf, prefix); target = bwt_restore_bwt(strcat(buf, ".bwt")); + strcpy(buf, prefix); bwt_restore_sa(strcat(buf, ".sa"), target); + bns = bns_restore(prefix); bsw2_aln(opt, bns, target, argv[optind+1], optind+2 < argc? argv[optind+2] : 0); diff --git a/main.c b/main.c index 7606a29..e4eaf66 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ #include "utils.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.6.1-r104" +#define PACKAGE_VERSION "0.6.1-r106-master" #endif static int usage()