Skip to content

Commit

Permalink
add auto check for updates to prebuilt UShER tree
Browse files Browse the repository at this point in the history
  • Loading branch information
jbloom committed Aug 14, 2024
1 parent a568399 commit 715665d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ The Nextstrain Auspice JSON files are placed in [./auspice/](auspice), where the
## Re-running the pipeline as data are updated
As the [pre-built UShER tree](https://hgdownload.gi.ucsc.edu/hubs/GCF/000/864/105/GCF_000864105.1/UShER_NC_007362.1/) is updated, you will want to re-run the pipeline.
To do that, just remove the contents of the [./results/](results), [./docs/](docs), and [./auspice](auspice) subidirectories and then just re-run the pipeline.

The script [check_for_prebuilt_usher_update.py](check_for_prebuilt_usher_update.py) can be set up to run using `crontab -e` to check for such updates.
55 changes: 55 additions & 0 deletions check_for_prebuilt_usher_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Check if UShER pre-built tree has been updated.
This script is designed to be run as a cron job to indicate if the
UShER pre-built tree has been updated, which means the repo should
be re-run.
Note it reads the Slack webhook from a file not tracked in this repo.
After creating that webhook file and giving it a valid Slack webhook,
add a line like the following via ``crontab -e``:
0 5 * * * python3 <full_path>/check_for_prebuilt_usher_update.py
"""


import json
import os
import urllib.request


currdir = os.path.dirname(__file__)


with open(os.path.join(currdir, "results/usher_prebuilt/version_info.txt")) as f:
existing_version = f.read()

response = urllib.request.urlopen("https://hgdownload.gi.ucsc.edu/hubs/GCF/000/864/105/GCF_000864105.1/UShER_NC_007362.1/fluA.GCF_000864105.1.NC_007362.1.latest.version.txt")
new_version = response.read().decode("utf-8")

if existing_version == new_version:
msg = "UShER H5N1 version unchanged"
else:
msg = f"UShER H5N1 version has **changed**"

msg += "\n\nnew_version=" + new_version + "\nexisting_version=" + existing_version + "\n"

print(msg)

with open(os.path.join(currdir, "_Slack_webhook_url.txt")) as f:
webhook_url = f.read()

payload = {"text": msg}
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(
webhook_url,
data=data,
headers={'Content-Type': 'application/json'}
)

with urllib.request.urlopen(req) as response:
if response.status == 200:
print("Message sent successfully.")
else:
raise ValueError(f"Failed to send message. Status code: {response.status}")

0 comments on commit 715665d

Please sign in to comment.