生信喵 发表于 2025-11-20 22:16:49

gganatogram

<h1>背景</h1>
<p>用之前泛癌分析<a href="https://bioinfoer.com/forum.php?mod=viewthread&amp;tid=610&amp;extra=page%3D1">https://bioinfoer.com/forum.php?mod=viewthread&amp;tid=610&amp;extra=page%3D1</a>输出的基因在TCGA + GTEx的表达量TPM值(easy_input.csv文件)作为输入,用gganatogram画出感兴趣的基因在各个器官里的表达分布。</p>
<h1>应用场景</h1>
<p>gganatogramR包介绍:https://github.com/jespermaag/gganatogram</p>
<h1>环境设置</h1>
<pre><code class="language-{r}">#devtools::install_github(&quot;jespermaag/gganatogram&quot;)
library(gganatogram)
library(stringr)
library(gridExtra)

Sys.setenv(LANGUAGE = &quot;en&quot;) #显示英文报错信息
options(stringsAsFactors = FALSE) #禁止chr转成factor
</code></pre>
<h1>输入文件预处理</h1>
<p>如果你的数据已经整理成very_easy_input.csv的格式,就可以跳过这步,进入“开始画图”。</p>
<p>此处以前面提到的easy_input.csv文件为例,需要把TCGA的癌症名称跟包里的organ对应上。</p>
<p>参照GEPIA help的Differential analysis:http://gepia.cancer-pku.cn/help.html,在此基础上添加gganatogram包的organ,整理成TCGA_organ.txt文件。</p>
<pre><code class="language-{r}"># TCGA和GTEx的tumor和normal的TPM
df &lt;- read.csv(&quot;easy_input.csv&quot;, row.names = 1)
head(df)
df$tt &lt;- paste(df$tissue, df$type2, sep = &quot;_&quot;)
df.median &lt;- aggregate(.~tt, df[,3:4], median)
df.median$TCGA &lt;- str_split_fixed(df.median$tt, &quot;_&quot;,2)[,1]
df.median$type &lt;- str_split_fixed(df.median$tt, &quot;_&quot;,2)[,2]
df.median$tt &lt;- NULL

### 把TCGA癌症名称缩写换成gganatogram包里的organ
#根据背景知识,已整理成TCGA_organ
#Name列来源:https://cn.bing.com/translator
TCGA.organ &lt;- read.table(&quot;TCGA_organ.txt&quot;, sep = &quot;\t&quot;, header = T)
TCGA.organ[,c(1:2,4)]

TCGA.organ.tpm &lt;- merge(TCGA.organ[,c(1,4)], df.median, by = &quot;TCGA&quot;)
TCGA.organ.tpm$TCGA &lt;- NULL
TCGA.organ.tpm &lt;- TCGA.organ.tpm
# 男人
hgMale_key_tpm &lt;- merge(hgMale_key, TCGA.organ.tpm, by = &quot;organ&quot;)
hgMale_key_tpm$value &lt;- hgMale_key_tpm$tpm #替换掉原来的value
hgMale_key_tpm$tpm &lt;- NULL
write.csv(hgMale_key_tpm,&quot;very_easy_input_Male.csv&quot;, quote = F, row.names = F)
# 女人
hgFemale_key_tpm &lt;- merge(hgFemale_key, TCGA.organ.tpm, by = &quot;organ&quot;)
hgFemale_key_tpm$value &lt;- hgFemale_key_tpm$tpm
hgFemale_key_tpm$tpm &lt;- NULL
write.csv(hgFemale_key_tpm,&quot;very_easy_input_Female.csv&quot;, quote = F, row.names = F)
</code></pre>
<p><strong>附:</strong> 查看gganatogram包里的organ:</p>
<pre><code class="language-{r}">#男人
hgMale_key$organ
#女人
#hgFemale_key$organ
#男女差异
setdiff(hgMale_key$organ, hgFemale_key$organ)

