Skip to content

Commit

Permalink
Merge pull request #184 from yceh/less-visit
Browse files Browse the repository at this point in the history
Bugfix and pruning direction to search
  • Loading branch information
yatisht committed Nov 3, 2021
2 parents 0cc02c3 + c8b8e3d commit 9917a94
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 100 deletions.
1 change: 1 addition & 0 deletions mutation_detailed.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ message node {
repeated int64 children_offsets =6;
repeated int32 children_lengths =7;
repeated string condensed_nodes =8;
int32 changed =9;
}

message meta {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,15 @@ Bounded_Mut_Change_Collection;
void search_subtree_bounded(MAT::Node *node, const src_side_info &src_side,
int radius_left,
Bounded_Mut_Change_Collection &par_muts,
int lower_bound,ignore_ranger_nop
int lower_bound,ignore_ranger_nop,Reachable
#ifdef CHECK_BOUND
,bool do_continue
#endif
);
void search_subtree_bounded(MAT::Node *node, const src_side_info &src_side,
int radius_left,
Bounded_Mut_Change_Collection &par_muts,
int lower_bound,ignore_ranger
int lower_bound,ignore_ranger,Reachable
#ifdef CHECK_BOUND
,bool do_continue
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ template <typename value_type> class range {
return end-curr;
}
};
void find_moves_bounded(MAT::Node* src,output_t& out,int search_radius,bool do_drift
struct Reachable{
bool reachable_change;
bool always_search;
};
void find_moves_bounded(MAT::Node* src,output_t& out,int search_radius,bool do_drift,Reachable
#ifdef CHECK_BOUND
,counters& count
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ template<typename T>
static void search_subtree_bounded_internal(MAT::Node *node, const src_side_info &src_side,
int radius_left,
Bounded_Mut_Change_Collection &par_muts,
int lower_bound,T tag
int lower_bound,T tag,Reachable reachable
#ifdef CHECK_BOUND
,bool do_continue
#endif
Expand Down Expand Up @@ -380,7 +380,17 @@ static void search_subtree_bounded_internal(MAT::Node *node, const src_side_info
#endif
}
}
search_subtree_bounded(child, src_side, radius_left-1, muts, child_specific_lower_bound,tag
auto child_reachable=reachable;
if (!reachable.always_search) {
if (!child->get_descendent_changed()) {
continue;
}
if (reachable.reachable_change&& child->get_self_changed()) {
child_reachable.always_search=true;
}
}

search_subtree_bounded(child, src_side, radius_left-1, muts, child_specific_lower_bound,tag,child_reachable
#ifdef CHECK_BOUND
,do_continue
#endif
Expand All @@ -390,12 +400,12 @@ static void search_subtree_bounded_internal(MAT::Node *node, const src_side_info
void search_subtree_bounded(MAT::Node *node, const src_side_info &src_side,
int radius_left,
Bounded_Mut_Change_Collection &par_muts,
int lower_bound,ignore_ranger_nop tag
int lower_bound,ignore_ranger_nop tag,Reachable reachable
#ifdef CHECK_BOUND
,bool do_continue
#endif
) {
search_subtree_bounded_internal(node, src_side,radius_left,par_muts,lower_bound,tag
search_subtree_bounded_internal(node, src_side,radius_left,par_muts,lower_bound,tag,reachable
#ifdef CHECK_BOUND
,do_continue
#endif
Expand All @@ -404,12 +414,12 @@ void search_subtree_bounded(MAT::Node *node, const src_side_info &src_side,
void search_subtree_bounded(MAT::Node *node, const src_side_info &src_side,
int radius_left,
Bounded_Mut_Change_Collection &par_muts,
int lower_bound,ignore_ranger tag
int lower_bound,ignore_ranger tag,Reachable reachable
#ifdef CHECK_BOUND
,bool do_continue
#endif
) {
search_subtree_bounded_internal(node, src_side,radius_left,par_muts,lower_bound,tag
search_subtree_bounded_internal(node, src_side,radius_left,par_muts,lower_bound,tag,reachable
#ifdef CHECK_BOUND
,do_continue
#endif
Expand Down
50 changes: 36 additions & 14 deletions src/matOptimize/Profitable_Moves_Enumerators/upward_integrated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,26 @@ void output_LCA(
template<typename T>
static void search_subtree_first_level(MAT::Node *node, MAT::Node *to_exclude,
const src_side_info &src_side, int radius_left,
Bounded_Mut_Change_Collection &either, T& ignored_range) {
Bounded_Mut_Change_Collection &either, T& ignored_range,Reachable reachable) {
for (auto child : node->children) {
if (child == to_exclude) {
continue;
} else {
search_subtree_bounded(child, src_side, radius_left - 1, either,
src_side.src_par_score_lower_bound,ignored_range
}
auto reachable_child=reachable;
if (!reachable.always_search) {
if (!child->get_descendent_changed()) {
continue;
}
if (reachable.reachable_change&&child->get_self_changed()) {
reachable_child.always_search=true;
}
}
search_subtree_bounded(child, src_side, radius_left - 1, either,
src_side.src_par_score_lower_bound,ignored_range,reachable_child
#ifdef CHECK_BOUND
,true
#endif
);
}
);
}
}
static void allele_count_reserve(
Expand Down Expand Up @@ -220,7 +228,7 @@ template <typename T,typename S>
static bool
upward_integrated(src_side_info &src_side,
std::vector<Mutation_Count_Change_W_Lower_Bound_to_ancestor> &src_mut_in, int radius_left,
std::vector<Mutation_Count_Change_W_Lower_Bound_to_ancestor> &mut_out, const T &src_branch, S ignore_iter) {
std::vector<Mutation_Count_Change_W_Lower_Bound_to_ancestor> &mut_out, const T &src_branch, S ignore_iter,Reachable reachable) {
auto old_LCA=src_side.LCA;
MAT::Node *node = old_LCA->parent;
if (!node) {
Expand Down Expand Up @@ -306,7 +314,7 @@ upward_integrated(src_side_info &src_side,
src_side.LCA = node;
sibling_muts.emplace_back();
search_subtree_first_level(node, old_LCA, src_side, radius_left,
sibling_muts,ignore_iter);
sibling_muts,ignore_iter,reachable);



Expand All @@ -321,17 +329,28 @@ template<typename T>
void __find_moves_bounded(MAT::Node *&src, int &search_radius,
std::vector<Mutation_Count_Change_W_Lower_Bound_to_ancestor> &src_mut,
std::vector<Mutation_Count_Change_W_Lower_Bound_to_ancestor> &src_mut_next,
src_side_info &src_side, T ignored_pos) {
src_side_info &src_side, T ignored_pos,Reachable reachable) {
upward_integrated(src_side, src_mut, search_radius, src_mut_next,
src->mutations,ignored_pos);
src->mutations,ignored_pos,reachable);
for (int radius_left = search_radius - 1; radius_left > 0; radius_left--) {
src_mut.swap(src_mut_next);
src_mut_next.clear();
if (!src_side.LCA) {
break;
}
if (!reachable.always_search) {
if (src_side.LCA->get_self_changed()&&reachable.reachable_change) {
reachable.always_search=true;
}
if(!src_side.LCA->get_ancestor_changed()){
break;
}
}
upward_integrated(src_side, src_mut, radius_left, src_mut_next,
src_side.allele_count_change_from_src,ignored_pos);
src_side.allele_count_change_from_src,ignored_pos,reachable);
}
}
void find_moves_bounded(MAT::Node *src, output_t &out, int search_radius,bool do_drift
void find_moves_bounded(MAT::Node *src, output_t &out, int search_radius,bool do_drift,Reachable reachable
#ifdef CHECK_BOUND
,
counters &count
Expand All @@ -346,6 +365,9 @@ void find_moves_bounded(MAT::Node *src, output_t &out, int search_radius,bool do
#else
src_side_info src_side {out,par_score_change_base,par_score_change_base,src,src};
#endif
if (reachable.reachable_change&&src->get_self_moved()) {
reachable.always_search=true;
}
for (const auto& mut : src->mutations) {
if (mut.get_all_major_allele()==0xf||mut.get_par_one_hot()==mut.get_all_major_allele()) {
continue;
Expand All @@ -355,8 +377,8 @@ void find_moves_bounded(MAT::Node *src, output_t &out, int search_radius,bool do
//sentinel
src_mut.emplace_back();
if (src->ignore.empty()) {
__find_moves_bounded(src, search_radius, src_mut, src_mut_next, src_side,ignore_ranger_nop{});
__find_moves_bounded(src, search_radius, src_mut, src_mut_next, src_side,ignore_ranger_nop{},reachable);
} else {
__find_moves_bounded(src, search_radius, src_mut, src_mut_next, src_side,ignore_ranger{src->ignore});
__find_moves_bounded(src, search_radius, src_mut, src_mut_next, src_side,ignore_ranger{src->ignore},reachable);
}
}
2 changes: 1 addition & 1 deletion src/matOptimize/apply_move/backward_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void reassign_backward_pass(
#endif
);
if (changed) {
changed_nodes.push_back(heap->altered_node->identifier);
heap->altered_node->set_self_changed();
}
} while (heap.next(changed));
}
2 changes: 1 addition & 1 deletion src/matOptimize/apply_move/forward_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void set_state_from_parent(MAT::Node *node,
MAT::Tree &new_tree
#endif
) {
changed_nodes.push_back(node->identifier);
node->set_self_changed();
MAT::Mutations_Collection new_mut;
auto iter = parent_altered.begin();
auto end = parent_altered.end();
Expand Down
14 changes: 8 additions & 6 deletions src/matOptimize/apply_move/move_node_no_reassign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ clean_up_after_remove(MAT::Node *node, std::unordered_set<size_t> &deleted,
MAT::Mutations_Collection::KEEP_SELF);
}*/
tree.all_nodes.erase(node->identifier);
child->set_self_changed();
//delete node;
return parent_node;
}
Expand Down Expand Up @@ -349,6 +350,7 @@ static MAT::Node *place_node_LCA(MAT::Node *&src, MAT::Node *parent,
update_src_mutation(src, this_unique);
MAT::Node *new_node = add_as_sibling(src, sibling, other_unique, common,
tree, flags, nodes_to_clean);
new_node->set_self_changed();
return new_node->parent;
}

Expand Down Expand Up @@ -419,25 +421,25 @@ void move_node(MAT::Node *src, MAT::Node *dst,
src_parent_children.erase(iter);

nodes_to_clean.push_back(src);
changed_nodes.push_back(src->identifier);
src->set_self_changed();
nodes_to_clean.push_back(dst);
changed_nodes.push_back(dst->identifier);

dst->set_self_changed();
dst->set_self_moved();
MAT::Node *dst_altered = dst;
//actually placing the node
if (dst_to_root_path.empty()) {
dst_altered = place_node_LCA(src, dst, tree, mutations,
src_to_root_path.back(), nodes_to_clean);
changed_nodes.push_back(src_to_root_path.back()->identifier);
src_to_root_path.back()->set_self_changed();
} else {
dst_altered = place_node(src, dst, tree, mutations, nodes_to_clean);
}
//push nodes with altered children for backward pass
altered_node.push_back(
clean_up_after_remove(src_parent, deleted, nodes_to_clean,tree));
changed_nodes.push_back(altered_node.back()->identifier);
altered_node.back()->set_self_changed();
altered_node.push_back(dst_altered);
changed_nodes.push_back(altered_node.back()->identifier);
altered_node.back()->set_self_changed();
#ifdef CHECK_PRIMARY_MOVE
MAT::Mutations_Collection after_move;
get_mutation_set_from_root(src, after_move);
Expand Down
1 change: 1 addition & 0 deletions src/matOptimize/detailed_mutations_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ struct Load_Subtree_pararllel : public tbb::task {
Mutation_Detailed::node node;
node.ParseFromCodedStream(&inputi);
out->identifier = node.identifier();
out->changed=node.changed();
// deserialize ignored range
size_t ignore_range_size = node.ignored_range_end_size();
int ignored_size = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/matOptimize/detailed_mutations_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ struct no_serialize_condensed_node {
};
static void serialize_node(Mutation_Detailed::node &this_node,
const MAT::Node *root, const MAT::Tree &tree) {
if (root->identifier=="s476s") {
fputc('a',stderr);
}
this_node.set_identifier(root->identifier);
this_node.set_changed(root->changed);
this_node.mutable_mutation_positions()->Reserve(root->mutations.size());
this_node.mutable_mutation_other_fields()->Reserve(root->mutations.size());
for (const auto &mut : root->mutations) {
Expand Down
Loading

0 comments on commit 9917a94

Please sign in to comment.