Removing duplicate edges?
이전 댓글 표시
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
2016년 10월 25일
Maybe you can provide a small example which reproduces the error.
Sawyer Smith
2016년 10월 25일
답변 (3개)
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
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
2016년 10월 25일
0 개 추천
댓글 수: 1
Sawyer Smith
2016년 10월 25일
편집: Sawyer Smith
2016년 10월 25일
카테고리
도움말 센터 및 File Exchange에서 Networks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!