Tim's suggestion suffix file name with .64

This commit is contained in:
Heng Li 2012-03-29 12:22:51 -04:00
parent a471f1918b
commit bdc953cad9
6 changed files with 65 additions and 11 deletions

12
bwape.c
View File

@ -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;
}

View File

@ -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] <prefix> <in.sai> <in.fq>\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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

2
main.c
View File

@ -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()