Martin Morgan 的回答抓住了解决方案的精髓,但是 有几个 gotchya 让新 R 用户非常困惑。这些 gotchya 源于 R 使用的独特的面向对象形式,这对于那些来自 C/C++ 或 Python 背景的人来说是难以置信的困惑。
使用我自己的数据集遵循 DESeq2 vignette:
$ cat synth.dat
sample g0 g1 g2 g3 g4 g5 g6 g7 g8 g9
samp0 132 192 19 133 247 297 110 104 93 103
samp1 173 152 23 139 245 307 83 77 76 123
samp2 179 129 18 130 208 244 89 138 71 142
samp3 178 145 22 157 323 277 79 93 102 97
samp4 250 208 8 101 202 257 142 140 76 113
samp5 221 157 12 79 261 341 140 94 56 123
samp6 139 220 15 125 282 261 124 154 117 118
samp7 213 121 16 115 377 322 117 154 57 81
samp8 234 152 11 103 281 321 76 160 71 139
samp9 254 120 13 134 323 207 122 122 82 91
samp10 159 207 17 143 385 217 126 113 106 89
samp11 214 136 14 90 364 365 149 102 93 111
samp12 180 159 15 136 226 309 72 111 69 113
samp13 151 137 17 122 229 297 131 108 112 70
samp14 254 151 8 118 254 222 138 114 66 89
samp15 275 121 13 105 238 408 122 156 57 72
samp16 204 134 8 111 352 332 89 134 73 90
samp17 265 144 11 144 211 281 134 98 71 114
samp18 212 111 14 138 321 391 84 112 88 96
samp19 155 164 12 119 174 380 129 106 66 86
$ cat synth_design_matrix.txt
samp0 group0
samp1 group0
samp2 group0
samp3 group0
samp4 group0
samp5 group0
samp6 group0
samp7 group0
samp8 group0
samp9 group0
samp10 group1
samp11 group1
samp12 group1
samp13 group1
samp14 group1
samp15 group1
samp16 group1
samp17 group1
samp18 group1
samp19 group1
> library("DESeq2")
> dat <- read.table(file="synth.dat", header=TRUE, stringsAsFactors=FALSE, row.names=1)
> groups <- read.table(file="synth_design_matrix.txt", header=FALSE, stringsAsFactors=TRUE, row.names=1)
> colnames(groups) <- c("condition")
> datM <- t(as.matrix(dat))
> dds <- DESeqDataSetFromMatrix(countData = datM, colData = groups, design = ~condition)
> dds$condition <-relevel(dds$condition, ref="group0")
> vsd <- vst(dds, blind=FALSE, nsub=10)
-- note: fitType='parametric', but the dispersion trend was not well captured by the
function: y = a/x + b, and a local regression fit was automatically substituted.
specify fitType='local' or 'mean' to avoid this message next time.
现在指定跟踪点并逐步执行。
> trace(what="plotPCA", tracer=browser, at=1, signature=c("DESeqTransform"))
[1] "plotPCA"
> plotPCA(vsd)
Tracing function ".local" in package "DESeq2"
Tracing .local(object, ...) step 1
Called from: eval(expr, p)
Browse[1]> n
debug: `{`
Browse[2]> n
debug at /tmp/RtmpaiGvIe/R.INSTALL5ef336529904/DESeq2/R/plots.R#184: rv <- rowVars(assay(object))
Browse[2]> n
debug at /tmp/RtmpaiGvIe/R.INSTALL5ef336529904/DESeq2/R/plots.R#187: select <- order(rv, decreasing = TRUE)[seq_len(min(ntop, length(rv)))]
Browse[2]> n
debug at /tmp/RtmpaiGvIe/R.INSTALL5ef336529904/DESeq2/R/plots.R#190: pca <- prcomp(t(assay(object)[select, ]))
Browse[2]> c
现在是gotchya的:
您只能在包中导出的函数/类上直接设置跟踪点。它们将包含#' @export。请参阅 Hillary Parker 的blog 了解简明详情。在此示例中,我们最终单步执行 plotPCA 方法并进入在 DESeq2 命名空间中不可见的 plotPCA.DESeqTransform 函数。
如果方法的签名有多个参数,则需要用 R 的c() 指定。
例如如果方法原型是:
setMethod("spin", signature(object="star", value="numeric"), function(object, value){some stuff here})
跟踪点是
trace(what="spin", tracer=browser, at=1, signature=c(object="star", value="numeric"))
注意替换方法。如果您不理解它们,那么在调试像 DESeq2(有多个)这样的包时可能会非常混乱。请参阅here 和here 了解更多详情。
熟悉S4 和S3 方法以及R 的object orientation。这将更容易理解包中发生的事情。
使用这些工具,您应该能够调试任何下载的 R 包 CRAN 或 Bioconductor 没有任何特殊的安装说明。