"""Prepare the inputs of our analysis and check each against the SHA-256 of the copy we used. Fact-Checked Science ("Our analysis"), 20 November 2026, for the check of Xie, W., et al. (2026), "Geomagnetic intensity variation and deprivation elicit distinct transcriptomic responses in a migratory insect", Insect Molecular Biology, doi:10.1111/imb.70066. Page: https://factchecked.science/planthopper-magnetic-genes/ The authors' data: Xie, W., et al. (2026), "Data and code from: ...", Dryad, doi:10.5061/dryad.r4xgxd2vx (CC0 1.0). Dryad's API refuses scripted downloads of the dataset (HTTP 401, "must have current bearer token"), so this script does not fetch it. Download it by hand: open https://datadryad.org/dataset/doi:10.5061/dryad.r4xgxd2vx in a browser and use "Download dataset". Then give this script the path of that zip. What it does 1. Checks the zip's three members against Dryad's own SHA-256 digests for version 7 (15 September 2026): README.md, Dataset_supporting_manuscript.zip, Code_for_this_manuscript.zip. 2. Extracts the six data files of Dataset_supporting_manuscript.zip into /dataset/ (member names are checked first; nothing is executed) and checks each against the SHA-256 of our copy. 3. Fetches, identifying itself as "factchecked-research/1.0", into /field/: igrf14coeffs.txt IGRF-14 (IAGA Working Group V-MOD), https://www.ngdc.noaa.gov/IAGA/vmod/coeffs/igrf14coeffs.txt WMM2025COF.zip NOAA's WMM2025 coefficients and test values (used only to check the field code), https://www.ncei.noaa.gov/sites/default/files/2025-01/WMM2025COF.zip and checks their SHA-256. Files already present with the right SHA-256 are kept. Needs Python 3.9+ (standard library only). Run: python3 prepare_inputs.py On any mismatch the script stops and says which file differs; the results computed from a different file may differ from ours. """ import hashlib import io import os import sys import urllib.error import urllib.request import zipfile UA = "factchecked-research/1.0" DRYAD = { # Dryad API, version 463781, /files: name -> (bytes, SHA-256) "README.md": (17030, "088ed60ab1e863151c6b644291ca3fc3d83bc50cf833e2bbce1a9cb1b61660dd"), "Dataset_supporting_manuscript.zip": (6087623, "ee471a756cabb532853bfb0695942d0b2a10665286d4ca1479069d08e70735a2"), "Code_for_this_manuscript.zip": (4555, "3d0dafa48938c6c957a7860402d3e8dd8af3d2d0a9ac04313a02952f7795f8c7"), } DATA = { # files inside Dataset_supporting_manuscript.zip -> (bytes, SHA-256 of our copy) "Raw_data_for_RNAseq_count_matrix.csv": (940997, "5c2ee20e8f795aa65c704f77f42e20e29ce78f6e9f3aa27e994f2d1768473628"), "Raw_data_for_Figure1-Complete list of differentially expressed genes in all comparisons.xlsx": (6170959, "ec62332e6d2137e66ebf5952ab81bf9f56fd35bcd243d578702f9985f40fb095"), "Raw_data_for_Figure2-Functional enrichment of transcriptional responses under different magnetic field conditions.xlsx": (133135, "e85bfe49760d078cc6bfebb5662ffaf382b9fe4c8792a5f3ddf75da4a60a0b7d"), "Raw_data_for_Figure3-RT-qPCR validation of representative genes responding to different magnetic field conditions.xlsx": (12837, "6893f0ca16d718f2d1be4a61c7d101af61a1a5aed4f7fd73fdbaaf0bcaf1e093"), "Raw_data_for_Figure4-Cry1 knockdown disrupts diel eclosion rhythmicity in female brown planthopper.xlsx": (13380, "ff83b40b8fd9a60e0c5cc1bd3431043de04f93ee077f094470b1239c4f819ef5"), "Raw_data_for_FigureS1-Control of magnetic field parameters under different magnetic field treatments. .xlsx": (12371, "490646d5a66984df76af49e2156786a844eed744a99b129874a32870e8f9c11a"), } FIELD = [ ("igrf14coeffs.txt", "https://www.ngdc.noaa.gov/IAGA/vmod/coeffs/igrf14coeffs.txt", "8f8d88403028fc4ee92c4f38d97b46e0a87e2cfc496045b43c9e26c1d6b0903c"), ("WMM2025COF.zip", "https://www.ncei.noaa.gov/sites/default/files/2025-01/WMM2025COF.zip", "999080a12c95122c2031aeac8be77229d97584530e87e0f1a6df7d946ecf90c5"), ] def sha(b): return hashlib.sha256(b).hexdigest() def safe(name): return not (name.startswith(("/", "\\")) or ":" in name or "\\" in name or ".." in name.split("/")) def fetch(url, path, want): if os.path.exists(path): with open(path, "rb") as f: if sha(f.read()) == want: print("have ", path) return req = urllib.request.Request(url, headers={"User-Agent": UA}) try: with urllib.request.urlopen(req, timeout=300) as r: data = r.read() except urllib.error.HTTPError as e: sys.exit(f"STOP: {url} answered HTTP {e.code}. Nothing was retried; fetch it by hand if you can.") except urllib.error.URLError as e: sys.exit(f"STOP: could not reach {url}: {e.reason}") if sha(data) != want: with open(path + ".mismatch", "wb") as f: f.write(data) sys.exit(f"STOP: {os.path.basename(path)} differs from the copy we used (kept as {path}.mismatch).") with open(path, "wb") as f: f.write(data) print("fetched", path) def main(): if len(sys.argv) != 3: sys.exit("usage: python3 prepare_inputs.py ") zpath, folder = sys.argv[1], sys.argv[2] with open(zpath, "rb") as f: print("your zip:", os.path.basename(zpath), "SHA-256", sha(f.read()), "(Dryad builds the zip; its own hash may vary)") outer = zipfile.ZipFile(zpath) members = {} for name, (size, want) in DRYAD.items(): hits = [n for n in outer.namelist() if n.split("/")[-1] == name] if not hits: sys.exit(f"STOP: {name} is not in the zip.") data = outer.read(hits[0]) if len(data) != size or sha(data) != want: sys.exit(f"STOP: {name} differs from Dryad's digest (bytes {len(data)}, SHA-256 {sha(data)}).") print("matches Dryad's SHA-256:", name) members[name] = data inner = zipfile.ZipFile(io.BytesIO(members["Dataset_supporting_manuscript.zip"])) if not all(safe(n) for n in inner.namelist()): sys.exit("STOP: an unsafe member name in Dataset_supporting_manuscript.zip.") out = os.path.join(folder, "dataset") os.makedirs(out, exist_ok=True) for name, (size, want) in DATA.items(): hits = [n for n in inner.namelist() if n.split("/")[-1] == name] if not hits: sys.exit(f"STOP: {name} is not in Dataset_supporting_manuscript.zip.") data = inner.read(hits[0]) if len(data) != size or sha(data) != want: sys.exit(f"STOP: {name} differs from our copy.") with open(os.path.join(out, name), "wb") as f: f.write(data) print("extracted and checked:", name) fdir = os.path.join(folder, "field") os.makedirs(fdir, exist_ok=True) for name, url, want in FIELD: fetch(url, os.path.join(fdir, name), want) print("ready:", out, "and", fdir) if __name__ == "__main__": main()