Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: HD line should be printed before SQ #345

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions bwa.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,14 @@ void bwa_print_sam_hdr(const bntseq_t *bns, const char *hdr_line)
if (p == hdr_line || *(p-1) == '\n') ++n_SQ;
p += 4;
}
// print the header line if @HD is in hdr_line
if (n_HD > 0) err_printf("%s\n", hdr_line);
}
// print a default header line if no @HD has been printed
if (n_HD == 0) {
err_printf("@HD\tVN:1.5\tSO:unsorted\tGO:query\n");
}
Comment on lines +428 to +430
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be a one-liner in the style of this repo

Suggested change
if (n_HD == 0) {
err_printf("@HD\tVN:1.5\tSO:unsorted\tGO:query\n");
}
if (n_HD == 0) err_printf("@HD\tVN:1.5\tSO:unsorted\tGO:query\n");

// print the @SQ lines right after the @HD line
if (n_SQ == 0) {
for (i = 0; i < bns->n_seqs; ++i) {
err_printf("@SQ\tSN:%s\tLN:%d", bns->anns[i].name, bns->anns[i].len);
Expand All @@ -430,10 +437,8 @@ void bwa_print_sam_hdr(const bntseq_t *bns, const char *hdr_line)
}
} else if (n_SQ != bns->n_seqs && bwa_verbose >= 2)
fprintf(stderr, "[W::%s] %d @SQ lines provided with -H; %d sequences in the index. Continue anyway.\n", __func__, n_SQ, bns->n_seqs);
if (n_HD == 0) {
err_printf("@HD\tVN:1.5\tSO:unsorted\tGO:query\n");
}
if (hdr_line) err_printf("%s\n", hdr_line);
// print the header line if header line is defined and is not a @HD (e.g. @CO); do this after the @SQ lines.
if (hdr_line && n_HD == 0) err_printf("%s\n", hdr_line);
if (bwa_pg) err_printf("%s\n", bwa_pg);
}

Expand Down