Debian Codegraph @

src/dr/evomodel/alloppnet/speciation/AlloppMSCoalescent.java

raw symbols SCIP
1 /*
2 * AlloppMSCoalescent.java
3 *
4 * Copyright (c) 2002-2017 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evomodel.alloppnet.speciation;
27
28
29 import dr.evolution.util.Units;
30 import dr.inference.model.Likelihood;
31
32
33 /**
34 * Computes coalescent log-likelihood of a set of gene trees embedded inside a
35 * allopolyploid species network.
36 *
37 * @author Graham Jones
38 * Date: 03/06/2011
39 */
40
41
42 /*
43 * AlloppMSCoalescent, AlloppSpeciesNetworkModel, AlloppLeggedTree,
44 * AlloppDiploidHistory, and AlloppSpeciesBindings collaborate closely.
45 *
46 * AlloppSpeciesNetworkModel contains an AlloppDiploidHistory and an array of
47 * AlloppLeggedTree's for representing the tetraploid trees. It also contains a
48 * multiply labelled tree as an alternative representation.
49 *
50 * AlloppSpeciesBindings represents the species-individual-genome structure
51 * of the data, and contains the gene trees.
52 *
53 * This module, AlloppMSCoalescent, uses AlloppSpeciesNetworkModel and
54 * AlloppSpeciesBindings to calculate P(g_i|S) = probability that gene tree
55 * g_i fits into network S.
56 *
57 * apsp.geneTreeFitsInNetwork calls
58 * FitsInNetwork (inside a gene tree) calls
59 * subTreeFitsInNetwork (recursive, inside a gene tree) calls
60 * CoalescenceIsCompatible to test a single coalescence against mullab tree
61 *
62 * apsp.geneTreeLogLikelihood calls
63 * TreeLogLikelihood (inside a gene tree) calls
64 * clearCoalescences (in mullab tree) and
65 * recordCoalescence (in mullab tree) and
66 * recordLineageCounts (in mullab tree) and
67 * to set up data in mullab tree nodes, then
68 * mullabTreeLogLikelihood which calls
69 * mullabSubTreeLogLikelihood (recursive, in mullab tree) calls
70 * limbLogLike calls
71 * limbLinPopIntegral
72 *
73 */
74
75
76
77
78 public class AlloppMSCoalescent extends Likelihood.Abstract implements Units {
79 private final AlloppSpeciesNetworkModel asnetwork;
80 private final AlloppSpeciesBindings apsp;
81
82
83
84 public AlloppMSCoalescent(AlloppSpeciesBindings apspecies, AlloppSpeciesNetworkModel apspnetwork) {
85 super(apspnetwork);
86 apsp = apspecies;
87 asnetwork = apspnetwork;
88
89 asnetwork.addModelListener(this);
90 apsp.addModelListeners(this);
91 }
92
93
94
95 @Override
96 protected double calculateLogLikelihood() {
97 for (int i = 0; i < apsp.numberOfGeneTrees(); i++) {
98 if (!apsp.geneTreeFitsInNetwork(i, asnetwork)) {
99 return Double.NEGATIVE_INFINITY;
100 }
101 }
102 // grjtodo-oneday JH has compatible flags for efficiency. I'm checking
103 // every time.
104
105 double logl = 0;
106 for(int i = 0; i < apsp.numberOfGeneTrees(); i++) {
107 final double v = apsp.geneTreeLogLikelihood(i, asnetwork);
108 assert ! Double.isNaN(v);
109 logl += v;
110 }
111 return logl;
112 }
113
114
115 @Override
116 protected boolean getLikelihoodKnown() {
117 return false;
118 }
119
120
121 public Type getUnits() {
122 return asnetwork.getUnits();
123 }
124
125 public void setUnits(Type units) {
126 // TODO Auto-generated method stub
127 // one day may allow units other than substitutions
128
129 }
130
131
132
133 }