#雄鼠
#mmMale_key$organ
#雌鼠
#mmFemale_key$organ

#细胞
#cell_key[['cell']]$organ

#支持的其他物种
names(other_key)
#以拟南芥为例查看organ
#other_key[[&quot;arabidopsis_thaliana&quot;]]$organ
</code></pre>
<h1>开始画图</h1>
<p>very_easy_input.csv,organ对应的数值。</p>
<ul>
<li>第一列是组织器官名,必须跟包里的organ一致</li>
<li>第二列color,每种organ给一种颜色</li>
<li>第三列组织所在的系统</li>
<li>第四列数值,可以是基因表达量,或者其他临床指标。</li>
<li>第五列tumor和normal</li>
</ul>
<p>其中第一列和第四列为必需</p>
<p>此处以人类为例,分别画男人和女人,对比tumor和normal。</p>
<p>还可以男女都画,然后ps成一半男一半女。</p>
<p>其他物种按照very_easy_input_*.csv的格式整理好数据,就可以套用了</p>
<pre><code class="language-{r,">#画女人
hgFemale_tpm &lt;- read.csv(&quot;very_easy_input_Female.csv&quot;)
head(hgFemale_tpm)
hgFemale_tpm$type &lt;- hgFemale_tpm$type.y #或对比不同的系统,换成type.x

#注意:
#fill里要么是color,要么是value,你自己数据的列名要跟它一致
#facet_wrap里的type,必须是type,你自己数据的列名要跟它一致
hgFemale &lt;- gganatogram(data=hgFemale_tpm,
                        fillOutline='white', #没有organ的位置用白色填充
                        #human、mouse或cell,其他物种拉丁名用names(other_key)查看
                        organism='human',
                        sex='female', #性别
                        fill=&quot;value&quot;) + #还可以用color列填充
facet_wrap(~type) + #对比tumor和normal
#用value填充时,可以设置渐变色
scale_fill_gradient(low = &quot;white&quot;, high = &quot;red&quot;) +
labs(fill = &quot;Log2(TPM + 1)&quot;) +
coord_cartesian(ylim = c(-120, 0))+ #不画小腿,如果想画到脚,就去掉这行
theme_void() #不画坐标轴

hgFemale

#画男人
hgMale_tpm &lt;- read.csv(&quot;very_easy_input_Male.csv&quot;)
head(hgMale_tpm)
hgMale_tpm$type &lt;- hgMale_tpm$type.y
hgMale &lt;- gganatogram(data=hgMale_tpm, fillOutline='white', organism='human', sex='male', fill=&quot;value&quot;) +
facet_wrap(~type) +
scale_fill_gradient(low = &quot;white&quot;, high = &quot;green&quot;) +
labs(fill = &quot;Log2(TPM + 1)&quot;) +
coord_cartesian(ylim = c(-120, 0)) +
theme_void()

hgMale

#组图并保存到pdf文件
pdf(&quot;gganatogram.pdf&quot;)
grid.arrange(hgFemale, hgMale, ncol=1)
dev.off()
</code></pre>
<p><img src="https://tcapi.voiceclouds.cn:8444/uploads/2025/11/20/mi7ijs7peon3xqfp0o.png" alt="" /></p>
<p>上图有些组织被盖住了,分开画更清晰。</p>
<pre><code class="language-{r}">hgFemale_tpm$type &lt;- hgFemale_tpm$type.x #换成type.x
gganatogram(data=hgFemale_tpm,
            fillOutline='white',
            organism='human',
            sex='female',
            fill=&quot;color&quot;) + #用color列的颜色填充
facet_wrap(~type) +
theme_void()
</code></pre>
<p><img src="https://tcapi.voiceclouds.cn:8444/uploads/2025/11/20/mi7il57fcd5ba3c7jfw.png" alt="" /></p>

生信喵 发表于 2025-11-20 22:18:15

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