<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>生信菜鸟团 &#187; 网络分析</title>
	<atom:link href="http://www.bio-info-trainee.com/tag/%e7%bd%91%e7%bb%9c%e5%88%86%e6%9e%90/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bio-info-trainee.com</link>
	<description>欢迎去论坛biotrainee.com留言参与讨论，或者关注同名微信公众号biotrainee</description>
	<lastBuildDate>Sat, 28 Jun 2025 14:30:13 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.33</generator>
	<item>
		<title>R语言画网络图三部曲之igraph</title>
		<link>http://www.bio-info-trainee.com/2082.html</link>
		<comments>http://www.bio-info-trainee.com/2082.html#comments</comments>
		<pubDate>Mon, 28 Nov 2016 10:08:59 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[网络分析]]></category>
		<category><![CDATA[网络图]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=2082</guid>
		<description><![CDATA[经过热心的小伙伴的提醒，我才知道我以前写的R语言画网络图三部曲竟然漏掉了最基础的 &#8230; <a href="http://www.bio-info-trainee.com/2082.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>经过热心的小伙伴的提醒，我才知道我以前写的R语言画网络图三部曲竟然漏掉了最基础的一个包，就是igraph，不了解这个，后面的两个也是无源之水。</p>
<h2><a title="详细阅读 R语言画网络图三部曲之networkD3" href="http://www.bio-info-trainee.com/1357.html" rel="bookmark">R语言画网络图三部曲之networkD3</a></h2>
<h2><a title="详细阅读 R语言画网络图三部曲之sna" href="http://www.bio-info-trainee.com/1355.html" rel="bookmark">R语言画网络图三部曲之sna</a></h2>
<div>包说明书：<a href="https://cran.r-project.org/web/packages/igraph/igraph.pdf">https://cran.r-project.org/web/packages/igraph/igraph.pdf</a></div>
<div>包例子：<a href="https://www.r-project.org/conferences/useR-2008/slides/Csardi.pdf">https://www.r-project.org/conferences/useR-2008/slides/Csardi.pdf</a></div>
<div>包函数：<a href="http://igraph.org/r/doc/">http://igraph.org/r/doc/</a></div>
<div>PPI实例：<a href="http://a-little-book-of-r-for-bioinformatics.readthedocs.io/en/latest/src/chapter11.html">http://a-little-book-of-r-for-bioinformatics.readthedocs.io/en/latest/src/chapter11.html</a></div>
<div>其实包括了3个包：igraph/RBGL/Rgraphviz</div>
<div>用到了一个测试数据，是构建好的PPI网络对象：We will first analyse a curated data set of protein-protein interactions in the yeast Saccharomyces cerevisiae extracted from published papers. This data set comes from with an R package called “yeastExpData”, which calls the data set “litG”. This data was first described in a paper by Ge et al (2001) in Nature Genetics (<a href="http://www.nature.com/ng/journal/v29/n4/full/ng776.html">http://www.nature.com/ng/journal/v29/n4/full/ng776.html</a>).</div>
<div></div>
<p><span id="more-2082"></span></p>
<div><span style="color: #ff0000;">重点是graphNEL graph对象如何构造以及如何用函数来处理它！</span></div>
<div><span style="color: #ff0000;">构造方式，请记住，构造网络对象是重点，就是graph.data.frame+as_graphnel即可，一系列以网络对象为基础的包都需要这个步骤，学会了，也就没有问题了！</span></div>
<div>读取PPI数据到data.frame里面，比如my_edges</div>
<div><img src="file:///C:/Users/jimmy1314/AppData/Local/YNote/data/jmzeng1314@163.com/218613774f924593bf4f8c0c9409d9ec/clipboard.png" alt="" data-media-type="image" data-attr-org-src-id="A5A10EECE0EE4050BB621ECF2A264D50" /><a href="http://www.bio-info-trainee.com/wp-content/uploads/2016/11/clipboard1.png"><img class="alignnone size-full wp-image-2083" src="http://www.bio-info-trainee.com/wp-content/uploads/2016/11/clipboard1.png" alt="clipboard" width="359" height="124" /></a></div>
<div>tmp &lt;- graph.data.frame(my_edges)</div>
<div>tmp;summary(tmp)</div>
<div>plot(tmp, layout=layout.kamada.kawai)</div>
<div>subnet &lt;- as_graphnel(tmp)</div>
<div>这个时候得到的subnet就是一个网络对象啦！</div>
<div>&gt; subnet</div>
<div>A graphNEL graph with directed edges</div>
<div>Number of Nodes = 818</div>
<div>Number of Edges = 12249</div>
<div>有了这个网络对象，就可以用BioNet来处理找<a href="http://www.bio-info-trainee.com/2071.html">maximal-scoring subgraph</a></div>
<div></div>
<div>对于网络对象，其它处理的函数有</div>
<div>mynodes &lt;- nodes(litG) 得到网络里面的所有节点信息</div>
<div>adj(litG, "YBR009C") 得到网络里面的YBR009C这个node节点的所有edges</div>
<div>mydegrees &lt;- graph::degree(litG) 算出网络里面的每个node的degree</div>
<div>table(mydegrees);mean(mydegrees);hist(mydegrees, col="red") 看看degree的分布情况。</div>
<div>对比较大的网络来说，并非里面的node都是连通的，可以用RBGL包来看看哪些nodes被隔离开了。</div>
<div>library("RBGL") myconnectedcomponents &lt;- connectedComp(litG)</div>
<div>返回的myconnectedcomponents这个list的每个元素都是一个被隔离开的网络图，可以去找最大连通图，也可以对这个list找到特定的某个node参与的连通图。</div>
<div>component3 &lt;- myconnectedcomponents[[3]]</div>
<div>mysubgraph &lt;- subGraph(component3, litG) 取指定的连通图，生成graphNEL对象，其实就是根据nodes来取子网络图。</div>
<div>下面代码可以把网络图展现出来：</div>
<div>library("Rgraphviz") mysubgraph &lt;- subGraph(component3, litG) mygraphplot &lt;- layoutGraph(mysubgraph, layoutType="neato") renderGraph(mygraphplot)</div>
<div></div>
<div>对网络图还可以找communities，这个又是一个网络图研究术语了： <a href="http://en.wikipedia.org/wiki/Community_structure">http://en.wikipedia.org/wiki/Community_structure</a></div>
<div>还可以进行聚类，就是cluster，还有很多，我就不一一介绍了。</div>
<div>上面的连通图也是一个网络研究术语：<a href="http://en.wikipedia.org/wiki/Connected_component_(graph_theory)">http://en.wikipedia.org/wiki/Connected_component_(graph_theory)</a></div>
<div></div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/2082.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用BioNet这个bioconductor包来找 maximal-scoring subgraph</title>
		<link>http://www.bio-info-trainee.com/2071.html</link>
		<comments>http://www.bio-info-trainee.com/2071.html#comments</comments>
		<pubDate>Fri, 25 Nov 2016 14:54:20 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[基础软件]]></category>
		<category><![CDATA[bioconductor]]></category>
		<category><![CDATA[BioNet]]></category>
		<category><![CDATA[网络分析]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=2071</guid>
		<description><![CDATA[## 此包是为了解决一个难题： maximal-scoring subgraph &#8230; <a href="http://www.bio-info-trainee.com/2071.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div>## 此包是为了解决一个难题： maximal-scoring subgraph (MSS) problem ，在一个巨大的复杂网络里面找到significantly differentially expressed subnetworks，就是说，得到了几百个差异基因，去PPI数据库做网络图的时候，发现还是巨大无比，所以需要用这个包来精简我们的网络图。</div>
<div>heuristically的中文意思：启发性地</div>
<div>## 而这个R包可以整合多种数据结果来给一个网络打分，</div>
<div>包的主页是：<a href="https://www.bioconductor.org/packages/release/bioc/html/BioNet.html">https://www.bioconductor.org/packages/release/bioc/html/BioNet.html</a></div>
<div>paper：<a href="http://bioinformatics.oxfordjournals.org/content/early/2010/02/25/bioinformatics.btq089">BioNet: an R-Package for the Functional Analysis of ... - Bioinformatics</a></div>
<div>它整合了PPI网络分析和寻找功能模块的需求。</div>
<div>脚本：<a href="https://www.bioconductor.org/packages/release/bioc/vignettes/BioNet/inst/doc/Tutorial.R">https://www.bioconductor.org/packages/release/bioc/vignettes/BioNet/inst/doc/Tutorial.R</a></div>
<div>教程：<a href="https://www.bioconductor.org/packages/release/bioc/vignettes/BioNet/inst/doc/Tutorial.pdf">https://www.bioconductor.org/packages/release/bioc/vignettes/BioNet/inst/doc/Tutorial.pdf</a></div>
<div>重点就是根据一个"igraph" or "graphNEL"对象和打分来找最大的MSS</div>
<div>subnet &lt;- subNetwork(dataLym$label, interactome)</div>
<div>module &lt;- runFastHeinz(subnet, scores)</div>
<div>plotModule(module, scores=scores, diff.expr=logFC) #这个就是精简后的我们的网络图。</div>
<div>其实另外一个函数也有类似的功能，dNetFind <a href="https://rdrr.io/cran/dnet/man/dNetFind.html">https://rdrr.io/cran/dnet/man/dNetFind.html</a></div>
<div></div>
<p><span id="more-2071"></span></p>
<div>## 里面用到的网络，都是基于igraph的包： A graph object, either in graphNEL or igraph format.</div>
<div>## 首先加载一系列的包和内置数据</div>
<div></div>
<div>library(BioNet)</div>
<div>library(DLBCL)</div>
<div>data(dataLym)</div>
<div>data(interactome)</div>
<div>## dataLym 里面是3个样本,t,s,o 分别对应着的每个基因的p值</div>
<div>## interactome是一个内置的PPI网络对象，可以根据指定的基因list来提取里面的信息</div>
<div></div>
<div>pvals &lt;- cbind(t=dataLym$t.pval, s=dataLym$s.pval)</div>
<div>rownames(pvals) &lt;- dataLym$label</div>
<div>pval &lt;- aggrPvals(pvals, order=2, plot=FALSE)</div>
<div></div>
<div>## 提取t,s样本的p值，然后用aggrPvals整合成一个p值</div>
<div></div>
<div>subnet &lt;- subNetwork(dataLym$label, interactome)</div>
<div>subnet &lt;- rmSelfLoops(subnet)</div>
<div>subnet</div>
<div>## 根据指定的dataLym$label基因信息来提取网络，但是这个基因信息有点奇怪,比如TP53(7157) ， 看起来是symbol跟entrez ID的合体。</div>
<div>## 函数rmSelfLoops是标配，只要是网络，都需要处理一下，去除自循环信息</div>
<div>## 因为指定的dataLym$label基因是有限的，一般不会太多，提取的网络一般也就上千个nodes，万把个edges的</div>
<div></div>
<div>fb &lt;- fitBumModel(pval, plot=FALSE)</div>
<div>## 对我们整合好的基因对应的P值进行Beta-Uniform-Mixture (BUM) model模型处理。</div>
<div>scores &lt;- scoreNodes(subnet, fb, fdr=0.001)</div>
<div></div>
<div>module &lt;- runFastHeinz(subnet, scores)</div>
<div>## Here we use a fast heuristic approach to calculate an approximation to the optimal scoring subnetwork.</div>
<div>logFC &lt;- dataLym$diff</div>
<div>names(logFC) &lt;- dataLym$label</div>
<div></div>
<div>plotModule(module, scores=scores, diff.expr=logFC)</div>
<div>## diff.expr是用来给nodes调色的</div>
<div>## scores是用来给nodes赋予性状的</div>
<div>## 这个函数本身是基于graphNEL or igraph format的定制版，其实可以直接用igraph包来绘图。</div>
<div>## 也可以把这个network导出成Cytoscape format，这样可以用cytoscape来绘图</div>
<div>## 一般来说，红色是上调基因，绿色是下调基因，圆形是得分为正，菱形是得分为负</div>
<div></div>
<div></div>
<div>## 下面是一个实际的例子，如何使用BioNet包来做网络分析</div>
<div>library(BioNet)</div>
<div>library(DLBCL)</div>
<div>data(exprLym)</div>
<div>data(interactome)</div>
<div>exprLym ## 内置对象，所以它的gene的laber是符合interactome的要求的</div>
<div>interactome</div>
<div>network &lt;- subNetwork(featureNames(exprLym), interactome)</div>
<div>network</div>
<div>network &lt;- largestComp(network)</div>
<div>## The function extracts the largest component of a network</div>
<div>network</div>
<div></div>
<div>library(genefilter)</div>
<div>library(impute)</div>
<div>expressions &lt;- impute.knn(exprs(exprLym))$data</div>
<div>## exprs得到的不再是纯粹的表达矩阵，需要用来 impute missing expression data</div>
<div>## 这里选择genefilter包的rowttests函数来做差异分析</div>
<div>t.test &lt;- rowttests(expressions, fac=exprLym$Subgroup)</div>
<div>t.test[1:10, ]</div>
<div>data(dataLym)</div>
<div></div>
<div>ttest.pval &lt;- t.test[, "p.value"]</div>
<div>surv.pval &lt;- dataLym$s.pval</div>
<div>names(surv.pval) &lt;- dataLym$label</div>
<div>pvals &lt;- cbind(ttest.pval, surv.pval)</div>
<div>pval &lt;- aggrPvals(pvals, order=2, plot=FALSE)</div>
<div>fb &lt;- fitBumModel(pval, plot=FALSE)</div>
<div>fb</div>
<div>## 用图来展示这个fitBumModel函数到底做了什么</div>
<div>dev.new(width=13, height=7)</div>
<div>par(mfrow=c(1,2))</div>
<div>hist(fb)</div>
<div>plot(fb)</div>
<div>dev.off()</div>
<div></div>
<div>## 下面这个图可以看到 Beta-Uniform-Mixture (BUM) 模型的两个参数是如何体现的</div>
<div>plotLLSurface(pval, fb)</div>
<div></div>
<div>scores &lt;- scoreNodes(network=network, fb=fb, fdr=0.001)</div>
<div>## 根据p值来对每个edge打分</div>
<div></div>
<div>network &lt;- rmSelfLoops(network)</div>
<div></div>
<div>## 下面是把网络数据写到txt文档，就可以导入到cytoscape啦！</div>
<div>writeHeinzEdges(network=network, file="lymphoma_edges_001", use.score=FALSE)</div>
<div>writeHeinzNodes(network=network, file="lymphoma_nodes_001", node.scores = scores)</div>
<div></div>
<div>datadir &lt;- file.path(path.package("BioNet"), "extdata")</div>
<div>dir(datadir)</div>
<div>## 本次算法变了：the heinz algorithm is used to calculate the maximum-scoring subnetwork</div>
<div>## 下面的文件需要借助heinz.py脚本生成，这里实例用的是包自带的数据</div>
<div>## 脚本代码是：heinz.py -e lymphoma_edges_001.txt -n lymphoma_nodes_001.txt -N True -E False</div>
<div></div>
<div>module &lt;- readHeinzGraph(node.file=file.path(datadir, "lymphoma_nodes_001.txt.0.hnz"), network=network)</div>
<div>diff &lt;- t.test[, "dm"]</div>
<div>names(diff) &lt;- rownames(t.test)</div>
<div></div>
<div>plotModule(module, diff.expr=diff, scores=scores)</div>
<div></div>
<div>sum(scores[nodes(module)])</div>
<div>sum(scores[nodes(module)]&gt;0)</div>
<div>sum(scores[nodes(module)]&lt;0)</div>
<div></div>
<div></div>
<div>###################################################</div>
<div>### code chunk number 27: Tutorial.Rnw:375-380</div>
<div>###################################################</div>
<div>library(BioNet)</div>
<div>library(DLBCL)</div>
<div>library(ALL)</div>
<div>data(ALL)</div>
<div>data(interactome)</div>
<div>## 这个ALL是另外一个包的数据，基因ID现在还没有，是探针ID，需要转换成BioNet识别的！</div>
<div>mapped.eset &lt;- mapByVar(ALL, network=interactome, attr="geneID")</div>
<div>mapped.eset[1:5,1:5]</div>
<div>length(intersect(rownames(mapped.eset), nodes(interactome)))</div>
<div>network &lt;- subNetwork(rownames(mapped.eset), interactome)</div>
<div>network</div>
<div>network &lt;- largestComp(network)</div>
<div>network &lt;- rmSelfLoops(network)</div>
<div>network</div>
<div></div>
<div>## 这里用limma来做差异分析</div>
<div>library(limma)</div>
<div>design &lt;- model.matrix(~ -1+ factor(c(substr(unlist(ALL$BT), 0, 1))))</div>
<div>colnames(design)&lt;- c("B", "T")</div>
<div>contrast.matrix &lt;- makeContrasts(B-T, levels=design)</div>
<div>contrast.matrix</div>
<div>fit &lt;- lmFit(mapped.eset, design)</div>
<div>fit2 &lt;- contrasts.fit(fit, contrast.matrix)</div>
<div>fit2 &lt;- eBayes(fit2)</div>
<div>pval &lt;- fit2$p.value[,1]</div>
<div>fb &lt;- fitBumModel(pval, plot=FALSE)</div>
<div>fb</div>
<div>dev.new(width=13, height=7)</div>
<div>par(mfrow=c(1,2))</div>
<div>hist(fb)</div>
<div>plot(fb)</div>
<div>scores &lt;- scoreNodes(network=network, fb=fb, fdr=1e-14)</div>
<div>## 还是把网络数据写到本地，供cytoscape导入</div>
<div>writeHeinzEdges(network=network, file="ALL_edges_001", use.score=FALSE)</div>
<div>writeHeinzNodes(network=network, file="ALL_nodes_001", node.scores = scores)</div>
<div>## 还是使用 heinz algorithm is used to calculate the maximum-scoring subnetwork</div>
<div>## A new implementation Heinz v2.0 is also available at https://software.cwi.nl/software/heinz ,</div>
<div></div>
<div>datadir &lt;- file.path(path.package("BioNet"), "extdata")</div>
<div>module &lt;- readHeinzGraph(node.file=file.path(datadir, "ALL_nodes_001.txt.0.hnz"), network=network)</div>
<div></div>
<div>nodeDataDefaults(module, attr="diff") &lt;- ""</div>
<div>nodeData(module, n=nodes(module), attr="diff") &lt;- fit2$coefficients[nodes(module),1]</div>
<div>nodeDataDefaults(module, attr="score") &lt;- ""</div>
<div>nodeData(module, n=nodes(module), attr="score") &lt;- scores[nodes(module)]</div>
<div>nodeData(module)[1]</div>
<div></div>
<div>## 保存为XGMML file，供cytoscape使用</div>
<div>saveNetwork(module, file="ALL_module", type="XGMML")</div>
<div></div>
<div><span style="color: #ff0000;">## 一般来说，红色是上调基因，绿色是下调基因，圆形是得分为正，菱形是得分为负</span></div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/2071.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
