efloat_t prior_HMM_rootless_scale(const data_partition& P) { const Tree& T = *P.T; #ifndef NDEBUG assert(P.has_IModel()); check_internal_nodes_connected(*P.A,T); #endif efloat_t Pr = 1; for(int i=T.n_leaves();i<T.n_nodes();i++) { int l = P.seqlength(i); efloat_t temp = P.IModel().lengthp(l); Pr /= (temp*temp); } return Pr; }
/// Probability of a multiple alignment if branch alignments independant efloat_t prior_HMM_nogiven(const data_partition& P) { const alignment& A = *P.A; const Tree& T = *P.T; #ifndef NDEBUG assert(P.has_IModel()); check_internal_nodes_connected(A,T); #endif efloat_t Pr = 1; for(int b=0;b<T.n_branches();b++) { int target = T.branch(b).target(); int source = T.branch(b).source(); Pr *= prior_branch(A, P.branch_HMMs[b], target, source); } return Pr; }
boost::shared_ptr<DPmatrixSimple> sample_alignment_base(data_partition& P,int b) { assert(P.has_IModel()); dynamic_bitset<> s1 = constraint_satisfied(P.alignment_constraint, *P.A); const Tree& T = *P.T; //FIXME - partitions data_partition P0 = P; // We COULD make this conditional... perhaps we should //FIXME - partitions alignment& old = *P0.A; const Matrix frequency = substitution::frequency_matrix(P.SModel()); int node1 = T.branch(b).target(); int node2 = T.branch(b).source(); dynamic_bitset<> group1 = T.partition(node2,node1); // Find sub-alignments and sequences vector<int> seq1; vector<int> seq2; vector<int> seq12; for(int column=0;column<old.length();column++) { if (not old.gap(column,node1)) seq1.push_back(column); if (not old.gap(column,node2)) seq2.push_back(column); if (not old.gap(column,node1) or old.gap(column,node2)) seq12.push_back(column); } //FIXME - this makes the debug routines crash if (not seq1.size() or not seq2.size()) return boost::shared_ptr<DPmatrixSimple>(); //NULL; /******** Precompute distributions at node2 from the 2 subtrees **********/ distributions_t_local distributions = distributions_tree; if (not P.smodel_full_tree) distributions = distributions_star; vector< Matrix > dists1 = distributions(P0,seq1,b,true); vector< Matrix > dists2 = distributions(P0,seq2,b,false); vector<int> state_emit(4,0); state_emit[0] |= (1<<1)|(1<<0); state_emit[1] |= (1<<1); state_emit[2] |= (1<<0); state_emit[3] |= 0; boost::shared_ptr<DPmatrixSimple> Matrices( new DPmatrixSimple(state_emit, P.branch_HMMs[b].start_pi(), P.branch_HMMs[b], P.beta[0], P.SModel().distribution(), dists1, dists2, frequency) ); //------------------ Compute the DP matrix ---------------------// vector<int> path_old = get_path(old,node1,node2); vector<vector<int> > pins = get_pins(P.alignment_constraint,old,group1,~group1,seq1,seq2,seq12); vector<int> path = Matrices->forward(pins); path.erase(path.begin()+path.size()-1); *P.A = construct(old,path,node1,node2,T,seq1,seq2); P.LC.set_length(P.A->length()); P.LC.invalidate_branch_alignment(T,b); P.note_alignment_changed_on_branch(b); #ifndef NDEBUG_DP assert(valid(*P.A)); dynamic_bitset<> s2 = constraint_satisfied(P.alignment_constraint, *P.A); report_constraints(s1,s2); vector<int> path_new = get_path(*P.A, node1, node2); path.push_back(3); assert(path_new == path); #endif return Matrices; }