| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evomodel.transmission; |
| 27 |
|
| 28 |
import dr.evolution.coalescent.Intervals; |
| 29 |
import dr.evolution.tree.NodeRef; |
| 30 |
import dr.evolution.tree.Tree; |
| 31 |
import dr.evolution.util.Taxa; |
| 32 |
import dr.evolution.util.TaxonList; |
| 33 |
import dr.evomodel.coalescent.DemographicModel; |
| 34 |
import dr.xml.*; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public class TransmissionSimulator { |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static final String TRANSMISSION_SIMULATOR = "transmissionSimulator"; |
| 53 |
public static final String SOURCE_PATIENT = "sourcePatient"; |
| 54 |
|
| 55 |
public TransmissionSimulator(Taxa taxa, Tree hostTree, DemographicModel demographic) |
| 56 |
throws TaxonList.MissingTaxonException { |
| 57 |
this(TRANSMISSION_SIMULATOR, taxa, hostTree, demographic); |
| 58 |
} |
| 59 |
|
| 60 |
public TransmissionSimulator(String name, Taxa taxa, Tree hostTree, DemographicModel demographic) |
| 61 |
throws TaxonList.MissingTaxonException { |
| 62 |
|
| 63 |
this.hostTree = hostTree; |
| 64 |
|
| 65 |
setupHosts(); |
| 66 |
} |
| 67 |
|
| 68 |
private void setupHosts() { |
| 69 |
|
| 70 |
hostCount = hostTree.getTaxonCount(); |
| 71 |
|
| 72 |
intervals = new Intervals[hostCount]; |
| 73 |
for (int i = 0; i < hostCount; i++) { |
| 74 |
|
| 75 |
intervals[i] = new Intervals(virusTree.getExternalNodeCount() * 3); |
| 76 |
} |
| 77 |
donorHost = new int[hostCount]; |
| 78 |
donorHost[0] = -1; |
| 79 |
transmissionTime = new double[hostCount]; |
| 80 |
transmissionTime[0] = Double.POSITIVE_INFINITY; |
| 81 |
|
| 82 |
setupHosts(hostTree.getRoot()); |
| 83 |
} |
| 84 |
|
| 85 |
private int setupHosts(NodeRef node) { |
| 86 |
|
| 87 |
int host; |
| 88 |
|
| 89 |
if (hostTree.isExternal(node)) { |
| 90 |
host = node.getNumber(); |
| 91 |
} else { |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
int host1 = setupHosts(hostTree.getChild(node, 0)); |
| 97 |
int host2 = setupHosts(hostTree.getChild(node, 1)); |
| 98 |
|
| 99 |
donorHost[host2] = host1; |
| 100 |
transmissionTime[host2] = hostTree.getNodeHeight(node); |
| 101 |
|
| 102 |
host = host1; |
| 103 |
} |
| 104 |
|
| 105 |
return host; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 113 |
|
| 114 |
public String getParserName() { return TRANSMISSION_SIMULATOR; } |
| 115 |
|
| 116 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 117 |
|
| 118 |
DemographicModel demoModel0 = (DemographicModel)xo.getElementFirstChild(SOURCE_PATIENT); |
| 119 |
TransmissionDemographicModel demoModel1 = (TransmissionDemographicModel)xo.getChild(TransmissionDemographicModel.class); |
| 120 |
Tree hostTree = (Tree)xo.getElementFirstChild("hostTree"); |
| 121 |
Tree virusTree = (Tree)xo.getElementFirstChild("parasiteTree"); |
| 122 |
|
| 123 |
TransmissionSimulator simulator = null; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
return simulator; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public String getParserDescription() { |
| 137 |
return "This element represents a simulator for a transmission history."; |
| 138 |
} |
| 139 |
|
| 140 |
public Class getReturnType() { return TransmissionSimulator.class; } |
| 141 |
|
| 142 |
public XMLSyntaxRule[] getSyntaxRules() { return rules; } |
| 143 |
|
| 144 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[] { |
| 145 |
new ElementRule(SOURCE_PATIENT, DemographicModel.class, |
| 146 |
"This describes the demographic process for the source donor patient."), |
| 147 |
new ElementRule(TransmissionDemographicModel.class, |
| 148 |
"This describes the demographic process for the recipient patients."), |
| 149 |
new ElementRule("hostTree", |
| 150 |
new XMLSyntaxRule[] { new ElementRule(Tree.class) }), |
| 151 |
new ElementRule("parasiteTree", |
| 152 |
new XMLSyntaxRule[] { new ElementRule(Tree.class) }) |
| 153 |
}; |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
private Tree hostTree = null; |
| 158 |
|
| 159 |
|
| 160 |
private Tree virusTree = null; |
| 161 |
|
| 162 |
|
| 163 |
private int hostCount; |
| 164 |
|
| 165 |
|
| 166 |
private Intervals[] intervals; |
| 167 |
|
| 168 |
|
| 169 |
private int[] donorHost; |
| 170 |
|
| 171 |
|
| 172 |
private double[] transmissionTime; |
| 173 |
|
| 174 |
} |