生信喵 发表于 2025-12-8 11:35:32

时间比例fish图

<h1>背景</h1>
<p>用R画文章里的这种肿瘤克隆进化的图。</p>
<p><img src="https://tcapi.voiceclouds.cn:8444/uploads/2025/12/08/miwkj4oyfg1t0s8yrh8.png" alt="" /></p>
<p>出自PMID: 25252869文章</p>
<h1>应用场景</h1>
<p>Create timecourse &quot;fish plots&quot; that show changes in the clonal architecture of tumors, https://github.com/chrisamiller/fishplot</p>
<p>展示肿瘤细胞克隆进化的时间、比例等信息。</p>
<p>像例文那样,在三维时间节点上共鉴定到4个克隆群,我们可以看到其中founding clone 在三个时间点上占比都非常高,70%左右,除去这个主克隆外,还有三个亚克隆,在三个时间点上变化比较大,其中主要是subclone 1 的逐渐消失,subclone2 的逐渐扩增以及subclone 3的从无到有。</p>
<p>**题外话:**还有一个R包timescape,画clonal evolution这种鱼图也很美,https://bioconductor.org/packages/release/bioc/vignettes/timescape/inst/doc/timescape_vignette.html。</p>
<p>克隆进化图有点像sankey。</p>
<h1>环境设置</h1>
<p>使用国内镜像安装包</p>
<pre><code class="language-r">options(&quot;repos&quot;= c(CRAN=&quot;https://mirrors.tuna.tsinghua.edu.cn/CRAN/&quot;))
options(BioC_mirror=&quot;http://mirrors.ustc.edu.cn/bioc/&quot;)

install.packages(&quot;devtools&quot;)
library(devtools)
install_github(&quot;chrisamiller/fishplot&quot;)
</code></pre>
<p>加载包</p>
<pre><code class="language-{r}">library(fishplot)

Sys.setenv(LANGUAGE = &quot;en&quot;) #显示英文报错信息
options(stringsAsFactors = FALSE) #禁止chr转成factor
</code></pre>
<h1>输入数据</h1>
<p>需要三种输入:</p>
<ul>
<li>easy_input.txt,每行表示每个克隆群在不同时间节点的VAF/CCF 占比,每列表示每个时间节点中各个克隆簇的情况。</li>
<li>timepoints,用来定义easy_input.txt的四列对应的4个时间节点。其中therapyTime列是化疗后休复期推断出的克隆群整体状况。</li>
<li>parents,与时间节点相对应的各个克隆群进化关系。例图中,“0”表示主克隆,“1, 1”表示在主克隆之后有两个平行发展的亚克隆簇,“3”表示在这个克隆簇发生时,已经有两次克隆事件。进一步根据各个时间节点,各个克隆簇占比情况,脚本便可实现。为便于理解parents的写法,结尾附上了几个例子。</li>
</ul>
<pre><code class="language-{r}">frac &lt;- read.table(&quot;easy_input.txt&quot;, header=T, sep='\t',row.names=1)
frac
frac.table &lt;- as.matrix(frac)
timepoints &lt;- c(0,75,110,120) #决定了鱼头、鱼身、鱼尾的长度
parents &lt;- c(0,1,1,3)
</code></pre>
<p>**题外话:**除了用上述方法构建输入以外,还可以用CloneEvol输出的结果作为输入,fisherplot可以跟ClonEvol(擅长画树枝图)无缝对接,详见:https://github.com/chrisamiller/fishplot里的“clonevol integration”</p>
<h1>开始画图</h1>
<pre><code class="language-{r,fig.width=10,">fish &lt;- createFishObject(frac.table, parents, timepoints)

#设置每种clone的颜色
fish &lt;- setCol(fish, c(&quot;#099D79&quot;, &quot;#70C7EC&quot;, &quot;#E8262D&quot;,&quot;#2C3789&quot;))
fish &lt;- layoutClones(fish)

pdf('fish.pdf', width=10, height=6)
par(mar = par()$mar + c(0,0,3,0)) #在底部留出画图例的地方

fishPlot(fish, shape = &quot;spline&quot;, #spline,圆滑的;或polygon,直的
         #title.btm = &quot;Clonal architecture of tumors&quot;, #左下角可以写字
         cex.title = 1.2, #字号
         pad.left = 0.25, #鱼头的边的倾斜角度
   
         vlines = timepoints, #画三条竖直实线
         col.vline = &quot;white&quot;, #线的颜色
         vlab = c(&quot;PMF&quot;, &quot;sAML&quot;, &quot;sAML\nREM&quot;), #竖线对应的文字,在画竖线的前提下才能写字
   
         bg.col = c(&quot;#F1F2F2&quot;,&quot;#F1F2F2&quot;,&quot;#F1F2F2&quot;), #灰色背景
         border = 0.1 #每个clone的轮廓线的宽度
         )

#如果三条竖线要画成虚线,就运行下面这行
#abline(v=timepoints, col=&quot;white&quot;, lty=2, lwd=1)

#添加clone的图例
par(xpd = T)
legend(&quot;bottomright&quot;,
       inset=c(.7,-.3), #把图例画到图外,根据自己的鱼调整
       pch=16, bty=&quot;n&quot;,
       col=fish@col, text.col = fish@col,
       legend = paste0(row.names(frac),&quot; &quot;,frac$PMF,&quot;%&quot;))

legend(&quot;bottomright&quot;,
       inset=c(.3,-.3),
       pch=16, bty=&quot;n&quot;,
       col=fish@col, text.col = fish@col,
       legend = paste0(frac$sAML,&quot;%&quot;))

legend(&quot;bottomright&quot;,
       inset=c(.0,-.3),
       pch=16, bty=&quot;n&quot;,
       col=fish@col, text.col = fish@col,
       legend = paste0(frac$Saml_REM,&quot;%&quot;))

dev.off()
</code></pre>
<p><img src="https://tcapi.voiceclouds.cn:8444/uploads/2025/12/08/miwksga2691c7zfl3nv.png" alt="" /></p>
<h1>后期加工处理</h1>
<p>前面输出的fish.pdf文件是矢量图,可以用illustrator等工具编辑,例如添加例文中的点、基因名,移动文字位置等等。</p>
<p>或者用<a href="https://bioinfoer.com/forum.php?mod=viewthread&amp;tid=631&amp;extra=">https://bioinfoer.com/forum.php?mod=viewthread&amp;tid=631&amp;extra=</a>导出矢量图,用ppt就能编辑。</p>
<h1>附</h1>
<p>如果有更多克隆,要怎样设置parents?</p>
<pre><code class="language-{r}">frac.table &lt;- read.table(&quot;easy_input2.txt&quot;, header=T, sep='\t', row.names=1)
frac.table
frac.table &lt;- as.matrix(frac.table)
timepoints &lt;- c(0,30,75,150)
parents &lt;- c(0,1,2,0,4,5)

pdf('fish2.pdf', width=8, height=5)
fish &lt;- createFishObject(frac.table, parents, timepoints)
fish &lt;- layoutClones(fish)
fishPlot(fish,shape=&quot;spline&quot;)
dev.off()
</code></pre>
<p><img src="https://tcapi.voiceclouds.cn:8444/uploads/2025/12/08/miwll5jscm2krpac0ik.png" alt="" /><br />
再进一步,互相对比着看fishplot自带的三条鱼https://github.com/chrisamiller/fishplot对应的代码:https://github.com/chrisamiller/fishplot/blob/master/tests/test.R,就能掌握写parents的规律。</p>

生信喵 发表于 2025-12-8 11:40:25

<p>文中所用数据可以关注公众号“生信喵实验柴”<br />
<img src="https://tcapi.voiceclouds.cn:8444/uploads/2025/09/07/mf9nu72s90ofyseu9hl.png" alt="" /><br />
发送关键词“20250514”获取</p>
页: [1]
查看完整版本: 时间比例fish图