2014-10-03 136 views
0

我有一個從-0.10100到0.28400的值範圍(總共120個連續值)。該值代表120個基因的基因表達。在我的網絡中,它們代表了TGFB1的相互作用基因。 我想通過使用igraph圖庫來繪製我的網絡。 我想對我的節點顏色有兩個影響:第一個是:根據值的範圍根據綠色的基因表達值(綠色的負值和紅色的正值)爲我的節點着色代表我的屬性。然後,我想讓透明度在-0.10100到 0.04720之間的紅綠節點。由於我不是R專家,我遇到了麻煩,在我的網絡上產生了如此多的影響。 任何人都可以幫助我嗎?igraph節點顏色根據基因表達值屬性

我嘗試:

tmp1= read.delim("mynet.txt", header= T) 
g <- graph.data.frame(tmp1, directed=FALSE) 
V(g)$name 
[1] "COL6A3" "PDGFRB" "COL3A1" "COL5A1" "LOXL1" .... 

g 
GRAPH UN-- 120 120 -- 
+ attr: name (v/c), GEX (v/c), color (v/c) 

tmp2= read.delim("myattributes.txt", header= T) 
GENE  S2N  
COL6A3  0.28400 
PDGFRB  0.28100 
COL3A1  0.26300 
......  .......  
V(g)$GEX=as.numeric(tmp2$S2N[match(V(g)$name,tmp2$GENE)]) 
V(g)$color=V(g)$GEX   

然後不幸的是我停下來,我不能夠繼續。 任何人都可以幫助我嗎?

最佳

+1

你能提供你的數據嗎? – jlhoward 2014-10-04 00:46:01

回答

0

也許這不是一個最佳的解決方案,但讓我們看看它是否對你有用。基本上,您必須將顏色分配給V(g)$color,而不是像現在這樣做。我的解決方案是定義連續數據的間隔,併爲每個間隔分配一個顏色。要將連續數據(即df $ S2N)映射到分類數據,您可以使用cut。這裏有一個例子:

library(igraph) 
library(org.Hs.eg.db) # Bioconductor annotation package for human. 

set.seed(123) 

# create toy network: 
g <- barabasi.game(10, directed = FALSE) 

# assign random gene ids. 
V(g)$name <- sample(keys(org.Hs.eg.db), 10) 

# assign the gene symbol to the label attribute: 
V(g)$label <- select(org.Hs.eg.db, keys = V(g)$name, columns="SYMBOL")$SYMBOL 
plot(g) 

# generate toy dataset: 
df <- data.frame(GENE=V(g)$label, S2N=sample(seq(-2,2,.1),10,replace=TRUE)) 

# if you are plotting e.g. fold changes, you may want dark blue for 
# FC between -2 and -1, blue for FC between -1 and -.5, grey for -.5 and .5, and so on. 
# define colors: 
col <- c("darkblue", "blue", "grey", "orange", "red") 

# map your continuous data to the intervals you want: 
(colc <- cut(df$S2N, breaks = c(-2, -1, -.5, .5, 1, 2), include.lowest = TRUE)) 

[1] (-1,-0.5] (0.5,1] (-0.5,0.5] (1,2]  (0.5,1] (-0.5,0.5] 
[7] (-0.5,0.5] (1,2]  (1,2]  [-2,-1] 
Levels: [-2,-1] (-1,-0.5] (-0.5,0.5] (0.5,1] (1,2] 

# assign the colors to the network 
V(g)$color=col[colc] 
plot(g) 

注意keysselect來自AnnotationDbi包處理中org.Hs.eg.db註釋(這是一個依賴),但在其他方面是沒有必要的。這裏僅用於例子的緣故。

+0

潛在*最優*解決方案是將連續數據映射到某個梯度比例。 – ddiez 2014-10-03 13:47:13