# -*- coding: utf-8 -*-
"""Round 274: Immunology/Microbiology PhD fourth wave - WashU DBBS, Northwestern IBiS, Vanderbilt IGP PATH, Georgetown M&I, UCLA MIMG."""
import os, re, json

ROOT = r"D:\work buddy\2026-11-05-14-15-52"
INDEX = os.path.join(ROOT, "index_main.html")
DETAILS = os.path.join(ROOT, "details")

DETAIL_TEMPLATE = """<!doctype html>
<html lang="en"><head><meta charset="utf-8">
<title>{title} | {school}</title>
<link rel="stylesheet" href="../style.css">
</head><body class="det">
<header class="det-hdr"><a class="back" href="../index_main.html">← Back to Program Database</a></header>
<main>
<h1>{title}</h1>
<p class="meta">{school} · {deg} · {lvl_label} · {stem_label}</p>

<section class="card"><h2>Overview</h2><p>{overview}</p></section>

<section class="card"><h2>Degree &amp; Requirements</h2><ul>
<li><strong>Degree:</strong> {deg}</li>
<li><strong>Field:</strong> {field}</li>
<li><strong>Typical duration:</strong> {duration}</li>
<li><strong>STEM-designated:</strong> {stem_label}</li>
<li><strong>Degree requirements:</strong> {reqs}</li>
</ul></section>

<section class="card"><h2>Application Deadline</h2><ul>
<li><strong>Deadline:</strong> {ddl}</li>
<li><strong>Application opens:</strong> {opens}</li>
<li><strong>Fee:</strong> {fee}</li>
<li><strong>Interviews:</strong> {interviews}</li>
</ul></section>

<section class="card"><h2>Language &amp; Standardized Tests</h2><ul>
<li><strong>English proficiency:</strong> {lang}</li>
<li><strong>TOEFL institution code:</strong> {ets}</li>
<li><strong>GRE policy:</strong> {gre}</li>
</ul></section>

<section class="card"><h2>Funding &amp; Stipend</h2><p>{funding}</p></section>

<section class="card"><h2>Notes</h2><ul>
<li>{note1}</li>
<li>{note2}</li>
<li>{note3}</li>
</ul></section>

<section class="card"><h2>Official Source</h2><p><a href="{source_url}" target="_blank" rel="noopener">{source_url}</a></p></section>
</main></body></html>
"""

