A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ncbi.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TAXONOMY_FORMATS_NCBI_H_
2 #define GENESIS_TAXONOMY_FORMATS_NCBI_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
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  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
37 
38 #include <string>
39 #include <unordered_map>
40 
41 namespace genesis {
42 namespace taxonomy {
43 
44 // =================================================================================================
45 // NCBI Reading stuff
46 // =================================================================================================
47 
48 struct NcbiNode
49 {
50  std::string tax_id;
51  std::string parent_tax_id;
52  std::string rank;
53 
54  mutable Taxon* taxon = nullptr;
55 };
56 
57 struct NcbiName
58 {
59  std::string tax_id;
60  std::string name;
61  std::string name_class;
62 };
63 
64 using NcbiNodeLookup = std::unordered_map<std::string, NcbiNode>;
65 using NcbiNameLookup = std::unordered_map<std::string, NcbiName>;
66 
68  utils::CsvReader::Table const& node_table,
69  size_t tax_id_pos = 0,
70  size_t parent_tax_id_pos = 1,
71  size_t rank_pos = 2
72 );
73 
75  utils::CsvReader::Table const& name_table,
76  size_t tax_id_pos = 0,
77  size_t name_pos = 1,
78  size_t name_class_pos = 3,
79  std::string name_class_filter = "scientific name"
80 );
81 
83  NcbiNodeLookup const& nodes,
84  NcbiNameLookup const& names
85 );
86 
87 Taxonomy read_ncbi_taxonomy( std::string const& node_file, std::string const& name_file );
88 
89 } // namespace taxonomy
90 } // namespace genesis
91 
92 #endif // include guard
std::string name_class
Definition: ncbi.hpp:61
Store a Taxonomy, i.e., a nested hierarchy of Taxa.
std::unordered_map< std::string, NcbiName > NcbiNameLookup
Definition: ncbi.hpp:65
NcbiNameLookup convert_ncbi_name_table(utils::CsvReader::Table const &name_table, size_t tax_id_pos, size_t name_pos, size_t name_class_pos, std::string name_class_filter)
Definition: ncbi.cpp:85
Taxonomy read_ncbi_taxonomy(std::string const &node_file, std::string const &name_file)
Definition: ncbi.cpp:210
Store a Taxon, i.e., an element in a Taxonomy, with its name, rank, ID and sub-taxa.
Definition: taxon.hpp:76
NcbiNodeLookup convert_ncbi_node_table(utils::CsvReader::Table const &node_table, size_t tax_id_pos, size_t parent_tax_id_pos, size_t rank_pos)
Definition: ncbi.cpp:46
std::unordered_map< std::string, NcbiNode > NcbiNodeLookup
Definition: ncbi.hpp:64
std::string parent_tax_id
Definition: ncbi.hpp:51
Taxonomy convert_ncbi_tables(NcbiNodeLookup const &nodes, NcbiNameLookup const &names)
Definition: ncbi.cpp:130