1 /****
2 DIAMOND protein aligner
3 Copyright (C) 2013-2017 Benjamin Buchfink <buchfink@gmail.com>
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 ****/
18 
19 #include <iostream>
20 #include "../basic/config.h"
21 #include "tools.h"
22 #include "../data/reference.h"
23 #include "workflow.h"
24 #include "../cluster/cluster_registry.h"
25 #include "../output/recursive_parser.h"
26 #include "../util/simd.h"
27 #include "../data/dmnd/dmnd.h"
28 
29 using std::cout;
30 using std::cerr;
31 using std::endl;
32 
33 void model_seqs();
34 void opt();
35 void run_masker();
36 void fastq2fasta();
37 void view_daa();
38 void view_tsv();
39 void db_info();
40 void test_main();
41 void benchmark_sw();
42 void db_annot_stats();
43 void read_sim();
44 void info();
45 void seed_stat();
46 void pairwise();
47 void translate();
48 void filter_blasttab();
49 void show_cbs();
50 void reverse();
51 void get_medoids_from_tree();
52 void roc();
53 void merge_tsv();
54 void roc_id();
55 void makeindex();
56 void find_shapes();
57 void composition();
58 void join();
59 void hash_seqs();
60 void list_seeds();
61 #ifdef WITH_BLASTDB
62 void prep_blast_db();
63 #endif
64 
65 void split();
66 namespace Benchmark { DECL_DISPATCH(void, benchmark, ()) }
67 namespace Util { namespace Algo { namespace UPGMA { void upgma(); } } }
68 namespace Util { namespace Algo { namespace UPGMA_MC { void upgma(); } } }
69 namespace Test { int run();
70 void simulate_seqs();
71 void mutate();
72 }
73 
main(int ac,const char * av[])74 int main(int ac, const char* av[])
75 {
76 	try {
77 		config = Config(ac, av);
78 
79 		switch (config.command) {
80 		case Config::help:
81 			break;
82 		case Config::version:
83 			cout << Const::program_name << " version " << Const::version_string << endl;
84 			break;
85 		case Config::makedb:
86 			DatabaseFile::make_db();
87 			break;
88 		case Config::blastp:
89 		case Config::blastx:
90 			Search::run();
91 			break;
92 		case Config::view:
93 			if (!config.daa_file.empty())
94 				view_daa();
95 			else if (!config.input_ref_file.empty())
96 				view_tsv();
97 			else
98 				throw std::runtime_error("The view command requires either a text (option --in) or DAA (option -a) input file.");
99 			break;
100 		case Config::getseq:
101 			get_seq();
102 			break;
103 		case Config::random_seqs:
104 			random_seqs();
105 			break;
106 		case Config::sort:
107 			sort_file();
108 			break;
109 		case Config::db_stat:
110 			db_stat();
111 			break;
112 		case Config::mask:
113 			run_masker();
114 			break;
115 		case Config::fastq2fasta:
116 			fastq2fasta();
117 			break;
118 		case Config::dbinfo:
119 			db_info();
120 			break;
121 		case Config::read_sim:
122 			read_sim();
123 			break;
124 		case Config::info:
125 			info();
126 			break;
127 		case Config::smith_waterman:
128 			pairwise();
129 			break;
130 		case Config::cluster:
131 			// Why is cluster_similarity not set at the end of the Config constructor?
132 			if(!config.cluster_similarity.empty()){
133 				string expression = RecursiveParser::clean_expression(&config.cluster_similarity);
134 				RecursiveParser rp(nullptr, expression.c_str(), true);
135 				try{
136 					rp.evaluate();
137 				}
138 				catch (const runtime_error& e){
139 					message_stream << "Could not evaluate the expression: " << config.cluster_similarity << endl;
140 					throw e;
141 				}
142 			}
143 			Workflow::Cluster::ClusterRegistry::get(config.cluster_algo)->run();
144 			break;
145 		case Config::translate:
146 			translate();
147 			break;
148 		case Config::filter_blasttab:
149 			filter_blasttab();
150 			break;
151 		case Config::show_cbs:
152 			show_cbs();
153 			break;
154 		case Config::simulate_seqs:
155 			Test::simulate_seqs();
156 			break;
157 		case Config::benchmark:
158 			Benchmark::benchmark();
159 			break;
160 		case Config::split:
161 			split();
162 			break;
163 		case Config::upgma:
164 			Util::Algo::UPGMA::upgma();
165 			break;
166 		case Config::upgma_mc:
167 			Util::Algo::UPGMA_MC::upgma();
168 			break;
169 		case Config::regression_test:
170 			return Test::run();
171 			break;
172 		case Config::reverse_seqs:
173 			reverse();
174 			break;
175 		case Config::compute_medoids:
176 			get_medoids_from_tree();
177 			break;
178 		case Config::mutate:
179 			Test::mutate();
180 			break;
181 		case Config::roc:
182 			roc();
183 			break;
184 		case Config::merge_tsv:
185 			merge_tsv();
186 			break;
187 		case Config::rocid:
188 			roc_id();
189 			break;
190 		case Config::makeidx:
191 			makeindex();
192 			break;
193 		case Config::find_shapes:
194 			find_shapes();
195 			break;
196 		case Config::HASH_SEQS:
197 			hash_seqs();
198 			break;
199 #ifdef WITH_BLASTDB
200 		case Config::prep_blast_db:
201 			prep_blast_db();
202 			break;
203 #endif
204 		case Config::composition:
205 			composition();
206 			break;
207 		case Config::JOIN:
208 			join();
209 			break;
210 		case Config::LIST_SEEDS:
211 			list_seeds();
212 			break;
213 		default:
214 			return 1;
215 		}
216 	}
217 	catch(const std::bad_alloc &e) {
218 		cerr << "Failed to allocate sufficient memory. Please refer to the manual for instructions on memory usage." << endl;
219 		log_stream << "Error: " << e.what() << endl;
220 		return 1;
221 	} catch(const std::exception& e) {
222         cerr << "Error: " << e.what() << endl;
223         log_stream << "Error: " << e.what() << endl;
224         return 1;
225     }
226     catch(...) {
227         cerr << "Exception of unknown type!" << endl;
228         return 1;
229     }
230 
231     return 0;
232 }
233