PAGES = [
    {
        "id": "wustl-dbbs-immunology-phd",
        "s": "wustl",
        "n": "Immunology PhD (DBBS)",
        "en": "PhD in Immunology, Roy and Diana Vagelos Division of Biology & Biomedical Sciences (DBBS)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "stem_label": "STEM-designated",
        "dur": "7 years",
        "ddl": "Nov 15, 2026 (11:59 PM EST; application opens Sept 1, 2026)",
        "lang": "TOEFL iBT min 100 (new scale 5.0) / IELTS Academic min 7.0 / GATEWAY min 525 / Duolingo min 130",
        "ets": "6929 (Washington University in St. Louis Graduate Programs)",
        "gre": "GRE General: NOT REQUIRED NOR ACCEPTED (submitted scores not reviewed). GRE Subject: not accepted.",
        "tui": "Full tuition waiver + yearly stipend + health insurance guaranteed to all accepted students; no debt.",
        "url": "details/wustl-dbbs-immunology-phd.html",
        "school": "Washington University in St. Louis",
        "title": "Immunology PhD (DBBS)",
        "overview": "The Immunology program is a graduate training program at Washington University in St. Louis, housed under the Roy and Diana Vagelos Division of Biology & Biomedical Sciences (DBBS). DBBS comprises 12 graduate programs, nearly 650 faculty from over 30 university-wide departments, and more than 600 students. Immunology (IMM) is a top-ranked program examining mechanisms of host defense against pathogenic agents, with a strong foundation in biochemistry, molecular biology, and cell biology. Founded in 1980, the program brings together a critical mass of immunologists.",
        "field": "Immunology / Host Defense",
        "reqs": "Total 36 units; required courses include BBS 5098 Graduate Research Fundamentals, BBS 5011 Ethics & Research Science, BBS 5053 Immunobiology I; must maintain 9 graduate credits per semester for full-time status; pass qualifying examination; complete doctoral candidacy; form Research Advisory Committee (RAC); write, defend, and submit dissertation. Competitive candidates have ~12 months lab research experience (cumulative), GPA 3.0-4.0 (US scale), rigorous STEM coursework, and 3 strong letters of recommendation. DBBS does not set minimum GPA.",
        "opens": "September 1, 2026",
        "fee": "$45 USD; fee waivers available in certain circumstances",
        "interviews": "No rolling admissions; admissions committee review after Nov 15 deadline; interviews and on-campus visits January-February; decisions by early March.",
        "funding": "All accepted PhD students receive no-debt funding: full tuition waiver, yearly stipend, and health insurance guaranteed for the duration of training regardless of department or program. DBBS has >700 faculty mentors across 30+ university-wide departments.",
        "note1": "DBBS unified admissions: regardless of admitted program, students may rotate and work with any of the >700 DBBS faculty.",
        "note2": "DBBS does NOT have rolling admissions; application must be complete by Nov 15 11:59 PM EST.",
        "note3": "Official scores must be less than two years old at the time of application; deferred admits may need to submit new scores.",
        "source_url": "https://dbbs.wustl.edu/programs/immunology/",
    },
    {
        "id": "nu-ibis-phd",
        "s": "nu",
        "n": "Biological Sciences PhD (IBiS, Immunology-related track)",
        "en": "Interdisciplinary Biological Sciences (IBiS) Program PhD, The Graduate School",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "stem_label": "STEM-designated",
        "dur": "5-6 years (Fall entry only)",
        "ddl": "Dec 1, 2026 (for full financial support consideration)",
        "lang": "TOEFL iBT min required (per IBiS FAQ: 577 paper-based or 90 iBT minimum; higher recommended); IELTS accepted",
        "ets": "1565 (Northwestern The Graduate School; no department code needed)",
        "gre": "GRE General: NOT REQUIRED. GRE Subject: NOT REQUIRED (per IBiS FAQ: 'No, neither GRE general nor subject scores are required').",
        "tui": "Full tuition waiver + stipend + health/dental insurance guaranteed to all admitted students (including international), contingent on satisfactory progress.",
        "url": "details/nu-ibis-phd.html",
        "school": "Northwestern University",
        "title": "Biological Sciences PhD (IBiS)",
        "overview": "The Interdisciplinary Biological Sciences (IBiS) Program at Northwestern's Weinberg College provides PhD training across molecular biosciences, cell biology, genetics, developmental biology, immunology, and quantitative biology. Approximately 55 training faculty are drawn from Molecular Biosciences, Biomedical Engineering, Neurobiology, Chemistry, Chemical and Biological Engineering, the Center for Cell and Developmental Systems Biology, the Chemistry of Life Processes Institute, the Center for Structural Biology, and the NSF-Simons Center for Quantitative Biology. IBiS admits approximately 20 students per year.",
        "field": "Biological Sciences / Immunology / Molecular Biosciences",
        "reqs": "Total 11 units; required courses IBIS 411 Fundamentals (Biochem/Molecular/Genetics), IBIS 412 Fundamentals (Genomics/Cell/Developmental), IBIS 432 Statistics for Life Sciences, IBIS 499 Independent Study (3 units across fall/winter/spring rotations), plus 1 additional core, 2 electives, 2 special topics. Non-credit: IBIS 421 Rigor & Reproducibility, IBIS 423 Ethics in Biological Research, IBIS 462 Seminar. Publication: at least one first-author data paper or two co-first-author papers before defense. Teaching: 2 quarters as TA. Fall admission only.",
        "opens": "September 15, 2026 (via TGS portal)",
        "fee": "$95 USD; IBiS cannot directly provide fee waivers but eligible applicants may receive TGS waivers on first-come first-served basis.",
        "interviews": "Admissions committee review December-January; selected candidates invited to interviews late January and early February; top applicants invited to in-person visit March; decisions shortly after interviews; offers by April 15 (CGS deadline).",
        "funding": "Stipend $47,748 for 2026-27. All admitted students receive full tuition waiver, competitive stipend, and health/dental insurance as long as they progress satisfactorily through the program. IBiS does not offer a terminal Master's degree.",
        "note1": "IBiS is Weinberg College PhD (Evanston campus); Feinberg School of Medicine has a separate Driskill Graduate Program (DGP) for biomedical PhD tracks including Immunology.",
        "note2": "Fall entry only - no winter or spring admission.",
        "note3": "No master's degree offered; doctorate in Biological Sciences is awarded upon completion.",
        "source_url": "https://ibis.northwestern.edu/graduate/prospective/",
    },
    {
        "id": "vanderbilt-igp-path-phd",
        "s": "vanderbilt",
        "n": "Molecular Pathology & Immunology PhD (IGP)",
        "en": "PhD in Molecular Pathology and Immunology, Interdisciplinary Graduate Pathway (IGP)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "stem_label": "STEM-designated",
        "dur": "5.5-6 years (Fall entry only)",
        "ddl": "Priority Nov 15, 2026; Final Dec 1, 2026 (12:00 midnight CST / UTC-6)",
        "lang": "TOEFL / IELTS / Duolingo required for international applicants (waiver possible if degree from English-speaking institution or English-medium university)",
        "ets": "1871 (Vanderbilt Graduate School; department code 0202 if required, otherwise any department code works)",
        "gre": "GRE General: Optional per Vanderbilt Graduate School program table (IGP = Optional). GRE Subject: not required. Per IGP international FAQ: 'Neither the general GRE exam... nor the subject tests are required for admission.'",
        "tui": "Guaranteed stipend + tuition waiver + health insurance; fee waiver for applicants with US-based research experience.",
        "url": "details/vanderbilt-igp-path-phd.html",
        "school": "Vanderbilt University",
        "title": "Molecular Pathology & Immunology PhD (IGP)",
        "overview": "The Interdisciplinary Graduate Pathway (IGP) in Biological and Biomedical Sciences is Vanderbilt's umbrella biomedical PhD pathway offering entry into 11 participating departments and programs including Molecular Pathology and Immunology. IGP receives over 1,200 applications per cycle. Students complete 4 required research rotations in Year 1 before selecting a dissertation lab. The IGP and QCB (Quantitative and Chemical Biology) pathways share the same 11+ departments and faculty; IGP is designed for applicants with strong wet-lab biology backgrounds.",
        "field": "Molecular Pathology / Immunology / Host-Pathogen Interactions",
        "reqs": "Apply through IGP (one application); 3 letters of recommendation; Personal Statement required. Undergraduate background typically in Biology, Cell & Molecular Biology, or Biochemistry. Fall admission only - no spring. At end of Year 1 students choose one of 11 departments including Molecular Pathology and Immunology, Microbe-Host Interactions, Cancer Biology, Cell & Developmental Biology, Human Genetics, Molecular Physiology & Biophysics, Biochemistry, Biological Sciences, Chemical & Physical Biology, Neuroscience, and Pharmacology.",
        "opens": "August 1, 2026",
        "fee": "Application fee; fee waiver available for applicants with US-based research (e.g., NIH-funded programs, VU-associated fellowship/training programs) and for international applicants who do not qualify for research waiver.",
        "interviews": "Initial review begins after Nov 15 priority deadline; full review after Dec 1 final; interview invitations January through end of February; on-campus interviews January-March; April 15 CGS reply deadline.",
        "funding": "Guaranteed stipend, tuition waiver, and health insurance for the duration of training. Vanderbilt VU School of Medicine receives ~$350M in NIH grants (ranked top 16 US News 2019).",
        "note1": "Two biomedical PhD pathways at Vanderbilt: IGP (wet-lab biology) and QCB (quantitative/chemical). Both pathways share faculty and departments; applicants choose one pathway at application.",
        "note2": "Fall admission only - no spring start.",
        "note3": "Vanderbilt also hosts VBI Neuroscience PhD as a separate program (already in database).",
        "source_url": "https://medschool.vanderbilt.edu/igp/igp-program-overview/",
    },
    {
        "id": "georgetown-microbiology-immunology-phd",
        "s": "geo",
        "n": "Microbiology & Immunology PhD",
        "en": "PhD in Microbiology and Immunology, Department of Microbiology & Immunology",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "stem_label": "STEM-designated",
        "dur": "5-6 years",
        "ddl": "Dec 1, 2026 (Summer admission program starts July 1, 2027)",
        "lang": "TOEFL iBT min 80 (old scale; new scale 4.0 as of Jan 21, 2026) / IELTS min 7.0; InitialView strongly recommended for international PhD applicants",
        "ets": "5244 (Georgetown University; no department code needed)",
        "gre": "GRE General: Not required, but invited to report if available. MCAT: Not required, but may be reported. No minimum score.",
        "tui": "Financial support packages available (contact program for details)",
        "url": "details/georgetown-microbiology-immunology-phd.html",
        "school": "Georgetown University",
        "title": "Microbiology & Immunology PhD",
        "overview": "The Department of Microbiology & Immunology at Georgetown University Medical Center offers a PhD in Microbiology and Immunology. Research spans infectious disease, immunology, microbial pathogenesis, and host defense. A distinctive feature is the GU-NIH Graduate Program partnership with the National Institutes of Health: most doctoral students conduct their dissertation research at NIH. Students may also apply directly through Georgetown's Graduate Admissions portal for on-campus dissertation research.",
        "field": "Microbiology / Immunology / Infectious Disease",
        "reqs": "Direct application via Georgetown Graduate Admissions portal OR through GU-NIH partnership portal. Students do not need to arrange a laboratory position prior to admission. Upon entering, students meet with advisors to plan coursework and select laboratories for research rotations. Highly competitive admission. Fall/Summer admission (program starts July 1); rolling notification after file complete.",
        "opens": "August 1 (rolling)",
        "fee": "Application fee (early January deadline for MS fee waiver; PhD fee details on application portal)",
        "interviews": "Admissions committee review after Dec 1 deadline; rolling notifications as files complete; summer start July 1.",
        "funding": "Financial support packages (assistantships, fellowships) available; contact department for current stipend and tuition details.",
        "note1": "Two application pathways: GU-NIH partnership (dissertation at NIH, separate portal) and Georgetown Direct (on-campus). Deadlines may differ between portals - follow GU-NIH portal instructions if applying via that route.",
        "note2": "Program starts Summer (July 1) - unusual for PhD programs which typically start Fall.",
        "note3": "InitialView is strongly recommended for international PhD applicants (in addition to TOEFL/IELTS).",
        "source_url": "https://microbiology.georgetown.edu/academics/phd-program/admissions/",
    },
    {
        "id": "ucla-mimg-phd",
        "s": "ucla",
        "n": "Microbiology, Immunology & Molecular Genetics PhD (GPB IMMP)",
        "en": "PhD in Microbiology, Immunology and Molecular Genetics, Home Area: Immunity, Microbes and Molecular Pathogenesis (GPB)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "stem_label": "STEM-designated",
        "dur": "6 years (18 academic quarters)",
        "ddl": "Dec 1, 2026 (for Fall 2027 admission)",
        "lang": "TOEFL iBT / IELTS / Duolingo accepted (per UCLA graduate division minimums)",
        "ets": "4837 (UCLA); major code 0440 (MIMG); IMMP home area code 0229",
        "gre": "GRE General: Optional (since September 2020, all Home Areas within UCLA GPB have decided to make GRE General optional). Submitted scores may be reported but not required. GRE Subject: not required.",
        "tui": "Full tuition waiver + competitive stipend + health insurance guaranteed to all admitted PhD students",
        "url": "details/ucla-mimg-phd.html",
        "school": "University of California, Los Angeles (UCLA)",
        "title": "Microbiology, Immunology & Molecular Genetics PhD (GPB IMMP)",
        "overview": "The Department of Microbiology, Immunology and Molecular Genetics (MIMG) offers PhD training through UCLA's Graduate Programs in Bioscience (GPB) umbrella. The Immunity, Microbes and Molecular Pathogenesis (IMMP) Home Area covers microbiology, immunology, microbial pathogenesis, host-pathogen relationships, molecular genetics, virology, and recombinant DNA research. MIMG 285 Immunology is a flagship 5-unit graduate course. The program prepares students for independent research careers in academia, industry, and government.",
        "field": "Microbiology / Immunology / Molecular Genetics / Pathogenesis",
        "reqs": "18 academic quarters (6 years) normal time-to-degree. Written and oral qualifying examinations must be completed by end of Fall Quarter of the third year (second year in department) and passed by Spring Quarter. Advancement to candidacy upon successful completion of QE. Dissertation and final oral examination by fifth year, no later than 18 quarters. Apply via GPB umbrella (one application covers multiple bioscience Home Areas).",
        "opens": "September 1, 2026",
        "fee": "$135 US / $155 International (non-refundable)",
        "interviews": "Admissions committee review after Dec 1; interview invitations January-February; on-campus recruitment March; decisions by early March.",
        "funding": "All admitted PhD students receive full tuition waiver, competitive stipend, and health insurance. UCLA GPB offers unified biosciences PhD training with cross-Home Area flexibility.",
        "note1": "UCLA GPB comprises 7 Home Areas: Biochemistry/Biophysics/Structural Biology; Bioinformatics; Cell & Developmental Biology; Gene Regulation/Epigenomics/Transcriptomics; Genetics & Genomics; Immunity/Microbes/Molecular Pathogenesis; plus Neurosciences (separate program code NE75).",
        "note2": "GRE General has been optional for all GPB Home Areas since September 2020 - submitted scores are not required.",
        "note3": "MIMG also offers an MS degree (terminal) but the PhD program is the primary research training pathway.",
        "source_url": "https://grad.ucla.edu/requirements/?app=admission&major=0440",
    },
]

