我不會做很多復雜的功能,通常會堅持使用非常基本的功能。我有一個問題,如何創建一個函式來獲取資料集并根據所需的規范化方法進??行規范化并對輸出進行箱線圖繪制?目前 norm_method 在 norm 方法之間是不同的,想知道是否有辦法在函式開始時呼叫它來拉出正確的方法?下面是我創建的代碼,但我卡住了如何繼續。
library(reshape2) # for melt
library(cowplot)
demoData;
# target_deoData will need to be changed at some point
TestFunc <- function(demoData) {
# Q3 norm (75th percentile)
target_demoData <- normalize(demoData ,
norm_method = "quant",
desiredQuantile = .75,
toElt = "q_norm")
# Background normalization without spike
target_demoData <- normalize(demoData ,
norm_method = "neg",
fromElt = "exprs",
toElt = "neg_norm")
boxplot(assayDataElement(demoData[,1:10], elt = "q_norm"),
col = "red", main = "Q3",
log = "y", names = 1:10, xlab = "Segment",
ylab = "Counts, Q3 Normalized")
boxplot(assayDataElement(demoData[,1:10], elt = "neg_norm"),
col = "blue", main = "Neg",
log = "y", names = 1:10, xlab = "Segment",
ylab = "Counts, Neg. Normalized")
}
uj5u.com熱心網友回復:
您可能需要考慮設計您的normalize()
和assayDataElement()
函式來...
提供更多的靈活性。
取而代之的是,鑒于上面的示例,您可以制作一個簡單的配置串列,并將該配置的元素傳遞給您的normalize()
和assayDataElement()
函式,如下所示:
TestFunc <- function(demoData, method=c("quant", "neg")) {
method = match.arg(method)
method_config = list(
"quant" = list("norm_args" = list("norm_method" = "quant", desired_quantile = 0.75, "toElt" = "q_norm"),
"plot_args" = list("col"="red", main="Q3", ylab = "Counts, Q3 Normalized")),
"neg" = list("norm_args" = list("fromElt" = "exprs", "toElt" = "neg_norm"),
"plot_args" = list("col"="blue", main="Neg", ylab = "Counts, Neg Normalized"))
)
mcn = method_config[[method]][["norm_args"]]
mcp = method_config[[method]][["plot_args"]]
# normalize the data
target_demoData = do.call(normalize, c(list(data = demoData[1:10]), mcn))
# get the plot
boxplot(assayDataElement(
demoData[1:10], elt=mcp[["toElt"]],col = mcp[["col"],main = mcp[["main"]],
log = "y", names = 1:10, xlab = "Segment",ylab = mcp[["ylab"]]
)
}
同樣,使用這種方法不如...
(并考慮拆分為兩個函式......一個回傳標準化資料,另一個函式生成繪圖......
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/506857.html
上一篇:函式的NaN結果
下一篇:串列不會自動更新撰寫