Skip to content

Commit e8540af

Browse files
committed
Get concentration/factors from most granular PKPD time to WH scope and print.
1 parent 51d4522 commit e8540af

6 files changed

Lines changed: 50 additions & 25 deletions

File tree

model/Host/WithinHost/CommonWithinHost.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ void CommonWithinHost::update(Host::Human &human, LocalRng& rng, int &nNewInfs_i
238238
// Inner vector has one entry "per drug" (really, per element of LSTMModel.m_drugs).
239239
// Each inner vector element is a drug id (integer), and a drug-specific drug factor.
240240
std::vector<std::vector<std::pair<size_t, double>>> identifiedComponentDrugFactors;
241+
242+
// One outer vector entry for each day for each infection.
243+
std::vector<std::vector<std::tuple<std::string, double, double>>> pkpdTimeToDrugConcentrationMaps;
244+
std::vector<std::vector<std::tuple<std::string, double, double>>> pkpdTimeToTotalFactorMaps;
241245

242246
for( SimTime now = sim::ts0(), end = sim::ts0() + sim::oneTS(); now < end; now = now + sim::oneDay() ){
243247
// every day, medicate drugs, update each infection, then decay drugs
@@ -250,10 +254,16 @@ void CommonWithinHost::update(Host::Human &human, LocalRng& rng, int &nNewInfs_i
250254
bool expires = ((*inf)->bloodStage() ? treatmentBlood : treatmentLiver);
251255

252256
if( !expires ){ /* no expiry due to simple treatment model; do update */
253-
// TODO : receive structure containing outputs of individual calculateDrugFactor calls here.
257+
// Using vector of pairs instead of a map, because otherwise values with same time key will get overwritten.
258+
std::vector<std::tuple<std::string, double, double>> pkpdTimeToDrugConcentrationMap;
259+
std::vector<std::tuple<std::string, double, double>> pkpdTimeToTotalFactorMap;
260+
254261
// The values within this structure need to somehow be associated with the specific drug they are from.
255262
// In the scenario in question, the particular override calculateDrugFactor being called is LSTMDrugOneComp::calculateDrugFactor.
256-
const std::pair<double, std::vector<std::pair<size_t, double>>> output = pkpdModel.getDrugFactor(rng, *inf, body_mass);
263+
const std::pair<double, std::vector<std::pair<size_t, double>>> output = pkpdModel.getDrugFactor(rng, *inf, body_mass,
264+
pkpdTimeToDrugConcentrationMap,
265+
pkpdTimeToTotalFactorMap
266+
);
257267
const double drugFactor = output.first;
258268
// Note this drug factor can in some cases be derived from more than one drug type.
259269
drugFactors.push_back(drugFactor);
@@ -289,9 +299,15 @@ void CommonWithinHost::update(Host::Human &human, LocalRng& rng, int &nNewInfs_i
289299
// Outer vector's elements correspond to individual days/infections.
290300
// Inner vector's elements correspond to individual drugs.
291301
// Format could possibly be improved w.r.t. days/infections.
292-
std::vector<std::vector<std::pair<std::string, double>>> namedComponentDrugFactors;
302+
// This drug factor, as opposed to the other drug factors which get printed out,
303+
// represents the product of all drugs' drug factors for the given human-day-infection.
304+
std::vector<std::vector<std::pair<std::string, double>>> namedComponentDrugFactorProducts;
293305
for (auto outer_vec : identifiedComponentDrugFactors)
294306
{
307+
if (!outer_vec.empty())
308+
{
309+
int x = 999; // Dummy instructions for breakpoint.
310+
}
295311
std::vector<std::pair<std::string, double>> namedDrugFactors;
296312
for (auto inner_vec : outer_vec)
297313
{
@@ -300,7 +316,7 @@ void CommonWithinHost::update(Host::Human &human, LocalRng& rng, int &nNewInfs_i
300316
const double drugFactor = inner_vec.second;
301317
namedDrugFactors.push_back(std::pair<std::string, double>{drugName, drugFactor});
302318
}
303-
namedComponentDrugFactors.push_back(namedDrugFactors);
319+
namedComponentDrugFactorProducts.push_back(namedDrugFactors);
304320
}
305321

306322
json special_info = json::object();
@@ -310,7 +326,9 @@ void CommonWithinHost::update(Host::Human &human, LocalRng& rng, int &nNewInfs_i
310326
special_info["parasite_density"] = parasite_density;
311327
special_info["getDrugFactor"] = drugFactors;
312328
special_info["drugConcentrations"] = drugConcentrationMap;
313-
special_info["namedComponentDrugFactors"] = namedComponentDrugFactors;
329+
special_info["namedComponentDrugFactorProducts"] = namedComponentDrugFactorProducts;
330+
special_info["pkpdTimeToDrugConcentrationMaps"] = pkpdTimeToDrugConcentrationMaps;
331+
special_info["pkpdTimeToTotalFactorMaps"] = pkpdTimeToTotalFactorMaps;
314332
std::cout << special_info.dump() << std::endl;
315333

316334
// As in AJTMH p22, cumulative_h (X_h + 1) doesn't include infections added

model/PkPd/Drug/LSTMDrug.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ class LSTMDrug {
7878
* @param body_mass Weight of patient in kg
7979
*/
8080
virtual double calculateDrugFactor(LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass,
81-
std::vector<std::pair<double, double>>& pkpdTimeToDrugConcentrationMap,
82-
std::vector<std::pair<double, double>>& pkpdTimeToTotalFactorMap
81+
const std::string& drugName,
82+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToDrugConcentrationMap,
83+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToTotalFactorMap
8384
) const =0;
8485

8586
/** Updates concentration variable and clears day's doses.

model/PkPd/Drug/LSTMDrugOneComp.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ double LSTMDrugOneComp::getConcentration(size_t index) const {
5050
// TODO: in high transmission, is this going to get called more often than updateConcentration?
5151
// When does it make sense to try to optimise (avoid doing decay calcuations here)?
5252
double LSTMDrugOneComp::calculateDrugFactor(LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass,
53-
std::vector<std::pair<double, double>>& pkpdTimeToDrugConcentrationMap,
54-
std::vector<std::pair<double, double>>& pkpdTimeToTotalFactorMap
53+
const std::string& drugName,
54+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToDrugConcentrationMap,
55+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToTotalFactorMap
5556
) const {
5657
if( concentration == 0.0 && doses.size() == 0 ) return 1.0; // nothing to do
5758

@@ -73,27 +74,27 @@ double LSTMDrugOneComp::calculateDrugFactor(LocalRng& rng, WithinHost::CommonInf
7374
// we iteratate through doses in time order (since doses are sorted)
7475
if( time_conc.first < 1.0 /*i.e. today*/ ){
7576
if( time < time_conc.first ){
76-
pkpdTimeToDrugConcentrationMap.push_back(std::pair<double, double>{time, concentration_today});
77+
pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, concentration_today});
7778
totalFactor *= drugPD.calcFactor( Kn, neg_elim_rate, &concentration_today, time_conc.first - time );
78-
pkpdTimeToTotalFactorMap.push_back(std::pair<double, double>{time, totalFactor});
79-
pkpdTimeToDrugConcentrationMap.push_back(std::pair<double, double>{time, concentration_today});
79+
pkpdTimeToTotalFactorMap.push_back(std::tuple<std::string, double, double>{drugName, time, totalFactor});
80+
pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, concentration_today});
8081
time = time_conc.first;
8182
}else{ assert( time == time_conc.first ); }
8283
// add dose (instantaneous absorption):
8384
concentration_today += time_conc.second / (vol_dist * body_mass);
84-
pkpdTimeToDrugConcentrationMap.push_back(std::pair<double, double>{time, concentration_today});
85+
pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, concentration_today});
8586
}else/*i.e. tomorrow or later*/{
8687
break;
8788
}
8889
}
8990
if( time < 1.0 ){
9091
totalFactor *= drugPD.calcFactor( Kn, neg_elim_rate, &concentration_today, 1.0 - time );
91-
pkpdTimeToTotalFactorMap.push_back(std::pair<double, double>{time, totalFactor});
92-
pkpdTimeToDrugConcentrationMap.push_back(std::pair<double, double>{time, concentration_today});
92+
pkpdTimeToTotalFactorMap.push_back(std::tuple<std::string, double, double>{drugName, time, totalFactor});
93+
pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, concentration_today});
9394

