Skip to content

Commit 7e1d6eb

Browse files
committed
Adjusted CD4 calculation ordering to make sense.
1 parent 562adcc commit 7e1d6eb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/hivpy/resistance_mutations.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,18 @@ def calc_cd4_delta(self, age, sex, active_drugs, cont_on_art, adherence, adheren
343343

344344
# calculate change in cd4
345345
cd4_delta = base_cd4_recovery_on_art + cd4_recovery_on_art * x
346-
cd4 = max(0, cd4_tm1 + cd4_delta)
347-
348-
# changes for people on PrEP/ART
346+
# changes for people on antiretroviral drugs
349347
if on_prep or on_art:
350-
# adjust cd4 delta for higher cd4 levels
348+
# adjust cd4 delta for higher previous cd4 levels
351349
if 100 < cd4_tm1 <= 200:
352350
cd4_delta *= 0.85
353351
elif cd4_tm1 > 200:
354352
cd4_delta *= 0.7
353+
354+
# calculate current cd4 levels
355+
cd4 = max(0, cd4_tm1 + cd4_delta)
356+
# changes for people on antiretroviral drugs
357+
if on_prep or on_art:
355358
# add cd4 variability
356359
cd4 = np.sqrt(cd4) + self.cd4_stdev_on_art * rng.normal() ** 2
357360
# adjust cd4 according to max value

src/tests/test_resistance_mutations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ def test_calc_cd4_delta():
103103

104104
# check adjustments on ARV
105105
# 6 + 0.2 * 6 = 12 >> 12 * 0.85 = 10.2
106-
# 150 + 12 = 162 >> sqrt(162) + cd4_stdev_on_art * rng.normal() ** 2
106+
# 150 + 10.2 = 160.2 >> sqrt(160.2) + cd4_stdev_on_art * rng.normal() ** 2
107107
cd4, delta = res.calc_cd4_delta(20, SexType.Male, 3, timedelta(months=6), 0.8, 0.8,
108108
False, False, False, False, False, False, 150, 0.2, 200, True, False)
109-
assert sqrt(162) - res.cd4_stdev_on_art * 3 <= cd4 <= sqrt(162) + res.cd4_stdev_on_art * 3
109+
assert sqrt(160.2) - res.cd4_stdev_on_art * 3 <= cd4 <= sqrt(160.2) + res.cd4_stdev_on_art * 3
110110
assert isclose(delta, 10.2)
111111

112112
# check max cd4 cap on ARV

0 commit comments

Comments
 (0)