int bam_sort_core(int is_by_qname, const char *fn, const char *prefix, size_t max_mem) { int ret; char *fnout = calloc(strlen(prefix) + 4 + 1, 1); sprintf(fnout, "%s.bam", prefix); ret = bam_sort_core_ext(is_by_qname, fn, prefix, fnout, "wb", max_mem, 0); free(fnout); return ret; }
int bam_sort(int argc, char *argv[]) { size_t max_mem = 500000000; int c, is_by_qname = 0, is_stdout = 0; while ((c = getopt(argc, argv, "nom:")) >= 0) { switch (c) { case 'o': is_stdout = 1; break; case 'n': is_by_qname = 1; break; case 'm': max_mem = atol(optarg); break; } } if (optind + 2 > argc) { fprintf(stderr, "Usage: samtools sort [-on] [-m <maxMem>] <in.bam> <out.prefix>\n"); return 1; } bam_sort_core_ext(is_by_qname, argv[optind], argv[optind+1], max_mem, is_stdout); return 0; }
int bam_sort(int argc, char *argv[]) { size_t max_mem = 768<<20; // 512MB int c, is_by_qname = 0, is_stdout = 0, n_threads = 0, level = -1, sort_type = 0; while ((c = getopt(argc, argv, "nom:@:l:s:")) >= 0) { switch (c) { case 'o': is_stdout = 1; break; case 'n': is_by_qname = 1; break; case 'm': { char *q; max_mem = strtol(optarg, &q, 0); if (*q == 'k' || *q == 'K') max_mem <<= 10; else if (*q == 'm' || *q == 'M') max_mem <<= 20; else if (*q == 'g' || *q == 'G') max_mem <<= 30; break; } case '@': n_threads = atoi(optarg); break; case 'l': level = atoi(optarg); break; case 's': sort_type = atoi(optarg); break; } } if (optind + 2 > argc) { fprintf(stderr, "\n"); fprintf(stderr, "Usage: samtools sort [options] <in.bam> <out.prefix>\n\n"); fprintf(stderr, "Options: -n sort by read name\n"); fprintf(stderr, " -o final output to stdout\n"); fprintf(stderr, " -l INT compression level, from 0 to 9 [-1]\n"); fprintf(stderr, " -s sorting algorithm type [0]\n"); fprintf(stderr, " 0: mergesort\n"); fprintf(stderr, " 1: introsort\n"); fprintf(stderr, " 2: combsort\n"); fprintf(stderr, " 3: heapsort\n"); #ifndef _PBGZF_USE fprintf(stderr, " -@ INT number of sorting and compression threads [1]\n"); #else fprintf(stderr, " -@ INT number of sorting threads [1]\n"); #endif fprintf(stderr, " -m INT max memory per thread; suffix K/M/G recognized [768M]\n"); fprintf(stderr, "\n"); return 1; } bam_sort_core_ext(is_by_qname, argv[optind], argv[optind+1], max_mem, is_stdout, n_threads, level, sort_type); return 0; }
int bam_sort(int argc, char *argv[]) { size_t max_mem = 768<<20; // 512MB int c, is_by_qname = 0, is_stdout = 0, n_threads = 0, level = -1, full_path = 0; while ((c = getopt(argc, argv, "fnom:@:l:")) >= 0) { switch (c) { case 'f': full_path = 1; break; case 'o': is_stdout = 1; break; case 'n': is_by_qname = 1; break; case 'm': { char *q; max_mem = strtol(optarg, &q, 0); if (*q == 'k' || *q == 'K') max_mem <<= 10; else if (*q == 'm' || *q == 'M') max_mem <<= 20; else if (*q == 'g' || *q == 'G') max_mem <<= 30; break; } case '@': n_threads = atoi(optarg); break; case 'l': level = atoi(optarg); break; } } if (optind + 2 > argc) { fprintf(stderr, "\n"); fprintf(stderr, "Usage: samtools sort [options] <in.bam> <out.prefix>\n\n"); fprintf(stderr, "Options: -n sort by read name\n"); fprintf(stderr, " -f use <out.prefix> as full file name instead of prefix\n"); fprintf(stderr, " -o final output to stdout\n"); fprintf(stderr, " -l INT compression level, from 0 to 9 [-1]\n"); fprintf(stderr, " -@ INT number of sorting and compression threads [1]\n"); fprintf(stderr, " -m INT max memory per thread; suffix K/M/G recognized [768M]\n"); fprintf(stderr, "\n"); return 1; } bam_sort_core_ext(is_by_qname, argv[optind], argv[optind+1], max_mem, is_stdout, n_threads, level, full_path); return 0; }
void bam_sort_core(int is_by_qname, const char *fn, const char *prefix, size_t max_mem) { bam_sort_core_ext(is_by_qname, fn, prefix, max_mem, 0, 0, -1, 0); }
int bam_sort(int argc, char *argv[]) { size_t max_mem = 768<<20; // 512MB int c, i, modern, nargs, is_by_qname = 0, is_stdout = 0, ret = EXIT_SUCCESS, n_threads = 0, level = -1, full_path = 0; char *fnout = "-", *fmtout = NULL, modeout[12], *tmpprefix = NULL; kstring_t fnout_buffer = { 0, 0, NULL }; modern = 0; for (i = 1; i < argc; ++i) if (argv[i][0] == '-' && strpbrk(argv[i], "OT")) { modern = 1; break; } while ((c = getopt(argc, argv, modern? "l:m:no:O:T:@:" : "fnom:@:l:")) >= 0) { switch (c) { case 'f': full_path = 1; break; case 'o': if (modern) fnout = optarg; else is_stdout = 1; break; case 'n': is_by_qname = 1; break; case 'm': { char *q; max_mem = strtol(optarg, &q, 0); if (*q == 'k' || *q == 'K') max_mem <<= 10; else if (*q == 'm' || *q == 'M') max_mem <<= 20; else if (*q == 'g' || *q == 'G') max_mem <<= 30; break; } case 'O': fmtout = optarg; break; case 'T': tmpprefix = optarg; break; case '@': n_threads = atoi(optarg); break; case 'l': level = atoi(optarg); break; default: return sort_usage(pysamerr, EXIT_FAILURE); } } nargs = argc - optind; if (argc == 1) return sort_usage(stdout, EXIT_SUCCESS); else if (modern? (nargs > 1) : (nargs != 2)) return sort_usage(pysamerr, EXIT_FAILURE); if (!modern) { fmtout = "bam"; if (is_stdout) fnout = "-"; else if (full_path) fnout = argv[optind+1]; else { ksprintf(&fnout_buffer, "%s.%s", argv[optind+1], fmtout); fnout = fnout_buffer.s; } tmpprefix = argv[optind+1]; } strcpy(modeout, "w"); if (sam_open_mode(&modeout[1], fnout, fmtout) < 0) { if (fmtout) fprintf(pysamerr, "[bam_sort] can't parse output format \"%s\"\n", fmtout); else fprintf(pysamerr, "[bam_sort] can't determine output format\n"); ret = EXIT_FAILURE; goto sort_end; } if (level >= 0) sprintf(strchr(modeout, '\0'), "%d", level < 9? level : 9); if (tmpprefix == NULL) { fprintf(pysamerr, "[bam_sort] no prefix specified for temporary files (use -T option)\n"); ret = EXIT_FAILURE; goto sort_end; } if (bam_sort_core_ext(is_by_qname, (nargs > 0)? argv[optind] : "-", tmpprefix, fnout, modeout, max_mem, n_threads) < 0) ret = EXIT_FAILURE; sort_end: free(fnout_buffer.s); return ret; }