When using samtools merge with multiple bam files (-b bamfilelist.txt) and
with selecting a specific region with e.g. -R chr1:1-1000,
I noticed that if one of the files (fileX.bam) is missing any reads within the region,
samtools merge will fail with the message:
[bam_merge_core2] failed to read first record from fileX.bam
I think I corrected this behavior by
replacing lines 1338-1339 in bam_sort.c :
print_error(cmd, "failed to read first record from \"%s\"", fn[i]);
goto fail;
with:
print_error(cmd, "failed to read first record from \"%s\", skipping file during merge", fn[i]);
h->pos = HEAP_EMPTY;
bam_destroy1(h->b);
h->b = NULL;
This appears to fix the problem, so that the new behavior is that
fileX.bam is skipped, and the rest of the merge proceeds with the rest of the files.
Do you think that this fix is correct and should be the default behavior of samtools merge?
When using samtools merge with multiple bam files (-b bamfilelist.txt) and
with selecting a specific region with e.g. -R chr1:1-1000,
I noticed that if one of the files (fileX.bam) is missing any reads within the region,
samtools merge will fail with the message:
[bam_merge_core2] failed to read first record from fileX.bam
I think I corrected this behavior by
replacing lines 1338-1339 in bam_sort.c :
with:
This appears to fix the problem, so that the new behavior is that
fileX.bam is skipped, and the rest of the merge proceeds with the rest of the files.
Do you think that this fix is correct and should be the default behavior of samtools merge?