def write_detail(page):
    html = DETAIL_TEMPLATE.format(**page)
    out = os.path.join(DETAILS, page["id"] + ".html")
    with open(out, "w", encoding="utf-8") as f:
        f.write(html)
    print("Wrote:", os.path.relpath(out, ROOT))
    return out

def build_programs_block(pages):
    lines = []
    for p in pages:
        lines.append(
            '{{id:"{id}",s:"{s}",n:"{n}",en:"{en}",deg:"{deg}",lvl:"{lvl}",stem:{stem},dur:"{dur}",ddl:"{ddl}",lang:"{lang}",test:{{cls:"{gre}"}},tui:"{tui}",url:"{url}"}}'.format(**p)
        )
    return ",\n".join(lines)

def append_programs_and_vd(html, new_block):
    m = re.search(r"const\s+PROGRAMS\s*=\s*\[", html)
    if not m:
        raise RuntimeError("PROGRAMS start not found")
    start = m.end()
    depth = 1
    i = start
    while i < len(html) and depth > 0:
        c = html[i]
        if c == "[":
            depth += 1
        elif c == "]":
            depth -= 1
        i += 1
    insert_pos = i - 1
    before = html[:insert_pos].rstrip()
    if before and not before.endswith(","):
        before = before + ","
    after = html[insert_pos:]
    html = before + "\n" + new_block + "\n" + after

    m2 = re.search(r"const\s+VERIFIED_DETAILS\s*=\s*new\s+Set\(\s*\[", html)
    if not m2:
        raise RuntimeError("VD Set start not found")
    vstart = m2.end()
    depth = 1
    j = vstart
    while j < len(html) and depth > 0:
        c = html[j]
        if c == "[":
            depth += 1
        elif c == "]":
            depth -= 1
        j += 1
    vd_close = j
    before_vd = html[:vd_close].rstrip()
    if before_vd and not before_vd.endswith(","):
        before_vd = before_vd + ","
    new_vd_items = ",".join('"{}"'.format(p["url"]) for p in PAGES)
    after_vd = html[vd_close:]
    html = before_vd + "\n" + new_vd_items + "\n" + after_vd
    return html

def main():
    for p in PAGES:
        p["lvl_label"] = "Doctoral" if p["lvl"] == "d" else "Master's"
        p["duration"] = p["dur"]
        write_detail(p)
    with open(INDEX, "r", encoding="utf-8") as f:
        html = f.read()
    block = build_programs_block(PAGES)
    html = append_programs_and_vd(html, block)
    with open(INDEX, "w", encoding="utf-8") as f:
        f.write(html)
    print(f"Appended {len(PAGES)} PROGRAMS entries and {len(PAGES)} VD entries")
    print("Done. File size:", os.path.getsize(INDEX))

if __name__ == "__main__":
    main()
