----------------------------------------------------------------------------------------------
# 匯入檔案
data_dir <- '/Users/irischang/Downloads/acidic_FPH'
SampleList <- list("C1_up_1", "C1_up_2", "C1_up_3", "C2_up_1", "C2_up_2", "C2_up_3")
for (i in SampleList){
a <- paste0(i, ".csv")
P.i <- file.path(data_dir, a)
nam <- paste0(i)
assign(nam, read.csv(P.i, header = TRUE))
}
# 建立功能性分析 function
doGO <- function(x){
x <- data.frame(x)
r <- regexpr("AT[0-9]+G[0-9]+", x$AGI) # 把 AGI 小數點後編號移除
x$AGI[which(r != -1)] <- regmatches(x$AGI, r)
x.df <- bitr(x$AGI, fromType = "TAIR", # 把 AGI 編號轉換為 ENTREZID
toType = "ENTREZID",
OrgDb = org.At.tair.db)
xgo <- enrichGO(gene = x.df$ENTREZID, # 進行功能性分析
OrgDb = org.At.tair.db,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 1.0,
readable = FALSE)
if (length(xgo) == 1) { # 如果無顯著結果則回傳 NULL
return(NULL)
}else{
d <- godata('org.At.tair.db', ont="BP") # 針對結果畫圖
xgo2 <- pairwise_termsim(xgo, method = "Wang",semData = d)
x_plot2 <- emapplot(xgo2, showCategory = 20)
return(x_plot2)
}
}
# 針對 SampleList 裡的基因列表執行功能
lapply(SampleList, doGO)
----------------------------------------------------------------------------------------------
獲得下面的結果
----------------------------------------------------------------------------------------------
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘pairwise_termsim’ for signature ‘"NULL"’
----------------------------------------------------------------------------------------------
感覺應該是在把 AGI 小數點後編號移除的步驟執行有問題,因為如果不把功能性分析流程寫成 function,直接用同樣的流程分析單一基因列表則可以正常獲得結果圖。
已經嘗試過把 function 裡指定 column 的符號 $ 改成 [[ ]],但仍然無法順利執行。
有人知道該如何修改嗎,感覺可能是 function() 裡指定 column 的部分沒寫好,但不確定是哪裡出錯了。