@@ -466,7 +466,7 @@ double PartitionModel::computeMarginalLh() {
466466 sub_tree2->copyTree (tree2);
467467 }
468468
469- if (inter_seqs_id.size () == 2 ) {
469+ if (inter_seqs_id.size () == 2 && tree2-> getModel ()-> isReversible () ) {
470470 // if only two seqs in the subset
471471 // add a gappy seq two the sub_aln
472472 string gappy_seq = " gappy_seq" ;
@@ -565,113 +565,8 @@ double PartitionModel::computeMarginalLh() {
565565 sub_tree2->aln = NULL ;
566566 delete sub_tree2;
567567 delete[] ptn_lh_array;
568- /*
569- } else if (inter_seqs_id.size() == 2) {
570- //AlignmentPairwise aln_pair(tree2, inter_seqs_id[0], inter_seqs_id[1]);
571- //double site_lh = aln_pair.computeFunction(1);
572-
573- //compute the distance between the tree nodes of the two "overlapping" taxa
574- auto it = inter_seqs.begin();
575- string inter_seq1 = *it;
576- Node *node1 = tree2->findLeafName(inter_seq1);
577- ++it;
578- string inter_seq2 = *it;
579- Node *node2 = tree2->findLeafName(inter_seq2);
580- double branch_len = tree2->pairDist(node1, node2, node1);
581-
582- //compute the transition probobility matrix based on tree2
583- RateHeterogeneity *site_rate = tree2->getRate();
584- int ncat = site_rate->getNDiscreteRate();
585- int trans_size = tree2->getModel()->getTransMatrixSize();
586- double *trans_matrix = new double[trans_size];
587- double *sum_trans_matrix = new double[trans_size];
588-
589- if (tree2->getModelFactory()->site_rate->getGammaShape() == 0.0)
590- tree2->getModelFactory()->computeTransMatrix(branch_len, sum_trans_matrix);
591- else {
592- tree2->getModelFactory()->computeTransMatrix(branch_len * site_rate->getRate(0), sum_trans_matrix);
593- for (int cat = 1; cat < ncat; cat++) {
594- tree2->getModelFactory()->computeTransMatrix(branch_len * site_rate->getRate(cat), trans_matrix);
595- for (int i = 0; i < trans_size; i++)
596- sum_trans_matrix[i] += trans_matrix[i];
597- }
598- }
599-
600- // take the log for the transition probobility matrix
601- vector<double> log_sum_trans_matrix(trans_size);
602- for (int n = 0; n < trans_size; n++) {
603- log_sum_trans_matrix[n] = log(sum_trans_matrix[n]);
604- }
605-
606- for (int l = 0; l < tree1_nsite; l++) {
607- double site_lh = 0.0;
608- Pattern p = tree1_aln->at(tree1_aln->getPatternID(l));
609- int state1 = p[inter_seqs_id[0]];
610- int state2 = p[inter_seqs_id[1]];
611-
612- // compute the site log-likelihood of the two "overlaping" sequences.
613- if (state1 < n_states && state2 < n_states) {
614- site_lh = log_sum_trans_matrix[state1 * n_states + state2] + log_state_freq[state1];
615- } else if (state1 >= n_states && state2 < n_states) {
616- // compute ambiguous frequencies
617- int cstate1 = state1 - n_states + 1;
618- double amb_lh = 0.0;
619- for (int m = 0; m < n_states; m++) {
620- if ((cstate1) & (1 << m)) {
621- amb_lh = sum_trans_matrix[m * n_states + state2] * state_freq[m];
622- site_lh *= amb_lh;
623- }
624- }
625- site_lh = log(site_lh);
626- } else if (state2 >= n_states && state1 < n_states) {
627- // compute ambiguous frequencies
628- int cstate2 = state2-n_states+1;
629- double amb_lh = 0.0;
630- for (int m = 0; m < n_states; m++) {
631- if ((cstate2) & (1 << m)) {
632- amb_lh = sum_trans_matrix[state1 * n_states + m] * state_freq[state1];
633- site_lh *= amb_lh;
634- }
635- }
636- site_lh = log(site_lh);
637- } else {
638- // compute ambiguous frequencies
639- int cstate1 = state1-n_states+1;
640- int cstate2 = state2-n_states+1;
641- double amb_lh = 0.0;
642- for (int m = 0; m < n_states; m++) {
643- for (int n = 0; n < n_states; n++) {
644- if (((cstate1) & (1 << m)) && ((cstate2) & (1 << n))) {
645- amb_lh = sum_trans_matrix[m * n_states + n] * state_freq[m];
646- site_lh *= amb_lh;
647- }
648- }
649- }
650- site_lh = log(site_lh);
651- }
652-
653- for (int missing_id: missing_seqs_id) {
654- int char_id = p[missing_id];
655- if (char_id < n_states) {
656- site_lh += log_state_freq[char_id];
657- } else {
658- // compute ambiguous frequencies
659- int cstate = char_id-n_states+1;
660- double amb_freq = 0;
661- for (int m = 0; m < n_states; m++) {
662- if ((cstate) & (1 << m)) {
663- amb_freq += state_freq[m];
664- }
665- }
666- site_lh += log(amb_freq);
667- }
668- }
669- lh_array[tree1_nsite * k + l] = site_lh;
670- }
671- delete[] trans_matrix;
672- delete[] sum_trans_matrix;
673- */
674- } else {
568+ } else if (tree2->getModel ()->isReversible ()) {
569+ // case when the intersection of taxon sets is 1
675570 for (int l = 0 ; l < tree1_nsite; l++) {
676571 double site_lh = 0.0 ;
677572 Pattern p = tree1_aln->at (tree1_aln->getPatternID (l));
@@ -705,6 +600,9 @@ double PartitionModel::computeMarginalLh() {
705600 }
706601 lh_array[tree1_nsite * k + l] = site_lh;
707602 }
603+ } else {
604+ // intersection has only 1 taxon and non-reversible model
605+ outError (" mAIC calculation doesn't work yet for intersection of 1 taxon and non-reversible model" );
708606 }
709607 delete[] state_freq;
710608 }
0 commit comments