From abaa69a61bb46b63b43513b1b81786920e5087d0 Mon Sep 17 00:00:00 2001 From: Benjamin Redelings Date: Tue, 3 Nov 2020 16:40:25 -0500 Subject: [PATCH 1/2] Pass taxonomy into find_node_by_id_str( ) to allow forwarding of OTT ids. --- otc/ws/tolws.cpp | 27 ++++++++++++++++----------- otc/ws/tolws.h | 2 +- ws/tolwsbooting.cpp | 6 +++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/otc/ws/tolws.cpp b/otc/ws/tolws.cpp index ed0574c4..4672f680 100644 --- a/otc/ws/tolws.cpp +++ b/otc/ws/tolws.cpp @@ -313,7 +313,7 @@ bool is_ancestor_of(N* f, N* s) return (sec_ind >= fdata->trav_enter and sec_ind <= fdata->trav_exit); } -node_lookup_t find_node_by_id_str(const SummaryTree_t & tree, const string & node_id) +node_lookup_t find_node_by_id_str(const SummaryTree_t & tree, const RichTaxonomy& taxonomy, const string & node_id) { const auto & tree_data = tree.get_data(); @@ -355,11 +355,11 @@ node_lookup_t find_node_by_id_str(const SummaryTree_t & tree, const string & nod assert(matches.size() >= 2); std::string first_id = matches[1]; std::string second_id = matches[2]; - auto result1 = find_node_by_id_str(tree, first_id); + auto result1 = find_node_by_id_str(tree, taxonomy, first_id); if (result1.node == nullptr) { return result1; } - auto result2 = find_node_by_id_str(tree, second_id); + auto result2 = find_node_by_id_str(tree, taxonomy, second_id); if (result2.node == nullptr) { return result2; } @@ -368,9 +368,9 @@ node_lookup_t find_node_by_id_str(const SummaryTree_t & tree, const string & nod return {}; } -node_lookup_t find_required_node_by_id_str(const SummaryTree_t & tree, const string & node_id) +node_lookup_t find_required_node_by_id_str(const SummaryTree_t & tree, const RichTaxonomy& taxonomy, const string & node_id) { - auto result = find_node_by_id_str(tree, node_id); + auto result = find_node_by_id_str(tree, taxonomy, node_id); if (not result.node) { throw OTCBadRequest() << "node_id '" << node_id << "' was not found!"; } @@ -512,7 +512,9 @@ string node_info_ws_method(const TreesToServe & tts, bool include_lineage) { LOG(DEBUG)<<"Got to node_info_ws_method( )"; - auto result = find_required_node_by_id_str(*tree_ptr, node_id); + auto locked_taxonomy = tts.get_readable_taxonomy(); + const auto & taxonomy = locked_taxonomy.first; + auto result = find_required_node_by_id_str(*tree_ptr, taxonomy, node_id); auto response = node_info_json(tts, sta, result.node, include_lineage); response["query"] = node_id; @@ -528,7 +530,7 @@ pair,json> find_nodes_for_id_strings(const RichTaxo json broken = json::object(); optional bad_node_id; for (auto node_id : node_ids) { - auto result = find_node_by_id_str(*tree_ptr, node_id); + auto result = find_node_by_id_str(*tree_ptr, taxonomy, node_id); if (not result.node or (result.was_broken and fail_broken)) { // Possible statuses: // - invalid (never minted id) @@ -718,12 +720,13 @@ auto lookup(const Map& m, const Key& k) const SumTreeNode_t * get_node_for_subtree(const SummaryTree_t * tree_ptr, - const string & node_id, + const string & node_id, + const RichTaxonomy& taxonomy, int height_limit, uint32_t tip_limit) { assert(tree_ptr != nullptr); - auto result = find_required_node_by_id_str(*tree_ptr, node_id); + auto result = find_required_node_by_id_str(*tree_ptr, taxonomy, node_id); if (result.was_broken) { json broken; broken["mrca"] = get_synth_node_label(result.node); @@ -849,9 +852,9 @@ string newick_subtree_ws_method(const TreesToServe & tts, int height_limit) { const uint32_t NEWICK_TIP_LIMIT = 100000; - auto focal = get_node_for_subtree(tree_ptr, node_id, height_limit, NEWICK_TIP_LIMIT); auto locked_taxonomy = tts.get_readable_taxonomy(); const auto & taxonomy = locked_taxonomy.first; + auto focal = get_node_for_subtree(tree_ptr, node_id, taxonomy, height_limit, NEWICK_TIP_LIMIT); NodeNamerSupportedByStasher nnsbs(label_format, taxonomy, tts); ostringstream out; write_newick_generic(out, focal, nnsbs, include_all_node_labels, height_limit); @@ -891,7 +894,9 @@ string arguson_subtree_ws_method(const TreesToServe & tts, const string & node_id, int height_limit) { const uint32_t NEWICK_TIP_LIMIT = 25000; - auto focal = get_node_for_subtree(tree_ptr, node_id, height_limit, NEWICK_TIP_LIMIT); + auto locked_taxonomy = tts.get_readable_taxonomy(); + const auto & taxonomy = locked_taxonomy.first; + auto focal = get_node_for_subtree(tree_ptr, node_id, taxonomy, height_limit, NEWICK_TIP_LIMIT); json response; response["synth_id"] = sta->synth_id; set usedSrcIds; diff --git a/otc/ws/tolws.h b/otc/ws/tolws.h index 11fd154e..d91d562e 100644 --- a/otc/ws/tolws.h +++ b/otc/ws/tolws.h @@ -257,7 +257,7 @@ struct node_lookup_t node_lookup_t(const SumTreeNode_t* n):node(n) {} }; -node_lookup_t find_node_by_id_str(const SummaryTree_t & tree, const std::string & node_id); +node_lookup_t find_node_by_id_str(const SummaryTree_t & tree, const RichTaxonomy&, const std::string & node_id); class TreesToServe; diff --git a/ws/tolwsbooting.cpp b/ws/tolwsbooting.cpp index c47c37f7..4887a6f4 100644 --- a/ws/tolwsbooting.cpp +++ b/ws/tolwsbooting.cpp @@ -1208,7 +1208,7 @@ bool read_tree_and_annotations(const fs::path & config_path, //const auto & n2n = sum_tree_data.name_to_node; for (json::const_iterator nit = node_obj.begin(); nit != node_obj.end(); ++nit) { string k = nit.key(); - auto result = find_node_by_id_str(tree, k); + auto result = find_node_by_id_str(tree, taxonomy, k); //auto stnit = n2n.find(k); if (result.node == nullptr) { throw OTCError() << "Node " << k << " from annotations not found in tree."; @@ -1327,11 +1327,11 @@ bool read_tree_and_annotations(const fs::path & config_path, for (json::const_iterator ai_it = attach_obj.begin(); ai_it != attach_obj.end(); ++ai_it) { attach_id_list.push_back(ai_it.key()); } - auto mrca_result = find_node_by_id_str(tree, mrca_id); + auto mrca_result = find_node_by_id_str(tree, taxonomy, mrca_id); vector avec; avec.reserve(attach_id_list.size()); for (auto attach_id : attach_id_list) { - auto [anptr, _] = find_node_by_id_str(tree, attach_id); + auto [anptr, _] = find_node_by_id_str(tree, taxonomy, attach_id); assert(anptr != nullptr); avec.push_back(anptr); } From 6e2120ea53f4983e7cf334f171a6698b2e3ea383 Mon Sep 17 00:00:00 2001 From: Benjamin Redelings Date: Tue, 3 Nov 2020 16:40:44 -0500 Subject: [PATCH 2/2] Use the taxonomy to forward the ott id. --- otc/ws/tolws.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/otc/ws/tolws.cpp b/otc/ws/tolws.cpp index 4672f680..1cb8270f 100644 --- a/otc/ws/tolws.cpp +++ b/otc/ws/tolws.cpp @@ -323,24 +323,39 @@ node_lookup_t find_node_by_id_str(const SummaryTree_t & tree, const RichTaxonomy // Get the OTT ID long raw_ott_id = long_ott_id_from_name(node_id); - // Try to find the OTT ID in the summary tree. - if (raw_ott_id >= 0) { - OttId ott_id = check_ott_id_size(raw_ott_id); - auto i2nit = tree_data.id_to_node.find(ott_id); - if (i2nit != tree_data.id_to_node.end()) { - return {i2nit->second}; - } - LOG(WARNING) << "not finding " << ott_id << " extracted from " << node_id; + // 1. Check that the ID is not negative + if (raw_ott_id < 0) + { + LOG(WARNING) << "OTT ID " << raw_ott_id << " (from '"<second}; + + // 4. We didn't find a summary tree node for this OTT ID. Is this node listed as broken? if (auto bt_it = tree_data.broken_taxa.find(node_id); bt_it != tree_data.broken_taxa.end()) { - // if found we return the MRCA pointer in the first slot of the pair. + // if found, we return the MRCA pointer in the first slot of the pair. return broken_taxon(bt_it->second.first); } else + { + LOG(WARNING) << "OTT ID" << ott_id << " (from '"<