创建一个没有生物信息学工具箱的网络?

use*_*039 1 matlab plot graph-theory graph graph-visualization

我有一个由三行组成的矩阵:基因1,基因2,距离.

我想创建一个网络,每个基因都是一个节点,连接线按两个基因之间的距离缩放.

如何在不使用生物信息学或神经网络工具箱的情况下实现这一目标?

谢谢!

RTL*_*RTL 12

一些信息

绘制边长与边缘权重成正比的图形几乎是不可能的,至少不太可能权重允许以这种方式绘制图形,大多数是不可能的...
参见:

P. Eades和NC Wormald.固定边长图形绘制是NP难的.离散应用数学,28(2):111-134,1990]

或引用:

"绘制边缘权重作为标准节点 - 链接图的平面图,边长与边缘权重成正比,是NP难问题"

M. Nollenburg,R.Prutkin和I. Rutter,平面图的边缘加权接触表示.Journal of Graph Algorithms and Applications,17(4):441-473,2013

考虑以这种数据格式连接的3个顶点的简单示例:

[1,2,1;
 1,3,1;
 2,3,10;]
Run Code Online (Sandbox Code Playgroud)

应该立即明白,这样的图形不可能以边长与重量成比例绘制(用直线).因为MATLAB中的这些替代方案包括使用颜色或线宽来表示重量.

对不起,这个答案的长度,而是要实现这不是小事,下面用于图形绘制的过程中也可以发现这里(debth) ,这里(最简单),并以类似的问题在这里.然而,这些并没有解决加权图...

因此,实现与重量成比例的线宽和颜色:

由于代码的长度,这里没有描述

首先是一些测试数据,包括在20个顶点之间随机分配的30个边,随机权重在0到10之间.

clear
%% generate testing data
[X,Y] = ndgrid(1:20); testdata = [X(:) Y(:)];  %// all possible edges
data(data(:,1)==data(:,2),:)=[];               %// delete self loops
data=data(randperm(size(data,1),20),:);   %// take random sample of edges
data(:,3)=rand(size(data,1),1)*10;        %// assign random weights in range 0-10
Run Code Online (Sandbox Code Playgroud)

首先对数据进行一些处理,使其成为所需的格式;

edges=data(:,1:2);
[Verticies,~,indEdges]=unique(edges); %// get labels & locations of vertices
indEdges=reshape(indEdges,[],2);

weights=data(:,3);
normalisedWeights=weights/max(weights); %// normalise weights (range 0-1)
numeEdge=numel(weights);

numVertex=numel(Verticies);
Run Code Online (Sandbox Code Playgroud)

现在,在单位圆上创建每个顶点的x和y坐标:

theta=linspace(0,2*pi,numVertex+1);
theta=theta(1:end-1);
[x,y]=pol2cart(theta,1); % create x,y coordinates for each vertex
Run Code Online (Sandbox Code Playgroud)

当MATLAB图中的线从轴颜色顺序继承它们的颜色时,我们创建一个RGB数组,该数组对应于一个颜色图,每条线的条目给出分配给该权重的颜色的RGB值.

秋季色图很容易手动实现,因为R = 1,B = 0表示所有值,G范围是0-1线性,因此我们可以将Cmap用作轴颜色顺序的变量设置如下:

clear Cmap %// to avoid errors due to the way it is created
Cmap(:,2)=normalisedWeights;
Cmap(:,1)=1;
Cmap(:,3)=0;
Run Code Online (Sandbox Code Playgroud)

现在我们创建一个图形,将colormap设置为Autumn(对于颜色条),保持按住,以便plot命令不重置颜色顺序,并应用颜色顺序

figure
colormap('autumn')
hold on
set(gca,'colororder',Cmap)  %// set axis colororder to Cmap
Run Code Online (Sandbox Code Playgroud)

我们如何使用先前在x和y给出的位置生成的边缘索引来绘制边缘.存储线的句柄(Hline)以供以后使用.

Hline=plot(x(indEdges).',y(indEdges).'); %// plot edges
Run Code Online (Sandbox Code Playgroud)

现在我们将轴设置为方形,以便正确显示点圆并关闭轴以隐藏它们(因为它们与绘制的图形无关).然后将轴颜色限制(Clim)设置为与权重范围匹配,并添加添加颜色条.

axis square off

set(gca,'Clim',[0 max(weights)]) 
colorbar
Run Code Online (Sandbox Code Playgroud)

绘制边缘的最后一步,将线宽设置为与重量成比例,标准化的权重按比例缩放到0-5范围内.然后将线宽设置为scalefactor*normalisedWeights ..

scalefactor=5; %// scale factor (width of highest weight line)
set(hline, {'LineWidth'}, num2cell(normalisedWeights*scalefactor));
Run Code Online (Sandbox Code Playgroud)

现在将顶点绘制在x和y坐标处(这里为黑色方块).增加轴限制以允许顶点标签适合.最后,顶点用原始矩阵的值标记,标签放置在比顶点稍大的圆上

plot(x,y,'ks')

xlim([-1.1,1.1]) % expand axis to fix labels
ylim([-1.1,1.1])
text(x(:)*1.1, y(:)*1.1, num2str(Verticies),...
        'FontSize',8,'HorizontalAlignment','center'); %// add Vertex labels
Run Code Online (Sandbox Code Playgroud)

结果

在此输入图像描述

  • +1,我认为这是[生活不公平]的案例之一(http://meta.stackexchange.com/questions/202652/life-isnt-fair).很棒的答案!=) (3认同)