Skip to content

Commit

Permalink
added parent to VirusStrain enum. Refactored Hospitalisation Model.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrehmann committed Oct 9, 2023
1 parent 7347d8a commit dcfc843
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 157 deletions.
203 changes: 102 additions & 101 deletions src/main/java/org/matsim/episim/analysis/HospitalNumbersFromEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@

public class HospitalNumbersFromEvents implements OutputAnalysis {

@CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/matsim-episim/A_originalImmHist")
@CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/matsim-episim/2023-10-06/1/output/")
// @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/matsim-episim/A_originalImmHist")
// @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/matsim-episim/B_startedFromImmHist")
// @CommandLine.Option(names = "--output", defaultValue = "/Users/jakob/git/public-svn/matsim/scenarios/countries/de/episim/battery/jakob/2022-10-18/3-meas/analysis/")
private Path output;
Expand Down Expand Up @@ -93,97 +94,103 @@ public class HospitalNumbersFromEvents implements OutputAnalysis {

// TODO: check age or strain based lags in literature
// source: incidence wave vs. hospitalization wave in cologne/nrw (see https://docs.google.com/spreadsheets/d/1jmaerl27LKidD1uk3azdIL1LmvHuxazNQlhVo9xO1z8/edit?usp=sharing)
private static final Object2IntMap<VirusStrain> lagBetweenInfectionAndHospitalisation = new Object2IntAVLTreeMap<>(
Map.of(VirusStrain.SARS_CoV_2, 14,
VirusStrain.ALPHA, 14,
VirusStrain.DELTA, 14,
VirusStrain.OMICRON_BA1, 14,
VirusStrain.OMICRON_BA2, 14,
VirusStrain.OMICRON_BA5, 14,
VirusStrain.STRAIN_A, 14,
VirusStrain.STRAIN_B, 14
));

// source: hospitalization wave vs. ICU wave in cologne/nrw (see https://docs.google.com/spreadsheets/d/1jmaerl27LKidD1uk3azdIL1LmvHuxazNQlhVo9xO1z8/edit?usp=sharing)
private static final Object2IntMap<VirusStrain> lagBetweenHospitalizationAndICU = new Object2IntAVLTreeMap<>(
Map.of(VirusStrain.SARS_CoV_2, 6,
VirusStrain.ALPHA, 6,
VirusStrain.DELTA, 6,
VirusStrain.OMICRON_BA1, 6,
VirusStrain.OMICRON_BA2, 6,
VirusStrain.OMICRON_BA5, 6,
VirusStrain.STRAIN_A, 6,
VirusStrain.STRAIN_B, 6
));
private static final Object2IntMap<VirusStrain> lagBetweenInfectionAndHospitalisation = setLagBetweenInfectionAndHospitalisation();

// Austria study in https://docs.google.com/spreadsheets/d/1jmaerl27LKidD1uk3azdIL1LmvHuxazNQlhVo9xO1z8/edit#gid=0
private static final Object2IntMap<VirusStrain> daysInHospitalGivenNoICU = new Object2IntAVLTreeMap<>(
Map.of(VirusStrain.SARS_CoV_2, 12,
VirusStrain.ALPHA, 12,
VirusStrain.DELTA, 12,
VirusStrain.OMICRON_BA1, 7,
VirusStrain.OMICRON_BA2, 7,
VirusStrain.OMICRON_BA5,7,
VirusStrain.STRAIN_A, 7,
VirusStrain.STRAIN_B, 7
));

private static final Object2IntMap<VirusStrain> daysInICU = new Object2IntAVLTreeMap<>(
Map.of(VirusStrain.SARS_CoV_2, 15, // Debeka & Ireland studies
VirusStrain.ALPHA, 15, // Debeka & Ireland studies
VirusStrain.DELTA, 15, // this and following values come from nrw analysis on Tabellenblatt 5
VirusStrain.OMICRON_BA1, 10, // TODO: Where does this number come from?
VirusStrain.OMICRON_BA2, 10,
VirusStrain.OMICRON_BA5,10,
VirusStrain.STRAIN_A, 10,
VirusStrain.STRAIN_B, 10
));
private static Object2IntAVLTreeMap<VirusStrain> setLagBetweenInfectionAndHospitalisation() {
Object2IntAVLTreeMap<VirusStrain> lagBetweenInfectionAndHospitalisation = new Object2IntAVLTreeMap<>();

// ??
private static final Object2IntMap<VirusStrain> daysInHospitalGivenICU = new Object2IntAVLTreeMap<>(
Map.of(VirusStrain.SARS_CoV_2, 60, // TODO: Where does this number come from?
VirusStrain.ALPHA, 60,
VirusStrain.DELTA, 60,
VirusStrain.OMICRON_BA1, 60,
VirusStrain.OMICRON_BA2, 60,
VirusStrain.OMICRON_BA5,60,
VirusStrain.STRAIN_A, 60,
VirusStrain.STRAIN_B, 60
));
for (VirusStrain strain : VirusStrain.values()) {
lagBetweenInfectionAndHospitalisation.put(strain, 14);
}

return lagBetweenInfectionAndHospitalisation;
}

// source: hospitalization wave vs. ICU wave in cologne/nrw (see https://docs.google.com/spreadsheets/d/1jmaerl27LKidD1uk3azdIL1LmvHuxazNQlhVo9xO1z8/edit?usp=sharing)
private static final Object2IntMap<VirusStrain> lagBetweenHospitalizationAndICU = setLagBetweenHospitalizationAndICU();

private static final double beta = 1.2;
private static Object2IntAVLTreeMap<VirusStrain> setLagBetweenHospitalizationAndICU() {
Object2IntAVLTreeMap<VirusStrain> lagBetweenHospitalizationAndICU = new Object2IntAVLTreeMap<>();

private static final double hospitalFactor = 0.3; // Based on "guess & check", accounts for unreported cases TODO: Potential follow-up
for (VirusStrain strain : VirusStrain.values()) {
lagBetweenHospitalizationAndICU.put(strain, 6);
}

private static final double factorWild = 1.0;
return lagBetweenHospitalizationAndICU;

}

private static final double factorAlpha = 1.0 * factorWild;
// Austria study in https://docs.google.com/spreadsheets/d/1jmaerl27LKidD1uk3azdIL1LmvHuxazNQlhVo9xO1z8/edit#gid=0
private static final Object2IntMap<VirusStrain> daysInHospitalGivenNoICU = setDaysInHospitalGivenNoICU();

// delta: 2.3x more severe than alpha - Hospital admission and emergency care attendance risk for SARS-CoV-2 delta (B.1.617.2) compared with alpha (B.1.1.7) variants of concern: a cohort study
private static final double factorDelta = 1.2 * factorWild; //1.6 * factorWild;
private static Object2IntAVLTreeMap<VirusStrain> setDaysInHospitalGivenNoICU() {
Object2IntAVLTreeMap<VirusStrain> daysInHospitalGivenNoICU = new Object2IntAVLTreeMap<>();
for (VirusStrain strain : VirusStrain.values()) {
daysInHospitalGivenNoICU.put(strain, 7);
}

// omicron: approx 0.3x (intrinsic) severity of delta - Comparative analysis of the risks of hospitalisation and death associated with SARS-CoV-2 omicron (B.1.1.529) and delta (B.1.617.2) variants in England: a cohort study
private static final double factorOmicron = 0.45 * factorDelta; // reportedShareOmicron / reportedShareDelta
// private static final double factorOmicron = 0.6 * factorDelta;// reportedShareOmicron / reportedShareDelta
daysInHospitalGivenNoICU.put(VirusStrain.SARS_CoV_2, 12);
daysInHospitalGivenNoICU.put(VirusStrain.ALPHA, 12);
daysInHospitalGivenNoICU.put(VirusStrain.DELTA, 12);

private static final double factorBA5 = 1.0 * factorOmicron; // old: 1.5
return daysInHospitalGivenNoICU;
}

private static final double factorScen2 = factorBA5; // reportedShareOmicron / reportedShareDelta
private static final double factorScen3 = factorBA5 * 3;// reportedShareOmicron / reportedShareDelta
private static final Object2IntMap<VirusStrain> daysInICU = setDaysInICU();

private static Object2IntAVLTreeMap<VirusStrain> setDaysInICU() {
Object2IntAVLTreeMap<VirusStrain> daysInICU = new Object2IntAVLTreeMap<>();

// private static final double factorBA5 = 1.0 * factorOmicron;
for (VirusStrain strain : VirusStrain.values()) {
daysInICU.put(strain, 10);
}

daysInICU.put(VirusStrain.SARS_CoV_2, 15);
daysInICU.put(VirusStrain.ALPHA, 15);
daysInICU.put(VirusStrain.DELTA, 15);

return daysInICU;
}

// ??
private static final double factorWildAndAlphaICU = 1.; // TODO : Check literature for reasonable values
private static final double factorDeltaICU = 1.;
private static final double factorOmicronICU = 1.;
private static final double factorBA5ICU = 1.;
private static final Object2IntMap<VirusStrain> daysInHospitalGivenICU = setDaysInHospitalGivenICU();

private static Object2IntAVLTreeMap<VirusStrain> setDaysInHospitalGivenICU() {
Object2IntAVLTreeMap<VirusStrain> daysInHospitalGivenICU = new Object2IntAVLTreeMap<>();

for (VirusStrain strain : VirusStrain.values()) {
daysInHospitalGivenICU.put(strain, 60);
}

return daysInHospitalGivenICU;
}


private static final double beta = 1.2;

private static final double hospitalFactor = 0.3; // Based on "guess & check", accounts for unreported cases TODO: Potential follow-up

private static final Map<VirusStrain, Double> seriouslySickFactorModifier_BASE = Map.of(
VirusStrain.DELTA, 1.2,
VirusStrain.OMICRON_BA1, 0.45
);

private static final Map<VirusStrain, Double> seriouslySickFactorModifier_MILD = Map.of(
VirusStrain.DELTA, 1.2,
VirusStrain.OMICRON_BA1, 0.45,
VirusStrain.A_1, 0.5
);


private static final Map<VirusStrain, Double> seriouslySickFactorModifier_SEVERE = Map.of(
VirusStrain.DELTA, 1.2,
VirusStrain.OMICRON_BA1, 0.45,
VirusStrain.A_1, 1.5
);


// ICU: so far, we assume no difference between strains
private static final double factorICU = 1.; // TODO : Check literature for reasonable values
public static void main(String[] args) {
System.exit(new CommandLine(new HospitalNumbersFromEvents()).execute(args));
}
Expand Down Expand Up @@ -225,8 +232,9 @@ public Integer call() throws Exception {
// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList);

//TODO: move to other class
// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Omicron", startDate, "Omicron");
// HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Delta", startDate, "Delta");
HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Base", startDate, "Base");
HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Mild", startDate, "Mild");
HospitalNumbersFromEventsPlotter.aggregateAndProducePlots(output, pathList, "_Severe", startDate, "Severe");


// }
Expand Down Expand Up @@ -264,14 +272,17 @@ public void analyzeOutput(Path pathToScenario) throws IOException {
private void calculateHospitalizationsAndWriteOutput(Path pathToScenario, Path tsvPath) throws IOException {
// open new buffered writer for hospitalization output and write the header row.
BufferedWriter bw = Files.newBufferedWriter(tsvPath);
bw.write(AnalysisCommand.TSV.join(DAY, DATE,"measurement", "severity", "n")); // + "\thospNoImmunity\thospBaseImmunity\thospBoosted\tincNoImmunity\tincBaseImmunity\tincBoosted"));
bw.write(AnalysisCommand.TSV.join(DAY, DATE,"measurement", "scenario", "n")); // + "\thospNoImmunity\thospBaseImmunity\thospBoosted\tincNoImmunity\tincBaseImmunity\tincBoosted"));


ConfigHolder holderOmicron = configure(factorScen2, 1.0); // scenario 2
ConfigHolder holderDelta = configure(factorScen3, 1.0); //scenario 3
ConfigHolder holderBase = configure(seriouslySickFactorModifier_BASE);
ConfigHolder holderMild = configure(seriouslySickFactorModifier_MILD);
ConfigHolder holderSevere = configure(seriouslySickFactorModifier_SEVERE);

List<Handler> handlers = List.of(
new Handler("Omicron", population, holderOmicron),
new Handler("Delta", population, holderDelta)
new Handler("Base", population, holderBase),
new Handler("Mild", population, holderMild),
new Handler("Severe", population, holderSevere)
);

// feed the output events file to the handler, so that the hospitalizations may be calculated
Expand Down Expand Up @@ -685,7 +696,7 @@ public int getAge() {
* necessary for post processing.
* @param
*/
private static ConfigHolder configure(double facA, double facAICU) {
private static ConfigHolder configure(Map<VirusStrain, Double> seriouslySickFactorModifier) {

Config config = ConfigUtils.createConfig(new EpisimConfigGroup());

Expand All @@ -695,26 +706,16 @@ private static ConfigHolder configure(double facA, double facAICU) {

// configure strainConfig: add factorSeriouslySick for each strain
VirusStrainConfigGroup strainConfig = ConfigUtils.addOrGetModule(config, VirusStrainConfigGroup.class);
strainConfig.getOrAddParams(VirusStrain.SARS_CoV_2).setFactorSeriouslySick(factorWild);
strainConfig.getOrAddParams(VirusStrain.SARS_CoV_2).setFactorCritical(factorWildAndAlphaICU);
strainConfig.getOrAddParams(VirusStrain.ALPHA).setFactorSeriouslySick(factorAlpha);
strainConfig.getOrAddParams(VirusStrain.ALPHA).setFactorCritical(factorAlpha);

strainConfig.getOrAddParams(VirusStrain.DELTA).setFactorSeriouslySick(factorDelta);
strainConfig.getOrAddParams(VirusStrain.DELTA).setFactorCritical(factorDeltaICU);

strainConfig.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorSeriouslySick(factorOmicron);
strainConfig.getOrAddParams(VirusStrain.OMICRON_BA1).setFactorCritical(factorOmicronICU);
strainConfig.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorSeriouslySick(factorOmicron);
strainConfig.getOrAddParams(VirusStrain.OMICRON_BA2).setFactorCritical(factorOmicronICU);
strainConfig.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorSeriouslySick(factorBA5);
strainConfig.getOrAddParams(VirusStrain.OMICRON_BA5).setFactorCritical(factorBA5ICU);

strainConfig.getOrAddParams(VirusStrain.STRAIN_A).setFactorSeriouslySick(facA);
strainConfig.getOrAddParams(VirusStrain.STRAIN_A).setFactorCritical(facAICU);

strainConfig.getOrAddParams(VirusStrain.STRAIN_B).setFactorSeriouslySick(facA);
strainConfig.getOrAddParams(VirusStrain.STRAIN_B).setFactorCritical(facAICU);

for (VirusStrain strain : VirusStrain.values()) {
double seriouslySickFactorParent = 1.0;
if (strain.parent != null) {
seriouslySickFactorParent = strainConfig.getParams(strain.parent).getFactorSeriouslySick();
}
strainConfig.getOrAddParams(strain).setFactorSeriouslySick(seriouslySickFactorParent * seriouslySickFactorModifier.getOrDefault(strain, 1.0));

strainConfig.getOrAddParams(strain).setFactorCritical(factorICU);
}

// configure vaccinationConfig: set beta factor
VaccinationConfigGroup vaccinationConfig = ConfigUtils.addOrGetModule(config, VaccinationConfigGroup.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class HospitalNumbersFromEventsPlotter {



static void aggregateAndProducePlots(Path output, List<Path> pathList, String outputAppendix, LocalDate startDate, String strainToPlot) throws IOException {
static void aggregateAndProducePlots(Path output, List<Path> pathList, String outputAppendix, LocalDate startDate, String scenarioToPlot) throws IOException {


// read hospitalization tsv for all seeds and aggregate them!
Expand Down Expand Up @@ -69,7 +69,7 @@ static void aggregateAndProducePlots(Path output, List<Path> pathList, String ou

for (CSVRecord record : parser) {

if (!record.get("severity").equals(strainToPlot)) {
if (!record.get("scenario").equals(scenarioToPlot)) {
continue;
}

Expand Down
Loading

0 comments on commit dcfc843

Please sign in to comment.