Skip to content

Commit 292f906

Browse files
committed
r132: optionally copy FASTA/Q comment to SAM
1 parent 3abfd07 commit 292f906

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

bwtsw2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define BSW2_FLAG_RESCUED 0x800
1313

1414
typedef struct {
15-
int skip_sw:16, hard_clip:16;
15+
int skip_sw:8, cpy_cmt:8, hard_clip:16;
1616
int a, b, q, r, t, qr, bw, max_ins, max_chain_gap;
1717
int z, is, t_seeds, multi_2nd;
1818
float mask_level, coef;
@@ -45,7 +45,7 @@ typedef struct {
4545

4646
typedef struct {
4747
int l, tid;
48-
char *name, *seq, *qual, *sam;
48+
char *name, *seq, *qual, *sam, *comment;
4949
} bsw2seq1_t;
5050

5151
#ifdef __cplusplus

bwtsw2_aux.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ bsw2opt_t *bsw2_init_opt()
5555
o->mask_level = 0.50f; o->coef = 5.5f;
5656
o->qr = o->q + o->r; o->n_threads = 1; o->chunk_size = 10000000;
5757
o->max_chain_gap = 10000;
58+
o->cpy_cmt = 0;
5859
return o;
5960
}
6061

@@ -551,14 +552,20 @@ static void print_hits(const bntseq_t *bns, const bsw2opt_t *opt, bsw2seq1_t *ks
551552
if (p->flag&0x10) kputc(ks->qual[ks->l - 1 - j], &str);
552553
else kputc(ks->qual[j], &str);
553554
}
554-
} else ksprintf(&str, "\t*");
555+
} else kputs("\t*", &str);
555556
// print optional tags
556557
ksprintf(&str, "\tAS:i:%d\tXS:i:%d\tXF:i:%d\tXE:i:%d\tNM:i:%d", p->G, p->G2, p->flag>>16, p->n_seeds, q->nm);
557558
if (q->nn) ksprintf(&str, "\tXN:i:%d", q->nn);
558559
if (p->l) ksprintf(&str, "\tXI:i:%d", p->l - p->k + 1);
559560
if (p->flag&BSW2_FLAG_MATESW) type |= 1;
560561
if (p->flag&BSW2_FLAG_TANDEM) type |= 2;
561562
if (type) ksprintf(&str, "\tXT:i:%d", type);
563+
if (opt->cpy_cmt && ks->comment) {
564+
int l = strlen(ks->comment);
565+
if (l >= 6 && ks->comment[2] == ':' && ks->comment[4] == ':') {
566+
kputc('\t', &str); kputs(ks->comment, &str);
567+
}
568+
}
562569
kputc('\n', &str);
563570
}
564571
ks->sam = str.s;
@@ -756,6 +763,7 @@ static void kseq_to_bsw2seq(const kseq_t *ks, bsw2seq1_t *p)
756763
p->name = strdup(ks->name.s);
757764
p->seq = strdup(ks->seq.s);
758765
p->qual = ks->qual.l? strdup(ks->qual.s) : 0;
766+
p->comment = ks->comment.l? strdup(ks->comment.s) : 0;
759767
p->sam = 0;
760768
}
761769

bwtsw2_main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int bwa_bwtsw2(int argc, char *argv[])
1818

1919
opt = bsw2_init_opt();
2020
srand48(11);
21-
while ((c = getopt(argc, argv, "q:r:a:b:t:T:w:d:z:m:s:c:N:Hf:MI:SG:")) >= 0) {
21+
while ((c = getopt(argc, argv, "q:r:a:b:t:T:w:d:z:m:s:c:N:Hf:MI:SG:C")) >= 0) {
2222
switch (c) {
2323
case 'q': opt->q = atoi(optarg); break;
2424
case 'r': opt->r = atoi(optarg); break;
@@ -37,6 +37,7 @@ int bwa_bwtsw2(int argc, char *argv[])
3737
case 'f': xreopen(optarg, "w", stdout); break;
3838
case 'I': opt->max_ins = atoi(optarg); break;
3939
case 'S': opt->skip_sw = 1; break;
40+
case 'C': opt->cpy_cmt = 1; break;
4041
case 'G': opt->max_chain_gap = atoi(optarg); break;
4142
}
4243
}
@@ -55,6 +56,7 @@ int bwa_bwtsw2(int argc, char *argv[])
5556
fprintf(stderr, " -t INT number of threads [%d]\n", opt->n_threads);
5657
fprintf(stderr, " -f FILE file to output results to instead of stdout\n");
5758
fprintf(stderr, " -H in SAM output, use hard clipping instead of soft clipping\n");
59+
fprintf(stderr, " -C copy FASTA/Q comment to SAM output\n");
5860
fprintf(stderr, " -M mark multi-part alignments as secondary\n");
5961
fprintf(stderr, " -S skip Smith-Waterman read pairing\n");
6062
fprintf(stderr, " -I INT ignore pairs with insert >=INT for inferring the size distr [%d]\n", opt->max_ins);

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "utils.h"
55

66
#ifndef PACKAGE_VERSION
7-
#define PACKAGE_VERSION "0.6.2-r131"
7+
#define PACKAGE_VERSION "0.6.2-r132"
88
#endif
99

1010
static int usage()

0 commit comments

Comments
 (0)