Description: Fix exit codes to be successful and output to stdout.
Author: Lance Lin <lq27267@gmail.com>
Last-Update: 2024-01-19

--- stacks.orig/scripts/stacks-gdb
+++ stacks/scripts/stacks-gdb
@@ -28,10 +28,10 @@
 "
 
 if [[ $# -eq 0 ]] ;then
-    echo -n "$usage" >&2
+    echo -n "$usage"
     echo
     echo -n "$gdb_req"
-    exit 1
+    exit 0
 fi
 
 if ! command -v gdb &>/dev/null ;then
--- stacks.orig/scripts/stacks-samtools-tview
+++ stacks/scripts/stacks-samtools-tview
@@ -28,15 +28,15 @@
 sample=
 if (( $# == 0 )) ;then
     echo -n "$help"
-    exit 1
+    exit 0
 fi
 while getopts 'vhP:c:s:' op ;do
     case $op in
     P) dir="$OPTARG" ;;
     c) locus="$OPTARG" ;;
     s) sample="$OPTARG" ;;
-    h) echo -n "$help"; exit 1 ;;
-    v) echo "$stacks_version"; exit 1 ;;
+    h) echo -n "$help"; exit 0 ;;
+    v) echo "$stacks_version"; exit 0 ;;
     *) echo "ERROR: while parsing arguments." >&2; exit 1 ;;
     esac
 done
--- stacks.orig/src/sstacks.cc
+++ stacks/src/sstacks.cc
@@ -1429,13 +1429,13 @@
 }
 
 void version() {
-    cerr << "sstacks " << VERSION << "\n\n";
+    cout << "sstacks " << VERSION << "\n\n";
 
-    exit(1);
+    exit(0);
 }
 
 void help() {
-    cerr << "sstacks " << VERSION << "\n"
+    cout << "sstacks " << VERSION << "\n"
               << "sstacks -P dir -M popmap [-t n_threads]" << "\n"
               << "sstacks -c catalog_path -s sample_path [-s sample_path ...] -o path [-t n_threads]" << "\n"
               << "  -P,--in-path: path to the directory containing Stacks files.\n"
@@ -1451,10 +1451,10 @@
               ;
 
 #ifdef DEBUG
-    cerr << "\n"
+    cout << "\n"
             "Debug options:\n"
             "  --write-all-matches: Write blacklisted matches. (Compatibility with the web interface?)\n";
 #endif
 
-    exit(1);
+    exit(0);
 }
--- stacks.orig/src/process_radtags.cc
+++ stacks/src/process_radtags.cc
@@ -2566,13 +2566,13 @@
 }
 
 void version() {
-    cerr << "process_radtags " << VERSION << "\n\n";
+    cout << "process_radtags " << VERSION << "\n\n";
 
-    exit(1);
+    exit(0);
 }
 
 void help() {
-    cerr << "process_radtags " << VERSION << "\n"
+    cout << "process_radtags " << VERSION << "\n"
 	 << "process_radtags -p in_dir [-P] [-b barcode_file] -o out_dir -e enz [--threads num] [-c] [-q] [-r] [-t len]\n"
          << "process_radtags -f in_file [-b barcode_file] -o out_dir -e enz [--threads num] [-c] [-q] [-r] [-t len]\n"
          << "process_radtags --in-path in_dir [--paired] [--barcodes barcode_file] --out-path out_dir --renz-1 enz [--renz-2 enz] [--threads num] [-c] [-q] [-r] [-t len]\n"
@@ -2613,20 +2613,20 @@
     uint cnt = renz_cnt.size();
     it = renz_cnt.begin();
     for (uint i = 1; i <= cnt; i++) {
-        cerr << "'" << it->first << "'";
+        cout << "'" << it->first << "'";
         if (i < cnt - 1)
-            cerr << ", ";
+            cout << ", ";
         else if (i == cnt - 1)
-            cerr << ", or ";
+            cout << ", or ";
 
         if (i % 8 == 0)
-            cerr << "\n      ";
+            cout << "\n      ";
 
         it++;
     }
-    cerr << "\n";
+    cout << "\n";
 
-    cerr << "\n"
+    cout << "\n"
          << "  Protocol-specific options:\n"
          << "    --bestrad: library was generated using BestRAD, check for restriction enzyme on either read and potentially tranpose reads.\n"
 	 << "    --methylrad: library was generated using enzymatic methyl-seq (EM-seq) or bisulphite sequencing.\n\n"
@@ -2651,5 +2651,5 @@
          << "    --barcode-dist-1: the number of allowed mismatches when rescuing single-end barcodes (default 1).\n"
          << "    --barcode-dist-2: the number of allowed mismatches when rescuing paired-end barcodes (defaults to --barcode-dist-1).\n";
 
-    exit(1);
+    exit(0);
 }
