From 8b05880f73c76ccc00d2d1aa62eb3c999ca1c130 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Tue, 29 Jan 2019 10:42:20 -0500 Subject: [PATCH] r911: option -o to output to file (#319) --- main.c | 14 +++++++++++--- minimap2.1 | 7 ++++++- splitidx.c | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 1421959..69c45b8 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ #include "mmpriv.h" #include "ketopt.h" -#define MM_VERSION "2.15-r910-dirty" +#define MM_VERSION "2.15-r911-dirty" #ifdef __linux__ #include @@ -99,7 +99,7 @@ static inline void yes_or_no(mm_mapopt_t *opt, int flag, int long_idx, const cha int main(int argc, char *argv[]) { - const char *opt_str = "2aSDw:k:K:t:r:f:Vv:g:G:I:d:XT:s:x:Hcp:M:n:z:A:B:O:E:m:N:Qu:R:hF:LC:yYP"; + const char *opt_str = "2aSDw:k:K:t:r:f:Vv:g:G:I:d:XT:s:x:Hcp:M:n:z:A:B:O:E:m:N:Qu:R:hF:LC:yYPo:"; ketopt_t o = KETOPT_INIT; mm_mapopt_t opt; mm_idxopt_t ipt; @@ -165,6 +165,14 @@ int main(int argc, char *argv[]) else if (c == 'R') rg = o.arg; else if (c == 'h') fp_help = stdout; else if (c == '2') opt.flag |= MM_F_2_IO_THREADS; + else if (c == 'o') { + if (strcmp(o.arg, "-") != 0) { + if (freopen(o.arg, "wb", stdout) == NULL) { + fprintf(stderr, "[ERROR]\033[1;31m failed to write the output to file '%s'\033[0m\n", o.arg); + exit(1); + } + } + } else if (c == 300) ipt.bucket_bits = atoi(o.arg); // --bucket-bits else if (c == 302) opt.seed = atoi(o.arg); // --seed else if (c == 303) mm_dbg_flag |= MM_DBG_NO_KALLOC; // --no-kalloc @@ -293,7 +301,7 @@ int main(int argc, char *argv[]) fprintf(fp_help, " -u CHAR how to find GT-AG. f:transcript strand, b:both strands, n:don't match GT-AG [n]\n"); fprintf(fp_help, " Input/Output:\n"); fprintf(fp_help, " -a output in the SAM format (PAF by default)\n"); - fprintf(fp_help, " -Q don't output base quality in SAM\n"); + fprintf(fp_help, " -o FILE output alignments to FILE [stdout]\n"); fprintf(fp_help, " -L write CIGAR with >65535 ops at the CG tag\n"); fprintf(fp_help, " -R STR SAM read group line in a format like '@RG\\tID:foo\\tSM:bar' []\n"); fprintf(fp_help, " -c output CIGAR in PAF\n"); diff --git a/minimap2.1 b/minimap2.1 index ffb8158..45ff89c 100644 --- a/minimap2.1 +++ b/minimap2.1 @@ -1,4 +1,4 @@ -.TH minimap2 1 "10 January 2019" "minimap2-2.15 (r905)" "Bioinformatics tools" +.TH minimap2 1 "10 January 2019" "minimap2-2.15-dirty (r911)" "Bioinformatics tools" .SH NAME .PP minimap2 - mapping and alignment between collections of DNA sequences @@ -384,6 +384,11 @@ Set 0 to disable [0]. Generate CIGAR and output alignments in the SAM format. Minimap2 outputs in PAF by default. .TP +.BI -o \ FILE +Output alignments to +.I FILE +[stdout]. +.TP .B -Q Ignore base quality in the input file. .TP diff --git a/splitidx.c b/splitidx.c index 478a76e..1054a64 100644 --- a/splitidx.c +++ b/splitidx.c @@ -13,7 +13,7 @@ FILE *mm_split_init(const char *prefix, const mm_idx_t *mi) sprintf(fn, "%s.%.4d.tmp", prefix, mi->index); if ((fp = fopen(fn, "wb")) == NULL) { if (mm_verbose >= 1) - fprintf(stderr, "[E::%s] failed to create file '%s'\n", __func__, fn); + fprintf(stderr, "[ERROR]\033[1;31m failed to write to temporary file '%s'\033[0m\n", fn); exit(1); } mm_err_fwrite(&k, 4, 1, fp);