Arteries and it's branches of the pelvis. In male and female separate Need the notes for mbbs student with detailed notes from basics to advance and veins and it's all branches with images

Reading File
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Reading File
Reading File
Finding Sources
Loading Image
Loading Image
Loading Image
Loading Image
Finding Sources
I now have all the content I need from Gray's Anatomy for Students. Let me compile the comprehensive MBBS notes.

Arteries and Veins of the Pelvis

Complete MBBS Notes - Basics to Advanced

Source: Gray's Anatomy for Students; Imaging Anatomy Vol. 3

INTRODUCTION & OVERVIEW

The pelvis receives its blood supply mainly from the internal iliac artery (hypogastric artery), with additional contributions from the median sacral artery (unpaired, from aorta) and the ovarian/testicular arteries (direct aortic branches).
The abdominal aorta bifurcates at the level of vertebral level LIV into the two common iliac arteries. Each common iliac divides at the level of the lumbosacral disc (LV-SI) - anteromedial to the sacro-iliac joint - into:
  • External iliac artery - becomes the femoral artery at the inguinal ligament
  • Internal iliac artery - the main vessel supplying the pelvis

PART 1: INTERNAL ILIAC ARTERY (Main Pelvic Artery)

The internal iliac artery courses inferiorly over the pelvic inlet and divides into two trunks at the level of the superior border of the greater sciatic foramen:
Abdominal Aorta (LIV)
        |
   Common Iliac Artery
        |
   _____|_____
   |         |
External    Internal Iliac Artery (LV-SI)
Iliac           |
           _____|_____
           |         |
      Posterior    Anterior
        Trunk        Trunk

PART 2: POSTERIOR TRUNK - Branches

The posterior trunk gives 3 branches (mnemonic: ILS - Iliolumbar, Lateral sacral, Superior gluteal):

1. Iliolumbar Artery

  • Ascends laterally back out of the pelvic inlet
  • Lumbar branch: supplies posterior abdominal wall, psoas and quadratus lumborum muscles, and cauda equina (via a spinal branch through L5-S1 intervertebral foramen)
  • Iliac branch: passes into the iliac fossa to supply muscle and bone

2. Lateral Sacral Arteries (usually 2)

  • Course medially and inferiorly along the posterior pelvic wall
  • Branches pass into the anterior sacral foramina to supply bone and soft tissues, structures in the sacral canal, and skin and muscle posterior to the sacrum
  • Anastomoses with the median sacral artery

3. Superior Gluteal Artery

  • The largest branch of the internal iliac artery
  • Terminal continuation of the posterior trunk
  • Passes between lumbosacral trunk and anterior ramus of S1
  • Exits through greater sciatic foramen above piriformis
  • Enters the gluteal region and supplies gluteal muscles and skin
  • Also supplies branches to adjacent pelvic wall muscles and bones

PART 3: ANTERIOR TRUNK - Branches

The anterior trunk gives branches to the pelvic viscera, perineum, gluteal region, and adductor region of the thigh.

Branches Common to Both Male and Female:

1. Umbilical Artery (first branch of anterior trunk)

  • Gives origin to the superior vesical artery, then travels forward just inferior to the pelvic inlet margin
  • Leaves pelvic cavity and ascends on the internal aspect of the anterior abdominal wall to the umbilicus
  • In fetus: large, carries fetal blood to placenta
  • After birth: distal portion closes to form the medial umbilical ligament (fibrous cord) - visible as the medial umbilical fold of peritoneum
  • Proximal portion remains patent and gives off the superior vesical artery

2. Superior Vesical Artery

  • Originates from the root of the umbilical artery
  • Courses medially and inferiorly to supply the superior aspect of the bladder and distal ureter
  • In men, may also give an artery to the ductus deferens

3. Obturator Artery

  • Courses anteriorly along the pelvic wall
  • Exits through the obturator canal (with obturator nerve above and obturator vein below)
  • Enters the adductor region of the thigh
  • Clinical note: An accessory or replaced obturator artery can arise from the inferior epigastric artery ("corona mortis" - "crown of death") - at risk during femoral hernia repair

4. Middle Rectal Artery

  • Courses medially to supply the rectum
  • Anastomoses with:
    • Superior rectal artery (from inferior mesenteric artery) - above
    • Inferior rectal artery (from internal pudendal) - below

5. Internal Pudendal Artery

  • The main artery of the perineum
  • Courses inferiorly, exits through the greater sciatic foramen inferior to piriformis
  • Associated with the pudendal nerve on its medial side
  • Passes laterally to the ischial spine, then through the lesser sciatic foramen to enter the perineum
  • Supplies erectile tissues of the clitoris (female) and penis (male)
  • Branches in the perineum: inferior rectal artery, perineal artery, dorsal artery of clitoris/penis, deep artery of clitoris/penis

6. Inferior Gluteal Artery

  • A large terminal branch of the anterior trunk
  • Passes between anterior rami S1-S2 or S2-S3 of sacral plexus
  • Exits through greater sciatic foramen inferior to piriformis (same gap as internal pudendal artery and pudendal nerve)
  • Enters the gluteal region, supplies gluteal muscles
  • Anastomoses with vessels around the hip joint

PART 4: MALE-SPECIFIC BRANCHES (Anterior Trunk)

