PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/readCleaner/Configuration.cpp

http://tud-scaffolding.googlecode.com/
C++ | 202 lines | 167 code | 6 blank | 29 comment | 36 complexity | 9064db1a661ede313fcb2b8da1f4efbd MD5 | raw file
Possible License(s): GPL-3.0
  1. /*
  2. * readCleaner : a tool used in debugging. Removes paired reads originating from
  3. * gaps
  4. * Copyright (C) 2011 Alexey Gritsenko
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see http://www.gnu.org/licenses/.
  18. *
  19. *
  20. *
  21. * Email: a.gritsenko@tudelft.nl
  22. * Mail: Delft University of Technology
  23. * Faculty of Electrical Engineering, Mathematics, and Computer Science
  24. * Department of Mediamatics
  25. * P.O. Box 5031
  26. * 2600 GA, Delft, The Netherlands
  27. */
  28. #include "Configuration.h"
  29. #include "Defines.h"
  30. #include "Helpers.h"
  31. #include <iostream>
  32. #include <cstring>
  33. #include <cstdlib>
  34. #include <sstream>
  35. using namespace std;
  36. // Construtor with default configuration parameter settings.
  37. Configuration::Configuration()
  38. {
  39. Success = false;
  40. }
  41. // Parses command line arguments. Returns true if successful.
  42. bool Configuration::ProcessCommandLine(int argc, char *argv[])
  43. {
  44. this->Success = true;
  45. stringstream serr;
  46. if (argc == 1)
  47. {
  48. serr << "[-] Not enough arguments. Consult -help." << endl;
  49. this->Success = false;
  50. }
  51. else
  52. {
  53. int i = 1;
  54. while (i < argc)
  55. {
  56. if (!strcmp("-help", argv[i]) || !strcmp("-h", argv[i]))
  57. {
  58. printHelpMessage(serr);
  59. this->Success = false;
  60. break;
  61. }
  62. else if (!strcmp("-454", argv[i]))
  63. {
  64. if (argc - i - 1 < 3)
  65. {
  66. serr << "[-] Parsing error in -454: must have 3 arguments." << endl;
  67. this->Success = false;
  68. break;
  69. }
  70. i++;
  71. string leftFileName = argv[i];
  72. i++;
  73. string rightFileName = argv[i];
  74. i++;
  75. string outputPrefix = argv[i];
  76. this->PairedReadInputs.push_back(PairedInput(leftFileName, rightFileName, outputPrefix, false));
  77. }
  78. else if (!strcmp("-illumina", argv[i]))
  79. {
  80. if (argc - i - 1 < 3)
  81. {
  82. serr << "[-] Parsing error in -illumina: must have 3 arguments." << endl;
  83. this->Success = false;
  84. break;
  85. }
  86. i++;
  87. string leftFileName = argv[i];
  88. i++;
  89. string rightFileName = argv[i];
  90. i++;
  91. string outputPrefix = argv[i];
  92. this->PairedReadInputs.push_back(PairedInput(leftFileName, rightFileName, outputPrefix, true));
  93. }
  94. else if (!strcmp("-tmp", argv[i]))
  95. {
  96. if (argc - i - 1 < 1)
  97. {
  98. serr << "[-] Parsing error in -tmp: must have an argument." << endl;
  99. this->Success = false;
  100. break;
  101. }
  102. i++;
  103. this->BWAConfig.TmpPath = this->NovoAlignConfig.TmpPath = this->SAMToolsConfig.TmpPath = argv[i];
  104. }
  105. else if (!strcmp("-bwathreads", argv[i]))
  106. {
  107. if (argc - i - 1 < 1)
  108. {
  109. serr << "[-] Parsing error in -bwathreads: must have an argument." << endl;
  110. this->Success = false;
  111. break;
  112. }
  113. i++;
  114. bool threadsSuccess;
  115. BWAConfig.NumberOfThreads = Helpers::ParseInt(argv[i], threadsSuccess);
  116. if (!threadsSuccess || BWAConfig.NumberOfThreads <= 0)
  117. {
  118. serr << "[-] Parsing error in -bwathreads: number of threads must be a positive number." << endl;
  119. this->Success = false;
  120. break;
  121. }
  122. }
  123. else if (!strcmp("-bwahits", argv[i]))
  124. {
  125. if (argc - i - 1 < 1)
  126. {
  127. serr << "[-] Parsing error in -bwahits: must have an argument." << endl;
  128. this->Success = false;
  129. break;
  130. }
  131. i++;
  132. bool hitsSuccess;
  133. BWAConfig.MaximumHits = Helpers::ParseInt(argv[i], hitsSuccess);
  134. if (!hitsSuccess || BWAConfig.MaximumHits <= 0)
  135. {
  136. serr << "[-] Parsing error in -bwahits: number of hits must be a positive number." << endl;
  137. this->Success = false;
  138. break;
  139. }
  140. }
  141. else if (!strcmp("-bwaexact", argv[i]))
  142. {
  143. if (argc - i - 1 < 1)
  144. {
  145. cerr << "[-] Parsing error in -bwaexact: must have an argument." << endl;
  146. this->Success = false;
  147. break;
  148. }
  149. i++;
  150. bool sw = false;
  151. if (!strcasecmp(argv[i], "yes"))
  152. sw = true;
  153. else if (!strcasecmp(argv[i], "no"))
  154. sw = false;
  155. else
  156. {
  157. cerr << "[-] Parsing error in -bwaexact: argument must be yes/no." << endl;
  158. this->Success = false;
  159. break;
  160. }
  161. BWAConfig.ExactMatch = sw;
  162. }
  163. else if (i == argc - 1)
  164. this->ReferenceFileName = argv[argc - 1];
  165. else
  166. {
  167. serr << "[-] Unknown argument: " << argv[i] << endl;
  168. this->Success = false;
  169. break;
  170. }
  171. i++;
  172. }
  173. if (this->ReferenceFileName == "")
  174. {
  175. serr << "[-] No reference file specified." << endl;
  176. this->Success = false;
  177. }
  178. }
  179. if (!this->Success)
  180. LastError = serr.str();
  181. return this->Success;
  182. }
  183. void Configuration::printHelpMessage(stringstream &serr)
  184. {
  185. serr << "[i] Repetitive read filter " << VERSION << " (" << DATE << ")" << endl;
  186. serr << "[i] By " << AUTHOR << endl;
  187. serr << "[i] Usage: dataLinker [arguments] <referece.fasta>" << endl;
  188. serr << "[i] -help Print this message and exit." << endl;
  189. serr << "[i] -454 <left.fq> <right.fq> <output prefix> Process 454 paired reads and output the filtered reads with new prefix." << endl;
  190. serr << "[i] -illumina <left.fq> <right.fq> <output prefix> Process Illumina paired reads and output the filtered reads with new prefix." << endl;
  191. serr << "[i] -tmp <path> Define scrap path for temporary files. [/tmp]" << endl;
  192. serr << "[i] BWA configuration options:" << endl;
  193. serr << "[i] -bwathreads <n> Number of threads used in BWA alignment. [8]" << endl;
  194. serr << "[i] -bwahits <n> Maximum number of alignment hits BWA should report. [1000]" << endl;
  195. serr << "[i] -bwaexact <yes/no> Use exact matching in BWA? [no]" << endl;
  196. }