--- stacks.orig/scripts/denovo_map.pl
+++ stacks/scripts/denovo_map.pl
@@ -920,13 +920,13 @@
 }
 
 sub version {
-    print STDERR "denovo_map.pl ", stacks_version, "\n";
+    print STDOUT "denovo_map.pl ", stacks_version, "\n";
 }
 
 sub usage {
     version();
 
-    print STDERR <<EOQ;
+    print STDOUT <<EOQ;
 denovo_map.pl --samples dir --popmap path --out-path dir [--paired [--rm-pcr-duplicates]] (assembly options) (filtering options) [-X prog:"opts" ...]
 
   Input/Output files:
@@ -964,5 +964,5 @@
     --time-components (for benchmarking)
 EOQ
 
-    exit 1;
+    exit 0;
 }
--- stacks.orig/scripts/ref_map.pl
+++ stacks/scripts/ref_map.pl
@@ -416,13 +416,13 @@
 }
 
 sub version {
-    print STDERR "ref_map.pl ", stacks_version, "\n";
+    print STDOUT "ref_map.pl ", stacks_version, "\n";
 }
 
 sub usage {
     version();
 
-    print STDERR <<EOQ;
+    print STDOUT <<EOQ;
 ref_map.pl --samples path --popmap path [-s spacer] --out-path path [--rm-pcr-duplicates] [-X prog:"opts" ...]
 
   Input/Output files:
@@ -456,5 +456,5 @@
   Miscellaneous:
     --time-components (for benchmarking)
 EOQ
-    exit 1;
+    exit 0;
 }
--- stacks.orig/src/clone_filter.cc
+++ stacks/src/clone_filter.cc
@@ -1311,13 +1311,13 @@
 }
 
 void version() {
-    std::cerr << "clone_filter " << VERSION << "\n\n";
+    std::cout << "clone_filter " << VERSION << "\n\n";
 
-    exit(1);
+    exit(0);
 }
 
 void help() {
-    std::cerr << "clone_filter " << VERSION << "\n"
+    std::cout << "clone_filter " << VERSION << "\n"
               << "clone_filter [-f in_file | -p in_dir [-P] [-I] | -1 pair_1 -2 pair_2] -o out_dir [-i type] [-y type] [-D] [-h]\n"
               << "  f: path to the input file if processing single-end sequences.\n"
               << "  p: path to a directory of files.\n"
@@ -1342,5 +1342,5 @@
               << "    --inline-index:  random oligo is inline with sequence on single-end read and second oligo occurs in FASTQ header.\n"
               << "    --index-inline:  random oligo occurs in FASTQ header (Illumina i5 or i7 read) and is inline with sequence on single-end read (if single read data) or paired-end read (if paired data).\n\n";
 
-    exit(1);
+    exit(0);
 }
--- stacks.orig/src/cstacks.cc
+++ stacks/src/cstacks.cc
@@ -1999,13 +1999,13 @@
 }
 
 void version() {
-    cerr << "cstacks " << VERSION << "\n";
+    cout << "cstacks " << VERSION << "\n";
 
-    exit(1);
+    exit(0);
 }
 
 void help() {
-    cerr << "cstacks " << VERSION << "\n"
+    cout << "cstacks " << VERSION << "\n"
               << "cstacks -P in_dir -M popmap [-n num_mismatches] [-t num_threads]" << "\n"
               << "cstacks -s sample1_path [-s sample2_path ...] -o path [-n num_mismatches] [-t num_threads]" << "\n"
               << "\n"
@@ -2026,5 +2026,5 @@
               << "  --k-len <len>: specify k-mer size for matching between between catalog loci (automatically calculated by default).\n"
               << "  --report-mmatches: report query loci that match more than one catalog locus.\n";
 
-    exit(1);
+    exit(0);
 }