Anterior trunk of internal iliac artery - Male
Fig. 5.66A - Branches of the Anterior Trunk of the Internal Iliac Artery in the Male (Gray's Anatomy for Students)

Inferior Vesical Artery (Male Equivalent of Vaginal Artery)

  • Supplies the bladder, ureter, seminal vesicle, and prostate
  • No equivalent female structure - in women this is replaced by the vaginal artery

Summary - Male Anterior Trunk Branches:

BranchSupply
Umbilical arteryGives off superior vesical; forms medial umbilical ligament
Superior vesicalSuperior bladder, distal ureter, artery to ductus deferens
Inferior vesicalBladder, ureter, seminal vesicle, prostate
Middle rectalRectum
ObturatorAdductor region of thigh
Internal pudendalPerineum, penis (erectile tissue)
Inferior glutealGluteal region, hip anastomosis

PART 5: FEMALE-SPECIFIC BRANCHES (Anterior Trunk)

Anterior trunk of internal iliac artery - Female
Fig. 5.66B - Branches of the Anterior Trunk of the Internal Iliac Artery in the Female (Gray's Anatomy for Students)
Uterine and Vaginal Arteries
Fig. 5.67 - Uterine and Vaginal Arteries, showing ovarian artery and broad ligament (Gray's Anatomy for Students)

Uterine Artery (Female)

  • Courses medially and anteriorly in the base of the broad ligament to reach the cervix
  • Crosses the ureter (passes superiorly to the lateral vaginal fornix)
  • Classic mnemonic: "Water (ureter) under the bridge (uterine artery)"
  • Ascends along the lateral margin of the uterus to reach the uterine tube
  • Curves laterally and anastomoses with the ovarian artery
  • Enlarges significantly during pregnancy
  • Through anastomoses, contributes to blood supply of ovary and vagina as well
  • Clinical significance: During hysterectomy, the ureter can be accidentally ligated when tying the uterine artery (they cross at the level of the lateral fornix)

Vaginal Artery (Female)

  • The female equivalent of the inferior vesical artery in men
  • Descends to the vagina
  • Supplies branches to the vagina, adjacent parts of the bladder, and rectum
  • May originate together with the uterine artery as a common branch, or independently

Ovarian Arteries (Female - Direct Aortic Branches, Not Internal Iliac)

  • Originate directly from the abdominal aorta (like testicular arteries in males)
  • Travel in the suspensory ligament of the ovary (infundibulopelvic ligament) as they cross the pelvic inlet
  • Branches pass through the mesovarium to reach the ovary and through the mesometrium to anastomose with the uterine artery
  • Enlarge significantly during pregnancy to augment uterine blood supply

Summary - Female Anterior Trunk Branches:

BranchSupply
Umbilical arteryGives off superior vesical; forms medial umbilical ligament
Superior vesicalSuperior bladder, distal ureter
Uterine arteryUterus, cervix, upper vagina, partial ovary; crosses ureter
Vaginal arteryVagina, adjacent bladder and rectum
Middle rectalRectum
ObturatorAdductor region of thigh
Internal pudendalPerineum, clitoris (erectile tissue)
Inferior glutealGluteal region, hip anastomosis

PART 6: MEDIAN SACRAL ARTERY

  • Originates from the posterior surface of the abdominal aorta just superior to its bifurcation at vertebral level LIV - this is an unpaired direct aortic branch
  • Descends in the midline, crosses the pelvic inlet
  • Courses along the anterior surface of the sacrum and coccyx
  • Gives rise to the last pair of lumbar arteries
  • Anastomoses with the iliolumbar and lateral sacral arteries
  • Its companion vein drains to the left common iliac vein or the IVC junction

PART 7: EXTERNAL ILIAC ARTERY (in the Pelvis)

While primarily a vessel of the lower limb, the external iliac artery gives off two branches before it crosses under the inguinal ligament:
  1. Inferior epigastric artery - ascends on the posterior surface of the anterior abdominal wall; anastomoses with the superior epigastric artery
  2. Deep circumflex iliac artery - passes laterally to supply the iliac crest region; anastomoses with iliolumbar artery branches

PART 8: VEINS OF THE PELVIS

Pelvic Veins - Male and Rectal Venous Plexus
Fig. 5.68 - Pelvic Veins (A) in a man with left side removed; (B) Veins of the rectum and anal canal - showing the portacaval anastomosis (Gray's Anatomy for Students)

General Rule

Pelvic veins follow the course of all branches of the internal iliac artery except the umbilical artery and the iliolumbar artery. On each side, veins drain into the internal iliac vein, which joins the external iliac vein to form the common iliac vein. The two common iliac veins unite on the right side of the fifth lumbar vertebra to form the inferior vena cava (IVC).
  • Right common iliac vein: ascends along a relatively straight course to the IVC
  • Left common iliac vein: runs transversely to join the right iliac vein at an acute angle
  • May-Thurner syndrome (Cockett syndrome): compression of the left common iliac vein between the right common iliac artery and vertebra - causes left-sided DVT, predominantly in young-to-middle-aged women

Pelvic Venous Plexuses

Within the pelvic cavity, extensive interconnected valveless venous plexuses surround the viscera, collectively forming the pelvic plexus of veins:
PlexusLocationAssociated VisceraDrains Into
Vesical plexusAround the bladderBladderInternal iliac vein
Prostatic plexus (male)Around prostateProstate, seminal vesiclesInternal iliac vein; receives deep dorsal vein of penis
Uterine plexus (female)Around uterusUterusInternal iliac vein
Vesicovaginal plexus (female)Between bladder and vaginaVagina, bladderInternal iliac vein
Rectal plexusAround rectum and anal canalRectumSee below (portacaval anastomosis)

Internal Iliac Vein - Tributaries

Visceral tributaries:
  • Hemorrhoidal (rectal) plexus veins
  • Vesicoprostatic plexus (male)
  • Uterine veins (female)
  • Gonadal veins (variable; usually direct aortic/renal)
  • Vesicovaginal plexus (female)
Parietal tributaries:
  • Superior and inferior gluteal veins
  • Sacral veins
  • Internal pudendal vein
  • Obturator vein
  • Sciatic/lumbar veins

PART 9: RECTAL VENOUS PLEXUS & PORTACAVAL ANASTOMOSIS (High Yield!)

The rectal plexus is an important portacaval anastomotic site:
Superior rectal vein  ------>  Inferior mesenteric vein  ------>  PORTAL SYSTEM
Middle rectal vein   ------>  Internal iliac vein        ------>  CAVAL SYSTEM
Inferior rectal vein  ------>  Internal pudendal vein    ------>  CAVAL SYSTEM
Clinical significance: In portal hypertension, these anastomoses dilate, forming rectal/anal varices (not to be confused with hemorrhoids, though the mechanism is similar).

Internal Rectal Plexus

  • Located in connective tissue between the internal anal sphincter and the epithelium
  • Connects superiorly with longitudinal branches of the superior rectal vein in each anal column
  • Enlargement = internal hemorrhoids (above pectinate line, covered by colonic mucosa)

External Rectal Plexus

  • Circles the external anal sphincter, subcutaneous
  • Enlargement = external hemorrhoids (below pectinate line)

PART 10: DEEP DORSAL VEIN (Male & Female)

  • A single deep dorsal vein drains erectile tissues of the penis (male) or clitoris (female)
  • Does NOT follow the internal pudendal artery
  • Passes directly into the pelvic cavity through a gap between the arcuate pubic ligament and the anterior margin of the perineal membrane
  • In men: joins the prostatic plexus of veins
  • In women: joins the vesical (bladder) plexus of veins
  • Note: Superficial veins draining the skin of the penis/clitoris drain into external pudendal veins → great saphenous vein in the thigh

PART 11: VEINS THAT LEAVE THE PELVIS VIA THE ABDOMEN

  1. Median sacral veins: coalesce into a single vein that joins the left common iliac vein or the IVC junction
  2. Ovarian veins (female):
    • Left ovarian vein drains into the left renal vein
    • Right ovarian vein drains directly into the IVC
    • Clinical: Left ovarian vein nutcracker compression can cause pelvic congestion syndrome

PART 12: KEY CLINICAL CORRELATIONS (MBBS Exam Favourites)

Clinical PointKey VesselRelevance
"Water under the bridge"Uterine artery crossing ureterHysterectomy - risk of ureteric injury
Corona mortisAccessory obturator artery from inferior epigastricFemoral hernia repair
Internal hemorrhoidsSuperior rectal vein (portal)Portal hypertension, pectinate line (above)
External hemorrhoidsExternal rectal plexus (caval)Below pectinate line, painful
May-Thurner syndromeLeft common iliac vein compressionLeft DVT in young women
Pelvic congestion syndromeIncompetent internal iliac tributaries, ovarian veinsChronic pelvic pain in women
Medial umbilical ligamentObliterated umbilical arteryFetal remnant, medial umbilical fold
Prostatic plexusDeep dorsal vein + internal iliac tributariesRoute of prostate cancer spread
Ovarian vein asymmetryRight → IVC; Left → left renal veinExplains left > right varicocele

QUICK REVISION SUMMARY

Arteries - Mnemonic for Internal Iliac Branches

Posterior Trunk (3): Iliolumbar, Lateral sacral, Superior gluteal → "ILS"
Anterior Trunk Common (5): Umbilical → Superior vesical, Middle rectal, Obturator, Internal pudendal, Inferior gluteal
Anterior Trunk Male-specific: Inferior vesical (bladder, prostate, seminal vesicle)
Anterior Trunk Female-specific: Uterine artery + Vaginal artery (replaces inferior vesical)

Veins

  • Pelvic veins are largely valveless - only 10% of internal iliac veins have valves, 27% of external iliac veins
  • Extensive plexuses allow collateral flow in IVC obstruction
  • Rectal plexus = most clinically important portacaval anastomosis in the pelvis

Sources: Gray's Anatomy for Students (9780323934237); Imaging Anatomy Vol. 3: Bones, Joints, Vessels and Nerves (9781626239845)

Create a comparison table (excel) of male vs female pelvic arterial supply and its branches

Reading File
Reading File
Running Command

ls -la /home/daytona/workspace/

Running Command

mkdir -p /home/daytona/workspace/pelvic-arteries

Writing File

~/pelvic-arteries/build_table.py

from openpyxl import Workbook
from openpyxl.styles import (
    Font, PatternFill, Alignment, Border, Side, GradientFill
)
from openpyxl.utils import get_column_letter

wb = Workbook()

# ── Sheet 1: Comparison Table ─────────────────────────────────────────────────
ws1 = wb.active
ws1.title = "Male vs Female Comparison"

# ── Colour palette ─────────────────────────────────────────────────────────────
BLUE_DARK   = "1F3864"   # deep navy  – main header bg
BLUE_MID    = "2E75B6"   # mid blue   – section headers
BLUE_LIGHT  = "BDD7EE"   # pale blue  – male column header
PINK_LIGHT  = "FCE4D6"   # pale pink  – female column header
PINK_DARK   = "C00000"   # deep red   – female header text
YELLOW_FILL = "FFFF00"   # highlight  – sex-specific cells
GREEN_FILL  = "E2EFDA"   # pale green – shared branches
GREY_ROW    = "F2F2F2"   # alternate row
WHITE       = "FFFFFF"

def hdr_font(bold=True, size=11, color="FFFFFF"):
    return Font(name="Arial", bold=bold, size=size, color=color)

def cell_font(bold=False, size=10, color="000000"):
    return Font(name="Arial", bold=bold, size=size, color=color)

thin = Side(style="thin", color="B8B8B8")
med  = Side(style="medium", color="595959")

def thin_border():
    return Border(left=thin, right=thin, top=thin, bottom=thin)

def med_border():
    return Border(left=med, right=med, top=med, bottom=med)

def fill(hex_color):
    return PatternFill("solid", start_color=hex_color, fgColor=hex_color)

def center_align(wrap=True):
    return Alignment(horizontal="center", vertical="center", wrap_text=wrap)

def left_align(wrap=True):
    return Alignment(horizontal="left", vertical="center", wrap_text=wrap)

# ── Title row ──────────────────────────────────────────────────────────────────
ws1.merge_cells("A1:G1")
c = ws1["A1"]
c.value = "PELVIC ARTERIAL SUPPLY — MALE vs FEMALE COMPARISON TABLE"
c.font  = Font(name="Arial", bold=True, size=14, color=WHITE)
c.fill  = fill(BLUE_DARK)
c.alignment = center_align()
ws1.row_dimensions[1].height = 30

# Sub-title
ws1.merge_cells("A2:G2")
c = ws1["A2"]
c.value = "Source: Gray's Anatomy for Students  |  For MBBS Students"
c.font  = Font(name="Arial", italic=True, size=9, color="595959")
c.fill  = fill("D9E1F2")
c.alignment = center_align(wrap=False)
ws1.row_dimensions[2].height = 16

# ── Column headers ─────────────────────────────────────────────────────────────
headers = [
    "Artery / Trunk",
    "Branch",
    "Origin",
    "Course / Relations",
    "Male Supply",
    "Female Supply",
    "Clinical Notes"
]

ws1.row_dimensions[3].height = 36
for col, h in enumerate(headers, start=1):
    c = ws1.cell(row=3, column=col, value=h)
    if col == 5:
        c.fill = fill(BLUE_LIGHT)
        c.font = hdr_font(color="1F3864")
    elif col == 6:
        c.fill = fill(PINK_LIGHT)
        c.font = hdr_font(color=PINK_DARK)
    else:
        c.fill = fill(BLUE_MID)
        c.font = hdr_font()
    c.alignment = center_align()
    c.border = thin_border()

# ── Data ───────────────────────────────────────────────────────────────────────
# Columns: Artery/Trunk | Branch | Origin | Course/Relations | Male Supply | Female Supply | Clinical Notes
data = [
    # ── AORTA DIRECT ──────────────────────────────────────────────────────────
    ("AORTA (direct)", "Common Iliac Artery (×2)",
     "Abdominal aorta bifurcation at LIV",
     "Divides at LV–SI disc, anteromedial to sacro-iliac joint",
     "Divides into external & internal iliac arteries",
     "Divides into external & internal iliac arteries",
     "Aortic bifurcation landmark: LIV vertebra"),

    ("AORTA (direct)", "Median Sacral Artery (unpaired)",
     "Posterior surface of aorta, just above bifurcation at LIV",
     "Descends in midline along anterior sacrum and coccyx",
     "Supplies sacrum, coccyx; last pair of lumbar arteries",
     "Supplies sacrum, coccyx; last pair of lumbar arteries",
     "Anastomoses with iliolumbar & lateral sacral arteries"),

    ("AORTA (direct)", "Testicular Artery (Male) / Ovarian Artery (Female)",
     "Abdominal aorta below renal arteries",
     "Descends retroperitoneally, crosses pelvic brim in suspensory ligament",
     "Supplies testes via inguinal canal; anastomoses with artery to ductus deferens",
     "Travels in infundibulopelvic ligament to ovary; anastomoses with uterine artery",
     "Right drains to IVC; left drains to left renal vein → explains left-sided varicocele"),

    # ── EXTERNAL ILIAC ────────────────────────────────────────────────────────
    ("External Iliac Artery", "Inferior Epigastric Artery",
     "External iliac artery, just above inguinal ligament",
     "Ascends on posterior surface of anterior abdominal wall",
     "Supplies lower anterior abdominal wall, rectus abdominis",
     "Supplies lower anterior abdominal wall, rectus abdominis",
     "Anastomoses with superior epigastric; landmark in hernia surgery; forms lateral umbilical fold of peritoneum"),

    ("External Iliac Artery", "Deep Circumflex Iliac Artery",
     "External iliac artery, just above inguinal ligament",
     "Passes laterally parallel to inguinal ligament to iliac crest",
     "Supplies iliac crest, iliacus, transversus abdominis",
     "Supplies iliac crest, iliacus, transversus abdominis",
     "Anastomoses with iliolumbar & superior gluteal arteries"),

    # ── INTERNAL ILIAC – POSTERIOR TRUNK ──────────────────────────────────────
    ("Internal Iliac — Posterior Trunk", "Iliolumbar Artery",
     "Posterior trunk of internal iliac",
     "Ascends laterally back out of pelvic inlet",
     "Lumbar branch: psoas, quadratus lumborum, cauda equina\nIliac branch: iliac fossa muscles & bone",
     "Lumbar branch: psoas, quadratus lumborum, cauda equina\nIliac branch: iliac fossa muscles & bone",
     "Spinal branch passes through L5–S1 foramen"),

    ("Internal Iliac — Posterior Trunk", "Lateral Sacral Arteries (usually ×2)",
     "Posterior trunk of internal iliac",
     "Course medially & inferiorly along posterior pelvic wall; enter anterior sacral foramina",
     "Sacral bone, sacral canal contents, skin & muscle posterior to sacrum",
     "Sacral bone, sacral canal contents, skin & muscle posterior to sacrum",
     "Anastomoses with median sacral artery"),

    ("Internal Iliac — Posterior Trunk", "Superior Gluteal Artery",
     "Posterior trunk (terminal branch) of internal iliac — LARGEST branch",
     "Passes between lumbosacral trunk & S1 anterior ramus; exits via greater sciatic foramen ABOVE piriformis",
     "Gluteal muscles (gluteus maximus, medius, minimus), skin of gluteal region",
     "Gluteal muscles, skin of gluteal region",
     "Largest branch of internal iliac; exits ABOVE piriformis — key differentiator from inferior gluteal"),

    # ── INTERNAL ILIAC – ANTERIOR TRUNK (COMMON) ──────────────────────────────
    ("Internal Iliac — Anterior Trunk\n(Common to Both)", "Umbilical Artery",
     "First branch of anterior trunk",
     "Travels forward just inferior to pelvic inlet margin, then ascends on internal anterior abdominal wall to umbilicus",
     "Gives origin to superior vesical artery; artery to ductus deferens (sometimes)\nFetal: carries blood to placenta",
     "Gives origin to superior vesical artery\nFetal: carries blood to placenta",
     "After birth, distal part obliterates → medial umbilical ligament (raises medial umbilical fold of peritoneum)"),

    ("Internal Iliac — Anterior Trunk\n(Common to Both)", "Superior Vesical Artery",
     "Root of the umbilical artery",
     "Courses medially & inferiorly",
     "Superior bladder, distal ureter, artery to ductus deferens",
     "Superior bladder, distal ureter",
     "Most constant branch; first branch given off by umbilical artery"),

    ("Internal Iliac — Anterior Trunk\n(Common to Both)", "Middle Rectal Artery",
     "Anterior trunk of internal iliac",
     "Courses medially to rectum",
     "Middle & lower rectum",
     "Middle & lower rectum",
     "Anastomoses with superior rectal (inf. mesenteric) and inferior rectal (internal pudendal) arteries — portacaval anastomotic zone"),

    ("Internal Iliac — Anterior Trunk\n(Common to Both)", "Obturator Artery",
     "Anterior trunk of internal iliac",
     "Courses anteriorly along pelvic wall; exits via obturator canal with obturator nerve (above) and vein (below)",
     "Adductor region of thigh, hip joint",
     "Adductor region of thigh, hip joint",
     "Corona mortis: accessory obturator artery from inferior epigastric — risk in femoral hernia repair"),

    ("Internal Iliac — Anterior Trunk\n(Common to Both)", "Internal Pudendal Artery",
     "Anterior trunk of internal iliac — main artery of perineum",
     "Exits via greater sciatic foramen BELOW piriformis → around ischial spine → lesser sciatic foramen → enters perineum (Alcock's canal)",
     "Perineum, scrotum, erectile tissue of penis (dorsal artery of penis, deep artery of penis, artery of bulb)",
     "Perineum, labia, erectile tissue of clitoris (dorsal artery of clitoris, deep artery of clitoris), artery of vestibular bulb",
     "Exits BELOW piriformis (inferior gluteal exits same gap); passes WITH pudendal nerve; branch: inferior rectal artery"),

    ("Internal Iliac — Anterior Trunk\n(Common to Both)", "Inferior Gluteal Artery",
     "Terminal branch of anterior trunk of internal iliac",
     "Passes between S1–S2 or S2–S3 anterior rami; exits via greater sciatic foramen BELOW piriformis",
     "Gluteal muscles (mainly gluteus maximus), sciatic nerve, anastomosis around hip joint",
     "Gluteal muscles (mainly gluteus maximus), sciatic nerve, anastomosis around hip joint",
     "Exits BELOW piriformis (same gap as internal pudendal); anastomoses with superior gluteal, femoral circumflex arteries"),

    # ── INTERNAL ILIAC – ANTERIOR TRUNK (MALE ONLY) ───────────────────────────
    ("Internal Iliac — Anterior Trunk\n(MALE ONLY)", "Inferior Vesical Artery",
     "Anterior trunk of internal iliac",
     "Passes inferiorly and medially to bladder base",
     "Bladder base, distal ureter, seminal vesicle, prostate, sometimes urethra",
     "— (Not present; replaced by vaginal artery in females) —",
     "Female equivalent = vaginal artery; supplies prostate — important in BPH / prostate cancer surgery"),

    # ── INTERNAL ILIAC – ANTERIOR TRUNK (FEMALE ONLY) ─────────────────────────
    ("Internal Iliac — Anterior Trunk\n(FEMALE ONLY)", "Uterine Artery",
     "Anterior trunk of internal iliac",
     "Courses medially & anteriorly in base of broad ligament to cervix; CROSSES OVER URETER at lateral fornix; ascends lateral uterus to uterine tube; curves lateral to anastomose with ovarian artery",
     "— (Not present; equivalent function via inferior vesical artery) —",
     "Uterus (major supply), cervix, upper vagina, uterine tube (via anastomosis with ovarian artery), partial ovary supply",
     "\"WATER UNDER THE BRIDGE\" — uterine artery (bridge) crosses over ureter (water); risk of ureteric ligation during hysterectomy; enlarged significantly in pregnancy"),

    ("Internal Iliac — Anterior Trunk\n(FEMALE ONLY)", "Vaginal Artery",
     "Anterior trunk of internal iliac (may share origin with uterine artery)",
     "Descends to vagina; may originate independently or as common trunk with uterine artery",
     "— (Not present; inferior vesical artery performs this role) —",
     "Vagina, adjacent bladder base, adjacent rectum",
     "Female equivalent of inferior vesical artery in males"),
]

# Section background mapping
section_fills = {
    "AORTA (direct)":                                      "FFF2CC",
    "External Iliac Artery":                               "EBF3FB",
    "Internal Iliac — Posterior Trunk":                    "E2EFDA",
    "Internal Iliac — Anterior Trunk\n(Common to Both)":   "FFFFFF",
    "Internal Iliac — Anterior Trunk\n(MALE ONLY)":        "DDEEFF",
    "Internal Iliac — Anterior Trunk\n(FEMALE ONLY)":      "FFE8E8",
}

prev_section = None
row_num = 4

for row_data in data:
    trunk, branch, origin, course, male_supply, female_supply, clinical = row_data
    section_bg = section_fills.get(trunk, WHITE)

    if trunk != prev_section:
        # Section header row
        ws1.merge_cells(f"A{row_num}:G{row_num}")
        sc = ws1.cell(row=row_num, column=1, value=trunk.replace("\n", " "))
        sc.font  = Font(name="Arial", bold=True, size=10, color=WHITE)
        sc.fill  = fill(BLUE_MID)
        sc.alignment = left_align(wrap=False)
        sc.border = thin_border()
        ws1.row_dimensions[row_num].height = 20
        row_num += 1
        prev_section = trunk

    values = [trunk, branch, origin, course, male_supply, female_supply, clinical]
    for col, val in enumerate(values, start=1):
        c = ws1.cell(row=row_num, column=col, value=val)
        c.alignment = left_align()
        c.border = thin_border()
        # Colour logic
        if col == 1:
            c.value = ""   # hide trunk name in data rows (shown in section header)
            c.fill = fill(section_bg)
        elif col == 5:  # Male
            if "Not present" in str(val) or val.startswith("—"):
                c.fill = fill("FFD7D7")
                c.font = Font(name="Arial", size=10, italic=True, color="888888")
            else:
                c.fill = fill(BLUE_LIGHT)
                c.font = cell_font()
        elif col == 6:  # Female
            if "Not present" in str(val) or val.startswith("—"):
                c.fill = fill("D7D7FF")
                c.font = Font(name="Arial", size=10, italic=True, color="888888")
            else:
                c.fill = fill(PINK_LIGHT)
                c.font = cell_font()
        elif col == 7:  # Clinical notes
            c.fill = fill("FFFACD")
            c.font = Font(name="Arial", size=9, italic=True, color="4A4A00")
        else:
            c.fill = fill(section_bg)
            c.font = cell_font(bold=(col == 2))

    ws1.row_dimensions[row_num].height = 60
    row_num += 1

# ── Column widths ──────────────────────────────────────────────────────────────
col_widths = [5, 28, 32, 42, 38, 38, 42]
for i, w in enumerate(col_widths, start=1):
    ws1.column_dimensions[get_column_letter(i)].width = w

# Freeze panes (keep headers visible)
ws1.freeze_panes = "A4"

# ── Sheet 2: Quick-Reference Summary ──────────────────────────────────────────
ws2 = wb.create_sheet("Quick Reference Summary")

ws2.merge_cells("A1:E1")
c = ws2["A1"]
c.value = "QUICK REFERENCE — Internal Iliac Artery Branches"
c.font  = Font(name="Arial", bold=True, size=13, color=WHITE)
c.fill  = fill(BLUE_DARK)
c.alignment = center_align()
ws2.row_dimensions[1].height = 28

sum_headers = ["Trunk", "Branch", "Exits Via", "Male ✔ / Female ✔", "Key Clinical Fact"]
ws2.row_dimensions[2].height = 30
for col, h in enumerate(sum_headers, start=1):
    c = ws2.cell(row=2, column=col, value=h)
    c.font      = hdr_font()
    c.fill      = fill(BLUE_MID)
    c.alignment = center_align()
    c.border    = thin_border()

summary_data = [
    ("Posterior", "Iliolumbar",            "Stays in pelvis",                        "Both ✔",              "Lumbar & iliac branches; supplies cauda equina"),
    ("Posterior", "Lateral Sacral (×2)",   "Anterior sacral foramina",               "Both ✔",              "Anastomoses with median sacral artery"),
    ("Posterior", "Superior Gluteal",      "Greater sciatic foramen — ABOVE piriformis", "Both ✔",          "Largest branch of internal iliac"),
    ("Anterior",  "Umbilical Artery",      "Ascends to umbilicus",                   "Both ✔",              "→ Medial umbilical ligament after birth"),
    ("Anterior",  "Superior Vesical",      "To bladder",                             "Both ✔",              "Arises from root of umbilical artery"),
    ("Anterior",  "Inferior Vesical",      "To bladder base / prostate",             "MALE ONLY ✔",         "Female equivalent = Vaginal artery"),
    ("Anterior",  "Uterine Artery",        "Base of broad ligament",                 "FEMALE ONLY ✔",       "'Water under bridge' — crosses over ureter"),
    ("Anterior",  "Vaginal Artery",        "To vagina",                              "FEMALE ONLY ✔",       "Male equivalent = Inferior vesical artery"),
    ("Anterior",  "Middle Rectal",         "Medially to rectum",                     "Both ✔",              "Portacaval anastomotic site"),
    ("Anterior",  "Obturator",             "Obturator canal",                        "Both ✔",              "Corona mortis risk in hernia surgery"),
    ("Anterior",  "Internal Pudendal",     "Greater sciatic foramen BELOW piriformis\n→ lesser sciatic foramen → perineum", "Both ✔", "Main artery of perineum; with pudendal nerve"),
    ("Anterior",  "Inferior Gluteal",      "Greater sciatic foramen — BELOW piriformis", "Both ✔",          "Exits same gap as internal pudendal"),
]

row_fills = [GREEN_FILL, "FFFFFF"]
for i, row_data in enumerate(summary_data, start=3):
    bg = row_fills[i % 2]
    # Highlight sex-specific rows
    if "MALE ONLY" in row_data[3]:
        bg = "DDEEFF"
    elif "FEMALE ONLY" in row_data[3]:
        bg = "FFE8E8"

    ws2.row_dimensions[i].height = 42
    for col, val in enumerate(row_data, start=1):
        c = ws2.cell(row=i, column=col, value=val)
        c.fill      = fill(bg)
        c.font      = Font(name="Arial", size=10,
                           bold=(col == 2),
                           color=("C00000" if "FEMALE ONLY" in str(row_data[3]) and col == 4
                                  else ("1F3864" if "MALE ONLY" in str(row_data[3]) and col == 4
                                        else "000000")))
        c.alignment = left_align()
        c.border    = thin_border()

ws2_widths = [12, 22, 40, 22, 48]
for i, w in enumerate(ws2_widths, start=1):
    ws2.column_dimensions[get_column_letter(i)].width = w

ws2.freeze_panes = "A3"

# ── Sheet 3: Anastomoses ───────────────────────────────────────────────────────
ws3 = wb.create_sheet("Anastomoses & Clinical")

ws3.merge_cells("A1:F1")
c = ws3["A1"]
c.value = "KEY ANASTOMOSES & CLINICAL CORRELATIONS — Pelvic Arteries"
c.font  = Font(name="Arial", bold=True, size=13, color=WHITE)
c.fill  = fill(BLUE_DARK)
c.alignment = center_align()
ws3.row_dimensions[1].height = 28

ana_headers = ["Artery 1", "Anastomoses With", "Artery 2", "Region", "Sex", "Clinical Significance"]
ws3.row_dimensions[2].height = 30
for col, h in enumerate(ana_headers, start=1):
    c = ws3.cell(row=2, column=col, value=h)
    c.font      = hdr_font()
    c.fill      = fill(BLUE_MID)
    c.alignment = center_align()
    c.border    = thin_border()

anastomoses = [
    ("Uterine artery", "←→", "Ovarian artery",           "Broad ligament / uterine tube", "Female only", "Enlarged in pregnancy; alternate route if uterine artery ligated"),
    ("Middle rectal artery", "←→", "Superior rectal artery (inf. mesenteric)", "Rectum", "Both", "Portacaval anastomosis — dilates in portal hypertension → rectal varices"),
    ("Middle rectal artery", "←→", "Inferior rectal artery (int. pudendal)", "Anal canal", "Both", "Three-way rectal anastomosis; hemorrhoidal plexus"),
    ("Superior gluteal artery", "←→", "Inferior gluteal artery", "Gluteal region", "Both", "Network around hip joint; collateral in iliac artery occlusion"),
    ("Obturator artery", "←→", "Inferior epigastric artery", "Femoral canal region", "Both", "Corona mortis — accessory obturator artery; risk in femoral hernia repair"),
    ("Lateral sacral artery", "←→", "Median sacral artery", "Anterior sacrum", "Both", "Important collateral in aortic / IVC occlusion"),
    ("Superior vesical artery", "←→", "Artery to ductus deferens", "Pelvis", "Male only", "Both from umbilical artery root; supply vas deferens"),
    ("Ovarian artery", "←→", "Uterine artery (in mesometrium)", "Broad ligament", "Female only", "Critical in pregnancy; ovarian artery enlarges to supplement uterus"),
    ("Internal pudendal artery", "←→", "External pudendal artery (femoral)", "Perineum / scrotum-labia", "Both", "Collateral supply to external genitalia"),
    ("Iliolumbar artery", "←→", "Deep circumflex iliac (ext. iliac)", "Iliac crest", "Both", "Collateral when either iliac compromised"),
]

for i, row_data in enumerate(anastomoses, start=3):
    bg = row_fills[i % 2]
    if "Female only" in row_data[4]:
        bg = "FFE8E8"
    elif "Male only" in row_data[4]:
        bg = "DDEEFF"
    ws3.row_dimensions[i].height = 44
    for col, val in enumerate(row_data, start=1):
        c = ws3.cell(row=i, column=col, value=val)
        c.fill      = fill(bg)
        c.font      = Font(name="Arial", size=10, bold=(col == 2),
                           color=("1F3864" if col == 2 else "000000"))
        c.alignment = center_align() if col in (2, 5) else left_align()
        c.border    = thin_border()

ws3_widths = [28, 8, 36, 28, 14, 52]
for i, w in enumerate(ws3_widths, start=1):
    ws3.column_dimensions[get_column_letter(i)].width = w

ws3.freeze_panes = "A3"

# ── Save ───────────────────────────────────────────────────────────────────────
out_path = "/home/daytona/workspace/pelvic-arteries/Pelvic_Arterial_Supply_Male_vs_Female.xlsx"
wb.save(out_path)
print(f"Saved → {out_path}")
Running Command

python /home/daytona/workspace/pelvic-arteries/build_table.py

Running Command

python -c " import io, openpyxl wb = openpyxl.Workbook() ws = wb.active ws['A1'] = 'test' buf = io.BytesIO() wb.save(buf) with open('/home/daytona/workspace/pelvic-arteries/test.xlsx', 'wb') as f: f.write(buf.getvalue()) print('ok') "

Your credits are exhausted. Your daily credits reset tomorrow, or you can purchase a top-up for more.

Create a comparison table (excel) of male vs female pelvic arterial supply and its branches

Reading File
Running Command

ls -la /home/daytona/workspace/pelvic-arteries/ 2>/dev/null || echo "DIR_NOT_FOUND"

Writing File

~/pelvic-arteries/build_table.py

import io
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter

wb = Workbook()

# ── colour palette ─────────────────────────────────────────────────────────────
BLUE_DARK  = "1F3864"
BLUE_MID   = "2E75B6"
BLUE_LIGHT = "BDD7EE"
PINK_LIGHT = "FCE4D6"
PINK_DARK  = "C00000"
GREEN_FILL = "E2EFDA"
YELLOW_BG  = "FFFACD"
GREY_ROW   = "F2F2F2"
WHITE      = "FFFFFF"

def hdr_font(bold=True, size=11, color="FFFFFF"):
    return Font(name="Arial", bold=bold, size=size, color=color)

def cell_font(bold=False, size=10, color="000000", italic=False):
    return Font(name="Arial", bold=bold, size=size, color=color, italic=italic)

thin = Side(style="thin",   color="B8B8B8")
med  = Side(style="medium", color="595959")

def tborder():
    return Border(left=thin, right=thin, top=thin, bottom=thin)

def fill(hex_color):
    return PatternFill("solid", fgColor=hex_color)

def cal(wrap=True):
    return Alignment(horizontal="center", vertical="center", wrap_text=wrap)

def lal(wrap=True):
    return Alignment(horizontal="left", vertical="center", wrap_text=wrap)

# ══════════════════════════════════════════════════════════════════════════════
# SHEET 1 – Full Comparison Table
# ══════════════════════════════════════════════════════════════════════════════
ws1 = wb.active
ws1.title = "Male vs Female Comparison"

# Title
ws1.merge_cells("A1:G1")
c = ws1["A1"]
c.value = "PELVIC ARTERIAL SUPPLY — MALE vs FEMALE COMPARISON TABLE"
c.font  = Font(name="Arial", bold=True, size=14, color=WHITE)
c.fill  = fill(BLUE_DARK)
c.alignment = cal()
ws1.row_dimensions[1].height = 32

# Subtitle
ws1.merge_cells("A2:G2")
c = ws1["A2"]
c.value = "Source: Gray's Anatomy for Students  |  MBBS Reference Notes"
c.font  = Font(name="Arial", italic=True, size=9, color="595959")
c.fill  = fill("D9E1F2")
c.alignment = cal(wrap=False)
ws1.row_dimensions[2].height = 16

# Column headers
headers = ["Trunk / Group", "Branch / Artery", "Origin",
           "Course & Relations", "MALE Supply", "FEMALE Supply", "Clinical Notes"]

ws1.row_dimensions[3].height = 36
for col, h in enumerate(headers, 1):
    c = ws1.cell(row=3, column=col, value=h)
    if col == 5:
        c.fill = fill(BLUE_LIGHT); c.font = hdr_font(color="1F3864")
    elif col == 6:
        c.fill = fill(PINK_LIGHT); c.font = hdr_font(color=PINK_DARK)
    else:
        c.fill = fill(BLUE_MID);   c.font = hdr_font()
    c.alignment = cal()
    c.border = tborder()

# ── data rows ─────────────────────────────────────────────────────────────────
# Trunk | Branch | Origin | Course | Male | Female | Clinical
rows = [
    # ── AORTA DIRECT ────────────────────────────────────────────────────────
    ("AORTA — Direct Branches",
     "Common Iliac Artery (x2)",
     "Abdominal aorta bifurcation at LIV",
     "Divides at LV-SI disc, anteromedial to sacroiliac joint, into external & internal iliac",
     "Divides into external iliac (lower limb) and internal iliac (pelvis)",
     "Divides into external iliac (lower limb) and internal iliac (pelvis)",
     "Landmark: aortic bifurcation at LIV; left common iliac vein can be compressed by right common iliac artery (May-Thurner syndrome)"),

    ("AORTA — Direct Branches",
     "Median Sacral Artery (unpaired)",
     "Posterior surface of aorta just above bifurcation at LIV",
     "Descends in midline along anterior surface of sacrum and coccyx",
     "Sacrum, coccyx, gives last pair of lumbar arteries",
     "Sacrum, coccyx, gives last pair of lumbar arteries",
     "Anastomoses with iliolumbar and lateral sacral arteries; vein drains to left common iliac vein"),

    ("AORTA — Direct Branches",
     "Testicular Artery",
     "Abdominal aorta below renal arteries",
     "Retroperitoneal descent through inguinal canal to scrotum",
     "Testis, epididymis; anastomoses with artery to ductus deferens",
     "NOT PRESENT (replaced by ovarian artery)",
     "Right testicular vein drains to IVC; left drains to left renal vein — explains left-sided varicocele more common"),

    ("AORTA — Direct Branches",
     "Ovarian Artery",
     "Abdominal aorta below renal arteries",
     "Descends retroperitoneally; crosses pelvic brim in suspensory (infundibulopelvic) ligament",
     "NOT PRESENT (replaced by testicular artery)",
     "Ovary (via mesovarium), uterine tube; anastomoses with uterine artery in mesometrium",
     "Right ovarian vein drains to IVC; left to left renal vein; enlarges significantly in pregnancy"),

    # ── EXTERNAL ILIAC ──────────────────────────────────────────────────────
    ("External Iliac Artery — Branches",
     "Inferior Epigastric Artery",
     "External iliac artery just above inguinal ligament",
     "Ascends on posterior surface of anterior abdominal wall; enters rectus sheath",
     "Lower anterior abdominal wall, rectus abdominis",
     "Lower anterior abdominal wall, rectus abdominis",
     "Anastomoses with superior epigastric; lateral umbilical fold of peritoneum; accessory obturator artery (corona mortis) may arise here — risk in femoral hernia repair"),

    ("External Iliac Artery — Branches",
     "Deep Circumflex Iliac Artery",
     "External iliac artery just above inguinal ligament",
     "Passes laterally parallel to inguinal ligament toward iliac crest",
     "Iliac crest, iliacus, transversus abdominis, internal oblique",
     "Iliac crest, iliacus, transversus abdominis, internal oblique",
     "Anastomoses with iliolumbar and superior gluteal arteries"),

    # ── POSTERIOR TRUNK ─────────────────────────────────────────────────────
    ("Internal Iliac — POSTERIOR Trunk",
     "Iliolumbar Artery",
     "Posterior trunk of internal iliac",
     "Ascends laterally back out of pelvic inlet; divides into lumbar and iliac branches",
     "Lumbar branch: psoas, quadratus lumborum, cauda equina (via spinal branch through L5-S1 foramen). Iliac branch: iliac fossa muscles & bone",
     "Lumbar branch: psoas, quadratus lumborum, cauda equina. Iliac branch: iliac fossa muscles & bone",
     "Spinal branch passes through L5-S1 intervertebral foramen"),

    ("Internal Iliac — POSTERIOR Trunk",
     "Lateral Sacral Arteries (usually x2)",
     "Posterior trunk of internal iliac",
     "Course medially and inferiorly along posterior pelvic wall; enter anterior sacral foramina",
     "Sacral bone, sacral canal contents (nerve roots), skin and muscle posterior to sacrum",
     "Sacral bone, sacral canal contents, skin and muscle posterior to sacrum",
     "Anastomoses with median sacral artery; important collateral pathway"),

    ("Internal Iliac — POSTERIOR Trunk",
     "Superior Gluteal Artery",
     "Terminal branch of posterior trunk — LARGEST branch of internal iliac",
     "Passes between lumbosacral trunk and S1 anterior ramus; exits greater sciatic foramen ABOVE piriformis",
     "Gluteus maximus, medius, minimus; skin of gluteal region; adjacent pelvic wall",
     "Gluteus maximus, medius, minimus; skin of gluteal region; adjacent pelvic wall",
     "EXITS ABOVE piriformis (key exam fact — differentiates from inferior gluteal). Anastomoses with inferior gluteal and lateral circumflex femoral arteries"),

    # ── ANTERIOR TRUNK COMMON ───────────────────────────────────────────────
    ("Internal Iliac — ANTERIOR Trunk (Both sexes)",
     "Umbilical Artery",
     "First branch of anterior trunk",
     "Travels forward just inferior to pelvic inlet margin, then ascends on internal surface of anterior abdominal wall to umbilicus",
     "Gives superior vesical artery + artery to ductus deferens (sometimes). Fetal: carries deoxygenated blood to placenta",
     "Gives superior vesical artery. Fetal: carries deoxygenated blood to placenta",
     "After birth: distal part obliterates -> medial umbilical ligament (raises medial umbilical fold of peritoneum). Proximal part stays patent"),

    ("Internal Iliac — ANTERIOR Trunk (Both sexes)",
     "Superior Vesical Artery",
     "Root of the umbilical artery (first branch given off)",
     "Courses medially and inferiorly to bladder dome",
     "Superior bladder, distal ureter, sometimes artery to ductus deferens",
     "Superior bladder, distal ureter",
     "Most constant and first branch from umbilical artery root; always present"),

    ("Internal Iliac — ANTERIOR Trunk (Both sexes)",
     "Middle Rectal Artery",
     "Anterior trunk of internal iliac",
     "Courses medially to middle and lower rectum",
     "Middle and lower rectum",
     "Middle and lower rectum",
     "Anastomoses with: superior rectal a. (from inf. mesenteric = PORTAL) and inferior rectal a. (from internal pudendal = CAVAL). This is a major portacaval anastomosis — dilates in portal hypertension causing rectal varices"),

    ("Internal Iliac — ANTERIOR Trunk (Both sexes)",
     "Obturator Artery",
     "Anterior trunk of internal iliac",
     "Courses anteriorly along pelvic side wall; exits via obturator canal with obturator nerve (above) and vein (below) to adductor region",
     "Adductor region of thigh, hip joint",
     "Adductor region of thigh, hip joint",
     "CORONA MORTIS: accessory/replaced obturator artery from inferior epigastric artery crosses femoral canal — can be cut during femoral hernia repair (\"crown of death\")"),

    ("Internal Iliac — ANTERIOR Trunk (Both sexes)",
     "Internal Pudendal Artery",
     "Anterior trunk of internal iliac — MAIN ARTERY OF PERINEUM",
     "Exits greater sciatic foramen BELOW piriformis -> wraps around ischial spine -> enters lesser sciatic foramen -> runs in Alcock's canal on lateral wall of ischioanal fossa",
     "Inferior rectal a., perineal a., artery to bulb of penis, deep artery of penis, dorsal artery of penis",
     "Inferior rectal a., perineal a., artery to vestibular bulb, deep artery of clitoris, dorsal artery of clitoris",
     "Exits BELOW piriformis (travels with pudendal nerve, S2-S4). Female equivalent supplies clitoris; male supplies penis. Injury in perineal trauma causes haematoma"),

    ("Internal Iliac — ANTERIOR Trunk (Both sexes)",
     "Inferior Gluteal Artery",
     "Terminal branch of anterior trunk of internal iliac (large vessel)",
     "Passes between S1-S2 or S2-S3 anterior rami; exits greater sciatic foramen BELOW piriformis (same gap as internal pudendal)",
     "Gluteus maximus (main supply), sciatic nerve, anastomosis network around hip joint",
     "Gluteus maximus (main supply), sciatic nerve, anastomosis network around hip joint",
     "EXITS BELOW piriformis. Anastomoses with superior gluteal, medial and lateral circumflex femoral arteries. Important collateral for hip joint vascularity"),

    # ── ANTERIOR TRUNK MALE SPECIFIC ─────────────────────────────────────────
    ("Internal Iliac — ANTERIOR Trunk (MALE ONLY)",
     "Inferior Vesical Artery",
     "Anterior trunk of internal iliac",
     "Passes inferiorly and medially to bladder base and prostate",
     "Bladder base, distal ureter, seminal vesicle, prostate, sometimes proximal urethra",
     "ABSENT IN FEMALES — replaced by vaginal artery",
     "Female equivalent = vaginal artery. Critical landmark in prostate surgery and endoscopic bladder procedures. Supplies seminal vesicles"),

    # ── ANTERIOR TRUNK FEMALE SPECIFIC ────────────────────────────────────────
    ("Internal Iliac — ANTERIOR Trunk (FEMALE ONLY)",
     "Uterine Artery",
     "Anterior trunk of internal iliac (may share origin with vaginal artery)",
     "Courses medially and anteriorly in BASE OF BROAD LIGAMENT to cervix; CROSSES OVER the ureter at lateral vaginal fornix; ascends along lateral uterus to uterine tube; curves laterally to anastomose with ovarian artery",
     "ABSENT IN MALES — inferior vesical artery is the male equivalent of the vaginal territory",
     "Uterus (MAJOR supply), cervix, upper vagina, uterine tube and partial ovary via anastomosis with ovarian artery",
     "WATER UNDER THE BRIDGE: uterine artery (bridge) crosses OVER the ureter (water) at lateral fornix. Risk of accidental ureteric ligation during hysterectomy. Enlarges dramatically in pregnancy"),

    ("Internal Iliac — ANTERIOR Trunk (FEMALE ONLY)",
     "Vaginal Artery",
     "Anterior trunk of internal iliac (may share origin with uterine artery or arise independently)",
     "Descends to lateral vagina; branches to anterior and posterior walls",
     "ABSENT IN MALES — inferior vesical artery performs this role",
     "Vagina (all parts), adjacent bladder base, adjacent rectum",
     "FEMALE EQUIVALENT of inferior vesical artery in males. May be multiple branches; anastomoses with uterine, internal pudendal, and middle rectal arteries"),
]

# Section fill colours
sec_fills = {
    "AORTA — Direct Branches":                              "FFF2CC",
    "External Iliac Artery — Branches":                     "EBF3FB",
    "Internal Iliac — POSTERIOR Trunk":                     "E2EFDA",
    "Internal Iliac — ANTERIOR Trunk (Both sexes)":         "FFFFFF",
    "Internal Iliac — ANTERIOR Trunk (MALE ONLY)":          "DDEEFF",
    "Internal Iliac — ANTERIOR Trunk (FEMALE ONLY)":        "FFE8E8",
}

sec_label_fills = {
    "AORTA — Direct Branches":                              "D6B900",
    "External Iliac Artery — Branches":                     "2E75B6",
    "Internal Iliac — POSTERIOR Trunk":                     "375623",
    "Internal Iliac — ANTERIOR Trunk (Both sexes)":         "595959",
    "Internal Iliac — ANTERIOR Trunk (MALE ONLY)":          "1F3864",
    "Internal Iliac — ANTERIOR Trunk (FEMALE ONLY)":        "C00000",
}

prev_sec = None
r = 4

for (trunk, branch, origin, course, male_s, female_s, clin) in rows:
    bg = sec_fills.get(trunk, WHITE)

    # Section divider row
    if trunk != prev_sec:
        ws1.merge_cells(f"A{r}:G{r}")
        sc = ws1.cell(row=r, column=1, value="  " + trunk)
        sc.font      = Font(name="Arial", bold=True, size=10, color=WHITE)
        sc.fill      = fill(sec_label_fills.get(trunk, BLUE_MID))
        sc.alignment = lal(wrap=False)
        sc.border    = tborder()
        ws1.row_dimensions[r].height = 22
        r += 1
        prev_sec = trunk

    row_vals = [None, branch, origin, course, male_s, female_s, clin]
    for col, val in enumerate(row_vals, 1):
        c = ws1.cell(row=r, column=col)
        c.value     = val or ""
        c.border    = tborder()
        c.alignment = lal()

        if col == 1:
            c.fill = fill(bg)
        elif col == 2:   # branch name — bold
            c.fill = fill(bg)
            c.font = cell_font(bold=True, size=10)
        elif col == 3:   # origin
            c.fill = fill(bg)
            c.font = cell_font(size=9)
        elif col == 4:   # course
            c.fill = fill(bg)
            c.font = cell_font(size=9)
        elif col == 5:   # male supply
            absent = "NOT PRESENT" in str(val) or "ABSENT" in str(val)
            c.fill = fill("FFD7D7" if absent else BLUE_LIGHT)
            c.font = cell_font(size=9, italic=absent, color="888888" if absent else "000000")
        elif col == 6:   # female supply
            absent = "NOT PRESENT" in str(val) or "ABSENT" in str(val)
            c.fill = fill("D7D7FF" if absent else PINK_LIGHT)
            c.font = cell_font(size=9, italic=absent, color="888888" if absent else "000000")
        elif col == 7:   # clinical notes
            c.fill = fill(YELLOW_BG)
            c.font = cell_font(size=9, italic=True, color="4A4A00")

    ws1.row_dimensions[r].height = 72
    r += 1

# Column widths
for idx, w in enumerate([4, 26, 30, 38, 34, 34, 46], 1):
    ws1.column_dimensions[get_column_letter(idx)].width = w

ws1.freeze_panes = "A4"

# ══════════════════════════════════════════════════════════════════════════════
# SHEET 2 – Quick Reference Summary
# ══════════════════════════════════════════════════════════════════════════════
ws2 = wb.create_sheet("Quick Reference")

ws2.merge_cells("A1:F1")
c = ws2["A1"]
c.value = "QUICK REFERENCE — Internal Iliac Artery Branches at a Glance"
c.font  = Font(name="Arial", bold=True, size=13, color=WHITE)
c.fill  = fill(BLUE_DARK)
c.alignment = cal()
ws2.row_dimensions[1].height = 28

qh = ["Trunk", "Branch", "Exits Via", "Present In", "Male Structures Supplied", "Female Structures Supplied"]
ws2.row_dimensions[2].height = 32
for col, h in enumerate(qh, 1):
    c = ws2.cell(row=2, column=col, value=h)
    c.font = hdr_font(); c.fill = fill(BLUE_MID)
    c.alignment = cal(); c.border = tborder()

qdata = [
    ("Posterior", "Iliolumbar Artery",          "Stays in pelvis",                          "Both",        "Psoas, QL, cauda equina, iliac fossa",                "Psoas, QL, cauda equina, iliac fossa"),
    ("Posterior", "Lateral Sacral Arteries (x2)","Anterior sacral foramina",                 "Both",        "Sacrum, sacral canal, gluteal skin",                  "Sacrum, sacral canal, gluteal skin"),
    ("Posterior", "Superior Gluteal Artery",     "Greater sciatic foramen — ABOVE piriformis","Both",        "Gluteus maximus, medius, minimus",                    "Gluteus maximus, medius, minimus"),
    ("Anterior",  "Umbilical Artery",            "Ascends to umbilicus (fetal)",             "Both",        "Superior vesical a.; artery to ductus deferens",     "Superior vesical artery"),
    ("Anterior",  "Superior Vesical Artery",     "To superior bladder",                      "Both",        "Superior bladder, distal ureter, ductus deferens",    "Superior bladder, distal ureter"),
    ("Anterior",  "Inferior Vesical Artery",     "To bladder base / prostate",               "MALE ONLY",   "Bladder base, ureter, seminal vesicle, prostate",     "— (replaced by vaginal artery) —"),
    ("Anterior",  "Uterine Artery",              "Base of broad ligament to cervix",         "FEMALE ONLY", "— (replaced by inferior vesical artery territory) —", "Uterus, cervix, upper vagina, uterine tube, partial ovary"),
    ("Anterior",  "Vaginal Artery",              "To lateral vaginal wall",                  "FEMALE ONLY", "— (replaced by inferior vesical artery) —",           "Vagina, bladder base, adjacent rectum"),
    ("Anterior",  "Middle Rectal Artery",        "Medially to rectum",                       "Both",        "Middle/lower rectum",                                "Middle/lower rectum"),
    ("Anterior",  "Obturator Artery",            "Obturator canal",                          "Both",        "Adductor region of thigh, hip joint",                "Adductor region of thigh, hip joint"),
    ("Anterior",  "Internal Pudendal Artery",    "Greater sciatic foramen BELOW piriformis -> lesser sciatic foramen -> perineum (Alcock's canal)", "Both", "Penis, scrotum, perineal muscles, external sphincters", "Clitoris, labia, vestibular bulb, perineal muscles"),
    ("Anterior",  "Inferior Gluteal Artery",     "Greater sciatic foramen — BELOW piriformis","Both",        "Gluteus maximus, sciatic nerve, hip joint anastomosis","Gluteus maximus, sciatic nerve, hip joint anastomosis"),
]

alt = ["FFFFFF", GREY_ROW]
for i, rd in enumerate(qdata, 3):
    trunk_v, branch_v, exit_v, present_v, male_v, female_v = rd
    if present_v == "MALE ONLY":
        bg = "DDEEFF"
    elif present_v == "FEMALE ONLY":
        bg = "FFE8E8"
    else:
        bg = alt[i % 2]

    ws2.row_dimensions[i].height = 48
    vals = [trunk_v, branch_v, exit_v, present_v, male_v, female_v]
    for col, val in enumerate(vals, 1):
        c = ws2.cell(row=i, column=col, value=val)
        c.fill = fill(bg)
        c.alignment = lal() if col != 4 else cal()
        c.border = tborder()
        bold = (col == 2)
        color = "000000"
        if col == 4:
            if present_v == "MALE ONLY":   color = "1F3864"
            elif present_v == "FEMALE ONLY": color = PINK_DARK
        c.font = cell_font(bold=bold, size=10, color=color)

for idx, w in enumerate([12, 28, 44, 16, 42, 42], 1):
    ws2.column_dimensions[get_column_letter(idx)].width = w
ws2.freeze_panes = "A3"

# ══════════════════════════════════════════════════════════════════════════════
# SHEET 3 – Anastomoses & Clinical Pearls
# ══════════════════════════════════════════════════════════════════════════════
ws3 = wb.create_sheet("Anastomoses & Clinical Pearls")

ws3.merge_cells("A1:F1")
c = ws3["A1"]
c.value = "KEY ANASTOMOSES & CLINICAL PEARLS — Pelvic Arteries"
c.font  = Font(name="Arial", bold=True, size=13, color=WHITE)
c.fill  = fill(BLUE_DARK)
c.alignment = cal()
ws3.row_dimensions[1].height = 28

ah = ["Vessel 1", "<-->", "Vessel 2", "Sex", "Region", "Clinical Significance"]
ws3.row_dimensions[2].height = 30
for col, h in enumerate(ah, 1):
    c = ws3.cell(row=2, column=col, value=h)
    c.font = hdr_font(); c.fill = fill(BLUE_MID)
    c.alignment = cal(); c.border = tborder()

adata = [
    ("Uterine artery", "<-->", "Ovarian artery", "Female", "Broad ligament / uterine tube", "Anastomosis enlarges in pregnancy; alternative supply route after uterine artery ligation"),
    ("Middle rectal artery (internal iliac)", "<-->", "Superior rectal artery (inferior mesenteric)", "Both", "Rectum", "PORTACAVAL ANASTOMOSIS — dilates in portal hypertension -> rectal varices; superior rectal = portal territory"),
    ("Middle rectal artery", "<-->", "Inferior rectal artery (internal pudendal)", "Both", "Anal canal / lower rectum", "Three-way rectal anastomosis; basis for hemorrhoidal plexus"),
    ("Superior gluteal artery", "<-->", "Inferior gluteal artery", "Both", "Gluteal region", "Hip joint anastomotic network; collateral in iliac artery occlusion"),
    ("Obturator artery (internal iliac)", "<-->", "Inferior epigastric artery (external iliac)", "Both", "Femoral canal region", "CORONA MORTIS — accessory obturator artery; can be cut in femoral hernia repair; potentially fatal haemorrhage"),
    ("Lateral sacral artery", "<-->", "Median sacral artery (aorta)", "Both", "Anterior sacrum", "Collateral in aortic or internal iliac occlusion"),
    ("Superior vesical artery", "<-->", "Artery to ductus deferens", "Male", "Pelvic brim / inguinal canal", "Both from umbilical artery root; collateral supply to vas deferens and bladder"),
    ("Ovarian artery (aorta)", "<-->", "Uterine artery (internal iliac)", "Female", "Mesometrium of broad ligament", "Critical anastomosis in pregnancy; ovarian artery enlarges to supplement uterus; preserved in uterine artery embolisation"),
    ("Internal pudendal artery", "<-->", "External pudendal artery (femoral)", "Both", "Perineum / scrotum / labia", "Collateral supply to external genitalia; relevant in pelvic trauma"),
    ("Iliolumbar artery", "<-->", "Deep circumflex iliac artery (external iliac)", "Both", "Iliac crest region", "Important collateral when either iliac system is compromised; relevant in EVAR planning"),
    ("Uterine artery", "<-->", "Vaginal artery", "Female", "Cervix / upper vagina", "Both supply cervix and upper vagina; anastomose freely; important in radical hysterectomy"),
]

for i, rd in enumerate(adata, 3):
    v1, arrow, v2, sex, region, clin = rd
    if sex == "Female":
        bg = "FFE8E8"
    elif sex == "Male":
        bg = "DDEEFF"
    else:
        bg = alt[i % 2]
    ws3.row_dimensions[i].height = 52
    for col, val in enumerate([v1, arrow, v2, sex, region, clin], 1):
        c = ws3.cell(row=i, column=col, value=val)
        c.fill      = fill(bg)
        c.alignment = cal() if col in (2, 4) else lal()
        c.border    = tborder()
        c.font      = cell_font(bold=(col == 2), size=10,
                                color=("1F3864" if col == 2 else
                                       (PINK_DARK if sex == "Female" and col == 4 else
                                        ("1F3864" if sex == "Male" and col == 4 else "000000"))))

for idx, w in enumerate([34, 6, 38, 12, 28, 54], 1):
    ws3.column_dimensions[get_column_letter(idx)].width = w
ws3.freeze_panes = "A3"

# ══════════════════════════════════════════════════════════════════════════════
# SHEET 4 – Mnemonic & Study Aid
# ══════════════════════════════════════════════════════════════════════════════
ws4 = wb.create_sheet("Mnemonics & Study Aid")

ws4.merge_cells("A1:C1")
c = ws4["A1"]
c.value = "MNEMONICS & EXAM TIPS — Pelvic Arteries"
c.font  = Font(name="Arial", bold=True, size=13, color=WHITE)
c.fill  = fill(BLUE_DARK)
c.alignment = cal()
ws4.row_dimensions[1].height = 28

mnemonics = [
    ("POSTERIOR TRUNK (3 branches) — Mnemonic: ILS",
     "I = Iliolumbar\nL = Lateral sacral (x2)\nS = Superior gluteal (terminal/largest)",
     "Superior gluteal exits ABOVE piriformis — only posterior trunk branch to exit pelvis"),

    ("ANTERIOR TRUNK — Common branches Mnemonic: US-MO-II",
     "U = Umbilical (-> superior vesical)\nS = Superior vesical\nM = Middle rectal\nO = Obturator\nI = Internal pudendal\nI = Inferior gluteal",
     "Internal pudendal and inferior gluteal both exit BELOW piriformis through greater sciatic foramen"),

    ("MALE ONLY branch",
     "Inferior VESICAL artery\n(bladder base, ureter, seminal vesicle, PROSTATE)",
     "Female equivalent = VAGINAL artery. Remember: men have a prostate, so inferior vesical supplies it"),

    ("FEMALE ONLY branches",
     "1. UTERINE artery — crosses OVER ureter (Water Under Bridge)\n2. VAGINAL artery — equivalent of male inferior vesical",
     "Uterine artery enlarges in pregnancy; 'Water Under Bridge' = ureter (water) under uterine artery (bridge) — risk of injury in hysterectomy"),

    ("ABOVE vs BELOW piriformis — EXIT POINTS",
     "ABOVE piriformis: Superior gluteal artery (posterior trunk)\nBELOW piriformis: Inferior gluteal + Internal pudendal + Sciatic nerve",
     "Common exam question — superior gluteal is the ONLY vessel to exit above piriformis"),

    ("PORTACAVAL ANASTOMOSIS in rectum",
     "Superior rectal vein (portal) <--> Middle rectal + Inferior rectal veins (caval)\nDilates in portal hypertension -> RECTAL VARICES",
     "Internal hemorrhoids (above pectinate line) = superior rectal vein territory = PORTAL. External hemorrhoids (below pectinate line) = inferior rectal vein = CAVAL"),

    ("OVARIAN/TESTICULAR VEIN ASYMMETRY",
     "RIGHT gonadal vein -> IVC (straight course)\nLEFT gonadal vein -> left renal vein (90-degree angle -> higher pressure)",
     "Left varicocele (male) and left ovarian vein compression (female pelvic congestion syndrome) more common due to higher pressure in left gonadal vein"),

    ("CORONA MORTIS (Crown of Death)",
     "Accessory/replaced obturator artery arising from inferior epigastric artery\nCrosses the femoral canal",
     "Can be divided during femoral hernia repair causing serious haemorrhage. Check for it before cutting any vessel near femoral ring"),

    ("MEDIAL UMBILICAL LIGAMENT",
     "= obliterated distal umbilical artery\nForms medial umbilical fold of peritoneum on inner anterior abdominal wall",
     "Lateral umbilical fold = inferior epigastric artery. Median umbilical fold (single, central) = obliterated urachus"),
]

ws4.row_dimensions[2].height = 22
for col, h in enumerate(["Topic / Mnemonic", "Details", "Exam Tip / Clinical Pearl"], 1):
    c = ws4.cell(row=2, column=col, value=h)
    c.font = hdr_font(); c.fill = fill(BLUE_MID)
    c.alignment = cal(); c.border = tborder()

row_bgs = ["FFF2CC", "E2EFDA", "EBF3FB", "FFE8E8", "DDEEFF",
           "FFF2CC", "E2EFDA", "FFE8E8", "DDEEFF"]
for i, (topic, detail, tip) in enumerate(mnemonics, 3):
    bg = row_bgs[(i - 3) % len(row_bgs)]
    ws4.row_dimensions[i].height = 72
    for col, val in enumerate([topic, detail, tip], 1):
        c = ws4.cell(row=i, column=col, value=val)
        c.fill      = fill(bg)
        c.alignment = lal()
        c.border    = tborder()
        c.font      = cell_font(bold=(col == 1), size=10,
                                color=("1F3864" if col == 1 else
                                       ("C00000" if col == 3 else "000000")))

for idx, w in enumerate([36, 54, 58], 1):
    ws4.column_dimensions[get_column_letter(idx)].width = w
ws4.freeze_panes = "A3"

# ══════════════════════════════════════════════════════════════════════════════
# Save via BytesIO
# ══════════════════════════════════════════════════════════════════════════════
out_path = "/home/daytona/workspace/pelvic-arteries/Pelvic_Arterial_Supply_Male_vs_Female.xlsx"
buf = io.BytesIO()
wb.save(buf)
with open(out_path, "wb") as f:
    f.write(buf.getvalue())

print(f"Saved -> {out_path}")
print(f"Size  -> {len(buf.getvalue()):,} bytes")
Editing File

~/pelvic-arteries/build_table.py

Error: String not found in file: 'import io
from openpyxl import Workbook'
Reading File
Running Command

cat > /home/daytona/workspace/pelvic-arteries/build2.py << 'PYEOF' import io from openpyxl import Workbook from openpyxl.styles import Font, PatternFill, Alignment, Border, Side from openpyxl.utils import get_column_letter wb = Workbook() BLUE_DARK = "1F3864" BLUE_MID = "2E75B6" BLUE_LIGHT = "BDD7EE" PINK_LIGHT = "FCE4D6" PINK_DARK = "C00000" YELLOW_BG = "FFFACD" GREY_ROW = "F2F2F2" WHITE = "FFFFFF" def hf(bold=True, size=11, color="FFFFFF"): return Font(name="Arial", bold=bold, size=size, color=color) def cf(bold=False, size=10, color="000000", italic=False): return Font(name="Arial", bold=bold, size=size, color=color, italic=italic) thin = Side(style="thin", color="B8B8B8") def tb(): return Border(left=thin, right=thin, top=thin, bottom=thin) def fl(hex_color): return PatternFill("solid", fgColor=hex_color) def ca(wrap=True): return Alignment(horizontal="center", vertical="center", wrap_text=wrap) def la(wrap=True): return Alignment(horizontal="left", vertical="center", wrap_text=wrap) # ─── SHEET 1: Full Comparison ───────────────────────────────────────────────── ws1 = wb.active ws1.title = "Male vs Female Comparison" ws1.merge_cells("A1:G1") c = ws1["A1"] c.value = "PELVIC ARTERIAL SUPPLY — MALE vs FEMALE COMPARISON TABLE" c.font = Font(name="Arial", bold=True, size=14, color=WHITE) c.fill = fl(BLUE_DARK); c.alignment = ca() ws1.row_dimensions[1].height = 32 ws1.merge_cells("A2:G2") c = ws1["A2"] c.value = "Source: Gray's Anatomy for Students | MBBS Reference Notes" c.font = Font(name="Arial", italic=True, size=9, color="595959") c.fill = fl("D9E1F2"); c.alignment = ca(wrap=False) ws1.row_dimensions[2].height = 16 headers = ["Trunk / Group","Branch / Artery","Origin","Course & Relations","MALE Supply","FEMALE Supply","Clinical Notes"] ws1.row_dimensions[3].height = 36 for col, h in enumerate(headers, 1): c = ws1.cell(row=3, column=col, value=h) if col == 5: c.fill = fl(BLUE_LIGHT); c.font = hf(color="1F3864") elif col == 6: c.fill = fl(PINK_LIGHT); c.font = hf(color=PINK_DARK) else: c.fill = fl(BLUE_MID); c.font = hf() c.alignment = ca(); c.border = tb() rows = [ ("AORTA — Direct Branches","Common Iliac Artery (x2)","Abdominal aorta bifurcation at LIV","Divides at LV-SI disc, anteromedial to sacroiliac joint, into external & internal iliac","Divides into external iliac (lower limb) and internal iliac (pelvis)","Divides into external iliac (lower limb) and internal iliac (pelvis)","Landmark: aortic bifurcation at LIV; left common iliac vein compressed by right common iliac artery = May-Thurner syndrome"), ("AORTA — Direct Branches","Median Sacral Artery (unpaired)","Posterior surface of aorta, just above bifurcation at LIV","Descends in midline along anterior surface of sacrum and coccyx","Sacrum, coccyx; gives last pair of lumbar arteries","Sacrum, coccyx; gives last pair of lumbar arteries","Anastomoses with iliolumbar and lateral sacral arteries"), ("AORTA — Direct Branches","Testicular Artery","Abdominal aorta below renal arteries","Retroperitoneal descent through inguinal canal to scrotum","Testis, epididymis; anastomoses with artery to ductus deferens","NOT PRESENT — replaced by ovarian artery in females","Right testicular vein -> IVC; left -> left renal vein. Explains left-sided varicocele more common"), ("AORTA — Direct Branches","Ovarian Artery","Abdominal aorta below renal arteries","Descends retroperitoneally; crosses pelvic brim in suspensory (infundibulopelvic) ligament","NOT PRESENT — replaced by testicular artery in males","Ovary (via mesovarium), uterine tube; anastomoses with uterine artery in mesometrium","Right ovarian vein -> IVC; left -> left renal vein; ovarian artery enlarges in pregnancy"), ("External Iliac Artery — Branches","Inferior Epigastric Artery","External iliac artery just above inguinal ligament","Ascends on posterior surface of anterior abdominal wall; enters rectus sheath","Lower anterior abdominal wall, rectus abdominis","Lower anterior abdominal wall, rectus abdominis","Anastomoses with superior epigastric; forms lateral umbilical fold of peritoneum; accessory obturator artery (corona mortis) may arise here"), ("External Iliac Artery — Branches","Deep Circumflex Iliac Artery","External iliac artery just above inguinal ligament","Passes laterally parallel to inguinal ligament toward iliac crest","Iliac crest, iliacus, transversus abdominis, internal oblique","Iliac crest, iliacus, transversus abdominis, internal oblique","Anastomoses with iliolumbar and superior gluteal arteries"), ("Internal Iliac — POSTERIOR Trunk","Iliolumbar Artery","Posterior trunk of internal iliac","Ascends laterally back out of pelvic inlet; divides into lumbar and iliac branches","Lumbar: psoas, QL, cauda equina (via spinal branch L5-S1 foramen). Iliac: iliac fossa muscles & bone","Lumbar: psoas, QL, cauda equina. Iliac: iliac fossa muscles & bone","Spinal branch passes through L5-S1 intervertebral foramen"), ("Internal Iliac — POSTERIOR Trunk","Lateral Sacral Arteries (x2)","Posterior trunk of internal iliac","Course medially and inferiorly along posterior pelvic wall; enter anterior sacral foramina","Sacral bone, sacral canal contents, skin and muscle posterior to sacrum","Sacral bone, sacral canal contents, skin and muscle posterior to sacrum","Anastomoses with median sacral artery; important collateral pathway"), ("Internal Iliac — POSTERIOR Trunk","Superior Gluteal Artery","Terminal branch of posterior trunk — LARGEST branch of internal iliac","Passes between lumbosacral trunk and S1 anterior ramus; exits greater sciatic foramen ABOVE piriformis","Gluteus maximus, medius, minimus; skin of gluteal region; adjacent pelvic wall","Gluteus maximus, medius, minimus; skin of gluteal region; adjacent pelvic wall","EXITS ABOVE piriformis — only posterior trunk branch to exit pelvis. Anastomoses with inferior gluteal and lateral circumflex femoral arteries"), ("Internal Iliac — ANTERIOR Trunk (Both Sexes)","Umbilical Artery","First branch of anterior trunk","Travels forward just inferior to pelvic inlet margin, then ascends on internal surface of anterior abdominal wall to umbilicus","Gives superior vesical artery + artery to ductus deferens (sometimes). Fetal: carries deoxygenated blood to placenta","Gives superior vesical artery. Fetal: carries deoxygenated blood to placenta","After birth: distal part obliterates -> medial umbilical ligament (raises medial umbilical fold of peritoneum). Proximal part stays patent"), ("Internal Iliac — ANTERIOR Trunk (Both Sexes)","Superior Vesical Artery","Root of the umbilical artery (first branch given off)","Courses medially and inferiorly to bladder dome","Superior bladder, distal ureter, sometimes artery to ductus deferens","Superior bladder, distal ureter","Most constant branch; always present; arises from root of umbilical artery"), ("Internal Iliac — ANTERIOR Trunk (Both Sexes)","Middle Rectal Artery","Anterior trunk of internal iliac","Courses medially to middle and lower rectum","Middle and lower rectum","Middle and lower rectum","Anastomoses with superior rectal a. (inf. mesenteric = PORTAL) and inferior rectal a. (int. pudendal = CAVAL) — major portacaval anastomosis; dilates in portal HTN causing rectal varices"), ("Internal Iliac — ANTERIOR Trunk (Both Sexes)","Obturator Artery","Anterior trunk of internal iliac","Courses anteriorly along pelvic side wall; exits via obturator canal with obturator nerve (above) and vein (below)","Adductor region of thigh, hip joint","Adductor region of thigh, hip joint","CORONA MORTIS: accessory obturator from inferior epigastric crosses femoral canal — risk in femoral hernia repair"), ("Internal Iliac — ANTERIOR Trunk (Both Sexes)","Internal Pudendal Artery","Anterior trunk of internal iliac — MAIN ARTERY OF PERINEUM","Exits greater sciatic foramen BELOW piriformis -> wraps around ischial spine -> enters lesser sciatic foramen -> runs in Alcock's canal","Inferior rectal a., perineal a., artery to bulb of penis, deep artery of penis, dorsal artery of penis","Inferior rectal a., perineal a., artery to vestibular bulb, deep artery of clitoris, dorsal artery of clitoris","Exits BELOW piriformis with pudendal nerve (S2-S4). Injury in perineal trauma causes haematoma. Main supply to erectile tissue in both sexes"), ("Internal Iliac — ANTERIOR Trunk (Both Sexes)","Inferior Gluteal Artery","Terminal branch of anterior trunk (large vessel)","Passes between S1-S2 or S2-S3 anterior rami; exits greater sciatic foramen BELOW piriformis (same gap as internal pudendal)","Gluteus maximus (main supply), sciatic nerve, anastomosis network around hip joint","Gluteus maximus (main supply), sciatic nerve, anastomosis network around hip joint","EXITS BELOW piriformis. Anastomoses with superior gluteal, medial and lateral circumflex femoral arteries. Important for hip joint vascularity"), ("Internal Iliac — ANTERIOR Trunk (MALE ONLY)","Inferior Vesical Artery","Anterior trunk of internal iliac","Passes inferiorly and medially to bladder base and prostate","Bladder base, distal ureter, seminal vesicle, prostate, sometimes proximal urethra","ABSENT IN FEMALES — replaced by vaginal artery","Female equivalent = vaginal artery. Critical in prostate surgery; supplies seminal vesicles"), ("Internal Iliac — ANTERIOR Trunk (FEMALE ONLY)","Uterine Artery","Anterior trunk of internal iliac (may share origin with vaginal artery)","Courses medially and anteriorly in BASE OF BROAD LIGAMENT to cervix; CROSSES OVER the ureter at lateral vaginal fornix; ascends along lateral uterus to uterine tube; curves laterally to anastomose with ovarian artery","ABSENT IN MALES — inferior vesical artery is the functional equivalent","Uterus (MAJOR supply), cervix, upper vagina, uterine tube and partial ovary via anastomosis with ovarian artery","WATER UNDER THE BRIDGE: uterine artery (bridge) crosses OVER ureter (water) at lateral fornix. Risk of ureteric ligation in hysterectomy. Enlarges dramatically in pregnancy"), ("Internal Iliac — ANTERIOR Trunk (FEMALE ONLY)","Vaginal Artery","Anterior trunk of internal iliac (may share origin with uterine artery or arise independently)","Descends to lateral vagina; branches to anterior and posterior vaginal walls","ABSENT IN MALES — inferior vesical artery performs this role","Vagina (all parts), adjacent bladder base, adjacent rectum","FEMALE EQUIVALENT of inferior vesical artery in males. May be multiple branches; anastomoses with uterine, internal pudendal, and middle rectal arteries"), ] sec_fills = { "AORTA — Direct Branches": "FFF2CC", "External Iliac Artery — Branches": "EBF3FB", "Internal Iliac — POSTERIOR Trunk": "E2EFDA", "Internal Iliac — ANTERIOR Trunk (Both Sexes)": "FFFFFF", "Internal Iliac — ANTERIOR Trunk (MALE ONLY)": "DDEEFF", "Internal Iliac — ANTERIOR Trunk (FEMALE ONLY)": "FFE8E8", } sec_hdr_fills = { "AORTA — Direct Branches": "B8860B", "External Iliac Artery — Branches": "2E75B6", "Internal Iliac — POSTERIOR Trunk": "375623", "Internal Iliac — ANTERIOR Trunk (Both Sexes)": "595959", "Internal Iliac — ANTERIOR Trunk (MALE ONLY)": "1F3864", "Internal Iliac — ANTERIOR Trunk (FEMALE ONLY)": "C00000", } prev = None r = 4 for (trunk, branch, origin, course, male_s, female_s, clin) in rows: bg = sec_fills.get(trunk, WHITE) if trunk != prev: ws1.merge_cells(f"A{r}:G{r}") sc = ws1.cell(row=r, column=1, value=" " + trunk) sc.font = Font(name="Arial", bold=True, size=10, color=WHITE) sc.fill = fl(sec_hdr_fills.get(trunk, BLUE_MID)) sc.alignment = la(wrap=False); sc.border = tb() ws1.row_dimensions[r].height = 22 r += 1 prev = trunk for col, val in enumerate([None, branch, origin, course, male_s, female_s, clin], 1): c = ws1.cell(row=r, column=col) c.value = val or ""; c.border = tb(); c.alignment = la() if col == 1: c.fill = fl(bg) elif col == 2: c.fill = fl(bg); c.font = cf(bold=True) elif col in (3, 4): c.fill = fl(bg); c.font = cf(size=9) elif col == 5: absent = any(x in str(val) for x in ["NOT PRESENT","ABSENT"]) c.fill = fl("FFD7D7" if absent else BLUE_LIGHT) c.font = cf(size=9, italic=absent, color="888888" if absent else "000000") elif col == 6: absent = any(x in str(val) for x in ["NOT PRESENT","ABSENT"]) c.fill = fl("D7D7FF" if absent else PINK_LIGHT) c.font = cf(size=9, italic=absent, color="888888" if absent else "000000") elif col == 7: c.fill = fl(YELLOW_BG); c.font = cf(size=9, italic=True, color="4A4A00") ws1.row_dimensions[r].height = 72 r += 1 for idx, w in enumerate([4,26,30,38,34,34,46], 1): ws1.column_dimensions[get_column_letter(idx)].width = w ws1.freeze_panes = "A4" # ─── SHEET 2: Quick Reference ───────────────────────────────────────────────── ws2 = wb.create_sheet("Quick Reference") ws2.merge_cells("A1:F1") c = ws2["A1"] c.value = "QUICK REFERENCE — Internal Iliac Artery Branches at a Glance" c.font = Font(name="Arial", bold=True, size=13, color=WHITE) c.fill = fl(BLUE_DARK); c.alignment = ca() ws2.row_dimensions[1].height = 28 qh = ["Trunk","Branch","Exits Via","Present In","Male Structures Supplied","Female Structures Supplied"] ws2.row_dimensions[2].height = 32 for col, h in enumerate(qh, 1): c = ws2.cell(row=2, column=col, value=h) c.font = hf(); c.fill = fl(BLUE_MID); c.alignment = ca(); c.border = tb() qdata = [ ("Posterior","Iliolumbar Artery","Stays in pelvis","Both","Psoas, QL, cauda equina, iliac fossa","Psoas, QL, cauda equina, iliac fossa"), ("Posterior","Lateral Sacral Arteries (x2)","Anterior sacral foramina","Both","Sacrum, sacral canal, gluteal skin","Sacrum, sacral canal, gluteal skin"), ("Posterior","Superior Gluteal Artery","Greater sciatic foramen — ABOVE piriformis","Both","Gluteus maximus, medius, minimus","Gluteus maximus, medius, minimus"), ("Anterior","Umbilical Artery","Ascends to umbilicus (fetal)","Both","Superior vesical a.; artery to ductus deferens","Superior vesical artery"), ("Anterior","Superior Vesical Artery","To superior bladder","Both","Superior bladder, distal ureter, ductus deferens","Superior bladder, distal ureter"), ("Anterior","Inferior Vesical Artery","To bladder base / prostate","MALE ONLY","Bladder base, ureter, seminal vesicle, prostate","— (replaced by vaginal artery) —"), ("Anterior","Uterine Artery","Base of broad ligament to cervix","FEMALE ONLY","— (replaced by inferior vesical artery territory) —","Uterus, cervix, upper vagina, uterine tube, partial ovary"), ("Anterior","Vaginal Artery","To lateral vaginal wall","FEMALE ONLY","— (replaced by inferior vesical artery) —","Vagina, bladder base, adjacent rectum"), ("Anterior","Middle Rectal Artery","Medially to rectum","Both","Middle/lower rectum","Middle/lower rectum"), ("Anterior","Obturator Artery","Obturator canal","Both","Adductor region of thigh, hip joint","Adductor region of thigh, hip joint"), ("Anterior","Internal Pudendal Artery","Greater sciatic foramen BELOW piriformis -> lesser sciatic foramen -> perineum","Both","Penis, scrotum, perineal muscles, external sphincters","Clitoris, labia, vestibular bulb, perineal muscles"), ("Anterior","Inferior Gluteal Artery","Greater sciatic foramen — BELOW piriformis","Both","Gluteus maximus, sciatic nerve, hip joint anastomosis","Gluteus maximus, sciatic nerve, hip joint anastomosis"), ] alt = ["FFFFFF", GREY_ROW] for i, rd in enumerate(qdata, 3): trunk_v, branch_v, exit_v, present_v, male_v, female_v = rd if present_v == "MALE ONLY": bg = "DDEEFF" elif present_v == "FEMALE ONLY": bg = "FFE8E8" else: bg = alt[i % 2] ws2.row_dimensions[i].height = 48 for col, val in enumerate([trunk_v, branch_v, exit_v, present_v, male_v, female_v], 1): c = ws2.cell(row=i, column=col, value=val) c.fill = fl(bg); c.alignment = la() if col != 4 else ca(); c.border = tb() color = "000000" if col == 4: if present_v == "MALE ONLY": color = "1F3864" elif present_v == "FEMALE ONLY": color = PINK_DARK c.font = cf(bold=(col==2), size=10, color=color) for idx, w in enumerate([12,28,44,16,42,42], 1): ws2.column_dimensions[get_column_letter(idx)].width = w ws2.freeze_panes = "A3" # ─── SHEET 3: Anastomoses ──────────────────────────────────────────────────── ws3 = wb.create_sheet("Anastomoses & Clinical Pearls") ws3.merge_cells("A1:F1") c = ws3["A1"] c.value = "KEY ANASTOMOSES & CLINICAL PEARLS — Pelvic Arteries" c.font = Font(name="Arial", bold=True, size=13, color=WHITE) c.fill = fl(BLUE_DARK); c.alignment = ca() ws3.row_dimensions[1].height = 28 for col, h in enumerate(["Vessel 1","<-->","Vessel 2","Sex","Region","Clinical Significance"], 1): c = ws3.cell(row=2, column=col, value=h) c.font = hf(); c.fill = fl(BLUE_MID); c.alignment = ca(); c.border = tb() ws3.row_dimensions[2].height = 30 adata = [ ("Uterine artery","<-->","Ovarian artery","Female","Broad ligament / uterine tube","Anastomosis enlarges in pregnancy; alternative supply after uterine artery ligation; preserved in uterine artery embolisation"), ("Middle rectal artery (internal iliac)","<-->","Superior rectal artery (inferior mesenteric)","Both","Rectum","PORTACAVAL ANASTOMOSIS — superior rectal = portal territory. Dilates in portal hypertension -> rectal varices"), ("Middle rectal artery","<-->","Inferior rectal artery (internal pudendal)","Both","Anal canal / lower rectum","Three-way rectal anastomosis; basis for hemorrhoidal plexus; internal haemorrhoids = portal territory (above pectinate line)"), ("Superior gluteal artery","<-->","Inferior gluteal artery","Both","Gluteal region","Hip joint anastomotic network; collateral in iliac artery occlusion"), ("Obturator artery (int. iliac)","<-->","Inferior epigastric artery (ext. iliac)","Both","Femoral canal region","CORONA MORTIS — accessory obturator artery crosses femoral canal; can be cut in femoral hernia repair causing serious haemorrhage"), ("Lateral sacral artery","<-->","Median sacral artery (aorta)","Both","Anterior sacrum","Collateral in aortic or internal iliac occlusion"), ("Ovarian artery (aorta)","<-->","Uterine artery (internal iliac)","Female","Mesometrium of broad ligament","Critical in pregnancy; ovarian artery enlarges to supplement uterus; anastomosis makes UAE effective"), ("Internal pudendal artery","<-->","External pudendal artery (femoral)","Both","Perineum / scrotum / labia","Collateral supply to external genitalia; relevant in pelvic trauma and reconstructive surgery"), ("Iliolumbar artery","<-->","Deep circumflex iliac artery (ext. iliac)","Both","Iliac crest region","Important collateral when either iliac system is compromised; relevant in EVAR planning"), ("Uterine artery","<-->","Vaginal artery","Female","Cervix / upper vagina","Both supply cervix and upper vagina; anastomose freely; important in radical hysterectomy"), ] for i, rd in enumerate(adata, 3): v1, arrow, v2, sex, region, clin = rd if sex == "Female": bg = "FFE8E8" elif sex == "Male": bg = "DDEEFF" else: bg = alt[i % 2] ws3.row_dimensions[i].height = 52 for col, val in enumerate([v1, arrow, v2, sex, region, clin], 1): c = ws3.cell(row=i, column=col, value=val) c.fill = fl(bg); c.alignment = ca() if col in (2,4) else la(); c.border = tb() color = "000000" if col == 2: color = "1F3864" elif col == 4 and sex == "Female": color = PINK_DARK elif col == 4 and sex == "Male": color = "1F3864" c.font = cf(bold=(col==2), size=10, color=color) for idx, w in enumerate([34,6,38,12,28,54], 1): ws3.column_dimensions[get_column_letter(idx)].width = w ws3.freeze_panes = "A3" # ─── SHEET 4: Mnemonics ────────────────────────────────────────────────────── ws4 = wb.create_sheet("Mnemonics & Study Aid") ws4.merge_cells("A1:C1") c = ws4["A1"] c.value = "MNEMONICS & EXAM TIPS — Pelvic Arteries" c.font = Font(name="Arial", bold=True, size=13, color=WHITE) c.fill = fl(BLUE_DARK); c.alignment = ca() ws4.row_dimensions[1].height = 28 for col, h in enumerate(["Topic / Mnemonic","Details","Exam Tip / Clinical Pearl"], 1): c = ws4.cell(row=2, column=col, value=h) c.font = hf(); c.fill = fl(BLUE_MID); c.alignment = ca(); c.border = tb() ws4.row_dimensions[2].height = 22 mnemonics = [ ("POSTERIOR TRUNK (3 branches) — ILS","I = Iliolumbar\nL = Lateral sacral (x2)\nS = Superior gluteal (terminal, LARGEST)","Superior gluteal exits ABOVE piriformis — the ONLY posterior trunk branch to exit the pelvis"), ("ANTERIOR TRUNK — Common Mnemonic: US-MO-II","U = Umbilical -> Superior vesical\nS = Superior vesical\nM = Middle rectal\nO = Obturator\nI = Internal pudendal\nI = Inferior gluteal","Internal pudendal and inferior gluteal BOTH exit BELOW piriformis through greater sciatic foramen"), ("MALE ONLY branch","Inferior VESICAL artery\n(bladder base, ureter, seminal vesicle, PROSTATE)","Female equivalent = VAGINAL artery. Men have a prostate, so inferior vesical supplies it"), ("FEMALE ONLY branches","1. UTERINE artery — 'Water Under Bridge': ureter (water) runs under uterine artery (bridge)\n2. VAGINAL artery — female equivalent of male inferior vesical artery","Uterine artery enlarged in pregnancy; 'Water Under Bridge' = risk of ureteric ligation in hysterectomy"), ("ABOVE vs BELOW piriformis — EXIT POINTS","ABOVE piriformis: Superior gluteal artery (posterior trunk)\nBELOW piriformis: Inferior gluteal + Internal pudendal + Sciatic nerve","Most common exam question on pelvic arteries — only superior gluteal exits ABOVE piriformis"), ("PORTACAVAL ANASTOMOSIS in rectum","Superior rectal vein (portal) <-> Middle + Inferior rectal veins (caval)\nDilates in portal hypertension -> rectal varices","Internal haemorrhoids (above pectinate line) = portal territory. External haemorrhoids (below) = caval territory"), ("GONADAL VEIN ASYMMETRY","Right gonadal vein -> IVC (straight course, low pressure)\nLeft gonadal vein -> left renal vein (90-degree angle, higher pressure)","Left varicocele (male) and left pelvic congestion syndrome (female) more common due to higher left gonadal vein pressure"), ("CORONA MORTIS (Crown of Death)","Accessory/replaced obturator artery arising from inferior epigastric artery crosses the femoral canal","Can be divided during femoral hernia repair causing serious haemorrhage. Always identify before cutting vessels near femoral ring"), ("MEDIAL UMBILICAL LIGAMENT","= obliterated distal umbilical artery\nForms medial umbilical fold of peritoneum on inner anterior abdominal wall","Lateral umbilical fold = inferior epigastric artery. Median umbilical fold (single, central) = obliterated urachus (different structure)"), ] row_bgs = ["FFF2CC","E2EFDA","EBF3FB","FFE8E8","DDEEFF","FFF2CC","E2EFDA","FFE8E8","DDEEFF"] for i, (topic, detail, tip) in enumerate(mnemonics, 3): bg = row_bgs[(i-3) % len(row_bgs)] ws4.row_dimensions[i].height = 72 for col, val in enumerate([topic, detail, tip], 1): c = ws4.cell(row=i, column=col, value=val) c.fill = fl(bg); c.alignment = la(); c.border = tb() c.font = cf(bold=(col==1), size=10, color=("1F3864" if col==1 else (PINK_DARK if col==3 else "000000"))) for idx, w in enumerate([36,54,58], 1): ws4.column_dimensions[get_column_letter(idx)].width = w ws4.freeze_panes = "A3" # ─── Save ────────────────────────────────────────────────────────────────────── out = "/home/daytona/workspace/pelvic-arteries/Pelvic_Arterial_Supply_Male_vs_Female.xlsx" buf = io.BytesIO() wb.save(buf) with open(out, "wb") as f: f.write(buf.getvalue()) print(f"Saved -> {out}") print(f"Size -> {len(buf.getvalue()):,} bytes") PYEOF echo "Written"

Your credits are exhausted. Your daily credits reset tomorrow, or you can purchase a top-up for more.

Create a comparison table (excel) of male vs female pelvic arterial supply and its branches

Running Command

python /home/daytona/workspace/pelvic-arteries/build2.py

Your Excel file is ready:

Pelvic Arterial Supply Male vs Female

Spreadsheet · XLSX


What's inside (4 sheets):

SheetContents
Male vs Female ComparisonFull row-by-row table covering every artery (aortic branches, external iliac branches, posterior trunk, anterior trunk common + male-only + female-only) with origin, course, male supply, female supply, and clinical notes. Blue = male column, pink = female column, grey-out for absent vessels
Quick ReferenceCondensed at-a-glance table of all internal iliac branches - trunk, exit route, sex, and structures supplied. Male-only rows in blue, female-only in pink
Anastomoses & Clinical PearlsAll key anastomoses (corona mortis, portacaval, uterine-ovarian, etc.) with sex coding and clinical significance
Mnemonics & Study AidILS mnemonic (posterior trunk), US-MO-II (anterior trunk), Water Under Bridge, above/below piriformis, gonadal vein asymmetry, corona mortis, and more
This is a shared conversation. Sign in to Orris to start your own chat.