annotate pyPRADA_1.2/tools/bwa-0.5.7-mh/bwtsw2_main.c @ 3:f17965495ec9 draft default tip

Uploaded
author siyuan
date Tue, 11 Mar 2014 12:14:01 -0400
parents acc2ca1a3ba4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
1 #include <unistd.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
2 #include <stdlib.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
3 #include <string.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
4 #include <stdio.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
5 #include <math.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
6 #include "bwt.h"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
7 #include "bwtsw2.h"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
8
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
9 int bwa_bwtsw2(int argc, char *argv[])
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
10 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
11 bsw2opt_t *opt;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
12 bwt_t *target[2];
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
13 char buf[1024];
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
14 bntseq_t *bns;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
15 int c;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
16
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
17 opt = bsw2_init_opt();
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
18 srand48(11);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
19 while ((c = getopt(argc, argv, "q:r:a:b:t:T:w:d:z:m:y:s:c:N:H:f:")) >= 0) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
20 switch (c) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
21 case 'q': opt->q = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
22 case 'r': opt->r = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
23 case 'a': opt->a = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
24 case 'b': opt->b = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
25 case 'w': opt->bw = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
26 case 'T': opt->t = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
27 case 't': opt->n_threads = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
28 case 'z': opt->z = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
29 case 'y': opt->yita = atof(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
30 case 's': opt->is = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
31 case 'm': opt->mask_level = atof(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
32 case 'c': opt->coef = atof(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
33 case 'N': opt->t_seeds = atoi(optarg); break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
34 case 'H': opt->hard_clip = 1; break;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
35 case 'f': freopen(optarg, "w", stdout);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
36 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
37 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
38 opt->qr = opt->q + opt->r;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
39
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
40 if (optind + 2 > argc) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
41 fprintf(stderr, "\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
42 fprintf(stderr, "Usage: bwa bwasw [options] <target.prefix> <query.fa>\n\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
43 fprintf(stderr, "Options: -a INT score for a match [%d]\n", opt->a);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
44 fprintf(stderr, " -b INT mismatch penalty [%d]\n", opt->b);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
45 fprintf(stderr, " -q INT gap open penalty [%d]\n", opt->q);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
46 fprintf(stderr, " -r INT gap extension penalty [%d]\n", opt->r);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
47 // fprintf(stderr, " -y FLOAT error recurrence coef. (4..16) [%.1f]\n", opt->yita);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
48 fprintf(stderr, "\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
49 fprintf(stderr, " -t INT nmber of threads [%d]\n", opt->n_threads);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
50 fprintf(stderr, " -s INT size of a chunk of reads [%d]\n", opt->chunk_size);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
51 fprintf(stderr, "\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
52 fprintf(stderr, " -w INT band width [%d]\n", opt->bw);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
53 fprintf(stderr, " -m FLOAT mask level [%.2f]\n", opt->mask_level);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
54 fprintf(stderr, "\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
55 fprintf(stderr, " -T INT score threshold divided by a [%d]\n", opt->t);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
56 fprintf(stderr, " -s INT maximum seeding interval size [%d]\n", opt->is);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
57 fprintf(stderr, " -z INT Z-best [%d]\n", opt->z);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
58 fprintf(stderr, " -N INT # seeds to trigger reverse alignment [%d]\n", opt->t_seeds);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
59 fprintf(stderr, " -c FLOAT coefficient of length-threshold adjustment [%.1f]\n", opt->coef);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
60 fprintf(stderr, " -H in SAM output, use hard clipping rather than soft\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
61 fprintf(stderr, " -f FILE file to output results to instead of stdout\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
62 fprintf(stderr, "\n");
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
63
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
64 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
65 double c, theta, eps, delta;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
66 c = opt->a / log(opt->yita);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
67 theta = exp(-opt->b / c) / opt->yita;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
68 eps = exp(-opt->q / c);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
69 delta = exp(-opt->r / c);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
70 fprintf(stderr, "mismatch: %lf, gap_open: %lf, gap_ext: %lf\n\n",
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
71 theta, eps, delta);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
72 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
73 return 1;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
74 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
75
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
76 // adjust opt for opt->a
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
77 opt->t *= opt->a;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
78 opt->coef *= opt->a;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
79
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
80 strcpy(buf, argv[optind]); target[0] = bwt_restore_bwt(strcat(buf, ".bwt"));
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
81 strcpy(buf, argv[optind]); bwt_restore_sa(strcat(buf, ".sa"), target[0]);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
82 strcpy(buf, argv[optind]); target[1] = bwt_restore_bwt(strcat(buf, ".rbwt"));
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
83 strcpy(buf, argv[optind]); bwt_restore_sa(strcat(buf, ".rsa"), target[1]);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
84 bns = bns_restore(argv[optind]);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
85
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
86 bsw2_aln(opt, bns, target, argv[optind+1]);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
87
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
88 bns_destroy(bns);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
89 bwt_destroy(target[0]); bwt_destroy(target[1]);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
90 free(opt);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
91
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
92 return 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
93 }