/
intrahost_model.go
204 lines (164 loc) · 4.66 KB
/
intrahost_model.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package contagiongo
import (
"math"
rv "github.com/kentwait/randomvariate"
)
// IntrahostModel is an interface for any type of intrahost model.
type IntrahostModel interface {
ModelID() int
ModelName() string
SetModelID(id int)
SetModelName(name string)
// Mutation
// MutationRate returns the mutation rate for this model.
MutationRate() float64
// TransitionMatrix returns the conditioned mutation rate matrix
// for this model.
TransitionMatrix() [][]float64
// TransitionProbs returns the conditioned transition probabilities
// for the given state.
TransitionProbs(char int) []float64
// Replication
// MaxPathogenPopSize returns the maximum number of pathogens allowed within
// a single host of this particular host type.
MaxPathogenPopSize() int
// NextPathogenPopSize returns the pathogen population size for the next
// generation of pathogens given the current population size.
// This is used in conjunction with a population model under
// relative fitness.
NextPathogenPopSize(n int) int
// ReplicationMethod returns whether relative, or absolute is used.
ReplicationMethod() string
// Recombination
// RecombinationRate returns the recombination rate for this model.
RecombinationRate() float64
// Infection duration
// StatusDuration
StatusDuration(status int) int
ProbabilisticDuration() bool
}
// ConstantPopModel models a constant pathogen population size within the host.
type ConstantPopModel struct {
modelMetadata
mutationParams
recombinationParams
durationParams
constantIntrahostPopModel
}
// BevertonHoltThresholdPopModel uses the Beverton-Holt population model
// modified to have a constant threshold population size.
type BevertonHoltThresholdPopModel struct {
modelMetadata
mutationParams
recombinationParams
durationParams
bhtIntrahostPopModel
}
// FitnessDependentPopModel does not use a population model to determine the
// population of pathogens. Instead population size is dependent on fitness
// which is implemented outside of this model.
// The NextPathogenPopSize method for this model always returns -1 regardless
// of the input value.
type FitnessDependentPopModel struct {
modelMetadata
mutationParams
recombinationParams
durationParams
fitnessIntrahostPopModel
}
type modelMetadata struct {
id int
name string
}
func (meta *modelMetadata) ModelID() int {
return meta.id
}
func (meta *modelMetadata) ModelName() string {
return meta.name
}
func (meta *modelMetadata) SetModelID(id int) {
meta.id = id
}
func (meta *modelMetadata) SetModelName(name string) {
meta.name = name
}
type mutationParams struct {
mutationRate float64
transitionMatrix [][]float64
}
func (params *mutationParams) MutationRate() float64 {
return params.mutationRate
}
func (params *mutationParams) TransitionMatrix() [][]float64 {
return params.transitionMatrix
}
func (params *mutationParams) TransitionProbs(char int) []float64 {
return params.transitionMatrix[char]
}
type recombinationParams struct {
recombinationRate float64
}
func (params *recombinationParams) RecombinationRate() float64 {
return params.recombinationRate
}
type durationParams struct {
statusDuration map[int]int
probDuration bool
}
func (params *durationParams) StatusDuration(status int) int {
if params.probDuration {
return rv.Poisson(float64(params.statusDuration[status]))
}
return params.statusDuration[status]
}
func (params *durationParams) ProbabilisticDuration() bool {
return params.probDuration
}
type constantIntrahostPopModel struct {
popSize int
}
func (m *constantIntrahostPopModel) MaxPathogenPopSize() int {
return m.popSize
}
func (m *constantIntrahostPopModel) NextPathogenPopSize(n int) int {
return m.popSize
}
func (m *constantIntrahostPopModel) ReplicationMethod() string {
return "relative"
}
type bhtIntrahostPopModel struct {
maxPopSize int
growthRate float64
}
func (m *bhtIntrahostPopModel) MaxPathogenPopSize() int {
return m.maxPopSize
}
func (m *bhtIntrahostPopModel) NextPathogenPopSize(n int) int {
n64 := float64(n)
k64 := float64(m.maxPopSize)
res := (m.growthRate * n64 * k64) / (k64 + ((m.growthRate - 1.0) * n64))
roundedRes := int(math.Ceil(res))
if m.maxPopSize > roundedRes {
return roundedRes
}
return m.maxPopSize
}
func (m *bhtIntrahostPopModel) GrowthRate() float64 {
return m.growthRate
}
func (m *bhtIntrahostPopModel) ReplicationMethod() string {
return "relative"
}
type fitnessIntrahostPopModel struct {
maxPopSize int
}
func (m *fitnessIntrahostPopModel) MaxPathogenPopSize() int {
return m.maxPopSize
}
func (m *fitnessIntrahostPopModel) NextPathogenPopSize(n int) int {
// Not applicable
return -1
}
func (m *fitnessIntrahostPopModel) ReplicationMethod() string {
return "absolute"
}