A library for working with phylogenetic and population genetic data.
v0.27.0
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-2019 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 const& 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
genesis::taxonomy::NcbiName::name
std::string name
Definition: ncbi.hpp:60
genesis::taxonomy::NcbiNode::tax_id
std::string tax_id
Definition: ncbi.hpp:50
genesis::taxonomy::Taxon
Store a Taxon, i.e., an element in a Taxonomy, with its name, rank, ID and sub-taxa.
Definition: taxon.hpp:76
genesis::taxonomy::NcbiName::tax_id
std::string tax_id
Definition: ncbi.hpp:59
genesis::taxonomy::NcbiNode::rank
std::string rank
Definition: ncbi.hpp:52
genesis::taxonomy::convert_ncbi_node_table
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:48
taxonomy.hpp
reader.hpp
genesis::taxonomy::NcbiName
Definition: ncbi.hpp:57
genesis::taxonomy::NcbiNode::taxon
Taxon * taxon
Definition: ncbi.hpp:54
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::taxonomy::NcbiNameLookup
std::unordered_map< std::string, NcbiName > NcbiNameLookup
Definition: ncbi.hpp:65
genesis::taxonomy::Taxonomy
Store a Taxonomy, i.e., a nested hierarchy of Taxa.
Definition: taxonomy/taxonomy.hpp:96
taxon.hpp
genesis::taxonomy::read_ncbi_taxonomy
Taxonomy read_ncbi_taxonomy(std::string const &node_file, std::string const &name_file)
Definition: ncbi.cpp:212
genesis::taxonomy::NcbiNode
Definition: ncbi.hpp:48
genesis::taxonomy::convert_ncbi_tables
Taxonomy convert_ncbi_tables(NcbiNodeLookup const &nodes, NcbiNameLookup const &names)
Definition: ncbi.cpp:132
genesis::taxonomy::NcbiNode::parent_tax_id
std::string parent_tax_id
Definition: ncbi.hpp:51
genesis::taxonomy::NcbiName::name_class
std::string name_class
Definition: ncbi.hpp:61
genesis::utils::CsvReader::Table
std::vector< Line > Table
Definition: utils/formats/csv/reader.hpp:80
genesis::taxonomy::NcbiNodeLookup
std::unordered_map< std::string, NcbiNode > NcbiNodeLookup
Definition: ncbi.hpp:64
genesis::taxonomy::convert_ncbi_name_table
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 const &name_class_filter)
Definition: ncbi.cpp:87