9495
}
9596

96-
pkpdTimeToTotalFactorMap.push_back(std::pair<double, double>{time, totalFactor});
97+
pkpdTimeToTotalFactorMap.push_back(std::tuple<std::string, double, double>{drugName, time, totalFactor});
9798
return totalFactor; // Drug effect per day per drug per parasite
9899
}
99100

model/PkPd/Drug/LSTMDrugOneComp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ class LSTMDrugOneComp : public LSTMDrug {
5151
virtual double getConcentration(size_t index) const;
5252

5353
virtual double calculateDrugFactor(LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass,
54-
std::vector<std::pair<double, double>>& pkpdTimeToDrugConcentrationMap,
55-
std::vector<std::pair<double, double>>& pkpdTimeToTotalFactorMap
54+
const std::string& drugName,
55+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToDrugConcentrationMap,
56+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToTotalFactorMap
5657
) const;
5758
virtual void updateConcentration (double body_mass);
5859

model/PkPd/LSTMModel.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,22 @@ double LSTMModel::getDrugConc (size_t drug_index) const{
133133
return c;
134134
}
135135

136-
std::pair<double, std::vector<std::pair<size_t, double>>> LSTMModel::getDrugFactor (LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass) const{
136+
std::pair<double, std::vector<std::pair<size_t, double>>> LSTMModel::getDrugFactor (LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass,
137+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToDrugConcentrationMap,
138+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToTotalFactorMap
139+
) const{
137140
double factor = 1.0; //no effect
138141

139142
// Using vector of pairs instead of map in case multiple elements in m_drugs have same drug index.
140143
std::vector<std::pair<size_t, double>> drugIndexToDrugFactor;
141144

142145
for( auto drug = m_drugs.begin(), end = m_drugs.end(); drug != end; ++drug ){
143-
// Can be used by caller to determine drug name.
146+
// Get name of current drug.
144147
const size_t drugIndex = (*drug)->getIndex();
145-
146-
// Using vector of pairs instead of a map, because otherwise values with same time key will get overwritten.
147-
std::vector<std::pair<double, double>> pkpdTimeToDrugConcentrationMap;
148-
std::vector<std::pair<double, double>> pkpdTimeToTotalFactorMap;
148+
const std::string& drugName = OM::PkPd::LSTMDrugType::getDrugAbbrev(drugIndex);
149149

150150
double drugFactor = (*drug)->calculateDrugFactor(rng, inf, body_mass,
151+
drugName,
151152
pkpdTimeToDrugConcentrationMap,
152153
pkpdTimeToTotalFactorMap
153154
);

model/PkPd/LSTMModel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ class LSTMModel {
124124
* Each time step, on each infection, the parasite density is multiplied by
125125
* the return value of this infection. The WithinHostModels are responsible
126126
* for clearing infections once the parasite density is negligible. */
127-
std::pair<double, std::vector<std::pair<size_t, double>>> getDrugFactor (LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass) const;
127+
std::pair<double, std::vector<std::pair<size_t, double>>> getDrugFactor (LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass,
128+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToDrugConcentrationMap,
129+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToTotalFactorMap
130+
) const;
128131

129132
/** After any resident infections have been reduced by getDrugFactor(),
130133
* this function is called to update drug levels to their effective level

0 commit comments

Comments
 (0)