"""Second, separately written reader for the DEG counts (RULES_deg_recount.txt, section 3). Data only. Fact-Checked Science ("Our analysis"), https://factchecked.science/planthopper-magnetic-genes/ Data: Xie, W., et al. (2026), Dryad, doi:10.5061/dryad.r4xgxd2vx (CC0); make the input folder with prepare_inputs.py, then pass /dataset (or /field for igrf_route.py) as the script's usage says. Different parsing path from xlsx_reader.py: streams each sheet's XML with ElementTree.iterparse, resolves shared strings itself, takes columns by letter (A, C, G), and counts with plain Python (no pandas, no numpy). Usage: python3 deg_recount_check.py """ import sys import zipfile import xml.etree.ElementTree as ET M = "{http://schemas.openxmlformats.org/spreadsheetml/2006/main}" R = "{http://schemas.openxmlformats.org/officeDocument/2006/relationships}" def main(): z = zipfile.ZipFile(sys.argv[1]) sst = [("".join(t.text or "" for t in si.iter(M + "t"))) for si in ET.fromstring(z.read("xl/sharedStrings.xml")).iter(M + "si")] wb = ET.fromstring(z.read("xl/workbook.xml")) rels = ET.fromstring(z.read("xl/_rels/workbook.xml.rels")) tgt = {r.get("Id"): r.get("Target") for r in rels} for sh in wb.iter(M + "sheet"): name = sh.get("name") path = "xl/" + tgt[sh.get(R + "id")].lstrip("/").replace("xl/", "") cols = {} rows = [] with z.open(path) as fh: for ev, el in ET.iterparse(fh, events=("end",)): if el.tag == M + "c": ref = el.get("r") letters = "".join(ch for ch in ref if ch.isalpha()) v = el.find(M + "v") val = None if v is not None and v.text is not None: val = sst[int(v.text)] if el.get("t") == "s" else v.text cols[letters] = val elif el.tag == M + "row": rows.append(cols) cols = {} el.clear() header = rows[0] assert header.get("A") == "GeneSymbol" and header.get("C") == "log2FoldChange" and header.get("G") == "padj", header total = up = down = 0 for r in rows[1:]: padj = r.get("G") if padj in (None, "NA", ""): continue p = float(padj) l = float(r.get("C")) if p < 0.05 and l > 0.25: up += 1 elif p < 0.05 and l < -0.25: down += 1 total = up + down print("%-22s rows %5d DEGs %4d (up %4d, down %4d)" % (name, len(rows) - 1, total, up, down)) if __name__ == "__main__": main()