KSORT_INIT(heap, heap1_t, heap_lt)
+/*!
+ @abstract Merge multiple sorted BAM.
+ @param is_by_qname whether to sort by query name
+ @param out output BAM file name
+ @param n number of files to be merged
+ @param fn names of files to be merged
+
+ @discussion Padding information may NOT correctly maintained. This
+ function is NOT thread safe.
+ */
void bam_merge_core(int by_qname, const char *out, int n, char * const *fn)
{
bamFile fpout, *fp;
else { // validate multiple baf
if (hout->n_targets != hin->n_targets) {
fprintf(stderr, "[bam_merge_core] file '%s' has different number of target sequences. Abort!\n", fn[i]);
- abort();
+ exit(1);
}
for (j = 0; j < hout->n_targets; ++j) {
- if (strcmp(hout->target_name[j], hin->target_name[j]) || hout->target_len[j] != hin->target_len[j]) {
- fprintf(stderr, "[bam_merge_core] file '%s' has a different target sequence. Abort!\n", fn[i]);
- abort();
+ if (strcmp(hout->target_name[j], hin->target_name[j])) {
+ fprintf(stderr, "[bam_merge_core] different target sequence name: '%s' != '%s' in file '%s'. Abort!\n",
+ hout->target_name[j], hin->target_name[j], fn[i]);
+ exit(1);
}
+ if (hout->target_len[j] != hin->target_len[j])
+ fprintf(stderr, "[bam_merge_core] different target sequence length: %d != %d in file '%s'. Continue.\n",
+ hout->target_len[j], hin->target_len[j], fn[i]);
}
bam_header_destroy(hin);
}
bam_close(fp);
}
+/*!
+ @abstract Sort an unsorted BAM file based on the chromosome order
+ and the leftmost position of an alignment
+
+ @param is_by_qname whether to sort by query name
+ @param fn name of the file to be sorted
+ @param prefix prefix of the output and the temporary files; upon
+ sucessess, prefix.bam will be written.
+ @param max_mem approxiate maximum memory (very inaccurate)
+
+ @discussion It may create multiple temporary subalignment files
+ and then merge them by calling bam_merge_core(). This function is
+ NOT thread safe.
+ */
void bam_sort_core(int is_by_qname, const char *fn, const char *prefix, size_t max_mem)
{
int n, ret, k, i;