1 /****
2 DIAMOND protein aligner
3 Copyright (C) 2016-2021 Max Planck Society for the Advancement of Science e.V.
4                         Benjamin Buchfink
5 
6 Code developed by Benjamin Buchfink <benjamin.buchfink@tue.mpg.de>
7 
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 ****/
21 #include <set>
22 #include "output_format.h"
23 #include "../data/taxonomy.h"
24 #include "../util/sequence/sequence.h"
25 
26 using std::set;
27 using std::endl;
28 
print_match(const HspContext & r,const Search::Config & cfg,TextBuffer & out)29 void Taxon_format::print_match(const HspContext &r, const Search::Config& cfg, TextBuffer &out)
30 {
31 	const vector<unsigned> taxons(cfg.db->taxids(r.subject_oid));
32 	if (taxons.empty())
33 		return;
34 	evalue = std::min(evalue, r.evalue());
35 	try {
36 		for (vector<unsigned>::const_iterator i = taxons.begin(); i != taxons.end(); ++i)
37 			taxid = cfg.taxon_nodes->get_lca(taxid, *i);
38 	}
39 	catch (std::exception &) {
40 		std::cerr << "Query=" << r.query_title << endl << "Subject=" << r.target_title << endl;
41 		throw;
42 	}
43 }
44 
print_query_epilog(TextBuffer & out,const char * query_title,bool unaligned,const Search::Config & params) const45 void Taxon_format::print_query_epilog(TextBuffer &out, const char *query_title, bool unaligned, const Search::Config &params) const
46 {
47 	out.write_until(query_title, Util::Seq::id_delimiters);
48 	out << '\t' << taxid << '\t';
49 	if (taxid != 0)
50 		out.print_e(evalue);
51 	else
52 		out << '0';
53 	out << '\n';
54 }