cytoscape繪製網路圖,導入數據的要求有哪些?
想用cytoscape繪製基因調控網路圖,描述基因與基因之間的拓撲關係,現有一張行為基因名,列為樣本單元,主體內容為基因之間相關程度指數的excel表格,不知道如何用cytoscape繪製。或者該用什麼工具實現基因調控網路的可視化
cytoscape可以處理多種格式的文本文件。你把你的數據轉成這些文件,然後就可以在cytoscape里打開了。
最簡單的是.sif格式(sif格式),格式是:nodeA &
nodeC &
...
就是說文件分三列,第一列和第三列是相互作用的基因名,第二列是相互作用的名稱。.sif格式的好處是簡單,容易處理。不過它不能規定每個節點的位置、大小、形狀等。
另一種是xgmml格式,它是一種xml格式,可以規定節點和邊的許多信息,但也更複雜。我在網上查了很久都沒有查到xgmml格式的詳細信息,沒辦法只好隨便畫個網路,讓cytoscape導出成xgmml,然後一行一行看,花了一晚上搞明白了。於是寫了幾個python小函數來專門寫這種格式。代碼附在最後。
然後要畫網路的時候寫小腳本就行了:(假設這幾個小函數的文件名叫xgmml.py)from xgmml import *
fid = open("test.xml", "w")
addHead(fid, "hehe")
addNode(fid, "A", "A")
addNode(fid, "B", "B")
addEdge(fid, "A", "B", "A to B")
fid.write("&
")
fid.close()
代碼應該很好理解吧?導入包,打開文件,用addHead寫文件頭,addNode加結點,addEdge加邊,補一句文件結尾,然後關閉文件。
最後把test.xml在cytoscape里打開就行啦:
==========================================
吐槽一下。其實我覺得cytoscape很不好用,各種操作反人類,還經常打不開關不掉。但似乎沒有更好的選擇。曾經有個叫gephi的軟體,還上過nature genetics的封面,找過了用了一下,摸了半天感覺比cytoscape還反人類,遂棄之。==========================================附畫xgmml的python代碼:# xgmml.py
def addHead(fid, GraphID):
""" addHead Add the head content of an XGMML file to a file handle.
fid The file handle of the XGMML file.
GraphID The name of the graph. """
import time;
fid.write("&
")
fid.write("&
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
" % time.localtime()[:6])
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
" % GraphID)
fid.write(" &
")
fid.write(" &
" % GraphID)
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
") # Network_Width to be specified.
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
") # Background_Color to be specified.
fid.write(" &
") # Network_Height to be specified.
fid.write(" &
")
fid.write(" &
")
return True
def addNode(fid, Label, ID, fill="#ff0000", shape="ELLIPSE", x=0.0, y=0.0, w=35.0, h=35.0, FontSize=15, LabelColor="#000000", Transparency=255, LabelPosition="C,C,c,0,0"):
""" addNode Add the content of a new node to an XGMML file.
fid The file handle of the XGMML file.
Label The label of the node.
ID ID of the node.
fill The color of the node.
shape The shape of the node. {"ELLIPSE","ROUND_RECTANGLE","TRIANGLE","DIAMOND",
"PARALLELOGRAM","HEXAGON","RECTANGLE","OCTAGON","V"}
x y The coordinates of the node.
w h The width and height of the node.
FontSize The font size of the label.
LabelColor The color of the label.
Transparency The transparency of the node.
LabelPosition The label position.
"""
fid.write(" &
" % (ID,Label) )
fid.write(" &
" % Label)
fid.write(" &
")
fid.write(" &
" % Label)
fid.write(" &
" % (fill,x,shape,y,h,w))
fid.write(" &
")
fid.write(" &
")
fid.write(" &
" % Transparency)
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
" % Label)
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
" % FontSize)
fid.write(" &
")
fid.write(" &
")
fid.write(" &
" % LabelColor)
fid.write(" &
")
fid.write(" &
")
fid.write(" &
") # Seleted_Paint to be specified.
fid.write(" &
")
fid.write(" &
")
fid.write(" &
" % LabelPosition)
fid.write(" &
") # is_Selected to be specified.
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
return True
def addEdge(fid, source, target, ID, Label="", directed="1", SourceArrowShape="ARROW", TargetArrowShape="ARROW", SourceArrowColor="#000000", TargetArrowColor="#000000",
LineType="SOLID", LineWidth=2.0, LineColor="#333333"):
""" addEdge Add the content of a new edge to an XGMML file.
fid The file handle of the XGMML file.
source The start node of the edge.
target The end node of the edge.
ID The ID of the edge, which must be special.
Label The label of the edge, which will be present on the graph but not necessarily special.
directed Whether the edge is directed.
SourceArrowShape The shape of the source arrow. {"ARROW","DELTA","CIRCLE","HALF_BOTTOM","DIAMOND","HALF_TOP","NONE","T"}
TargetArrowShape The shape of the target arrow. {"ARROW","DELTA","CIRCLE","HALF_BOTTOM","DIAMOND","HALF_TOP","NONE","T"}
SourceArrowColor The color of the source arror. (unselected)
TargetArrowColor The color of the target arrow. (unselected)
LineType The presented type of the line. {"SOLID","DASHDOT","ZIGZAG","FORWARD_SLASH","SINEWAVE","SEPARATE_ARROW",
"BACKWARD_SLASH","EQUAL_DASH","PARALLEL_LINES","DASH","VERTICAL_SLASH",
"CONTIGUOUS_ARROW","DOTS"}
LineWidth The width of the line.
LineColor The color of the line. """
fid.write(" &
" % (ID,source,target,source,target,directed))
fid.write(" &
")
fid.write(" &
" % (source,target))
fid.write(" &
")
fid.write(" &
" % (source,target))
fid.write(" &
")
fid.write(" &
" % (LineWidth,LineColor))
fid.write(" &
")
fid.write(" &
" % SourceArrowShape)
fid.write(" &
")
fid.write(" &
")
fid.write(" &
" % TargetArrowColor)
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
fid.write(" &
") # Label_Font_Size to be specified.
fid.write(" &
" % LineType)
fid.write(" &
")
fid.write(" &
" % SourceArrowColor)
fid.write(" &
")
fid.write(" &
")
fid.write(" &
" % Label)
fid.write(" &
")
fid.write(" &
" % TargetArrowShape)
fid.write(" &
") # Label color to be specified.
fid.write(" &
")
fid.write(" &
")
fid.write(" &
")
return True
最簡單的方法:用tab分割的純文本文件。
描述邊的文件可以是每行一個邊,tab分割的兩個token分別是from頂點和to頂點。注意導入的時候選擇正確的列映射。並且去掉「第一行是屬性標題」這一選項,不然它會認為你第一行是標題而不是內容,你會憑空少一個邊。
然後再弄幾個tab分割的純文本描述頂點屬性和邊屬性,ID對上就行。各位兄弟,我想請教一個問題,如何通過兩個點去選擇它們之間的邊呢,要能批量操作的那種
0贊8回復慘案
----------------------------------------------------------------------
第一個答主一看就是編程底子深厚啊,我提供一種簡單的方式。
我的數據一般是txt文件,做成兩列,每一列都是基因名稱,同一行表示有互作關係(這是準備畫無方向網路圖的,如果是要畫有方向網路圖則第一列是上游基因,第二列是被調控的基因)。如果是有調控強弱係數,就放在第三列。
然後file-&>import-&>network-&>file..
選擇你的txt文件,打開後如圖
就是從彈出來的窗口選擇,source interaction選擇第一列基因,targets interaction選擇第二列基因,(中間的interaction type選擇調控係數)
然後點擊導入,選擇有向網路或者無項網路,初步的網路圖就做出來了。
可以通過cytoscape自帶的network analysis包,或者安裝其他的包來對這個網路進行一定的分析或者形狀改變,這點挺像R的。
最後,調控關係並沒有顯示,而是作為邊的屬性存在,所以可以根據這個屬性值,顯示成粗細不同,或者做一個篩選,等等。(這個我沒做過,但是屬性值看到過,肯定有包是可以的。)
好,就是這樣,歡迎批評指正,新手,求輕拍!
兄弟,你現在弄好了嗎?我愁死了,該怎麼用cytoscape去打開xgmml文件
推薦閱讀:
※暴雪可能重做魔獸世界的模型嗎?
※實現EGE這樣的圖形庫需要什麼技術支持?
※計算幾何有何經典書籍?
※計算機視覺中video understanding領域有什麼研究方向和比較重要的成果?