--- stacks.orig/src/phasedstacks.cc
+++ stacks/src/phasedstacks.cc
@@ -1938,13 +1938,13 @@
 }
 
 void version() {
-    cerr << "phasedstacks " << VERSION << "\n\n";
+    cout << "phasedstacks " << VERSION << "\n\n";
 
-    exit(1);
+    exit(0);
 }
 
 void help() {
-    cerr << "phasedstacks " << VERSION << "\n"
+    cout << "phasedstacks " << VERSION << "\n"
               << "phasedstacks -b id -S path -P path -t file_type [-p threads] [-M popmap] [-v] [-h]" << "\n"
               << "  b: Stacks batch ID.\n"
               << "  P: path to the phased output files.\n"
@@ -1963,5 +1963,5 @@
               << "  --min-inform-pairs: when building D' haplotype blocks, the minimum number of informative D' measures to combine two blocks (default 0.9).\n\n";
 
 
-    exit(1);
+    exit(0);
 }
--- stacks.orig/src/populations.cc
+++ stacks/src/populations.cc
@@ -4384,5 +4384,5 @@
          #endif
          ;
 
-    exit(1);
+    exit(0);
 }
--- stacks.orig/src/process_shortreads.cc
+++ stacks/src/process_shortreads.cc
@@ -1120,13 +1120,13 @@
 }
 
 void version() {
-    cerr << "process_shortreads " << VERSION << "\n\n";
+    cout << "process_shortreads " << VERSION << "\n\n";
 
-    exit(1);
+    exit(0);
 }
 
 void help() {
-    cerr << "process_shortreads " << VERSION << "\n"
+    cout << "process_shortreads " << VERSION << "\n"
               << "process_shortreads [-f in_file | -p in_dir [-P] [-I] | -1 pair_1 -2 pair_2] -b barcode_file -o out_dir [-i type] [-y type] [-c] [-q] [-r] [-E encoding] [-t len] [-D] [-w size] [-s lim] [-h]\n"
               << "  f: path to the input file if processing single-end seqeunces.\n"
               << "  i: input file type, either 'bustard' for the Illumina BUSTARD format, 'bam', 'fastq' (default), or 'gzfastq' for gzipped FASTQ.\n"
@@ -1170,5 +1170,5 @@
               << "    --mate-pair: raw reads are circularized mate-pair data, first read will be reverse complemented.\n"
               << "    --no-overhang: data does not contain an overhang nucleotide between barcode and seqeunce.\n";
 
-    exit(1);
+    exit(0);
 }
--- stacks.orig/src/ustacks.cc
+++ stacks/src/ustacks.cc
@@ -3013,13 +3013,13 @@
 }
 
 void version() {
-    cerr << "ustacks " << VERSION << "\n\n";
+    cout << "ustacks " << VERSION << "\n\n";
 
-    exit(1);
+    exit(0);
 }
 
 void help() {
-    cerr << "ustacks " << VERSION << "\n"
+    cout << "ustacks " << VERSION << "\n"
          << "ustacks -f in_path -o out_path [-M max_dist] [-m min_reads] [-t num_threads]" << "\n"
          << "  -f,--file: input file path.\n"
          << "  -o,--out-path: output path to write results.\n"
@@ -3055,5 +3055,5 @@
          << "\n"
          << "  h: display this help message.\n";
 
-    exit(1);
+    exit(0);
 }
--- stacks.orig/src/kmer_filter.cc
+++ stacks/src/kmer_filter.cc
@@ -1800,13 +1800,13 @@
 }
 
 void version() {
-    cerr << "kmer_filter " << VERSION << "\n\n";
+    cout << "kmer_filter " << VERSION << "\n\n";
 
-    exit(1);
+    exit(0);
 }
 
 void help() {
-    cerr << "kmer_filter " << VERSION << "\n"
+    cout << "kmer_filter " << VERSION << "\n"
               << "kmer_filter [-f in_file_1 [-f in_file_2...] | -p in_dir] [-1 pair_1 -2 pair_2 [-1 pair_1...]] -o out_dir [-i type] [-y type] [-D] [-h]\n"
               << "  f: path to the input file if processing single-end seqeunces.\n"
               << "  i: input file type, either 'bustard' for the Illumina BUSTARD output files, 'fasta', 'fastq', 'gzfasta', or 'gzfastq' (default 'fastq').\n"
@@ -1834,5 +1834,5 @@
               << "    --read-k-freq <path>: read a set of kmers along with their frequencies of occurrence instead of reading raw input files.\n"
               << "\n";
 
-    exit(1);
+    exit(0);
 }
