Skip to content

Commit 91ee5b1

Browse files
authored
Merge pull request #127 from nextstrain/export-pivot-ga
Export pivot growth advantage
2 parents 7571541 + b2c353f commit 91ee5b1

File tree

5 files changed

+546
-136
lines changed

5 files changed

+546
-136
lines changed

config/mlr-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ settings:
1313

1414
model:
1515
generation_time: 4.8
16-
pivot: "24A"
16+
pivot: "24F"
1717
hierarchical: true
1818

1919
inference:

scripts/run-mlr-model.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,10 @@ def make_raw_freq_tidy(data, location):
276276
return {"metadata": metadata, "data": entries}
277277

278278

279-
def export_results(multi_posterior, ps, path, data_name, hier):
279+
def export_results(multi_posterior, ps, path, data_name, hier, pivot):
280280
EXPORT_SITES = ["freq", "ga", "freq_forecast"]
281281
EXPORT_DATED = [True, False, True]
282282
EXPORT_FORECASTS = [False, False, True]
283-
EXPORT_ATTRS = ["pivot"]
284283

285284
# Make directories
286285
make_model_directories(path)
@@ -351,6 +350,27 @@ def get_group_samples(samples, sites, group):
351350

352351
results = ef.posterior.combine_sites_tidy(results)
353352
results["metadata"]["updated"] = pd.to_datetime(date.today())
353+
354+
# Add hard-coded pivot data if a pivot is provided
355+
if pivot:
356+
results["metadata"]["pivot"] = pivot
357+
# Mirroring the ps keys generated within evofr
358+
# <https://github.com/blab/evofr/blob/e883784dc397805c50bbcd56b083f4f232b03e17/evofr/posterior/posterior_helpers.py#L296C5-L299C54>
359+
ps_keys = ["median"]
360+
for p in ps:
361+
ps_keys.append(f"HDI_{round(p * 100)}_upper")
362+
ps_keys.append(f"HDI_{round(p * 100)}_lower")
363+
364+
for location, _ in multi_posterior.locator.items():
365+
for ps_key in ps_keys:
366+
results["data"].append({
367+
"location": location,
368+
"site": "ga",
369+
"variant": pivot,
370+
"value": 1.0,
371+
"ps": ps_key
372+
})
373+
354374
ef.save_json(results, path=f"{path}/{data_name}_results.json")
355375

356376

@@ -390,7 +410,7 @@ def get_group_samples(samples, sites, group):
390410
print(f"Config loaded: {config.path}")
391411

392412
raw_seq, locations = config.load_data(args.seq_path)
393-
print("Data loaded sucessfuly")
413+
print("Data loaded successfully")
394414

395415
override_hier = None
396416
if args.hier:
@@ -452,4 +472,4 @@ def get_group_samples(samples, sites, group):
452472
config.config["settings"], "ps", dflt=[0.5, 0.8, 0.95]
453473
)
454474
data_name = args.data_name or config.config["data"]["name"]
455-
export_results(multi_posterior, ps, export_path, data_name, hier)
475+
export_results(multi_posterior, ps, export_path, data_name, hier, pivot)

viz/nextstrain-evofr-viz-0.1.0.tgz

-325 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)