options.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * nvbio
  3. * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the NVIDIA CORPORATION nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "options.h"
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. struct runtime_options command_line_options;
  32. static void usage(void)
  33. {
  34. fprintf(stderr, "usage: nvmem [-f|--file-ref] <genome> <input.fastq> <output-file>\n");
  35. fprintf(stderr, "\n");
  36. fprintf(stderr, " -f, --file-ref Read the genome from file directly (do not use mmap)\n");
  37. fprintf(stderr, "\n");
  38. exit(1);
  39. }
  40. #if defined(WIN32)
  41. void parse_command_line(int argc, char **argv)
  42. {
  43. for (int i = 0; i < argc-3; ++i)
  44. {
  45. if (strcmp( argv[i], "-f" ) == 0 ||
  46. strcmp( argv[i], "--file-ref" ) == 0)
  47. command_line_options.genome_use_mmap = false;
  48. }
  49. if (argc < 3)
  50. {
  51. // missing required arguments or too many arguments
  52. usage();
  53. }
  54. command_line_options.genome_file_name = argv[argc-3];
  55. command_line_options.input_file_name = argv[argc-2];
  56. command_line_options.output_file_name = argv[argc-1];
  57. }
  58. #else
  59. #include <unistd.h>
  60. #include <getopt.h>
  61. #include <nvbio/basic/console.h>
  62. void parse_command_line(int argc, char **argv)
  63. {
  64. static const char *options_short = "f:o";
  65. static struct option options_long[] = {
  66. { "file-ref", no_argument, NULL, 'f' },
  67. { NULL, 0, NULL, 0 },
  68. };
  69. int ch;
  70. while((ch = getopt_long(argc, argv, options_short, options_long, NULL)) != -1)
  71. {
  72. switch(ch)
  73. {
  74. case 'f':
  75. // -f, --file-ref
  76. command_line_options.genome_use_mmap = false;
  77. break;
  78. case '?':
  79. case ':':
  80. default:
  81. usage();
  82. }
  83. }
  84. if (optind != argc - 3)
  85. {
  86. // missing required arguments or too many arguments
  87. usage();
  88. }
  89. command_line_options.genome_file_name = argv[optind];
  90. command_line_options.input_file_name = argv[optind + 1];
  91. command_line_options.output_file_name = argv[optind + 2];
  92. }
  93. #endif