int find_node(thread_t& t, xg::XG::ThreadMapping node, int hint) { if(hint > t.size()) { hint = (t.size() - 1)/2; } if(t[hint].node_id == node.node_id && t[hint].is_reverse == node.is_reverse) { return hint; } else { int above = t.size() - hint; int bound = max(above,hint); int search_up = hint; int search_down = hint; for(int i = 1; i < bound; i++) { if(search_up < t.size() - 1) { search_up++; if(t[search_up].node_id == node.node_id && t[search_up].is_reverse == node.is_reverse) { return search_up; } } if(search_down > 0) { search_down--; if(t[search_down].node_id == node.node_id && t[search_down].is_reverse == node.is_reverse) { return search_down; } } } } // wasn't found! return -1; }
void rectangle::simple_extend(thread_t& extension, xg::XG& graph, int delta_start = 0, int delta_end = 0) { if(extension.size() > 0) { xg::XG::ThreadMapping next_node = extension.back(); int64_t next_side = graph.id_to_rank(next_node.node_id) * 2 + next_node.is_reverse; state.current_side = next_side; } state.range_start -= delta_start; state.range_end -= delta_end; }
int rectangle::get_next_J(thread_t& extension, XG& graph) { if(extension.size() == 1) { return get_next_J(extension.back(), graph); } else { xg::XG::ThreadMapping second_last_node = extension.end()[-2]; state.current_side = graph.id_to_rank(second_last_node.node_id) * 2 + second_last_node.is_reverse; extend(extension.back(), graph); J = state.count(); return state.count(); } }
~delayed_thread() { if(m_state == DISMISSED) { return; } trigger(); if(m_thread.joinable()) { m_thread.join(); } }
void zmq::thread_ctx_t::start_thread (thread_t &thread_, thread_fn *tfn_, void *arg_) const { static unsigned int nthreads_started = 0; thread_.setSchedulingParameters (_thread_priority, _thread_sched_policy, _thread_affinity_cpus); thread_.start (tfn_, arg_); #ifndef ZMQ_HAVE_ANDROID std::ostringstream s; if (!_thread_name_prefix.empty ()) s << _thread_name_prefix << "/"; s << "ZMQbg/" << nthreads_started; thread_.setThreadName (s.str ().c_str ()); #endif nthreads_started++; }
bool check_if_thread_t_broken(const thread_t& t, XG& graph) { bool broken = false; XG::ThreadMapping current_node = t[0]; for(int i = 1; i < t.size(); i++) { XG::ThreadMapping next_node = t[i]; bool edge_exists = check_for_edges(current_node.node_id, current_node.is_reverse, next_node.node_id, next_node.is_reverse, graph); if(!edge_exists) { broken = true; break; } current_node = next_node; } return broken; }
haplo_d::haplo_d(const thread_t& t, XG& graph) { rectangle rect; rect.J = rect.get_next_J(t[0],graph); // At the leftmost node there is only one strip, so I = J rect.I = rect.J; int last_height = rect.J; cs.push_back(cross_section(rect.J,0,t[0])); cs.back().S.push_back(rect); int width = 0; int new_height; bool add_rectangle; bool add_A; for(int i = 1; i < t.size(); i++) { // Count the number of base pairs since the last entry or exit node width += graph.node_length(t[i-1].node_id); new_height = graph.node_height(t[i]); if(cs.back().S.size() != 0) { rect = cs.back().S[0]; rect.J = rect.get_next_J(t[i],graph); // step this strip forward // Did any threads leave? if(last_height > rect.J) { add_A = 1; } // Are there any threads here which didn't come from the previous node? if(rect.J < new_height) { add_rectangle = 1; add_A = 1; } // This is an entry or exit node, add a cross-section to the vector of // cross-sections (which corresponds to the "A" set in the theory doc) if(add_A) { cs.back().width = width; width = 0; cs.push_back(cross_section(new_height,i,t[i])); } else { // This isn't a node where anything leaves or joins, let's skip over it cs.back().bridge.push_back(t[i]); for (size_t a = 0; a < cs.back().S.size(); a++) { cs.back().S[a].extend(t[i],graph); } } // This is an entry node; we also need a new rectangle corresponding to the // new strip. We need to do this *before* we populate since cross_sections // arrange rectangles newest -> oldest // NB that add_rectangle implies add_A if(add_rectangle) { rectangle new_rect; new_rect.extend(t[i],graph); new_rect.J = new_height; cs.back().height = new_rect.J; cs.back().S.push_back(new_rect); cs.back().S.back().I = new_rect.J - rect.J; } if(add_A) { int b = cs.size()-1; if(rect.J > 0) { cs[b].S.push_back(rect); cs[b].S.back().prev = 0; cs[b-1].S[0].next = cs[b].S.size()-1; } } last_height = new_height; add_A = 0; add_rectangle = 0; } else { cs.back().width = width; width = 0; cs.push_back(cross_section(new_height,i,t[i])); if(new_height > 0) { rectangle new_rect; new_rect.extend(t[i],graph); new_rect.J = new_height; cs.back().height = new_rect.J; cs.back().S.push_back(new_rect); cs.back().S.back().I = new_rect.J - rect.J; } } } if(cs.size() == 1) { cs.back().width = width; } cs.back().width += graph.node_length(t.back().node_id) - 1; for(int i = 0; i < cs.size(); i++) { tot_width += cs[i].width; } }
int find_node(thread_t& t, xg::XG::ThreadMapping node) { int hint = (t.size() - 1)/2; return find_node(t, node, hint); }
void haplo_d::initialize_skeleton(thread_t& t, int start, cross_section& prevAs, xg::XG& graph) { assert(cs.size() == 0); initialize_skeleton(t, make_pair(start, t.size()-1), prevAs, graph); }
void zmq::ctx_t::start_thread (thread_t &thread_, thread_fn *tfn_, void *arg_) const { thread_.start(tfn_, arg_); thread_.setSchedulingParameters(thread_priority, thread_sched_policy); }