diff --git a/bdsg/src/snarl_distance_index.cpp b/bdsg/src/snarl_distance_index.cpp index 0806b0fa..eee7ae45 100644 --- a/bdsg/src/snarl_distance_index.cpp +++ b/bdsg/src/snarl_distance_index.cpp @@ -5457,7 +5457,7 @@ SnarlDistanceIndex::SnarlRecordWriter SnarlDistanceIndex::ChainRecordWriter::add #ifdef debug_distance_indexing cerr << (*records)->size() << " Adding child snarl length to the end of the array " << endl; cerr << "Previous child was at " << previous_child_offset << endl; - assert(SnarlDistanceIndex::get_record_type((*records)->at(previous_child_offset))== DISTANCED_TRIVIAL_SNARL); + assert(SnarlDistanceIndex::get_record_type((*records)->at(previous_child_offset))== DISTANCED_TRIVIAL_SNARL || SnarlDistanceIndex::get_record_type((*records)->at(previous_child_offset))== TRIVIAL_SNARL); #endif @@ -5490,7 +5490,7 @@ SnarlDistanceIndex::SimpleSnarlRecordWriter SnarlDistanceIndex::ChainRecordWrite size_t snarl_record_size = SIMPLE_SNARL_RECORD_SIZE + 2*snarl_size; #ifdef debug_distance_indexing cerr << (*records)->size() << " Adding simple snarl to the end of the array " << endl; - assert(SnarlDistanceIndex::get_record_type((*records)->at(previous_child_offset))== DISTANCED_TRIVIAL_SNARL); + assert(SnarlDistanceIndex::get_record_type((*records)->at(previous_child_offset))== DISTANCED_TRIVIAL_SNARL || SnarlDistanceIndex::get_record_type((*records)->at(previous_child_offset))== TRIVIAL_SNARL); #endif @@ -6143,10 +6143,12 @@ void SnarlDistanceIndex::get_snarl_tree_records(const vectorsize()); + bool ignore_distances = (snarl_size_limit == 0) || (only_top_level_chain_distances && temp_chain_record.tree_depth != 0); + ChainRecordWriter chain_record_constructor; - if (temp_chain_record.chain_components.back() == 0 || snarl_size_limit == 0) { - record_t record_type = snarl_size_limit == 0 ? CHAIN : DISTANCED_CHAIN; + if (temp_chain_record.chain_components.back() == 0 || ignore_distances) { + record_t record_type = ignore_distances ? CHAIN : DISTANCED_CHAIN; chain_record_constructor = ChainRecordWriter(snarl_tree_records->size(), record_type, temp_chain_record.prefix_sum.size(), &snarl_tree_records); chain_record_constructor.set_start_end_connected(); @@ -6156,7 +6158,7 @@ void SnarlDistanceIndex::get_snarl_tree_records(const vector node_rank2 = it.first.second; const size_t distance = it.second; - if (snarl_size_limit != 0) { + if (!ignore_distances) { //If we are keeping track of distances //If the distance exceeded the limit, then it wasn't found in the first place snarl_record_constructor.set_distance(node_rank1.first, node_rank1.second, @@ -6361,8 +6365,9 @@ void SnarlDistanceIndex::get_snarl_tree_records(const vectortemp_node_records[temp_chain_record.children[0].second-min_node_id]; - record_t record_type = snarl_size_limit == 0 ? NODE : DISTANCED_NODE; + + //TODO: I don't think we ever need distances if its a top-level chain distance only index but it doesn't change much + bool ignore_distances = (snarl_size_limit == 0) || (only_top_level_chain_distances && temp_chain_record.tree_depth != 0); + + record_t record_type = ignore_distances ? NODE : DISTANCED_NODE; NodeRecordWriter node_record(snarl_tree_records->size(), 0, record_type, &snarl_tree_records, temp_node_record.node_id); node_record.set_node_id(temp_node_record.node_id); node_record.set_rank_in_parent(temp_chain_record.rank_in_parent); node_record.set_parent_record_offset(record_to_offset[make_pair(temp_index_i, temp_chain_record.parent)]); - if (snarl_size_limit != 0) { + if (!ignore_distances) { node_record.set_node_length(temp_node_record.node_length); node_record.set_distance_left_start(temp_chain_record.distance_left_start); node_record.set_distance_right_start(temp_chain_record.distance_right_start); @@ -6444,8 +6453,10 @@ void SnarlDistanceIndex::get_snarl_tree_records(const vectorstructure_start_end_as_string(current_record_index) << endl; #endif + + bool ignore_distances = (snarl_size_limit == 0) || only_top_level_chain_distances; //This is a root-level snarl - record_t record_type = snarl_size_limit == 0 ? ROOT_SNARL : DISTANCED_ROOT_SNARL; + record_t record_type = ignore_distances ? ROOT_SNARL : DISTANCED_ROOT_SNARL; const TemporaryDistanceIndex::TemporarySnarlRecord& temp_snarl_record = temp_index->temp_snarl_records[current_record_index.second]; record_to_offset.emplace(make_pair(temp_index_i,current_record_index), snarl_tree_records->size()); @@ -6457,7 +6468,7 @@ void SnarlDistanceIndex::get_snarl_tree_records(const vectortemp_node_records[current_record_index.second-min_node_id]; - record_t record_type = snarl_size_limit == 0 ? NODE : DISTANCED_NODE; + + bool ignore_distances = (snarl_size_limit == 0) || only_top_level_chain_distances; + record_t record_type = ignore_distances ? NODE : DISTANCED_NODE; NodeRecordWriter node_record(snarl_tree_records->size(), 0, record_type, &snarl_tree_records, temp_node_record.node_id); node_record.set_node_id(temp_node_record.node_id); node_record.set_rank_in_parent(temp_node_record.rank_in_parent); node_record.set_parent_record_offset(record_to_offset[make_pair(temp_index_i, temp_node_record.parent)]); - if (snarl_size_limit != 0) { + if (!ignore_distances) { node_record.set_node_length(temp_node_record.node_length); node_record.set_distance_left_start(temp_node_record.distance_left_start); node_record.set_distance_right_start(temp_node_record.distance_right_start);