OpenIslet

scripts/harvest_corpus.py

OpenIslet.org (Project Islet-1) — Multi-Source Corpus Finder & Harvester (v0.3)

script Release v0.8.0 gen-eb955f8266035aba 60 KB · 5 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/harvest_corpus.py · SHA-256: c61503b386f1f486…

        if preprint_records:
            ppr_file = RAW_DIR / "preprints_sc_islets_hypoimmune.jsonl"
            with open(ppr_file, "w", encoding="utf-8") as fp:
                for ppr in preprint_records:
                    fp.write(json.dumps(ppr, ensure_ascii=False) + "\n")
            print(f"[PREPRINTS] Saved {len(preprint_records)} deduplicated bioRxiv/medRxiv/PPR records to {ppr_file}")

    all_pmids = sorted(pillar_map.keys(), reverse=True)
    overlap_stats = compute_overlap_breakdown(pillar_map)

    print(f"\n[SUMMARY] Total Deduplicated Primary PubMed PMIDs: {len(all_pmids)}")
    print(f"[OVERLAP] Multi-Sub-Pillar Hit Distribution: {json.dumps(overlap_stats['subpillar_hit_distribution'])}")
    print(f"[OVERLAP] Multi-Major-Pillar Hit Distribution: {json.dumps(overlap_stats['major_pillar_hit_distribution'])}")
    print(f"[OVERLAP] SC-Islet Multi-Gate Intersections: {json.dumps(overlap_stats['sc_islet_multi_gate_intersections'])}")
    print(f"[OVERLAP] Pairwise Major Pillar Intersections: {json.dumps(overlap_stats['major_pillar_pairwise_intersections'])}")

    if args.dry_run_counts:
        id_manifest = RAW_DIR / f"discovered_pmids_{args.mode}.json"
        with open(id_manifest, "w", encoding="utf-8") as fid:
            json.dump({
                "generated_at": "2026-10-20",
                "mode": args.mode,
                "total_deduplicated_pmids": len(all_pmids),
                "total_preprints": len(preprint_records),
                "total_patents": len(patent_records),
                "total_geo_gse_series": len(geo_datasets),
                "golden_seed_recall": f"{len(caught_seeds)}/{len(GOLDEN_SEED_PMIDS)}",
                "overlap_breakdown": overlap_stats,
                "pmid_to_pillars": pillar_map,
            }, fid, indent=2)
        print(f"[MANIFEST] Saved deduplicated PMID & source map ({len(all_pmids)} PMIDs) to {id_manifest}")
        return

    out_file = RAW_DIR / f"corpus_manifest_{args.mode}.jsonl"
    n_written = efetch_metadata(all_pmids, pillar_map, out_file)
    print(f"Done. Wrote {n_written} records to {out_file}")


if __name__ == "__main__":
    main()