Permalink
Browse files

included prettyprint editstring in sam extra flags

  • Loading branch information...
mateidavid committed Mar 6, 2012
1 parent 63dae17 commit 8387416ec1a0113792ccf8ba6352898b3a01a778
Showing with 58 additions and 5 deletions.
  1. +3 −3 common/output.c
  2. +1 −0 common/output.h
  3. +54 −2 gmapper/output.c
View
@@ -57,8 +57,8 @@ readtostr(const uint32_t *read, u_int len, bool use_colours, int initbp)
* Two sequencing errors: 4x15x6 (25 total matches)
* etc.
*/
-static char *
-editstr(const char *dbalign, const char *qralign)
+char *
+alignment_edit_string(const char *dbalign, const char *qralign)
{
strbuf_t sb;
char *str;
@@ -328,7 +328,7 @@ output_normal(const char *readname, const char *contigname,
strbuf_append(sb, ">%s\t%s\t%c", readname, contigname,
(revcmpl) ? '-' : '+');
- edit = editstr(dbalign, qralign);
+ edit = alignment_edit_string(dbalign, qralign);
/*
ret = editstr_to_sfr(edit, &sfr_tmp);
assert(ret &&
View
@@ -6,3 +6,4 @@ char *output_pretty(const char *, const char *, const struct
sw_full_results *, uint32_t *, uint32_t, bool, uint32_t *, u_int,int, bool);
char *output_normal(const char *, const char *, const struct
sw_full_results *, uint32_t, bool, uint32_t *, u_int, int, bool, bool);
+char *alignment_edit_string(char const *, char const *);
View
@@ -80,6 +80,48 @@ reverse_cigar(cigar_t * cigar)
}
+static char *
+reverse_alignment_edit_string(char * editstr)
+{
+ int n = strlen(editstr);
+ char * res = (char *)malloc((n + 1) * sizeof(char));
+ int i = 0;
+ while (i < n) {
+ if (isdigit(editstr[n - 1 - i])) {
+ int j = i + 1;
+ while (j < n && isdigit(editstr[n - 1 - j])) j++;
+ j--;
+ memcpy(&res[i], &editstr[n - 1 - j], (j - i + 1) * sizeof(char));
+ i = j + 1;
+ } else if (editstr[n - 1 - i] == '-' || editstr[n - 1 - i] == 'x') {
+ res[i] = editstr[n - 1 - i];
+ i++;
+ } else if (editstr[n - 1 - i] == ')') {
+ res[i] = '(';
+ i++;
+ } else if (editstr[n - 1 - i] == '(') {
+ res[i] = ')';
+ i++;
+ } else if (editstr[n - 1 - i] == 'A') {
+ res[i] = 'T';
+ i++;
+ } else if (editstr[n - 1 - i] == 'C') {
+ res[i] = 'G';
+ i++;
+ } else if (editstr[n - 1 - i] == 'G') {
+ res[i] = 'C';
+ i++;
+ } else if (editstr[n - 1 - i] == 'T') {
+ res[i] = 'A';
+ i++;
+ } else
+ assert(0);
+ }
+ res[n] = 0;
+ return res;
+}
+
+
static char *
make_cigar_string(cigar_t * cigar)
{
@@ -699,8 +741,18 @@ hit_output(struct read_entry * re, struct read_hit * rh, struct read_hit * rh_mp
*output_buffer+=snprintf(*output_buffer,output_buffer_end-*output_buffer,"\tRG:Z:%s",sam_read_group_name);
}
if (extra_sam_fields) {
- *output_buffer += snprintf(*output_buffer, output_buffer_end - *output_buffer, "\tZM:i:%d\tZR:i:%d\tZV:i:%d\tZH:i:%d",
- rh->matches, rh->score_window_gen, rh->score_vector, rh->sfrp->score);
+ char * editstr = alignment_edit_string(rh->sfrp->dbalign, rh->sfrp->qralign);
+ if (reverse_strand) {
+ char * tmp = reverse_alignment_edit_string(editstr);
+ free(editstr);
+ editstr = tmp;
+ }
+ *output_buffer += snprintf(*output_buffer, output_buffer_end - *output_buffer,
+ "\tZM:i:%d\tZR:i:%d\tZV:i:%d\tZH:i:%d\tZE:Z:%s",
+ rh->matches, rh->score_window_gen,
+ rh->score_vector, rh->sfrp->score,
+ editstr);
+ free(editstr);
}
if (cigar_binary!=NULL) {
free_cigar(cigar_binary);

0 comments on commit 8387416

Please sign in to comment.