用Graphviz產生Trial流程圖

林協霆🦎The Lizard
Research On My Way
Published in
6 min readDec 16, 2023

Introduction

最近要報的seminar有點多,要整理不同的Trial。然而,要用google slide, powerpoint, keynote等簡報軟體畫出一張流程圖很麻煩,要花時間在排版、對齊、拉線,對於一份要包含20多個Trial的簡報來說,CP值太低。然而,去搬CCO、ESMO的Conference Slide,找到的圖不一定符合我們的需要,同時還要面對版權問題。因此找出有效率產圖方法非常重要。
#Method
Graphviz使用dot語法,最基本的graph { a-> b} ,就可以畫出一圖,由a點到b點。基他產生、形狀、線條、字體,都可以用語法表示。我只需要去調整每個節點 (node)的文字內容 (label),就會自動幫我對齊、排版。

Result

例如其中一個node: (完整程式碼在最下面)

    control[label="
CONTROL: Placebo
| Carboplatin + Paclitaxel
| Doxo/Epirubicin + Cyclophosphamide
| {Q3W|4 + 4 cycles}
" ]

這樣就會把一格畫好。我只需要把這個畫好的範本留存後,下次就可以快速修改內容生圖出來,你也可以請ChatGPT閱讀某篇Trial,請他照這個格式寫出程式碼。另外生成的svg檔,可以匯入ppt裡,展開成圖形做微調。

Discussion

類似Graphviz產生圖片的工具還有GNUPLOT、D3.js、Mermaid,選擇Graphviz是因為他在command line裡執行的效率最高,不像是Mermaid或D3.js需要很多其他的依賴。在command line中,可以做到更多自動化。
後續探索的方向,是用clinicaltrial gov 所提供的API來撈取所需要資料,只要 Identifier: NCTxxxxxxxx,就可以得到json response,然後可以依這個範本自動產生簡圖。

digraph {
compound=true;
graph [
splines=ortho,
nodesep=1
rankdir="LR"
// fontname="Arial",
fontname="FiraSans-SemiBoldItalic"
label="TITLE" //TODO: ___
labelloc = "b"
fontsize="24pt"
]
node[
color="#2d696a",
penwidth=1.5,
fontsize="18pt",
shape=record,
// fontname="FiraSans-Regular"
fontname="Arial",
]
edge[color=black, penwidth=2]
background[
color="white",
fontsize="20pt",
//TODO: Stratification ___
label="Stratification by
\nnodal status, tumor size,
\ncarboplatin schedule"
]
pupulation [
fillcolor="#eefffaff",
style="filled",
// TODO: Population ___
label="primary stage I-IIA/B TNBC
| aged ≥18 yr
| T1cN1-2 or T2-4N0-2 TNBC
| ECOG PS 0/1
| available for PD-L1 testing
| (N = 1174)"
]
method [
shape=circle,
fillcolor="#2d696a",
penwidth=5,
color = "#6c9a77",
fontcolor="#ffffff",
style="filled",
fontsize="14pt",
// TODO: Randomize ___
label="🎲\n2:1"
]
subgraph cluster_armA {
label="Intervention Arm"
labelloc = "t"
color=white
fontcolor="#2d696a"
node[
color=white,
fillcolor="#2d696a:#6c9a77",
style="filled",
fontcolor="#ffffff",
]
// TODO: Intervention arm ___
intervention[label="
💊 Pembrolizumab 200 mg IV
| Carboplatin + Paclitaxel
| Doxo/Epirubicin + Cyclophosphamide
| {Q3W|4 + 4 cycles}
" ]
surgery1[label="Surgery"]
intervention -> surgery1
}
subgraph cluster_armB {
label="Control Arm"
labelloc = "t"
color=white
fontcolor="#2d696a"
node[
color="#2d696a:#6c9a77",
fillcolor=white,
style="filled",
fontcolor="#2d696a:#6c9a77",
]
// TODO: Control Arm ___
control[label="
CONTROL: Placebo
| Carboplatin + Paclitaxel
| Doxo/Epirubicin + Cyclophosphamide
| {Q3W|4 + 4 cycles}
" ]
surgery2[label="Surgery"]
control -> surgery2
}
pupulation -> method
method -> intervention [ltail=cluster_armA lhead=cluster_armA];
method -> control [ltail=cluster_armB lhead=cluster_armB];
}

--

--