Removing duplicate edges?

6 次查看(过去 30 天)
Sawyer Smith
Sawyer Smith 2016-10-24
Hey all, very new to matlab and am trying to use it to generate protein-protein interaction networks. The first dataset I used went through just fine, but I'm having some trouble with my second one.
Gene1 'MAP2K4' 'MYPN' 'ACVR1' 'GATA2' 'RPA2'
Gene2 'FLNC' 'ACTN2' 'FNTA' 'PML' 'STAT3'
I have two cell arrays like shown above, where spot 1 in Gene1 interacts with spot 1 in Gene2 (forms an edge). The first time I did this it was easy to just use the graph function >> graph(Gene1,Gene2). But with my second dataset I have double edges(usually flipped around), and when I go to use the graph function I get the error "matlab.internal.graph.MLGraph" and am not sure how to go about removing them.
If you need any more info from me I will be happy to provide it, just starting out and not sure how to say it all quite yet though :)
  2 个评论
Jiro Doke
Jiro Doke 2016-10-25
Maybe you can provide a small example which reproduces the error.
Sawyer Smith
Sawyer Smith 2016-10-25
gene3 =
'abc'
'bcd'
'def'
gene4 =
'def'
'efg'
'abc'
graph(gene3,gene4)
Should do it (not at a place where I can check it, but pretty sure).

请先登录,再进行评论。

回答(3 个)

Christine Tobler
Christine Tobler 2016-11-2
If your duplicates are always one that is A->B and another B->A, Alexandra's elegant solution will work very well.
If you have duplicate edges that are exactly the same (say A->B and A->B appears twice), you would need some workaround as unique(..., 'rows') is not supported for cell arrays. The simplest is probably to cast your cell array to a categorical, apply unique(..., 'rows'), and cast back to cellstr. Then, you can apply Alexandra's solution to this new array.
A = [Gene1(:), Gene2(:)];
uniqueA = cellstr(unique(categorical(A), 'rows'));
d = digraph(uniqueA(:,1), uniqueA(:,2));
m = full(adjacency(d));
g = graph(m|m',d.Nodes);

Alexandra Harkai
Alexandra Harkai 2016-10-25
A graph-driven workaround could be:
d = digraph(Gene1,Gene2);
m = full(adjacency(d));
g = graph(m|m',d.Nodes);
This creates a digraph with edges A->B and B->A being different directed edges, then making sure we get a symmetric adjacency matrix out of it, and smashing on the Node names we got from the original digraph.
This of course depends how fast and large you need this to be. This may not be the most efficient solution.

Alexandra Harkai
Alexandra Harkai 2016-10-25
Seems like this was a similar question, only with numeric graph node names.
If you have 2016b, then you can treat Gene1 and Gene2 as string arrays and sort them the same way.
  1 个评论
Sawyer Smith
Sawyer Smith 2016-10-25
编辑:Sawyer Smith 2016-10-25
Mmk, that is pretty dang similar. But I have 2016a and the sorting function doesn't seem to work on my arrays :( At least when I try to sort it by rows.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Genomics and Next Generation Sequencing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by