Browse code

bioconductor revision

mpirkl authored on 17/11/2020 11:13:51
Showing 23 changed files

... ...
@@ -2,15 +2,23 @@ Package: bnem
2 2
 Type: Package
3 3
 Title: Training of logical models from indirect measurements of perturbation
4 4
     experiments
5
-Version: 0.99.1
6
-Authors@R: person("Martin", "Pirkl", email = "martinpirkl@yahoo.de",role = c("aut", "cre"))
5
+Version: 0.99.3
6
+Authors@R: person("Martin", "Pirkl",
7
+    email = "martinpirkl@yahoo.de",
8
+    role = c("aut", "cre"))
7 9
 Description: bnem combines the use of indirect measurements of Nested Effects
8
-    Models (package mnem) with the Boolean networks of CellNOptR. Perturbation experiments of signalling nodes in cells are analysed for their effect on the global gene expression profile. Those profiles give evidence for the Boolean regulation of down-stream nodes in the network, e.g., whether two parents activate their child independently (OR-gate) or jointly (AND-gate).
10
+    Models (package mnem) with the Boolean networks of CellNOptR. Perturbation
11
+    experiments of signalling nodes in cells are analysed for their effect 
12
+    on the global gene expression profile. Those profiles give evidence 
13
+    for the Boolean regulation of down-stream nodes in the network, 
14
+    e.g., whether two parents activate their child independently 
15
+    (OR-gate) or jointly (AND-gate).
9 16
 Depends:
10 17
     R (>= 4.0)
11 18
 License: GPL-3
12 19
 Encoding: UTF-8
13
-biocViews: Pathways, SystemsBiology, NetworkInference, Network, GeneExpression, GeneRegulation, Preprocessing
20
+biocViews: Pathways, SystemsBiology, NetworkInference, Network, 
21
+    GeneExpression, GeneRegulation, Preprocessing
14 22
 Imports:
15 23
     CellNOptR,
16 24
     matrixStats,
... ...
@@ -36,4 +44,6 @@ VignetteBuilder: knitr
36 44
 Suggests:
37 45
     knitr, 
38 46
     BiocGenerics
47
+BugReports: https://github.com/MartinFXP/bnem/issues
48
+URL: https://github.com/MartinFXP/bnem/
39 49
 RoxygenNote: 7.1.1
... ...
@@ -1,10 +1,11 @@
1 1
 # Generated by roxygen2: do not edit by hand
2 2
 
3 3
 S3method(plot,bnem)
4
-S3method(plot,bnembs)
4
+S3method(plot,bnemBs)
5 5
 S3method(plot,bnemsim)
6 6
 export(absorption)
7 7
 export(absorptionII)
8
+export(addNoise)
8 9
 export(bnem)
9 10
 export(bnemBs)
10 11
 export(computeFc)
... ...
@@ -51,10 +52,11 @@ importFrom(limma,contrasts.fit)
51 52
 importFrom(limma,eBayes)
52 53
 importFrom(limma,lmFit)
53 54
 importFrom(limma,makeContrasts)
55
+importFrom(matrixStats,rowMaxs)
54 56
 importFrom(matrixStats,rowMins)
55 57
 importFrom(mnem,plotDnf)
56 58
 importFrom(sva,ComBat)
57 59
 importFrom(utils,combn)
58
-importFrom(utils,flush.console)
60
+importFrom(utils,glob2rx)
59 61
 importFrom(utils,write.table)
60 62
 importFrom(vsn,justvsn)
... ...
@@ -1,77 +1,76 @@
1 1
 #' @noRd
2 2
 preprocessInput <- function(stimuli=NULL, inhibitors=NULL, signals=NULL,
3
-                            design = NULL, exprs=NULL, fc=NULL, pkn,
3
+                            design = NULL, expression=NULL, fc=NULL, pkn,
4 4
                             maxInputsPerGate=100) {
5
-
5
+    
6 6
     if (is.null(design)) {
7
-
7
+        
8 8
         stimcols <- stimcols2 <- matrix(0, length(stimuli), ncol(fc))
9
-
9
+        
10 10
         for (i in seq_len(length(stimuli))) {
11
-
11
+            
12 12
             tmp <- numeric(ncol(fc))
13
-
13
+            
14 14
             tmp[grep(stimuli[i], gsub("_vs_.*", "", colnames(fc)))] <- 1
15
-
15
+            
16 16
             stimcols[i, ] <- tmp
17
-
17
+            
18 18
             tmp <- numeric(ncol(fc))
19
-
19
+            
20 20
             tmp[grep(stimuli[i], gsub(".*_vs_", "", colnames(fc)))] <- 1
21
-
21
+            
22 22
             stimcols2[i, ] <- tmp
23
-
23
+            
24 24
         }
25
-
26
-        maxStim <- max(c(apply(stimcols, 2, sum), apply(stimcols2, 2, sum)))
27
-
25
+        
26
+        maxStim <- max(c(colSums(stimcols), colSums(stimcols2)))
27
+        
28 28
         inhibitcols <- inhibitcols2 <- matrix(0, length(inhibitors), ncol(fc))
29
-
29
+        
30 30
         for (i in seq_len(length(inhibitors))) {
31
-
31
+            
32 32
             tmp <- numeric(ncol(fc))
33
-
33
+            
34 34
             tmp[grep(inhibitors[i], gsub("_vs_.*", "", colnames(fc)))] <- 1
35
-
35
+            
36 36
             inhibitcols[i, ] <- tmp
37
-
37
+            
38 38
             tmp <- numeric(ncol(fc))
39
-
39
+            
40 40
             tmp[grep(inhibitors[i], gsub(".*_vs_", "", colnames(fc)))] <- 1
41
-
41
+            
42 42
             inhibitcols2[i, ] <- tmp
43
-
43
+            
44 44
         }
45
-
46
-        maxInhibit <- max(c(apply(inhibitcols, 2, sum), apply(inhibitcols2, 2,
47
-                                                              sum)))
48
-
45
+        
46
+        maxInhibit <- max(c(colSums(inhibitcols), colSums(inhibitcols2)))
47
+        
49 48
         if (is.null(signals)) { signals <- unique(c(stimuli, inhibitors)) }
50
-
49
+        
51 50
         CNOlist <- dummyCNOlist(stimuli=stimuli, inhibitors=inhibitors,
52 51
                                 maxStim=maxStim, maxInhibit=maxInhibit,
53 52
                                 signals=signals)
54
-
53
+        
55 54
         model <- preprocessing(CNOlist, pkn, maxInputsPerGate=maxInputsPerGate)
56
-
55
+        
57 56
     }
58
-
57
+    
59 58
     NEMlist <- list()
60
-
59
+    
61 60
     NEMlist$fc <- fc
62
-
63
-    if (is.null(exprs)) {
64
-        NEMlist$exprs <- matrix(rnorm(nrow(CNOlist@cues)*10), 10,
65
-                                nrow(CNOlist@cues))
61
+    
62
+    if (is.null(expression)) {
63
+        NEMlist$expression <- matrix(rnorm(nrow(getCues(CNOlist))*10), 10,
64
+                                nrow(getCues(CNOlist)))
66 65
     } else {
67
-        NEMlist$exprs <- exprs
66
+        NEMlist$expression <- expression
68 67
     }
69
-
68
+    
70 69
     return(list(CNOlist=CNOlist, model=model, NEMlist=NEMlist))
71
-
70
+    
72 71
 }
73 72
 #' @importFrom graphics abline axis legend mtext par screen split.screen
74
-#' @importFrom utils combn flush.console write.table
73
+#' @importFrom utils combn write.table
75 74
 #' @noRd
76 75
 addEdge <-
77 76
     function(edges, CNOlist, model, n = 100, full = FALSE) {
... ...
@@ -86,14 +85,14 @@ addEdge <-
86 85
                                                 tmp2[2]))
87 86
             }
88 87
         }
89
-        write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
88
+        temp.file <- tempfile(pattern="interaction",fileext=".sif")
89
+        write.table(sifMatrix, file = temp.file, sep = "\t", row.names = FALSE,
90 90
                     col.names = FALSE, quote = FALSE)
91
-        PKN2 <- readSIF("temp.sif")
92
-        unlink("temp.sif")
91
+        PKN2 <- readSIF(temp.file)
93 92
         model2 <- preprocessing(CNOlist, PKN2, maxInputsPerGate=n)
94 93
         if (!full) {
95
-            index <- which(!(model2$reacID %in% model$reacID) &
96
-                           !(model2$reacID %in% edges))
94
+            index <- !(model2$reacID %in% model$reacID) &
95
+                !(model2$reacID %in% edges)
97 96
             model2$reacID <- model2$reacID[-index]
98 97
             model2$interMat[, -index]
99 98
             model2$notMat[, -index]
... ...
@@ -104,37 +103,39 @@ addEdge <-
104 103
 addSignal <-
105 104
     function(s, CNOlist, stim = NULL, inhibit = NULL) {
106 105
         CNOlist2 <- CNOlist
107
-        CNOlist2@signals[[1]] <- cbind(CNOlist2@signals[[1]], s = 0)
108
-        CNOlist2@signals[[2]] <- cbind(CNOlist2@signals[[2]], s = 0)
109
-        colnames(CNOlist2@signals[[1]]) <- c(colnames(CNOlist@signals[[1]]), s)
110
-        colnames(CNOlist2@signals[[2]]) <- c(colnames(CNOlist@signals[[2]]), s)
106
+        CNOlist2@signals[[1]] <- cbind(getSignals(CNOlist2)[[1]], s = 0)
107
+        CNOlist2@signals[[2]] <- cbind(getSignals(CNOlist2)[[2]], s = 0)
108
+        colnames(CNOlist2$signals[[1]]) <-
109
+            c(colnames(getSignals(CNOlist)[[1]]), s)
110
+        colnames(CNOlist2$signals[[2]]) <-
111
+            c(colnames(getSignals(CNOlist)[[2]]), s)
111 112
         if (!is.null(inhibit)) {
112
-            CNOlist2@cues <- cbind(CNOlist2@cues, 0)
113
-            CNOlist2@cues <- rbind(CNOlist2@cues,
113
+            CNOlist2@cues <- cbind(getCues(CNOlist2), 0)
114
+            CNOlist2@cues <- rbind(getCues(CNOlist2),
114 115
                                    matrix(0, nrow =nrow(inhibit),
115
-                                          ncol = ncol(CNOlist2@cues)))
116
-            CNOlist2@cues[(nrow(CNOlist2@cues) -
117
-                           nrow(inhibit) + 1):nrow(CNOlist2@cues),
118
-                          which(colnames(CNOlist2@cues) %in%
119
-                                colnames(inhibit))] <- inhibit
120
-            CNOlist2@cues[(nrow(CNOlist2@cues) -
121
-                           nrow(inhibit) + 1):nrow(CNOlist2@cues),
122
-                          ncol(CNOlist2@cues)] <- 1
123
-            colnames(CNOlist2@cues)[ncol(CNOlist2@cues)] <- s
116
+                                          ncol = ncol(getCues(CNOlist2))))
117
+            CNOlist2@cues[(nrow(getCues(CNOlist2)) -
118
+                               nrow(inhibit) + 1):nrow(getCues(CNOlist2)),
119
+                          colnames(getCues(CNOlist2)) %in%
120
+                              colnames(inhibit)] <- inhibit
121
+            CNOlist2@cues[(nrow(getCues(CNOlist2)) -
122
+                               nrow(inhibit) + 1):nrow(getCues(CNOlist2)),
123
+                          ncol(getCues(CNOlist2))] <- 1
124
+            colnames(CNOlist2@cues)[ncol(getCues(CNOlist2))] <- s
124 125
             CNOlist2@stimuli <-
125
-                CNOlist2@cues[, which(colnames(CNOlist2@cues) %in%
126
-                                      colnames(CNOlist2@stimuli))]
126
+                getCues(CNOlist2)[, colnames(getCues(CNOlist2)) %in%
127
+                                      colnames(getStimuli(CNOlist2))]
127 128
             CNOlist2@inhibitors <-
128
-                CNOlist2@cues[, which(colnames(CNOlist2@cues) %in%
129
-                                      c(colnames(CNOlist2@inhibitors), s))]
129
+                getCues(CNOlist2)[, colnames(getCues(CNOlist2)) %in%
130
+                                      c(colnames(getInhibitors(CNOlist2)), s)]
130 131
             CNOlist2@signals[[1]] <-
131
-                rbind(CNOlist2@signals[[1]],
132
+                rbind(getSignals(CNOlist2)[[1]],
132 133
                       matrix(0, nrow = nrow(inhibit),
133
-                             ncol = ncol(CNOlist2@signals[[1]])))
134
+                             ncol = ncol(getSignals(CNOlist2)[[1]])))
134 135
             CNOlist2@signals[[2]] <-
135
-                rbind(CNOlist2@signals[[2]],
136
+                rbind(getSignals(CNOlist2)[[2]],
136 137
                       matrix(0, nrow = nrow(inhibit),
137
-                             ncol = ncol(CNOlist2@signals[[2]])))
138
+                             ncol = ncol(getSignals(CNOlist2)[[2]])))
138 139
         }
139 140
         CNOlist2 <- checkCNOlist(CNOlist2)
140 141
         return(CNOlist2)
... ...
@@ -142,27 +143,19 @@ addSignal <-
142 143
 #' @noRd
143 144
 adj2dnf <-
144 145
     function(A) {
145
-
146 146
         dnf <- NULL
147
-
148
-        for (i in seq_len(ncol(A))) {
149
-            for (j in seq_len(nrow(A))) {
150
-                if (i %in% j) { next() }
151
-                if (A[i, j] == 1) {
152
-                    dnf <- c(dnf, paste(colnames(A)[i], rownames(A)[j],
153
-                                        sep = "="))
154
-                }
155
-                if (A[i, j] == -1) {
156
-                    dnf <- c(dnf, paste("!", colnames(A)[i], "=",
157
-                                        rownames(A)[j], sep = ""))
158
-                }
147
+        edges <- which(A!=0,arr.ind=TRUE)
148
+        for (i in seq_len(nrow(edges))) {
149
+            if (A[edges[i,1],edges[i,2]]>0) {
150
+                dnf <- c(dnf, paste(colnames(A)[edges[i,1]],
151
+                                    rownames(A)[edges[i,2]], sep = "="))
152
+            } else {
153
+                dnf <- c(dnf, paste0("!",colnames(A)[edges[i,1]],"=",
154
+                                     rownames(A)[edges[i,2]]))
159 155
             }
160 156
         }
161
-
162 157
         dnf <- unique(dnf)
163
-
164 158
         return(dnf)
165
-
166 159
     }
167 160
 #' @noRd
168 161
 adj2graph <-
... ...
@@ -178,31 +171,35 @@ adj2graph <-
178 171
         return(gR)
179 172
     }
180 173
 #' @noRd
174
+#' @import CellNOptR
181 175
 checkCNOlist <-
182 176
     function(CNOlist) {
183
-        if (dim(CNOlist@stimuli)[2] > 1) {
184
-            CNOlist@stimuli <- CNOlist@stimuli[,
185
-                                               order(colnames(CNOlist@stimuli))]
177
+        if (ncol(getStimuli(CNOlist)) > 1) {
178
+            CNOlist@stimuli <- getStimuli(CNOlist)[,
179
+                                                   order(colnames(
180
+                                                       getStimuli(CNOlist)))]
186 181
         }
187
-        if (dim(CNOlist@inhibitors)[2] > 1) {
182
+        if (ncol(getInhibitors(CNOlist)) > 1) {
188 183
             CNOlist@inhibitors <-
189
-                CNOlist@inhibitors[, order(colnames(CNOlist@inhibitors))]
184
+                getInhibitors(CNOlist)[, order(colnames(
185
+                    getInhibitors(CNOlist)))]
190 186
         }
191
-        CNOlist@cues <- cbind(CNOlist@stimuli, CNOlist@inhibitors)
192
-        if (ncol(CNOlist@signals[[1]]) > 1) {
193
-            for (i in seq_len(length(CNOlist@signals))) {
187
+        CNOlist@cues <- cbind(getStimuli(CNOlist), getInhibitors(CNOlist))
188
+        if (ncol(getSignals(CNOlist)[[1]]) > 1) {
189
+            for (i in seq_len(length(getSignals(CNOlist)))) {
194 190
                 CNOlist@signals[[i]] <-
195
-                    CNOlist@signals[[i]][,
196
-                                         order(colnames(CNOlist@signals[[i]]))]
191
+                    getSignals(CNOlist)[[i]][,
192
+                                             order(colnames(
193
+                                                 getSignals(CNOlist)[[i]]))]
197 194
             }
198 195
         }
199 196
         rownames(CNOlist@cues) <- rownames(CNOlist@stimuli) <-
200 197
             rownames(CNOlist@inhibitors) <-
201
-            unlist(lapply(rownames(CNOlist@cues), function(x) {
198
+            unlist(lapply(rownames(getCues(CNOlist)), function(x) {
202 199
                 y <- unlist(strsplit(x, "_"))
203
-                y <- paste(c(sort(y[which(y %in% colnames(CNOlist@stimuli))]),
204
-                             sort(y[which(!(y %in%
205
-                                            colnames(CNOlist@stimuli)))])),
200
+                y <- paste(c(sort(y[y %in% colnames(getStimuli(CNOlist))]),
201
+                             sort(y[!(y %in%
202
+                                          colnames(getStimuli(CNOlist)))])),
206 203
                            collapse = "_")
207 204
                 return(y)
208 205
             }))
... ...
@@ -222,11 +219,10 @@ checkMethod <-
222 219
         if (!(any(c("llr", "cosine", "euclidean", "maximum", "manhattan",
223 220
                     "canberra", "binary", "minkowski", "spearman", "pearson",
224 221
                     "kendall", "mLL", "cp", "none") %in% method))) {
225
-            stop(paste0("I'm sorry, Dave. I'm afraid I can't do that. ",
226
-                        "You have to pick a valid method: ",
227
-                        "llr, cosine, euclidean, maximum, manhattan, ",
228
-                        "canberra, binary, ",
229
-                        "minkowski, spearman, pearson, kendall"))
222
+            stop("You have to pick a valid method: ",
223
+                 "llr, cosine, euclidean, maximum, manhattan, ",
224
+                 "canberra, binary, ",
225
+                 "minkowski, spearman, pearson, kendall")
230 226
             ## , mLL, cp, none"))
231 227
         }
232 228
         return(method)
... ...
@@ -234,66 +230,58 @@ checkMethod <-
234 230
 #' @noRd
235 231
 #' @importFrom matrixStats rowMins
236 232
 checkNEMlist <-
237
-    function(NEMlist, CNOlist, parameters, approach, method) {
233
+    function(NEMlist, CNOlist, parameters, approach, method,verbose=FALSE) {
238 234
         NEMlistTmp <- NEMlist
239 235
         if("abs" %in% approach) {
240
-            if (length(table(NEMlist$exprs)) == 2) {
241
-                NEMlist$norm <- NEMlist$exprs
242
-                NEMlist$norm[
243
-                            which(NEMlist$norm
244
-                                  ==
245
-                                  as.numeric(names(
246
-                                      table(NEMlist$exprs))[1]))] <-
247
-                    0
248
-                NEMlist$norm[
249
-                            which(NEMlist$norm
250
-                                  ==
251
-                                  as.numeric(
252
-                                      names(table(NEMlist$exprs))[2]))] <-
253
-                    1
236
+            if (length(table(NEMlist$expression)) == 2) {
237
+                NEMlist$norm <- NEMlist$expression
238
+                NEMlist$norm[NEMlist$norm==as.numeric(names(
239
+                    table(NEMlist$expression))[1])] <- 0
240
+                NEMlist$norm[NEMlist$norm==as.numeric(
241
+                    names(table(NEMlist$expression))[2])] <- 1
254 242
             }
255 243
             if (length(NEMlist$norm) == 0 &
256 244
                 !any(c("pearson", "spearman", "kendall") %in% method)) {
257 245
                 if ("pam" %in% approach) {
258
-                    print("data is not discretized/normed to (0,1);
246
+                    warning("data is not discretized/normalized to (0,1);
259 247
 performing two cluster pam normalization")
260
-                    NEMlist$norm <- pamNorm(NEMlist$exprs)
248
+                    NEMlist$norm <- pamNorm(NEMlist$expression)
261 249
                 } else {
262
-                    print("data is not discretized/normed to (0,1);
250
+                    warning("data is not discretized/normalized to (0,1);
263 251
 performing simple normalization")
264
-                    NEMlist$norm <- simpleNorm(NEMlist$exprs)
252
+                    NEMlist$norm <- simpleNorm(NEMlist$expression)
265 253
                 }
266 254
                 if ("kmeans" %in% approach) {
267
-                    print("data is not discretized/normed to (0,1);
255
+                    warning("data is not discretized/normalized to (0,1);
268 256
 performing two means normalization")
269
-                    NEMlist$norm <- pamNorm(NEMlist$exprs)
257
+                    NEMlist$norm <- pamNorm(NEMlist$expression)
270 258
                 } else {
271
-                    print("data is not discretized/normed to (0,1);
259
+                    warning("data is not discretized/normed to (0,1);
272 260
 performing simple normalization")
273
-                    NEMlist$norm <- simpleNorm(NEMlist$exprs)
261
+                    NEMlist$norm <- simpleNorm(NEMlist$expression)
274 262
                 }
275 263
             }
276 264
             if ("spearman" %in% method) {
277
-                colnames.exprs <- colnames(NEMlist$exprs)
278
-                rownames.exprs <- rownames(NEMlist$exprs)
279
-                NEMlist$exprs <- t(apply(NEMlist$exprs, 1, rank))
280
-                colnames(NEMlist$exprs) <- colnames.exprs
281
-                rownames(NEMlist$exprs) <- rownames.exprs
265
+                colnames.expression <- colnames(NEMlist$expression)
266
+                rownames.expression <- rownames(NEMlist$expression)
267
+                NEMlist$expression <- t(apply(NEMlist$expression, 1, rank))
268
+                colnames(NEMlist$expression) <- colnames.expression
269
+                rownames(NEMlist$expression) <- rownames.expression
282 270
             }
283 271
             if ("cosine" %in% method) {
284
-                colnames.exprs <- colnames(NEMlist$exprs)
285
-                rownames.exprs <- rownames(NEMlist$exprs)
272
+                colnames.expression <- colnames(NEMlist$expression)
273
+                rownames.expression <- rownames(NEMlist$expression)
286 274
                 vprod <- function(x) { return(x%*%x) }
287
-                NEMlist$exprs <-
288
-                    NEMlist$exprs/(apply(NEMlist$exprs, 1, vprod)^0.5)
289
-                colnames(NEMlist$exprs) <- colnames.exprs
290
-                rownames(NEMlist$exprs) <- rownames.exprs
275
+                NEMlist$expression <-
276
+                    NEMlist$expression/(apply(NEMlist$expression, 1, vprod)^0.5)
277
+                colnames(NEMlist$expression) <- colnames.expression
278
+                rownames(NEMlist$expression) <- rownames.expression
291 279
             }
292 280
         }
293 281
         if ("fc" %in% approach) {
294 282
             if (length(NEMlist$fc) == 0)  {
295
-                print("foldchanges missing; automatic calculation")
296
-                NEMlist$fc <- computeFc(CNOlist, NEMlist$exprs)
283
+                warning("foldchanges missing; automatic calculation")
284
+                NEMlist$fc <- computeFc(CNOlist, NEMlist$expression)
297 285
                 egenes <- NEMlist$egenes
298 286
                 if (parameters$cutOffs[2] != 0) {
299 287
                     NEMlist <- computeSm(CNOlist, NEMlist, parameters,
... ...
@@ -329,22 +317,22 @@ performing simple normalization")
329 317
         }
330 318
         if (!is.null(NEMlist$egenes) & is.null(NEMlist$geneGrid)) {
331 319
             sgeneAdd <- matrix(Inf, nrow = nrow(NEMlist$fc),
332
-                               ncol = (ncol(CNOlist@signals[[1]])*2))
320
+                               ncol = (ncol(getSignals(CNOlist)[[1]])*2))
333 321
             for (i in seq_len(nrow(NEMlist$fc))) {
334 322
                 egeneName <- rownames(NEMlist$fc)[i]
335 323
                 sgeneCols <- numeric()
336 324
                 for (j in seq_len(length(NEMlist$egenes))) {
337 325
                     if (egeneName %in% NEMlist$egenes[[j]]) {
338
-                        colTmp <- which(colnames(CNOlist@signals[[1]]) ==
339
-                                        names(NEMlist$egenes)[j])
326
+                        colTmp <- which(colnames(getSignals(CNOlist)[[1]]) ==
327
+                                            names(NEMlist$egenes)[j])
340 328
                         sgeneCols <- c(sgeneCols, colTmp,
341
-                        (colTmp+ncol(CNOlist@signals[[1]])))
329
+                                       (colTmp+ncol(getSignals(CNOlist)[[1]])))
342 330
                     }
343 331
                 }
344 332
                 sgeneAdd[i, sgeneCols] <- 0
345 333
             }
346 334
             sgeneAddCheck <- rowMins(sgeneAdd)
347
-            sgeneAdd[which(sgeneAddCheck == Inf), ] <- 0
335
+            sgeneAdd[sgeneAddCheck == Inf, ] <- 0
348 336
             NEMlist$geneGrid <- sgeneAdd
349 337
         }
350 338
         if (!is.null(NEMlistTmp$weights)) {
... ...
@@ -359,10 +347,6 @@ computeFcII <-
359 347
         design <- makeDesign(y, stimuli, inhibitors, c(batches, runs))
360 348
         CompMat <- numeric()
361 349
         CompMatNames <- character()
362
-        ctrlsSum <- apply(design[, -grep(paste(c(runs, batches),
363
-                                               collapse = "|"),
364
-                                         colnames(design))], 1, sum)
365
-        ctrlsSum <- which(ctrlsSum == 0)
366 350
         stimuliDesign <- design[, grep(paste(stimuli, collapse = "|"),
367 351
                                        colnames(design))]
368 352
         inhibitorsDesign <- design[, grep(paste(inhibitors, collapse = "|"),
... ...
@@ -386,9 +370,9 @@ computeFcII <-
386 370
                 stimuliSum <- design[, grep(paste(stimuli, collapse = "|"),
387 371
                                             colnames(design))]
388 372
             } else {
389
-                stimuliSum <- apply(design[, grep(paste(stimuli,
390
-                                                        collapse = "|"),
391
-                                                  colnames(design))], 1, sum)
373
+                stimuliSum <- rowSums(design[, grep(paste(stimuli,
374
+                                                          collapse = "|"),
375
+                                                    colnames(design))])
392 376
             }
393 377
         }
394 378
         if (is.null(inhibitors) == TRUE) {
... ...
@@ -400,13 +384,13 @@ computeFcII <-
400 384
                                                colnames(design))]
401 385
             } else {
402 386
                 inhibitorsSum <-
403
-                    apply(design[, grep(paste(inhibitors, collapse = "|"),
404
-                                        colnames(design))], 1, sum)
387
+                    rowSums(design[, grep(paste(inhibitors, collapse = "|"),
388
+                                          colnames(design))])
405 389
             }
406 390
         }
407 391
         cuesSum <-
408
-            apply(design[, grep(paste(c(stimuli, inhibitors), collapse = "|"),
409
-                                colnames(design))], 1, sum)
392
+            rowSums(design[, grep(paste(c(stimuli, inhibitors), collapse = "|"),
393
+                                  colnames(design))])
410 394
         maxStim <- max(stimuliSum)
411 395
         maxKd <- max(inhibitorsSum)
412 396
         for (run in runs) {
... ...
@@ -426,9 +410,9 @@ computeFcII <-
426 410
                                           targetRows)
427 411
                 grepStimsStims <- intersect(intersect(which(stimuliSum >= 2),
428 412
                                                       which(inhibitorsSum ==
429
-                                                            0)),
413
+                                                                0)),
430 414
                                             targetRows)
431
-                                        # get ctrl_vs_stim:
415
+                # get ctrl_vs_stim:
432 416
                 for (i in grepStims) {
433 417
                     if (is.na(grepCtrl)) { next() }
434 418
                     stimNames <-
... ...
@@ -442,7 +426,7 @@ computeFcII <-
442 426
                         CompMat <- cbind(CompMat, (y[, i] - y[, grepCtrl]))
443 427
                     }
444 428
                 }
445
-                                        # get ctrl_vs_kd:
429
+                # get ctrl_vs_kd:
446 430
                 for (i in grepKds) {
447 431
                     if (is.na(grepCtrl)) { next() }
448 432
                     kdNames <-
... ...
@@ -456,7 +440,7 @@ computeFcII <-
456 440
                         CompMat <- cbind(CompMat, (y[, i] - y[, grepCtrl]))
457 441
                     }
458 442
                 }
459
-                                        # get kd_vs_kd_stim:
443
+                # get kd_vs_kd_stim:
460 444
                 for (i in grepKds) {
461 445
                     kdNames <-
462 446
                         paste(sort(names(which(inhibitorsDesign[i, ] >= 1))),
... ...
@@ -481,7 +465,7 @@ computeFcII <-
481 465
                         }
482 466
                     }
483 467
                 }
484
-                                        # get stim_vs_stim_kd:
468
+                # get stim_vs_stim_kd:
485 469
                 for (i in grepStims) {
486 470
                     if (is.na(grepCtrl)) { next() }
487 471
                     stimNames <-
... ...
@@ -517,8 +501,8 @@ computeFcII <-
517 501
                             if (length(unlist(strsplit(stimNames, "_")) %in%
518 502
                                        names(which(stimuliDesign[j, ] >= 1)))
519 503
                                 == length(unlist(strsplit(stimNames, "_"))) &
520
-                                   length(unlist(strsplit(stimNames, "_")) %in%
521
-                                          names(which(stimuliDesign[j, ] >= 1)))
504
+                                length(unlist(strsplit(stimNames, "_")) %in%
505
+                                       names(which(stimuliDesign[j, ] >= 1)))
522 506
                                 < length(names(which(stimuliDesign[j, ] >= 1))))
523 507
                             {
524 508
                                 stim2Names <-
... ...
@@ -556,7 +540,7 @@ computeFcII <-
556 540
                         }
557 541
                     }
558 542
                 }
559
-                                        # get s - sk - (k - ctrl): not trivial
543
+                # get s - sk - (k - ctrl): not trivial
560 544
                 ## for (i in stimuli) {
561 545
                 ##   for (j in inhibitors) {
562 546
                 ##     name <-
... ...
@@ -587,7 +571,7 @@ computeScoreNemT1 <-
587 571
              method = "s",
588 572
              verbose = TRUE,
589 573
              opt = "min"
590
-             ) {
574
+    ) {
591 575
         cutModel2 <- function (model, bString) {
592 576
             if (sum(bString == 1) > 0) {
593 577
                 bs = as.logical(bString)
... ...
@@ -608,7 +592,7 @@ computeScoreNemT1 <-
608 592
             }
609 593
             return(newmodel)
610 594
         }
611
-
595
+        
612 596
         method <- checkMethod(method)
613 597
         ## if (is.null(simList) == TRUE) {
614 598
         ##   simList = prep4sim(model)
... ...
@@ -629,17 +613,17 @@ computeScoreNemT1 <-
629 613
                     simulateStatesRecursive(CNOlist = CNOlist, model = modelCut,
630 614
                                             bString =
631 615
                                                 (numeric(
632
-                                                length(modelCut$reacID)) + 1),
633
-                                            NEMlist)
616
+                                                    length(modelCut$reacID))
617
+                                                 + 1), NEMlist)
634 618
             }
635 619
         }
636 620
         nInTot <- length(unlist(strsplit(model$reacID, "\\+")))
637
-        nTmp <- unlist(strsplit(model$reacID[which(bString == 1)], "\\+"))
621
+        nTmp <- unlist(strsplit(model$reacID[bString == 1], "\\+"))
638 622
         nInputsNeg <- length(grep("!", nTmp))
639 623
         nInputs <- length(nTmp) - nInputsNeg
640 624
         ## nInTot <- 1 # use this for no normalization
641 625
         sizePen <- sum((c(nInputs, nInputsNeg)/nInTot)*sizeFac)
642
-                                        #/nrow(NEMlist$fc)
626
+        #/nrow(NEMlist$fc)
643 627
         suppressWarnings(Score <- getNemFit(simResults = simResults,
644 628
                                             CNOlist = CNOlist, model = modelCut,
645 629
                                             timePoint = timeIndex,
... ...
@@ -651,7 +635,7 @@ computeScoreNemT1 <-
651 635
                                             relFit = relFit, method = method,
652 636
                                             verbose = verbose, opt = opt))
653 637
         if (!is(CNOlist, "CNOlist")) {
654
-            CNOlist = CNOlist(CNOlist)
638
+            CNOlist <- CNOlist(CNOlist)
655 639
         }
656 640
         return(Score)
657 641
     }
... ...
@@ -661,90 +645,90 @@ computeSm <-
661 645
               NEMlist,
662 646
               parameters,
663 647
               method="standard"
664
-              ) {
648
+    ) {
665 649
         CompMatCont <- NEMlist$fc
666 650
         fitScore <- -1 # match of high degree
667 651
         errorScore <- parameters$scoring[3] # mismatch of high degree
668 652
         fitMult <- parameters$scoring[2] # multiplicator for match of low degree
669 653
         errorMult <- parameters$scoring[2] # multi. mismatch of low degree
670 654
         zeroMult <- parameters$scoring[1]
671
-
655
+        
672 656
         CompMat <- CompMatCont
673 657
         Epos <- CompMat
674 658
         Eneg <- CompMat
675 659
         E0 <- CompMat
676 660
         EposI <- CompMat*(-1)
677 661
         EnegI <- CompMat*(-1)
678
-
662
+        
679 663
         beta <- parameters$cutOffs[2]
680 664
         alpha <- parameters$cutOffs[1]
681
-
682
-        wrongPos <- which(Epos < -beta)
683
-        rightPosII <- which(Epos > alpha & Epos < beta)
684
-        rightPosI <- which(Epos >= beta)
685
-        zerosPosI <- which(Epos <= alpha & Epos >= -alpha)
686
-        zerosPosII <- which(Epos < -alpha & Epos > -beta)
687
-
688
-        wrongNeg <- which(Eneg > beta)
689
-        rightNegII <- zerosPosII # which(Eneg < -alpha & Eneg > -beta)
690
-        rightNegI <- which(Eneg <= -beta)
691
-        zerosNegI <- zerosPosI # which(Eneg >= -alpha & Eneg <= alpha)
692
-        zerosNegII <- rightPosII # which(Eneg > alpha & Eneg < beta)
693
-
694
-        right0I <- which(abs(E0) <= alpha)
695
-        right0II <- which(abs(E0) > alpha & abs(E0) < beta)
696
-        wrong0 <- which(abs(E0) >= beta)
697
-
665
+        
666
+        wrongPos <- Epos < -beta
667
+        rightPosII <- Epos > alpha & Epos < beta
668
+        rightPosI <- Epos >= beta
669
+        zerosPosI <- Epos <= alpha & Epos >= -alpha
670
+        zerosPosII <- Epos < -alpha & Epos > -beta
671
+        
672
+        wrongNeg <- Eneg > beta
673
+        rightNegII <- zerosPosII # Eneg < -alpha & Eneg > -beta
674
+        rightNegI <- Eneg <= -beta
675
+        zerosNegI <- zerosPosI # Eneg >= -alpha & Eneg <= alpha
676
+        zerosNegII <- rightPosII # Eneg > alpha & Eneg < beta
677
+        
678
+        right0I <- abs(E0) <= alpha
679
+        right0II <- abs(E0) > alpha & abs(E0) < beta
680
+        wrong0 <- abs(E0) >= beta
681
+        
698 682
         if ("mLL" %in% method | "cp" %in% method) {
699
-
683
+            
700 684
             E0 <- E0*0
701 685
             E0[right0I] <- 1
702
-
686
+            
703 687
             Epos <- Epos*0
704 688
             Epos[rightPosI] <- 1
705
-
689
+            
706 690
             Eneg <- Eneg*0
707 691
             Eneg[rightNegI] <- 1
708
-
692
+            
709 693
             EposI <- EposI*0
710 694
             EposI[rightPosII] <- 1
711
-
695
+            
712 696
             EnegI <- EnegI*0
713 697
             EnegI[rightNegII] <- 1
714
-
698
+            
715 699
         } else {
716
-
700
+            
717 701
             E0[wrong0] <- errorScore*zeroMult
718 702
             E0[right0II] <- fitScore*zeroMult*fitMult
719 703
             E0[right0I] <- fitScore*zeroMult
720
-
704
+            
721 705
             Epos[zerosPosI] <- errorScore*errorMult*zeroMult
722 706
             Epos[zerosPosII] <- errorScore*errorMult
723 707
             Epos[wrongPos] <- errorScore
724 708
             Epos[rightPosI] <- fitScore
725 709
             Epos[rightPosII] <- fitScore*fitMult
726
-
710
+            
727 711
             Eneg[zerosNegI] <- -errorScore*errorMult*zeroMult
728 712
             Eneg[zerosNegII] <- -errorScore*errorMult
729 713
             Eneg[wrongNeg] <- -errorScore
730 714
             Eneg[rightNegI] <- -fitScore
731 715
             Eneg[rightNegII] <- -fitScore*fitMult
732
-
716
+            
733 717
             EposI[zerosNegI] <- errorScore*errorMult*zeroMult
734 718
             EposI[zerosNegII] <- errorScore*errorMult
735 719
             EposI[wrongNeg] <- errorScore
736 720
             EposI[rightNegI] <- fitScore
737 721
             EposI[rightNegII] <- fitScore*fitMult
738
-
722
+            
739 723
             EnegI[zerosPosI] <- -errorScore*errorMult*zeroMult
740 724
             EnegI[zerosPosII] <- -errorScore*errorMult
741 725
             EnegI[wrongPos] <- -errorScore
742 726
             EnegI[rightPosI] <- -fitScore
743 727
             EnegI[rightPosII] <- -fitScore*fitMult
744
-
728
+            
745 729
         }
746
-
747
-        return(list(exprs = NEMlist$exprs, fc = CompMatCont, E0 = E0,
730
+        
731
+        return(list(expression = NEMlist$expression, fc = CompMatCont, E0 = E0,
748 732
                     Epos = Epos, Eneg = Eneg, EposI = EposI, EnegI = EnegI))
749 733
     }
750 734
 #' @noRd
... ...
@@ -754,7 +738,7 @@ deleteEdge <-
754 738
         graph <- model$reacID[-grep("\\+", model$reacID)]
755 739
         for (i in edges) {
756 740
             if (i %in% graph) {
757
-                graph <- graph[-which(graph %in% i)]
741
+                graph <- graph[!graph %in% i]
758 742
             }
759 743
         }
760 744
         for (i in graph) {
... ...
@@ -766,10 +750,10 @@ deleteEdge <-
766 750
                                                 tmp2[2]))
767 751
             }
768 752
         }
769
-        write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
753
+        temp.file <- tempfile(pattern="interaction",fileext=".sif")
754
+        write.table(sifMatrix, file = temp.file, sep = "\t", row.names = FALSE,
770 755
                     col.names = FALSE, quote = FALSE)
771
-        PKN2 <- readSIF("temp.sif")
772
-        unlink("temp.sif")
756
+        PKN2 <- readSIF(temp.file)
773 757
         checkSignals(CNOlist,PKN2)
774 758
         indices<-indexFinder(CNOlist,PKN2,verbose=FALSE)
775 759
         NCNOindices<-findNONC(PKN2,indices,verbose=FALSE)
... ...
@@ -788,48 +772,48 @@ deleteSignal <-
788 772
     function(s, CNOlist) {
789 773
         CNOlist2 <- CNOlist
790 774
         for (i in s) {
791
-            if (i %in% colnames(CNOlist2@signals[[1]])) {
775
+            if (i %in% colnames(getSignals(CNOlist2)[[1]])) {
792 776
                 CNOlist2@signals[[1]] <-
793
-                    CNOlist2@signals[[1]][
794
-                               , -which(colnames(CNOlist2@signals[[1]]) %in% i)]
777
+                    getSignals(CNOlist2)[[1]][
778
+                        , !colnames(getSignals(CNOlist2)[[1]]) %in% i]
795 779
                 CNOlist2@signals[[2]] <-
796
-                    CNOlist2@signals[[2]][
797
-                               , -which(colnames(CNOlist2@signals[[2]]) %in% i)]
780
+                    getSignals(CNOlist2)[[2]][
781
+                        , !colnames(getSignals(CNOlist2)[[2]]) %in% i]
798 782
             }
799
-            if (i %in% colnames(CNOlist2@stimuli)) {
783
+            if (i %in% colnames(getStimuli(CNOlist2))) {
800 784
                 CNOlist2@cues <-
801
-                    CNOlist2@cues[, -which(colnames(CNOlist2@cues) %in% i)]
785
+                    getCues(CNOlist2)[, !colnames(getCues(CNOlist2)) %in% i]
802 786
                 if (!is.null(
803
-                         dim(CNOlist2@stimuli[
804
-                                        , -which(colnames(CNOlist2@stimuli)
805
-                                                 %in% i)]))) {
787
+                    dim(getStimuli(CNOlist2)[
788
+                        , colnames(getStimuli(CNOlist2))
789
+                        %in% i]))) {
806 790
                     CNOlist2@stimuli <-
807
-                        CNOlist2@stimuli[
808
-                                   , -which(colnames(CNOlist2@stimuli) %in% i)]
791
+                        getStimuli(CNOlist2)[
792
+                            , !colnames(getStimuli(CNOlist2)) %in% i]
809 793
                 } else {
810 794
                     CNOlist2@stimuli <-
811
-                        as.matrix(CNOlist2@stimuli[
812
-                                             , -which(colnames(CNOlist2@stimuli)
813
-                                                      %in% i)])
795
+                        as.matrix(getStimuli(CNOlist2)[
796
+                            , !colnames(getStimuli(CNOlist2))
797
+                            %in% i])
814 798
                 }
815 799
             }
816
-            if (i %in% colnames(CNOlist2@inhibitors)) {
800
+            if (i %in% colnames(getInhibitors(CNOlist2))) {
817 801
                 CNOlist2@cues <-
818
-                    CNOlist2@cues[, -which(colnames(CNOlist2@cues) %in% i)]
802
+                    getCues(CNOlist2)[, !colnames(getCues(CNOlist2)) %in% i]
819 803
                 if (!is.null(
820
-                         dim(CNOlist2@inhibitors[
821
-                                        , -which(colnames(CNOlist2@inhibitors)
822
-                                                 %in% i)]))) {
804
+                    dim(getInhibitors(CNOlist2)[
805
+                        , !colnames(getInhibitors(CNOlist2))
806
+                        %in% i]))) {
823 807
                     CNOlist2@inhibitors <-
824
-                        CNOlist2@inhibitors[
825
-                                   , -which(colnames(CNOlist2@inhibitors)
826
-                                            %in% i)]
808
+                        getInhibitors(CNOlist2)[
809
+                            , !colnames(getInhibitors(CNOlist2))
810
+                            %in% i]
827 811
                 } else {
828 812
                     CNOlist2@inhibitors <-
829 813
                         as.matrix(
830
-                            CNOlist2@inhibitors[
831
-                                       , -which(colnames(CNOlist2@inhibitors)
832
-                                                %in% i)])
814
+                            getInhibitors(CNOlist2)[
815
+                                , !colnames(getInhibitors(CNOlist2))
816
+                                %in% i])
833 817
                 }
834 818
             }
835 819
         }
... ...
@@ -839,9 +823,9 @@ deleteSignal <-
839 823
 disc <-
840 824
     function(x, beta = 0.5) { # simple discretization
841 825
         x.disc <- x
842
-        x.disc[which(abs(x.disc) <= beta)] <- 0
843
-        x.disc[which(x.disc > beta)] <- 1
844
-        x.disc[which(x.disc < -beta)] <- -1
826
+        x.disc[abs(x.disc) <= beta] <- 0
827
+        x.disc[x.disc > beta] <- 1
828
+        x.disc[x.disc < -beta] <- -1
845 829
         return(x.disc)
846 830
     }
847 831
 #' @noRd
... ...
@@ -865,11 +849,11 @@ dnf2adj <-
865 849
                 parents <- unlist(strsplit(tmp[1], "\\+"))
866 850
                 for (j in parents) {
867 851
                     if (gsub("!", "", j) %in% j) {
868
-                        adjmat[which(rownames(adjmat) %in% j),
869
-                               which(colnames(adjmat) %in% child)] <- 1
852
+                        adjmat[rownames(adjmat) %in% j,
853
+                               colnames(adjmat) %in% child] <- 1
870 854
                     } else {
871
-                        adjmat[which(rownames(adjmat) %in% gsub("!", "", j)),
872
-                               which(colnames(adjmat) %in% child)] <- -1
855
+                        adjmat[rownames(adjmat) %in% gsub("!", "", j),
856
+                               colnames(adjmat) %in% child] <- -1
873 857
                     }
874 858
                 }
875 859
             }
... ...
@@ -902,18 +886,18 @@ drawLocal <-
902 886
             min.local.edges <- min(local.edges)
903 887
             convert.edges <- seq(min(l$scores[[1]]), max(l$scores[[1]]),
904 888
                                  length.out = max(local.edges -
905
-                                                  min.local.edges))
889
+                                                      min.local.edges))
906 890
             convert.legend <- sort(unique(local.edges))
907 891
         } else {
908 892
             min.local.edges <- min(local.edges)
909 893
             convert.edges <- seq(min(l$scores[[1]]), max(l$scores[[1]]),
910 894
                                  length.out = max(local.edges -
911
-                                                  min.local.edges)+1)
895
+                                                      min.local.edges)+1)
912 896
             convert.legend <- sort(unique(local.edges))
913 897
             for (i in seq_len((max(local.edges - min.local.edges)+1))) {
914
-                local.edges[which(local.edges == (i+min.local.edges)-1)] <-
915
-                    convert.edges[which(convert.legend ==
916
-                                        (i+min.local.edges)-1)]
898
+                local.edges[local.edges == (i+min.local.edges)-1] <-
899
+                    convert.edges[convert.legend ==
900
+                                      (i+min.local.edges)-1]
917 901
             }
918 902
         }
919 903
         ylim <- c(min(l$scores[[1]]), max(l$scores[[1]]))
... ...
@@ -933,7 +917,7 @@ drawScores <-
933 917
         gens <- CNOresult$results[, 1]
934 918
         stallGens <- as.numeric(unlist(strsplit(gens, " / ")))
935 919
         stallGens <- stallGens[(seq_len((length(stallGens)/2)))*2 - 1]
936
-        getInfo <- CNOresult$results[which(stallGens == 0), ]
920
+        getInfo <- CNOresult$results[stallGens == 0, ]
937 921
         bestScore <- unlist(strsplit(getInfo[, 2], " "))
938 922
         bestScore <- as.numeric(gsub("\\(", "", gsub("\\)", "", bestScore)))
939 923
         bestScore <- bestScore[(seq_len((length(bestScore)/2)))*2 - 1]
... ...
@@ -1008,9 +992,9 @@ drawScores <-
1008 992
 #' @noRd
1009 993
 expandNEM <-
1010 994
     function(model, ignoreList=NA,maxInputsPerGate=2){
1011
-
995
+        
1012 996
         Model = model
1013
-                                        # check that Model is a Model list
997
+        # check that Model is a Model list
1014 998
         if(!is.list(Model)) stop("This function expects as input a Model
1015 999
 as output by readSIF")
1016 1000
         if(length(Model) == 4) {
... ...
@@ -1027,10 +1011,10 @@ as output by readSIF")
1027 1011
 as output by readSIF")
1028 1012
             }
1029 1013
         }
1030
-
1014
+        
1031 1015
         SplitANDs <- list(initialReac=c("split1","split2"))
1032 1016
         splitR <- 1
1033
-
1017
+        
1034 1018
         ## split all the ANDs
1035 1019
         ## remove any ANDs 2/3 and save >3 to add later
1036 1020
         ## +3 won't get added here again but are part of prior
... ...
@@ -1039,12 +1023,12 @@ as output by readSIF")
1039 1023
         remove.and = c()
1040 1024
         reacs2Ignore = c()
1041 1025
         initialReacN <- length(Model$reacID)
1042
-
1026
+        
1043 1027
         ## TODO: move into readSIF ?
1044 1028
         if (initialReacN == 1){
1045 1029
             Model$interMat <- as.matrix(Model$interMat)
1046 1030
         }
1047
-
1031
+        
1048 1032
         ## which reactions have ignoreList as output?
1049 1033
         if(!is.na(ignoreList[1])) {
1050 1034
             for(s in seq_len(initialReacN)) {
... ...
@@ -1053,7 +1037,7 @@ as output by readSIF")
1053 1037
                 }
1054 1038
             }
1055 1039
         }
1056
-
1040
+        
1057 1041
         for(r in seq_len(initialReacN)) {
1058 1042
             inNodes <- which(Model$interMat[,r] == -1)
1059 1043
             if(length(inNodes) > 1) {
... ...
@@ -1061,12 +1045,12 @@ as output by readSIF")
1061 1045
                     andToAdd = c(andToAdd, r)
1062 1046
                 }
1063 1047
                 remove.and = c(remove.and, r)
1064
-
1048
+                
1065 1049
                 if(!any(reacs2Ignore == r)) {
1066 1050
                     outNode <- which(Model$interMat[,r] == 1)
1067
-                    newReacs <- matrix(data=0,nrow=dim(Model$interMat)[1],
1051
+                    newReacs <- matrix(data=0,nrow=nrow(Model$interMat),
1068 1052
                                        ncol=length(inNodes))
1069
-                    newReacsNots <- matrix(data=0,nrow=dim(Model$interMat)[1],
1053
+                    newReacsNots <- matrix(data=0,nrow=nrow(Model$interMat),
1070 1054
                                            ncol=length(inNodes))
1071 1055
                     newReacs[outNode,] <- 1
1072 1056
                     newReacsIDs <- rep("a",length(inNodes))
... ...
@@ -1091,7 +1075,7 @@ as output by readSIF")
1091 1075
                 }
1092 1076
             }
1093 1077
         }
1094
-
1078
+        
1095 1079
         if(length(andToAdd)) {
1096 1080
             toAdd = list()
1097 1081
             toAdd$notMat <- Model$notMat[,andToAdd]
... ...
@@ -1100,18 +1084,18 @@ as output by readSIF")
1100 1084
         } else {
1101 1085
             toAdd <- NA
1102 1086
         }
1103
-
1087
+        
1104 1088
         if(length(remove.and)) {
1105 1089
             Model$notMat <- Model$notMat[,-remove.and]
1106 1090
             Model$interMat <- Model$interMat[,-remove.and]
1107 1091
             Model$reacID <- Model$reacID[-remove.and]
1108 1092
         }
1109
-
1093
+        
1110 1094
         newANDs <- list(finalReac=c("or1","or2"))
1111 1095
         ANDsadded <- 1
1112 1096
         total.list = seq_len(length(Model$namesSpecies))
1113
-
1114
-
1097
+        
1098
+        
1115 1099
         ## functions to get lhs and rhs of reactions
1116 1100
         getlhs <- function(x) {
1117 1101
             spec1 = strsplit(x, "=")[[1]][1]
... ...
@@ -1119,7 +1103,7 @@ as output by readSIF")
1119 1103
         getrhs <- function(x) {
1120 1104
             spec2 = strsplit(x, "=")[[1]][2]
1121 1105
         }
1122
-
1106
+        
1123 1107
         ## scan all species and build and gates if required
1124 1108
         for(sp in total.list) {
1125 1109
             inReacsIndex <- which(Model$interMat[sp,] == 1)
... ...
@@ -1129,27 +1113,27 @@ as output by readSIF")
1129 1113
                     inNode<-which(x == -1)
1130 1114
                 }
1131 1115
                 inSp <- apply(inReacs,2,findInput)
1132
-
1116
+                
1133 1117
                 ## let
1134 1118
                 ## find the input species first and store in a vector
1135 1119
                 inSpecies = apply(as.matrix(colnames(inReacs)), 1, getlhs)
1136 1120
                 outname = Model$namesSpecies[sp]
1137
-
1121
+                
1138 1122
                 ## just for sanity check, all outputs must be the same
1139 1123
                 outnames = apply(as.matrix(colnames(inReacs)), 1, getrhs)
1140 1124
                 if (length(unique(outnames))!=1 | outname!=outnames[1]){
1141 1125
                     stop("error in expandGates.
1142 1126
 should not happen here. please report")
1143 1127
                 }
1144
-
1145
-                                        # an alias
1128
+                
1129
+                # an alias
1146 1130
                 myrownames = rownames(Model$interMat)
1147
-
1148
-                                        # first the 2 inputs cases
1149
-
1131
+                
1132
+                # first the 2 inputs cases
1133
+                
1150 1134
                 combinations = combn(seq(1,length(inSpecies)), 2)
1151
-
1152
-                for (this in seq(1, dim(combinations)[2])){
1135
+                
1136
+                for (this in seq(1, ncol(combinations))){
1153 1137
                     i = combinations[1,this]
1154 1138
                     j = combinations[2,this]
1155 1139
                     ## names[i] and names[j] contains possibly the !
... ...
@@ -1160,13 +1144,13 @@ should not happen here. please report")
1160 1144
                     realname2 = ifelse(substr(inSpecies[j], 1,1) =="!",
1161 1145
                                        substr(inSpecies[j],2,10000),
1162 1146
                                        inSpecies[j])
1163
-
1147
+                    
1164 1148
                     realnames = c(realname1,realname2)
1165 1149
                     if (any(combn(realnames,2)[1,] == combn(realnames,2)[2,])){
1166 1150
                         ## exclude reaction if any name are indentical
1167 1151
                         next()
1168 1152
                     }
1169
-
1153
+                    
1170 1154
                     ## create the new reaction Id to be used as a column name
1171 1155
                     newcolname = paste(paste(inSpecies[i],
1172 1156
                                              inSpecies[j],sep="+"),
... ...
@@ -1175,42 +1159,42 @@ should not happen here. please report")
1175 1159
                         next() # skip if exist already
1176 1160
                     }
1177 1161
                     Model$reacID <- c(Model$reacID,newcolname)
1178
-
1162
+                    
1179 1163
                     ## fill the interMat (-1 if in lhs, 1 if in rhs)
1180 1164
                     values = as.matrix(rep(0, length(Model$namesSpecies)))
1181 1165
                     colnames(values)<-newcolname
1182
-                    values[which(myrownames == realname1)]<- -1
1183
-                    values[which(myrownames == realname2)]<- -1
1184
-                    values[which(myrownames == outname)]<- 1
1166
+                    values[myrownames == realname1]<- -1
1167
+                    values[myrownames == realname2]<- -1
1168
+                    values[myrownames == outname]<- 1
1185 1169
                     Model$interMat= cbind(Model$interMat, values)
1186
-
1187
-                                        # now, the notMat, 0 by default
1170
+                    
1171
+                    # now, the notMat, 0 by default
1188 1172
                     values = as.matrix(rep(0, length(Model$namesSpecies)))
1189 1173
                     colnames(values)<-newcolname
1190 1174
                     if (substr(inSpecies[i],1,1) == "!"){ #look first specy
1191
-                        values[which(myrownames == realname1)]<- 1
1175
+                        values[myrownames == realname1]<- 1
1192 1176
                     }
1193 1177
                     if (substr(inSpecies[j],1,1) == "!"){# and second one
1194
-                        values[which(myrownames == realname2)]<- 1
1178
+                        values[myrownames == realname2]<- 1
1195 1179
                     }
1196 1180
                     Model$notMat= cbind(Model$notMat, values)
1197
-
1198
-                                        # finally, fill the newAnd list
1181
+                    
1182
+                    # finally, fill the newAnd list
1199 1183
                     newreac1 = paste(inSpecies[i], outname, sep="=")
1200 1184
                     newreac2 = paste(inSpecies[j], outname, sep="=")
1201 1185
                     newANDs[[length(newANDs)+1]] <- c(newreac1, newreac2)
1202 1186
                     names(newANDs)[[length(newANDs)]] <- newcolname
1203 1187
                 }
1204
-
1188
+                
1205 1189
                 ## Same code as above but to create the 3 inputs combinations
1206 1190
                 if (length(inSpecies)>=3 & maxInputsPerGate>=3){
1207 1191
                     combinations = combn(seq(1,length(inSpecies)), 3)
1208
-                    indices = seq(1,dim(combinations)[2])
1192
+                    indices = seq(1,ncol(combinations))
1209 1193
                 }
1210 1194
                 else{
1211 1195
                     indices = seq(length=0)
1212 1196
                 }
1213
-
1197
+                
1214 1198
                 for (this in indices){
1215 1199
                     i = combinations[1,this]
1216 1200
                     j = combinations[2,this]
... ...
@@ -1224,7 +1208,7 @@ should not happen here. please report")
1224 1208
                     realname3 = ifelse(substr(inSpecies[k], 1,1) =="!",
1225 1209
                                        substr(inSpecies[k],2,10000),
1226 1210
                                        inSpecies[k])
1227
-
1211
+                    
1228 1212
                     realnames = c(realname1,realname2, realname3)
1229 1213
                     if (any(combn(realnames,2)[1,] == combn(realnames,2)[2,])){
1230 1214
                         ## exclude reaction if any name are indentical
... ...
@@ -1237,31 +1221,31 @@ should not happen here. please report")
1237 1221
                         next() # skip if exist already
1238 1222
                     }
1239 1223
                     Model$reacID <- c(Model$reacID,newcolname)
1240
-
1241
-                                        # intermat first
1224
+                    
1225
+                    # intermat first
1242 1226
                     values = as.matrix(rep(0, length(Model$namesSpecies)))
1243 1227
                     colnames(values)<-newcolname
1244 1228
                     for (name in inSpecies){
1245 1229
                         realname = ifelse(substr(name, 1,1)=="!",
1246 1230
                                           substr(name,2,10000), name)
1247
-                        values[which(myrownames == realname)]<- -1
1231
+                        values[myrownames == realname]<- -1
1248 1232
                     }
1249
-                    values[which(myrownames == outname)]<- 1
1233
+                    values[myrownames == outname]<- 1
1250 1234
                     Model$interMat= cbind(Model$interMat, values)
1251
-
1252
-                                        # now, the notMat
1235
+                    
1236
+                    # now, the notMat
1253 1237
                     values = as.matrix(rep(0, length(Model$namesSpecies)))
1254 1238
                     colnames(values)<-newcolname
1255 1239
                     for (name in inSpecies){
1256 1240
                         if (substr(name,1,1) == "!"){
1257 1241
                             realname = ifelse(substr(name, 1,1) =="!",
1258 1242
                                               substr(name,2,10000), name)
1259
-                            values[which(myrownames == realname)]<- 1
1243
+                            values[myrownames == realname]<- 1
1260 1244
                         }
1261 1245
                     }
1262 1246
                     Model$notMat= cbind(Model$notMat, values)
1263
-
1264
-                                        # finally the newAnd
1247
+                    
1248
+                    # finally the newAnd
1265 1249
                     newreac1 = paste(inSpecies[i], outname, sep="=")
1266 1250
                     newreac2 = paste(inSpecies[j], outname, sep="=")
1267 1251
                     newreac3 = paste(inSpecies[k], outname, sep="=")
... ...
@@ -1269,16 +1253,16 @@ should not happen here. please report")
1269 1253
                                                       newreac3)
1270 1254
                     names(newANDs)[[length(newANDs)]] <- newcolname
1271 1255
                 }
1272
-
1256
+                
1273 1257
                 ## Same code as above but to create the 4 inputs combinations
1274 1258
                 if (length(inSpecies)>=4 & maxInputsPerGate>=4){
1275 1259
                     combinations = combn(seq(1,length(inSpecies)), 4)
1276
-                    indices = seq(1,dim(combinations)[2])
1260
+                    indices = seq(1,ncol(combinations))
1277 1261
                 }
1278 1262
                 else{
1279 1263
                     indices = seq(length=0)
1280 1264
                 }
1281
-
1265
+                
1282 1266
                 for (this in indices){
1283 1267
                     i = combinations[1,this]
1284 1268
                     j = combinations[2,this]
... ...
@@ -1308,31 +1292,31 @@ should not happen here. please report")
1308 1292
                         next() # skip if exist already
1309 1293
                     }
1310 1294
                     Model$reacID <- c(Model$reacID,newcolname)
1311
-
1312
-                                        # intermat first
1295
+                    
1296
+                    # intermat first
1313 1297
                     values = as.matrix(rep(0, length(Model$namesSpecies)))
1314 1298
                     colnames(values)<-newcolname
1315 1299
                     for (name in inSpecies){
1316 1300
                         realname = ifelse(substr(name, 1,1)=="!",
1317 1301
                                           substr(name,2,10000), name)
1318
-                        values[which(myrownames == realname)]<- -1
1302
+                        values[myrownames == realname]<- -1
1319 1303
                     }
1320
-                    values[which(myrownames == outname)]<- 1
1304
+                    values[myrownames == outname]<- 1
1321 1305
                     Model$interMat= cbind(Model$interMat, values)
1322
-
1323
-                                        # now, the notMat
1306
+                    
1307
+                    # now, the notMat
1324 1308
                     values = as.matrix(rep(0, length(Model$namesSpecies)))
1325 1309
                     colnames(values)<-newcolname
1326 1310
                     for (name in inSpecies){
1327 1311
                         if (substr(name,1,1) == "!"){
1328 1312
                             realname = ifelse(substr(name, 1,1) =="!",
1329 1313
                                               substr(name,2,10000), name)
1330
-                            values[which(myrownames == realname)]<- 1
1314
+                            values[myrownames == realname]<- 1
1331 1315
                         }
1332 1316
                     }
1333 1317
                     Model$notMat= cbind(Model$notMat, values)
1334
-
1335
-                                        # finally the newAnd
1318
+                    
1319
+                    # finally the newAnd
1336 1320
                     newreac1 = paste(inSpecies[i], outname, sep="=")
1337 1321
                     newreac2 = paste(inSpecies[j], outname, sep="=")
1338 1322
                     newreac3 = paste(inSpecies[k], outname, sep="=")
... ...
@@ -1340,7 +1324,7 @@ should not happen here. please report")
1340 1324
                     newANDs[[length(newANDs)+1]] <- c(newreac1, newreac2,
1341 1325
                                                       newreac3, newreac4)
1342 1326
                     names(newANDs)[[length(newANDs)]] <- newcolname
1343
-
1327
+                    
1344 1328
                 } # end if length(inSp) == 2
1345 1329
                 if (maxInputsPerGate >= 5) {
1346 1330
                     for (mip in 5:maxInputsPerGate) {
... ...
@@ -1348,7 +1332,7 @@ should not happen here. please report")
1348 1332
                             mip) {
1349 1333
                             combinations = combn(seq(1, length(inSpecies)),
1350 1334
                                                  mip)
1351
-                            indices = seq(1, dim(combinations)[2])
1335
+                            indices = seq(1, ncol(combinations))
1352 1336
                         }
1353 1337
                         else {
1354 1338
                             indices = seq(length = 0)
... ...
@@ -1360,8 +1344,8 @@ should not happen here. please report")
1360 1344
                                 combs[i] = combinations[i, this]
1361 1345
                                 realnames[i] =
1362 1346
                                     ifelse(substr(inSpecies[combs[i]], 1, 1) ==
1363
-                                           "!", substr(inSpecies[i],
1364
-                                                       2, 10000),
1347
+                                               "!", substr(inSpecies[i],
1348
+                                                           2, 10000),
1365 1349
                                            inSpecies[combs[i]])
1366 1350
                             }
1367 1351
                             if (any(combn(realnames, 2)[1, ] ==
... ...
@@ -1382,9 +1366,9 @@ should not happen here. please report")
1382 1366
                             for (name in inSpecies) {
1383 1367
                                 realname = ifelse(substr(name, 1, 1) == "!",
1384 1368
                                                   substr(name, 2, 10000), name)
1385
-                                values[which(myrownames == realname)] <- -1
1369
+                                values[myrownames == realname] <- -1
1386 1370
                             }
1387
-                            values[which(myrownames == outname)] <- 1
1371
+                            values[myrownames == outname] <- 1
1388 1372
                             Model$interMat = cbind(Model$interMat, values)
1389 1373
                             values = as.matrix(rep(0,
1390 1374
                                                    length(Model$namesSpecies)))
... ...
@@ -1394,7 +1378,7 @@ should not happen here. please report")
1394 1378
                                     realname = ifelse(substr(name, 1, 1) == "!",
1395 1379
                                                       substr(name, 2, 10000),
1396 1380
                                                       name)
1397
-                                    values[which(myrownames == realname)] <- 1
1381
+                                    values[myrownames == realname] <- 1
1398 1382
                                 }
1399 1383
                             }
1400 1384
                             Model$notMat = cbind(Model$notMat, values)
... ...
@@ -1412,16 +1396,16 @@ should not happen here. please report")
1412 1396
                         }
1413 1397
                     }
1414 1398
                 }
1415
-
1399
+                
1416 1400
             }
1417 1401
         }
1418
-
1402
+        
1419 1403
         if(!is.na(toAdd)) {
1420 1404
             Model$notMat = cbind(Model$notMat, toAdd$notMat)
1421 1405
             Model$interMat = cbind(Model$interMat, toAdd$interMat)
1422 1406
             Model$reacID = c(Model$reacID, toAdd$reacID)
1423 1407
         }
1424
-
1408
+        
1425 1409
         modelExp <- Model
1426 1410
         modelExp$SplitANDs <- SplitANDs
1427 1411
         modelExp$newANDs <- newANDs
... ...
@@ -1446,9 +1430,9 @@ expNorm <-
1446 1430
                 }
1447 1431
             }
1448 1432
         }
1449
-        cuesSum <- apply(design[, grep(paste(c(stimuli, inhibitors),
1450
-                                             collapse = "|"),
1451
-                                       colnames(design))], 1, sum)
1433
+        cuesSum <- rowSums(design[, grep(paste(c(stimuli, inhibitors),
1434
+                                               collapse = "|"),
1435
+                                         colnames(design))])
1452 1436
         grepCtrl <- which(cuesSum == 0)
1453 1437
         for (run in runs) {
1454 1438
             for (batch in batches) {
... ...
@@ -1503,7 +1487,7 @@ exSearch <-
1503 1487
              parameters=list(cutOffs=c(0,1,0), scoring=c(0.1,0.2,0.9)),
1504 1488
              parallel = NULL, method = "s", relFit = FALSE, verbose = TRUE,
1505 1489
              reduce = TRUE, approach = "fc", ...) {
1506
-
1490
+        
1507 1491
         cutModel2 <- function (model, bString) {
1508 1492
             if (sum(bString == 1) > 0) {
1509 1493
                 bs = as.logical(bString)
... ...
@@ -1524,14 +1508,14 @@ exSearch <-
1524 1508
             }
1525 1509
             return(newmodel)
1526 1510
         }
1527
-
1528
-
1511
+        
1512
+        
1529 1513
         bin2dec <- function(x) {
1530 1514
             exp2 <- 2^c((length(x)-1):0)
1531 1515
             y <- exp2%*%x
1532 1516
             return(y)
1533 1517
         }
1534
-
1518
+        
1535 1519
         dec2bin <- function(x) {
1536 1520
             if (x == 0) {
1537 1521
                 y <- 0
... ...
@@ -1541,7 +1525,7 @@ exSearch <-
1541 1525
             }
1542 1526
             return(y)
1543 1527
         }
1544
-
1528
+        
1545 1529
         dec2binOld <- function(x) {
1546 1530
             if (x == 0) {
1547 1531
                 y <- 0
... ...
@@ -1563,7 +1547,7 @@ exSearch <-
1563 1547
             }
1564 1548
             return(y)
1565 1549
         }
1566
-
1550
+        
1567 1551
         if (!is.null(parallel)) {
1568 1552
             if (is.list(parallel)) {
1569 1553
                 if (length(parallel[[1]]) != length(parallel[[2]])) {
... ...
@@ -1582,13 +1566,17 @@ must be the same.") }
1582 1566
             sfLibrary(bnem)
1583 1567
         }
1584 1568
         spaceExp <- 2^length(model$reacID)
1585
-        print(paste("structurally different networks: ", spaceExp, sep = ""))
1569
+        if (verbose) {
1570
+            message("structurally different networks: ",
1571
+                    spaceExp)
1572
+        }
1586 1573
         ## reduce to equivalent classes by absorption
1587 1574
         bigBang <- function(j) {
1588 1575
             essential <- dec2bin((j-1))
1589
-            tmp <- reduceGraph(c(rep(0,
1590
-            (length(model$reacID)-length(essential))), essential), model,
1591
-            CNOlist)
1576
+            tmp <-
1577
+                reduceGraph(c(rep(0, (length(model$reacID)-
1578
+                                          length(essential))),
1579
+                              essential), model, CNOlist)
1592 1580
             return(tmp)
1593 1581
         }
1594 1582
         pop <- matrix(NA, nrow = spaceExp, ncol = length(model$reacID))
... ...
@@ -1603,11 +1591,13 @@ must be the same.") }
1603 1591
         res <- apply(res, 1, paste, collapse = "")
1604 1592
         realSpace <- seq_len(spaceExp)
1605 1593
         if (sum(duplicated(res) == TRUE) > 0 & reduce) {
1606
-            realSpace <- realSpace[-which(duplicated(res) == TRUE)]
1594
+            realSpace <- realSpace[!duplicated(res)]
1595
+        }
1596
+        ## pop <- pop[!duplicated(res), ]
1597
+        if (verbose) {
1598
+            message("reduction to structurally different equivalence classes: ",
1599
+                    length(realSpace))
1607 1600
         }
1608
-        ## pop <- pop[-which(duplicated(res) == TRUE), ]
1609
-        print(paste("reduction to structurally different equivalence classes: ",
1610
-                    length(realSpace), sep = ""))
1611 1601
         scores <- numeric(spaceExp)
1612 1602
         getBinScore <- function(j) {
1613 1603
             cat(".")
... ...
@@ -1639,21 +1629,22 @@ must be the same.") }
1639 1629
         } else {
1640 1630
             bString <- (pop[realSpace, ])[which(res == min(res))[1], ]
1641 1631
         }
1642
-        print(bString)
1643 1632
         dtmRatio <- mean(abs(res - mean(res)))/abs(min(res) - mean(res))
1644 1633
         dtmRatio2 <- 1 - abs(min(res) - mean(res))/abs(min(res) - max(res))
1645
-        print("best network found:")
1646
-        print(toString(bString))
1647
-        print("score:")
1648
-        print(min(res))
1649
-        print("distance to mean ratio (smaller is better):")
1650
-        print(dtmRatio)
1651
-        print(dtmRatio2)
1652
-                                        #hist(res)
1653 1634
         if (!is.null(parallel)) {
1654 1635
             sfStop()
1655 1636
         }
1656
-        plotDnf(model$reacID[as.logical(bString)])
1637
+        if (verbose) {
1638
+            message(bString)
1639
+            message("best network found:")
1640
+            message(toString(bString))
1641
+            message("score:")
1642
+            message(min(res))
1643
+            message("distance to mean ratio (smaller is better):")
1644
+            message(dtmRatio)
1645
+            message(dtmRatio2)
1646
+            plotDnf(model$reacID[as.logical(bString)])
1647
+        }
1657 1648
         ## names(res) <- samples
1658 1649
         return(list(bString = bString, score = min(res), bStrings = pop,
1659 1650
                     scores = res, dtmRatio = dtmRatio))
... ...
@@ -1697,15 +1688,13 @@ gaBinaryNemT1 <-
1697 1688
               exhaustive = FALSE,
1698 1689
               delcyc = TRUE,
1699 1690
               ...
1700
-              ) {
1691
+    ) {
1701 1692
         addPriorKnowledge <- get("addPriorKnowledge",
1702 1693
                                  envir = asNamespace("CellNOptR"))
1703 1694
         method <- checkMethod(method)
1704 1695
         if (parameters$cutOffs[1] > parameters$cutOffs[2]) {
1705 1696
             parameters$cutOffs <- sort(parameters$cutOffs)
1706
-            print(paste("your're cutoff parameters didn't make any sense.
1707
-I can't let you do this, Dave. I changed them to ", parameters$cutOffs, ".",
1708
-sep = ""))
1697
+            stop("Your're cutoff parameters don't make any sense.")
1709 1698
         }
1710 1699
         if (is.null(elitism) == TRUE) { elitism <- ceiling(popSize*0.1) }
1711 1700
         if (elitism >= popSize) { elitism <- floor(0.1*popSize) }
... ...
@@ -1727,25 +1716,25 @@ sep = ""))
1727 1716
                                        -ncol(initBstring)]
1728 1717
         }
1729 1718
         if (!is(CNOlist, "CNOlist")) {
1730
-            CNOlist = CNOlist(CNOlist)
1719
+            CNOlist <- CNOlist(CNOlist)
1731 1720
         }
1732 1721
         spaceExp <- 2^length(model$reacID)
1733 1722
         if ((popSize*stallGenMax) >= spaceExp & exhaustive) {
1734
-            print(paste("the genetic algorithm would score at least ",
1735
-                        popSize*stallGenMax,
1736
-                        " networks, while the size of
1723
+            warning("the genetic algorithm would score at least ",
1724
+                    popSize*stallGenMax,
1725
+                    " networks, while the size of
1737 1726
 the search space is only ", spaceExp,
1738
-"; therefore an exhaustive search is initialised", sep = ""))
1727
+                    "; therefore an exhaustive search is initialised")
1739 1728
             result <- exSearch(CNOlist,model,sizeFac,NAFac,NEMlist,parameters,
1740 1729
                                parallel=parallel,relFit = relFit,
1741 1730
                                method = method, ...)
1742 1731
             PopTolScores <-
1743
-                result$scores[which(result$scores <
1744
-                                    (result$score + abs(result$score)*relTol))]
1732
+                result$scores[result$scores <
1733
+                                  (result$score + abs(result$score)*relTol)]
1745 1734
             PopTol <-
1746
-                result$bStrings[which(result$scores <
1747
-                                      (result$score +
1748
-                                       abs(result$score)*relTol))]
1735
+                result$bStrings[result$scores <
1736
+                                    (result$score +
1737
+                                         abs(result$score)*relTol)]
1749 1738
             return(list(bString = result$bString, stringsTol = PopTol,
1750 1739
                         stringsTolScores = PopTolScores,
1751 1740
                         dtmRatio = result$dtmRatio, population = result$scores))
... ...
@@ -1758,27 +1747,28 @@ the search space is only ", spaceExp,
1758 1747
                     selPressPct <- 0
1759 1748
                 }
1760 1749
                 if (selPress < 1) {
1761
-                    print("with selPress less than 1
1762
-low ranking networks are favoured")
1750
+                    warning("with selPress less than 1",
1751
+                            " low ranking networks are favoured")
1763 1752
                     msg1 <- 1
1764 1753
                 }
1765 1754
                 if (selPress > 2 & fit == "linear") {
1766 1755
                     selPress <- 2
1767
-                    print("if selPress is greater than 2,
1768
-fit cannot be set to linear; selPress set to 2; or restart with
1769
-fit set to nonlinear")
1756
+                    warning("if selPress is greater than 2, ",
1757
+                            "fit cannot be set to linear; ",
1758
+                            "selPress set to 2; or restart with ",
1759
+                            "fit set to nonlinear")
1770 1760
                     msg2 <- 1
1771 1761
                 }
1772 1762
                 if (selPress >= popSize) {
1773 1763
                     selPress <- popSize - 1
1774
-                    print(paste("selPress must be lower than popSize;
1775
-selPress set to ", selPress, sep = ""))
1764
+                    warning("selPress must be lower than popSize; ",
1765
+                            "selPress set to ", selPress)
1776 1766
                     msg3 <- 1
1777 1767
                 }
1778 1768
                 if (selPress < 0) {
1779 1769
                     selPress <- 1
1780
-                    print("selPress has to be greater than zero and should be
1781
-greater than 1; selPress set to 1")
1770
+                    warning("selPress has to be greater than zero ",
1771
+                            "and should be greater than 1; selPress set to 1")
1782 1772
                     msg3 <- 1
1783 1773
                 }
1784 1774
             }
... ...
@@ -1786,17 +1776,22 @@ greater than 1; selPress set to 1")
1786 1776
                 selPress <- floor(min(max(2, selPress[1]), popSize/2))
1787 1777
             }
1788 1778
             bLength <- length(model$reacID) # changed from length(initBstring)
1789
-            ## simList = prep4sim(model)
1779
+            ## simList <- prep4sim(model)
1790 1780
             simList <- NULL
1791
-            indexList = indexFinder(CNOlist, model)
1781
+            indexList <- indexFinder(CNOlist, model)
1792 1782
             ## initialize starting population
1793 1783
             if (is.null(nrow(initBstring))) {
1794 1784
                 initBstring <- t(as.matrix(initBstring))
1795 1785
             }
1796
-            Pop <- rbind(1 - initBstring, matrix(sample(c(0,1),
1797
-            (bLength * (popSize - (nrow(initBstring)*2))), replace = TRUE),
1798
-            nrow = (popSize - (nrow(initBstring)*2)), ncol = bLength),
1799
-            initBstring) # also the inverted initBstring is added
1786
+            Pop <-
1787
+                rbind(1 - initBstring,
1788
+                      matrix(sample(c(0,1),
1789
+                                    (bLength *
1790
+                                         (popSize -
1791
+                                              (nrow(initBstring)*2))),
1792
+                                    replace = TRUE),
1793
+                             nrow = (popSize - (nrow(initBstring)*2)),
1794
+                             ncol = bLength), initBstring)
1800 1795
             Pop <- addPriorKnowledge(Pop, priorBitString)
1801 1796
             bestbit <- Pop[1, ]
1802 1797
             bestobj <- Inf
... ...
@@ -1917,12 +1912,12 @@ the same.")
1917 1912
                 } else {
1918 1913
                     scores <- apply(Pop, 1, getObj)
1919 1914
                 }
1920
-                scores[which(is.nan(scores) == TRUE)] <-
1921
-                    max(scores[which(is.nan(scores) == FALSE)]) + 1
1915
+                scores[is.nan(scores)] <-
1916
+                    max(scores[!is.nan(scores)]) + 1
1922 1917
                 rankP <- order(scores, decreasing = TRUE)
1923 1918
                 Pop <- Pop[rankP, ]
1924 1919
                 ## something to remember the samples:
1925
-                ## for (sample in 1:nrow(Pop)) {
1920
+                ## for (sample in seq_len(nrow(Pop))) {
1926 1921
                 ##   if (!(toString(Pop[sample, ]) %in% lh.samples)) {
1927 1922
                 ##     likelihoods <- c(likelihoods, scores[sample])
1928 1923
                 ##     lh.samples <- c(lh.samples, toString(Pop[sample, ]))
... ...
@@ -1930,7 +1925,7 @@ the same.")
1930 1925
                 ## }
1931 1926
                 ## try to alternatively keep in mind the best networks:
1932 1927
                 if (graph) {
1933
-                    if (bestMem == "off") {
1928
+                    if (bestMem[1] == "off") {
1934 1929
                         bestMem <- list()
1935 1930
                         bestMem[[1]] <- Pop[popSize, ]
1936 1931
                         bestMem[[2]] <- Pop[popSize, ]
... ...
@@ -1963,7 +1958,8 @@ the same.")
1963 1958
                 ##   uniquePopPos <- c(uniquePopPos,
1964 1959
                 ## which(bitsInDec %in% uniquePop[i])[1])
1965 1960
                 ## }
1966
-                ## uniquePopPos <- c(uniquePopPos, sample(1:nrow(popFull),
1961
+                ## uniquePopPos <- c(uniquePopPos,
1962
+                ## sample(seq_len(nrow(popFull)),
1967 1963
                 ## (popSize - length(uniquePopPos))))
1968 1964
                 ## popMem <- popFull[uniquePopPos, ]
1969 1965
                 ## scoresMem <- scores[uniquePopPos]
... ...
@@ -1974,9 +1970,9 @@ the same.")
1974 1970
                     ## nonlinear or linear fitness
1975 1971
                     if (fit == "nonlinear") {
1976 1972
                         x <- as.double(polyroot(c(rep(selPress, popSize-1),
1977
-                        (selPress - popSize))))
1973
+                                                  (selPress - popSize))))
1978 1974
                         y <- polyroot(c(rep(selPress, popSize-1),
1979
-                        (selPress - popSize)))
1975
+                                        (selPress - popSize)))
1980 1976
                         x <- x[order(abs(y - as.double(y)))[1]]
1981 1977
                         fitness <-
1982 1978
                             (popSize*x^(seq_len(popSize-1)))/(
... ...
@@ -1984,15 +1980,15 @@ the same.")
1984 1980
                     }
1985 1981
                     if (fit == "linear") {
1986 1982
                         fitness <- 2 - selPress + (2 * (selPress - 1) *
1987
-                                                   (c(seq_len(popSize))
1988
-                                                       - 1)/(popSize - 1))
1983
+                                                       (c(seq_len(popSize))
1984
+                                                        - 1)/(popSize - 1))
1989 1985
                     }
1990 1986
                     wheel1 <- cumsum(fitness/sum(fitness))
1991 1987
                     breaks <- runif(1) * 1/popSize
1992 1988
                     breaks <- c(breaks, breaks +
1993
-                                        ((seq_len((popSize - 1))))/popSize)
1989
+                                    ((seq_len((popSize - 1))))/popSize)
1994 1990
                     sel <- rep(1, popSize)
1995
-
1991
+                    
1996 1992
                     if (!is.null(parallel) & popSize > 10000) {
1997 1993
                         sel <- sfApply(as.matrix(seq_len(popSize)), 1, susSel,
1998 1994
                                        wheel1, breaks)
... ...
@@ -2002,7 +1998,7 @@ the same.")
2002 1998
                     }
2003 1999
                 }
2004 2000
                 if ("t" %in% selection) {
2005
-
2001
+                    
2006 2002
                     pRanks <- sample(seq_len(popSize), popSize)
2007 2003
                     t.size <- min(popSize/2, selPress)
2008 2004
                     ppRanks <- matrix(0, popSize, t.size)
... ...
@@ -2013,10 +2009,10 @@ the same.")
2013 2009
                         } else {
2014 2010
                             ppRanks[, i] <- ppRanks[c(popSize,
2015 2011
                                                       seq_len((popSize-1))),
2016
-                            (i-1)]
2012
+                                                    (i-1)]
2017 2013
                         }
2018 2014
                     }
2019
-
2015
+                    
2020 2016
                     if (!is.null(parallel) & popSize > 10000) {
2021 2017
                         sel <-
2022 2018
                             as.vector(unlist(sfApply(
... ...
@@ -2025,36 +2021,36 @@ the same.")
2025 2021
                         sel <- as.vector(unlist(apply(
2026 2022
                             cbind(pRanks, ppRanks), 1, tsReduce, scores)))
2027 2023
                     }
2028
-
2024
+                    
2029 2025
                 }
2030 2026
                 if ("r" %in% selection) {
2031
-
2027
+                    
2032 2028
                     sel <- rep(seq_len(popSize),
2033 2029
                                round((seq_len(popSize))/sum(seq_len(popSize))*
2034
-                                     popSize))
2035
-
2030
+                                         popSize))
2031
+                    
2036 2032
                     if (length(sel) < popSize) {
2037 2033
                         sel <- c(sel, sel[length(sel)])
2038 2034
                     }
2039
-
2035
+                    
2040 2036
                 }
2041 2037
                 if ("f" %in% selection) {
2042
-
2038
+                    
2043 2039
                     scoresF <- scores*(-1)
2044 2040
                     scoresF <- scoresF - min(scoresF)
2045
-
2041
+                    
2046 2042
                     sel <- rep(seq_len(popSize),
2047 2043
                                round((scoresF)/sum(seq_len(scoresF))*popSize))
2048
-
2044
+                    
2049 2045
                     if (length(sel) < popSize) {
2050 2046
                         sel <- c(sel, sel[seq_len((popSize-length(sel)))])
2051 2047
                     }
2052
-
2048
+                    
2053 2049
                 }
2054
-                ##print(sel)
2055
-                ##print(scores)
2050
+                ##message(sel)
2051
+                ##message(scores)
2056 2052
                 Pop2 <- Pop[sel, ]
2057
-                PSize2 <- dim(Pop2)[1]
2053
+                PSize2 <- nrow(Pop2)
2058 2054
                 mates <- cbind(ceiling(runif(PSize3) * PSize2),
2059 2055
                                ceiling(runif(PSize3) * PSize2))
2060 2056
                 InhBit <- matrix(runif((PSize3 * bLength)), nrow = PSize3,
... ...
@@ -2074,8 +2070,7 @@ the same.")
2074 2070
                 thisGenBestBit <- Pop[popSize, ]
2075 2071
                 if (is.na(thisGenBest)) {
2076 2072
                     thisGenBest <- min(scores, na.rm = TRUE)
2077
-                    thisGenBestBit <- Pop[which(scores == thisGenBest)[1],
2078
-                                          ]
2073
+                    thisGenBestBit <- Pop[which(scores == thisGenBest)[1],]
2079 2074
                 }
2080 2075
                 if (thisGenBest < bestobj) {
2081 2076
                     bestobj <- thisGenBest
... ...
@@ -2099,10 +2094,12 @@ the same.")
2099 2094
                 }
2100 2095
                 ## the following code needs changes if elitism is set to 0:
2101 2096
                 resThisGen <- c(g, bestobj, toString(bestbit), stallGen,
2102
-                (mean(scores, na.rm = TRUE)), thisGenBest,
2103
-                toString(thisGenBestBit),
2104
-                as.numeric((t[length(t)] - t[length(t) - 1]), units = "secs"),
2105
-                "----------------------------------")
2097
+                                (mean(scores, na.rm = TRUE)), thisGenBest,
2098
+                                toString(thisGenBestBit),
2099
+                                as.numeric((t[length(t)] -
2100
+                                                t[length(t) - 1]),
2101
+                                           units = "secs"),
2102
+                                "----------------------------------")
2106 2103
                 names(resThisGen) <- c("Generation", "Best_score",
2107 2104
                                        "Best_bitString",
2108 2105
                                        "Stall_Generation", "Avg_Score_Gen",
... ...
@@ -2112,11 +2109,12 @@ the same.")
2112 2109
                 ## verbose output based on elitism on or off
2113 2110
                 if (elitism >= 1) {
2114 2111
                     resThisGen <- c(g, bestobj, toString(bestbit), stallGen,
2115
-                    (mean(scores, na.rm = TRUE)), thisGenBest,
2116
-                    toString(thisGenBestBit),
2117
-                    as.numeric((t[length(t)] - t[length(t) - 1]),
2118
-                               units = "secs"),
2119
-                    "----------------------------------")
2112
+                                    (mean(scores, na.rm = TRUE)), thisGenBest,
2113
+                                    toString(thisGenBestBit),
2114
+                                    as.numeric((t[length(t)] -
2115
+                                                    t[length(t) - 1]),
2116
+                                               units = "secs"),
2117
+                                    "----------------------------------")
2120 2118
                     names(resThisGen) <- c("Generation", "Best_score",
2121 2119
                                            "Best_bitString",
2122 2120
                                            "Stall_Generation", "Avg_Score_Gen",
... ...
@@ -2151,11 +2149,12 @@ the same.")
2151 2149
                     }
2152 2150
                 } else {
2153 2151
                     resThisGen <- c(g, bestobj, toString(bestbit), stallGen,
2154
-                    (mean(scores, na.rm = TRUE)), thisGenBest,
2155
-                    toString(thisGenBestBit),
2156
-                    as.numeric((t[length(t)] - t[length(t) - 1]),
2157
-                               units = "secs"),
2158
-                    "----------------------------------")
2152
+                                    (mean(scores, na.rm = TRUE)), thisGenBest,
2153
+                                    toString(thisGenBestBit),
2154
+                                    as.numeric((t[length(t)] -
2155
+                                                    t[length(t) - 1]),
2156
+                                               units = "secs"),
2157
+                                    "----------------------------------")
2159 2158
                     names(resThisGen) <- c("Generation", "Best_score",
2160 2159
                                            "Best_bitString",
2161 2160
                                            "Stall_Generation",
... ...
@@ -2197,60 +2196,69 @@ the same.")
2197 2196
                 if (verbose) {
2198 2197
                     if (elitism >= 1) {
2199 2198
                         if (targetBstring[1] == "none") {
2200
-                            print(paste(names(resThisGen)[3], ":", sep = ""))
2201
-                            print(as.vector(resThisGen[3]))
2202
-                            print(paste(names(resThisGen)[1], ": ",
2203
-                                        resThisGen[1], sep = ""))
2204
-                            print(paste(names(resThisGen)[2], ": ",
2205
-                                        resThisGen[2], sep = ""))
2206
-                            print(paste(names(resThisGen)[4], ": ",
2207
-                                        paste(resThisGen[4], "s @ ",
2208
-                                              Sys.time(), sep = ""), sep = ""))
2209
-                            print(paste(names(resThisGen)[5], ": ",
2210
-                                        resThisGen[5], sep = ""))
2199
+                            message(names(resThisGen)[3], ":")
2200
+                            message(as.vector(resThisGen[3]))
2201
+                            message(names(resThisGen)[1], ": ",
2202
+                                    resThisGen[1])
2203
+                            message(names(resThisGen)[2], ": ",
2204
+                                    resThisGen[2])
2205
+                            message(names(resThisGen)[4], ": ",
2206
+                                    resThisGen[4], "s @ ",
2207
+                                    Sys.time())
2208
+                            message(names(resThisGen)[5], ": ",
2209
+                                    resThisGen[5])
2211 2210
                         } else {
2212
-                            print(paste(names(resThisGen)[3], ":", sep = ""))
2213
-                            print(as.vector(resThisGen[3]))
2214
-                            print(paste(names(resThisGen)[4], ":", sep = ""))
2215
-                            print(as.vector(resThisGen[4]))
2216
-                            print(paste(names(resThisGen)[1], ": ",
2217
-                                        resThisGen[1], sep = ""))
2218
-                            print(paste(names(resThisGen)[2], ": ",
2219
-                                        resThisGen[2], sep = ""))
2220
-                            print(paste(names(resThisGen)[5], ": ",
2221
-                                        resThisGen[5], sep = ""))
2222
-                            print(paste(names(resThisGen)[6], ": ",
2223
-                                        paste(resThisGen[6], "s @ ",
2224
-                                              Sys.time(), sep = ""), sep = ""))
2211
+                            message(names(resThisGen)[3], ":")
2212
+                            message(as.vector(resThisGen[3]))
2213
+                            message(names(resThisGen)[4], ":")
2214
+                            message(as.vector(resThisGen[4]))
2215
+                            message(names(resThisGen)[1], ": ",
2216
+                                    resThisGen[1])
2217
+                            message(names(resThisGen)[2], ": ",
2218
+                                    resThisGen[2])
2219
+                            message(names(resThisGen)[5], ": ",
2220
+                                    resThisGen[5])
2221
+                            message(names(resThisGen)[6], ": ",
2222
+                                    paste(resThisGen[6], "s @ ",
2223
+                                          Sys.time()))
2225 2224
                         }
2226 2225
                     } else {
2227
-                        print(resThisGen)
2226
+                        message(resThisGen)
2228 2227
                     }
2229 2228
                 }
2230 2229
                 res <- rbind(res, resThisGen)
2231 2230
                 Criteria <- c((stallGen > stallGenMax),
2232
-                (as.numeric((t[length(t)] -
2233
-                             t[1]), units = "secs") > maxTime), (g > maxGens))
2231
+                              (as.numeric((t[length(t)] -
2232
+                                               t[1]), units = "secs") > 
2233
+                                   maxTime), (g > maxGens))
2234 2234
                 ## introduce a stop criteria for a target network
2235 2235
                 if (targetBstring[1] != "none" & g >= 2) {
2236 2236
                     Criteria <- c((stallGen > stallGenMax),
2237
-                    (as.numeric((t[length(t)] -
2238
-                                 t[1]), units = "secs") > maxTime),
2239
-                    (g > maxGens),
2240
-                    (computeScoreNemT1(CNOlist=CNOlist,
2241
-                                       model=model,
2242
-                                       bString=bestbit,
2243
-                                       sizeFac=sizeFac,
2244
-                                       NAFac=NAFac,
2245
-                                       approach = approach,
2246
-                                       NEMlist = NEMlist,
2247
-                                       parameters=parameters, tellme = 0,
2248
-                                       relFit = relFit, ...) <=
2249
-                     computeScoreNemT1(CNOlist=CNOlist, model=model,
2250
-                                       bString=targetBstring, sizeFac=sizeFac,
2251
-                                       NAFac=NAFac, approach = approach,
2252
-                                       NEMlist = NEMlist, parameters=parameters,
2253
-                                       tellme = 0, relFit = relFit, ...)))
2237
+                                  (as.numeric((t[length(t)] -
2238
+                                                   t[1]), units = "secs") > 
2239
+                                       maxTime),
2240
+                                  (g > maxGens),
2241
+                                  (computeScoreNemT1(CNOlist=CNOlist,
2242
+                                                     model=model,
2243
+                                                     bString=bestbit,
2244
+                                                     sizeFac=sizeFac,
2245
+                                                     NAFac=NAFac,
2246
+                                                     approach = approach,
2247
+                                                     NEMlist = NEMlist,
2248
+                                                     parameters=parameters, 
2249
+                                                     tellme = 0,
2250
+                                                     relFit = relFit, ...) <=
2251
+                                       computeScoreNemT1(CNOlist=CNOlist, 
2252
+                                                         model=model,
2253
+                                                         bString=targetBstring,
2254
+                                                         sizeFac=sizeFac,
2255
+                                                         NAFac=NAFac, 
2256
+                                                         approach = approach,
2257
+                                                         NEMlist = NEMlist, 
2258
+                                                         parameters=parameters,
2259
+                                                         tellme = 0,
2260
+                                                         relFit = relFit, 
2261
+                                                         ...)))
2254 2262
                 }
2255 2263
                 if (any(Criteria)) {
2256 2264
                     stop <- TRUE
... ...
@@ -2285,7 +2293,7 @@ the same.")
2285 2293
                                 ModelCut$reacID[as.logical(Pop[popSize, ])]
2286 2294
                             screen(2, new = TRUE)
2287 2295
                             plotDnf(ModelCut$reacID, CNOlist = CNOlist)
2288
-                                        #}
2296
+                            #}
2289 2297
                             graphVal <-
2290 2298
                                 c(graphVal,
2291 2299
                                   scores[order(scores,
... ...
@@ -2338,9 +2346,9 @@ the same.")
2338 2346
                                  yaxt = "n",
2339 2347
                                  ylim = c(1,max(2,ceiling(max(graphValSp)))))
2340 2348
                             axis(4, at = (10:max(20,(ceiling(max(
2341
-                                                 graphValSp))*10)))/10,
2342
-                                 labels = (10:max(20,(ceiling(max(
2343
-                                                  graphValSp))*10)))/10)
2349
+                                graphValSp))*10)))/10,
2350
+                                labels = (10:max(20,(ceiling(max(
2351
+                                    graphValSp))*10)))/10)
2344 2352
                         } else {
2345 2353
                             legend(gUp, max(c(graphVal, graphValAvg)),
2346 2354
                                    legend = c("Best Score", "Average Score"),
... ...
@@ -2368,14 +2376,14 @@ the same.")
2368 2376
             PopTolT <- cbind(PopTol, PopTolScores)
2369 2377
             PopTolT <- unique(PopTolT, MARGIN = 1)
2370 2378
             if (!is.null(dim(PopTolT))) {
2371
-                PopTol <- PopTolT[, seq_len((dim(PopTolT)[2] - 1))]
2372
-                PopTolScores <- PopTolT[, dim(PopTolT)[2]]
2379
+                PopTol <- PopTolT[, seq_len((ncol(PopTolT) - 1))]
2380
+                PopTolScores <- PopTolT[, ncol(PopTolT)]
2373 2381
             }
2374 2382
             else {
2375 2383
                 PopTol <- PopTolT[seq_len((length(PopTolT) - 1))]
2376 2384
                 PopTolScores <- PopTolT[length(PopTolT)]
2377 2385
             }
2378
-            res <- res[2:dim(res)[1], ]
2386
+            res <- res[2:nrow(res), ]
2379 2387
             rownames(res) <- NULL
2380 2388
             if (!is.null(parallel)) {
2381 2389
                 sfStop()
... ...
@@ -2402,7 +2410,7 @@ getHierarchy <-
2402 2410
         count <- 0
2403 2411
         for (i in sort(unique(Ypos), decreasing = TRUE)) {
2404 2412
             count <- count + 1
2405
-            hierarchy[[count]] <- Ynames[which(Ypos == i)]
2413
+            hierarchy[[count]] <- Ynames[Ypos == i]
2406 2414
         }
2407 2415
         return(hierarchy)
2408 2416
     }
... ...
@@ -2424,11 +2432,11 @@ getNemFit <-
2424 2432
               method = "pearson",
2425 2433
               verbose = FALSE,
2426 2434
               opt = "min"
2427
-              ) {
2435
+    ) {
2428 2436
         if (!is(CNOlist, "CNOlist")) {
2429
-            CNOlist = CNOlist(CNOlist)
2437
+            CNOlist <- CNOlist(CNOlist)
2430 2438
         }
2431
-        simResults <- simResults[, colnames(CNOlist@signals[[1]])]
2439
+        simResults <- simResults[, colnames(getSignals(CNOlist)[[1]])]
2432 2440
         if (timePoint == "t1") {
2433 2441
             tPt <- 2
2434 2442
         }
... ...
@@ -2448,17 +2456,17 @@ getNemFit <-
2448 2456
         if ("abs" %in% approach) {
2449 2457
             MSEE <- rep(Inf, nrow(NEMlist$norm))
2450 2458
             S.mat <- simResults
2451
-            colnames(NEMlist$norm)[which(colnames(NEMlist$norm) %in% "")] <-
2459
+            colnames(NEMlist$norm)[colnames(NEMlist$norm) %in% ""] <-
2452 2460
                 "Base"
2453
-            rownames(S.mat)[which(rownames(S.mat) %in% "")] <- "Base"
2461
+            rownames(S.mat)[rownames(S.mat) %in% ""] <- "Base"
2454 2462
             S.mat <- S.mat[colnames(NEMlist$norm), ]
2455 2463
             if (any(c("spearman", "pearson", "kendall") %in% method)) {
2456 2464
                 if ("spearman" %in% method) {
2457
-                    E.mat <- NEMlist$exprs
2465
+                    E.mat <- NEMlist$expression
2458 2466
                     S.mat.ranks <- t(S.mat)
2459 2467
                     cosine.sim <- -t(cor(S.mat.ranks, t(E.mat), method = "p"))
2460 2468
                 } else {
2461
-                    E.mat <- NEMlist$exprs
2469
+                    E.mat <- NEMlist$expression
2462 2470
                     cosine.sim <- -t(cor(S.mat, t(E.mat), method = method))
2463 2471
                 }
2464 2472
                 R <- cbind(cosine.sim, -cosine.sim)
... ...
@@ -2467,11 +2475,12 @@ getNemFit <-
2467 2475
                 ES0 <- abs(1 - NEMlist$norm)%*%S.mat*parameters$scoring[2]
2468 2476
                 ESposI <- NEMlist$norm%*%S.mat*parameters$scoring[1]
2469 2477
                 ES0I <- abs(1 -
2470
-                            NEMlist$norm)%*%abs(1 - S.mat)*parameters$scoring[2]
2478
+                                NEMlist$norm)%*%
2479
+                    abs(1 - S.mat)*parameters$scoring[2]
2471 2480
                 MSEAabs <- (ESpos + ES0)
2472 2481
                 MSEIabs <- (ESposI + ES0I)
2473 2482
                 R <- cbind(MSEAabs, MSEIabs)
2474
-                R <- R/ncol(NEMlist$exprs)
2483
+                R <- R/ncol(NEMlist$expression)
2475 2484
             }
2476 2485
             R[is.na(R)] <- max(R[!is.na(R)])
2477 2486
             MSEE <- rowMins(R)
... ...
@@ -2485,13 +2494,6 @@ getNemFit <-
2485 2494
             SCompMat <- SCompMat*signtmp
2486 2495
             SCompMat <- t(SCompMat)
2487 2496
             SCompMat <- rbind(SCompMat, null = 0)
2488
-            ## for debugging:
2489
-            ## if (any(!(colnames(NEMlist$fc) %in% rownames(SCompMat)))) {
2490
-            ##     print(colnames(NEMlist$fc)[which(!(colnames(NEMlist$fc) %in%
2491
-            ##                                        rownames(SCompMat)))]);
2492
-            ##     print("-------------------------------------------")
2493
-            ##     print(rownames(SCompMat))
2494
-            ## }
2495 2497
             if (is.null(rownames(SCompMat))) {
2496 2498
                 SCompMat <- SCompMat[, colnames(NEMlist$fc)]
2497 2499
             } else {
... ...
@@ -2511,7 +2513,7 @@ getNemFit <-
2511 2513
                 if (any(c("euclidean", "maximum", "manhattan", "canberra",
2512 2514
                           "binary", "minkowski") %in% method)) {
2513 2515
                     power <- as.numeric(method)
2514
-                    power <- power[-which(is.na(power)==TRUE)]
2516
+                    power <- power[!is.na(power)]
2515 2517
                     if (length(power) == 0) {
2516 2518
                         power <- 2
2517 2519
                     }
... ...
@@ -2538,7 +2540,7 @@ getNemFit <-
2538 2540
                         }
2539 2541
                     }
2540 2542
                     if (parameters$scoring[1] == 0) {
2541
-                        S.mat[which(S.mat == 0)] <- NA
2543
+                        S.mat[S.mat == 0] <- NA
2542 2544
                     }
2543 2545
                     if ("pearson" %in% method) {
2544 2546
                         cosine.sim <- -t(cor(t(S.mat), t(E.mat), method = "p",
... ...
@@ -2588,9 +2590,9 @@ getNemFit <-
2588 2590
                 } else {
2589 2591
                     S0 <- as.matrix(1 - abs(SCompMat))
2590 2592
                     Spos <- SCompMat
2591
-                    Spos[which(Spos == -1)] <- 0
2593
+                    Spos[Spos == -1] <- 0
2592 2594
                     Sneg <- SCompMat
2593
-                    Sneg[which(Sneg == 1)] <- 0
2595
+                    Sneg[Sneg == 1] <- 0
2594 2596
                     if ("mLL" %in% method | "cp" %in% method) {
2595 2597
                         Sneg <- abs(Sneg)
2596 2598
                         E0 <- NEMlist$E0
... ...
@@ -2673,9 +2675,9 @@ getNemFit <-
2673 2675
                     if (relFit) {
2674 2676
                         S0 <- as.matrix(1 - abs(SCompMat))
2675 2677
                         Spos <- SCompMat
2676
-                        Spos[which(Spos == -1)] <- 0
2678
+                        Spos[Spos == -1] <- 0
2677 2679
                         Sneg <- SCompMat
2678
-                        Sneg[which(Sneg == 1)] <- 0
2680
+                        Sneg[Sneg == 1] <- 0
2679 2681
                         SS0 <- t(S0*parameters$scoring[1])%*%S0
2680 2682
                         SSpos <- t(Spos)%*%Spos
2681 2683
                         SSneg <- t(Sneg)%*%Sneg
... ...
@@ -2710,7 +2712,8 @@ getNemFit <-
2710 2712
                             y <- sum(x[order(x)[seq_len(N)]])
2711 2713
                             return(y)
2712 2714
                         }
2713
-                        MSEE <- apply(R, 1, topNsum, ncol(CNOlist@signals[[1]]))
2715
+                        MSEE <- apply(R, 1, topNsum,
2716
+                                      ncol(getSignals(CNOlist)[[1]]))
2714 2717
                         MSEE <- MSEE*NEMlist$weights
2715 2718
                     }
2716 2719
                 }
... ...
@@ -2718,27 +2721,26 @@ getNemFit <-
2718 2721
         }
2719 2722
         if (parameters$cutOffs[3] == -1) {
2720 2723
             ## do median polish over gene clusters
2721
-            data.med <- NEMlist$fc[seq_len(ncol(CNOlist@signals[[2]])), ]*0
2724
+            data.med <- NEMlist$fc[seq_len(ncol(getSignals(CNOlist)[[2]])), ]*0
2722 2725
             Epos <- which(R == MSEE, arr.ind = TRUE)
2723
-            for (i in seq_len(ncol(CNOlist@signals[[1]]))) {
2726
+            for (i in seq_len(ncol(getSignals(CNOlist)[[1]]))) {
2724 2727
                 tmp <-
2725 2728
                     medpolish(rbind(
2726
-                        NEMlist$fc[Epos[
2727
-                                    which(Epos[, 2] == i), 1], ],
2728
-                        -NEMlist$fc[Epos[which(Epos[, 2] ==
2729
-                                               (i+ncol(CNOlist@signals[[2]]))),
2730
-                                         1], ]), trace.iter=FALSE)
2729
+                        NEMlist$fc[Epos[Epos[, 2] == i, 1], ],
2730
+                        -NEMlist$fc[Epos[Epos[, 2] ==
2731
+                                             (i+ncol(getSignals(CNOlist)[[2]])
2732
+                                             ),1], ]), trace.iter=FALSE)
2731 2733
                 data.med[i, ] <- tmp$col
2732 2734
             }
2733 2735
             E.mat <- data.med
2734 2736
             E.mat[is.na(E.mat)] <- 0
2735
-            tmp <- which(apply(E.mat, 1, sum) != 0)
2736
-            E.mat <- as.matrix(E.mat[which(apply(E.mat, 1, sum) != 0), ])
2737
+            tmp <- rowSums(E.mat) != 0
2738
+            E.mat <- as.matrix(E.mat[rowSums(E.mat) != 0, ])
2737 2739
             rownames(E.mat) <- rownames(S.mat)[tmp]
2738 2740
             NEMlist$fc <- E.mat
2739 2741
             S.mat <- SCompMat
2740 2742
             if (parameters$scoring[1] == 0) {
2741
-                S.mat[which(S.mat == 0)] <- NA
2743
+                S.mat[S.mat == 0] <- NA
2742 2744
             }
2743 2745
             if ("pearson" %in% method) {
2744 2746
                 cosine.sim <- -t(cor(t(S.mat), t(E.mat), method = "p",
... ...
@@ -2759,13 +2761,13 @@ getNemFit <-
2759 2761
         if (tellme == 1) {
2760 2762
             names(MSEE) <- rownames(NEMlist$fc)
2761 2763
             if (parameters$cutOffs[3] > 0 & parameters$cutOffs[3] <= 1) {
2762
-                R <- R[which(MSEE < -parameters$cutOffs[3]), ]
2763
-                MSEE <- MSEE[which(MSEE < -parameters$cutOffs[3])]
2764
+                R <- R[MSEE < -parameters$cutOffs[3], ]
2765
+                MSEE <- MSEE[MSEE < -parameters$cutOffs[3]]
2764 2766
             }
2765 2767
             if (parameters$cutOffs[3] < 0 & parameters$cutOffs[3] > -1) {
2766 2768
                 score.quantile <- quantile(MSEE, -parameters$cutOffs[3])
2767
-                R <- R[which(MSEE < score.quantile), ]
2768
-                MSEE <- MSEE[which(MSEE < score.quantile)]
2769
+                R <- R[MSEE < score.quantile, ]
2770
+                MSEE <- MSEE[MSEE < score.quantile]
2769 2771
             }
2770 2772
             if (parameters$cutOffs[3] > 1 & parameters$cutOffs[3] <=
2771 2773
                 length(MSEE)) {
... ...
@@ -2774,21 +2776,21 @@ getNemFit <-
2774 2776
             }
2775 2777
             topEgenes <- 0
2776 2778
             subtopo <- matrix(0, nrow = length(MSEE),
2777
-                              ncol = ncol(CNOlist@signals[[1]]))
2778
-            colnames(subtopo) <- colnames(CNOlist@signals[[1]])
2779
+                              ncol = ncol(getSignals(CNOlist)[[1]]))
2780
+            colnames(subtopo) <- colnames(getSignals(CNOlist)[[1]])
2779 2781
             if (is.null(NEMlist$weights)) {
2780 2782
                 Epos <- which(R == MSEE, arr.ind = TRUE)
2781 2783
             } else {
2782 2784
                 Epos <-
2783 2785
                     which(NEMlist$geneGrid[
2784
-                                    , seq_len(ncol(CNOlist@signals[[1]]))] == 0,
2785
-                          arr.ind = TRUE)
2786
+                        , seq_len(ncol(getSignals(CNOlist)[[1]]))]
2787
+                        == 0, arr.ind = TRUE)
2786 2788
             }
2787 2789
             if (length(Epos) != 0) {
2788 2790
                 if (is.null(dim(Epos))) {
2789 2791
                     Epos <- t(as.matrix(Epos))
2790 2792
                 }
2791
-                posReg <- Epos[which(Epos[, 2] <= ncol(CNOlist@signals[[1]])), ]
2793
+                posReg <- Epos[Epos[, 2] <= ncol(getSignals(CNOlist)[[1]]), ]
2792 2794
                 if (length(posReg) > 0) {
2793 2795
                     if (length(posReg) > 3) {
2794 2796
                         subtopo[posReg] <- 1
... ...
@@ -2796,29 +2798,31 @@ getNemFit <-
2796 2798
                         subtopo[posReg[1], posReg[2]] <- 1
2797 2799
                     }
2798 2800
                 }
2799
-                negReg <- Epos[which(Epos[, 2] > ncol(CNOlist@signals[[1]])), ]
2801
+                negReg <- Epos[Epos[, 2] > ncol(getSignals(CNOlist)[[1]]), ]
2800 2802
                 if (length(negReg) > 0) {
2801 2803
                     if (length(negReg) > 3) {
2802
-                        negReg[, 2] <- negReg[, 2] - ncol(CNOlist@signals[[1]])
2804
+                        negReg[, 2] <- negReg[, 2] -
2805
+                            ncol(getSignals(CNOlist)[[1]])
2803 2806
                         subtopo[negReg] <- -1
2804 2807
                     } else {
2805
-                        negReg[2] <- negReg[2] - ncol(CNOlist@signals[[1]])
2808
+                        negReg[2] <- negReg[2] -
2809
+                            ncol(getSignals(CNOlist)[[1]])
2806 2810
                         subtopo[negReg[1], negReg[2]] <- -1
2807 2811
                     }
2808 2812
                 }
2809
-
2813
+                
2810 2814
                 EtoS <- matrix(0, nrow = nrow(Epos), ncol = 4)
2811 2815
                 colnames(EtoS) <- c("Egene", "Sgene", "Type", "MSE")
2812 2816
                 rownames(EtoS) <- names(MSEE)[Epos[, 1]]
2813
-
2814
-                Epos[which(Epos[, 2] > ncol(subtopo)), 2] <-
2815
-                    Epos[which(Epos[, 2] > ncol(subtopo)), 2] - ncol(subtopo)
2816
-
2817
+                
2818
+                Epos[Epos[, 2] > ncol(subtopo), 2] <-
2819
+                    Epos[Epos[, 2] > ncol(subtopo), 2] - ncol(subtopo)
2820
+                
2817 2821
                 EtoS[, 1] <- Epos[, 1]
2818 2822
                 EtoS[, 2] <- Epos[, 2]
2819 2823
                 EtoS[, 3] <- subtopo[cbind(Epos[, 1], Epos[, 2])]
2820 2824
                 EtoS[, 4] <- MSEE[Epos[, 1]]
2821
-
2825
+                
2822 2826
                 EtoS <- EtoS[order(EtoS[, 4], decreasing = FALSE), ]
2823 2827
                 sgeneScore <- numeric(ncol(subtopo))
2824 2828
             } else {
... ...
@@ -2827,29 +2831,29 @@ getNemFit <-
2827 2831
             }
2828 2832
             if (verbose) {
2829 2833
                 for (j in seq_len(ncol(subtopo))) {
2830
-                    print(paste(j, ".", colnames(simResults)[j], ": ",
2831
-                                sum(EtoS[, 2] == j), sep = ""))
2832
-                    print(paste("Activated: ", sum(EtoS[, 2] == j &
2833
-                                                   EtoS[, 3] == 1), sep = ""))
2834
-                    print(paste("Inhibited: ", sum(EtoS[, 2] == j &
2835
-                                                   EtoS[, 3] == -1), sep = ""))
2836
-                    print("Summary Score:")
2837
-                    print(summary(EtoS[which(EtoS[, 2] == j), 4]))
2834
+                    message(j, ".", colnames(simResults)[j], ": ",
2835
+                            sum(EtoS[, 2] == j))
2836
+                    message("Activated: ", sum(EtoS[, 2] == j &
2837
+                                                   EtoS[, 3] == 1))
2838
+                    message("Inhibited: ", sum(EtoS[, 2] == j &
2839
+                                                   EtoS[, 3] == -1))
2840
+                    message("Summary Score:")
2841
+                    message(summary(EtoS[EtoS[, 2] == j, 4]))
2838 2842
                 }
2839 2843
                 dups <- sum(duplicated(rownames(Epos)) == TRUE)
2840 2844
                 if (dups > 0) {
2841 2845
                     used <-
2842
-                        sum(EtoS[-which(duplicated(rownames(Epos)) == TRUE), 2]
2846
+                        sum(EtoS[!duplicated(rownames(Epos)), 2]
2843 2847
                             %in% seq_len(ncol(subtopo)))
2844 2848
                 } else {
2845 2849
                     used <- nrow(EtoS)
2846 2850
                 }
2847
-                print(paste("Unique genes used: ",
2848
-                (used), " (", round((used/nrow(NEMlist$fc))*100, 2), " %)",
2849
-                sep = ""))
2850
-                print(paste("Duplicated genes: ", dups, sep = ""))
2851
-                print("Overall fit:")
2852
-                print(summary(EtoS[, 4]))
2851
+                message("Unique genes used: ",
2852
+                        (used), " (", round((used/nrow(NEMlist$fc))*100, 2), " 
2853
+                        %)")
2854
+                message("Duplicated genes: ", dups)
2855
+                message("Overall fit:")
2856
+                message(summary(EtoS[, 4]))
2853 2857
             }
2854 2858
         }
2855 2859
         if ("mLL" %in% method) {
... ...
@@ -2862,12 +2866,12 @@ getNemFit <-
2862 2866
             }
2863 2867
             if (parameters$cutOffs[3] > 0 & parameters$cutOffs[3] <= 1 &
2864 2868
                 tellme == 0) {
2865
-                MSEE <- MSEE[which(MSEE < -parameters$cutOffs[3])]
2869
+                MSEE <- MSEE[MSEE < -parameters$cutOffs[3]]
2866 2870
             }
2867 2871
             if (parameters$cutOffs[3] < 0 & parameters$cutOffs[3] > -1 &
2868 2872
                 tellme == 0) {
2869 2873
                 score.quantile <- quantile(MSEE, -parameters$cutOffs[3])
2870
-                MSEE <- MSEE[which(MSEE < score.quantile)]
2874
+                MSEE <- MSEE[MSEE < score.quantile]
2871 2875
             }
2872 2876
             if ("cp" %in% method) {
2873 2877
                 deviationPen <- sum(MSEE[!is.na(MSEE)])/nrow(NEMlist$fc)
... ...
@@ -2902,25 +2906,24 @@ graph2adj <-
2902 2906
         adj.matrix <- matrix(0,
2903 2907
                              length(nodes(gR)),
2904 2908
                              length(nodes(gR))
2905
-                             )
2909
+        )
2906 2910
         rownames(adj.matrix) <- nodes(gR)
2907 2911
         colnames(adj.matrix) <- nodes(gR)
2908 2912
         for (i in seq_len(length(nodes(gR)))) {
2909 2913
             adj.matrix[nodes(gR)[i],adj(gR,nodes(gR)[i])[[1]]] <- 1
2910 2914
         }
2911
-
2915
+        
2912 2916
         return(adj.matrix)
2913 2917
     }
2914 2918
 #' @noRd
2915 2919
 isDag <-
2916 2920
     function(graph = NULL, bString = 0, model = NULL) {
2917 2921
         if (any(bString != 0)) {
2918
-            graph <- model$reacID[which(bString == 1)]
2922
+            graph <- model$reacID[bString == 1]
2919 2923
         }
2920 2924
         if (!is.null(graph)) {
2921 2925
             adjmat <- dnf2adj(graph)
2922
-            ##.order <- apply(adjmat, 1, sum)
2923
-            get.order2 <- apply(adjmat, 2, sum)
2926
+            get.order2 <- colSums(adjmat)
2924 2927
             adjmat <- adjmat[order(get.order2, decreasing = FALSE),
2925 2928
                              order(get.order2, decreasing = FALSE)]
2926 2929
             if (all(adjmat[lower.tri(adjmat)] == 0)) {
... ...
@@ -2944,23 +2947,19 @@ kmeansNorm <-
2944 2947
         }
2945 2948
         y <- x
2946 2949
         for (i in seq_len(nrow(x))) {
2947
-
2948 2950
             if (sd(x[i, ]) == 0) { next() }
2949
-
2950 2951
             cat('\r', paste(round(i/nrow(x)*100), "%", sep = ""))
2951
-            flush.console()
2952
-
2953 2952
             x.clust <- kmeans(x[i, ], k)
2954 2953
             x.dist <- dist(x[i, ])
2955 2954
             x.sil <- silhouette(x.clust$cluster, x.dist)
2956 2955
             x.norm <- x.sil[, 3]
2957
-            if (sum(x[i, which(x.clust$cluster == 1)]) <
2958
-                sum(x[i, which(x.clust$cluster == 2)])) {
2959
-                x.norm[which(x.clust$cluster == 1)] <-
2960
-                    x.norm[which(x.clust$cluster == 1)]*(-1)
2956
+            if (sum(x[i, x.clust$cluster == 1]) <
2957
+                sum(x[i, x.clust$cluster == 2])) {
2958
+                x.norm[x.clust$cluster == 1] <-
2959
+                    x.norm[x.clust$cluster == 1]*(-1)
2961 2960
             } else {
2962
-                x.norm[which(x.clust$cluster == 2)] <-
2963
-                    x.norm[which(x.clust$cluster == 2)]*(-1)
2961
+                x.norm[x.clust$cluster == 2] <-
2962
+                    x.norm[x.clust$cluster == 2]*(-1)
2964 2963
             }
2965 2964
             x.norm <- x.norm - min(x.norm)
2966 2965
             x.norm <- x.norm/max(x.norm)
... ...
@@ -2975,6 +2974,7 @@ kmeansNorm <-
2975 2974
 #' CellNOptR
2976 2975
 #' @importFrom mnem plotDnf
2977 2976
 #' @importFrom Biobase rowMin rowMax
2977
+#' @importFrom matrixStats rowMaxs
2978 2978
 localSearch <-
2979 2979
     function(CNOlist, NEMlist, model, approach = "fc", initSeed = NULL,
2980 2980
              seeds = 1,
... ...
@@ -3001,7 +3001,7 @@ localSearch <-
3001 3001
             seeds2 <- "none"
3002 3002
         }
3003 3003
         if (!is(CNOlist, "CNOlist")) {
3004
-            CNOlist = CNOlist(CNOlist)
3004
+            CNOlist <- CNOlist(CNOlist)
3005 3005
         }
3006 3006
         bLength <- length(model$reacID)
3007 3007
         ##simList = prep4sim(model)
... ...
@@ -3016,7 +3016,13 @@ localSearch <-
3016 3016
         }
3017 3017
         ## add a few random (but good) strings:
3018 3018
         if (seeds >= 2 & seeds2 != "max") {
3019
-            bitStrings[2:seeds, ] <- createCube(ncol(bitStrings), seeds-1)
3019
+            seed.cube <- createCube(ncol(bitStrings),seeds-1)
3020
+            if (nrow(seed.cube)>nrow(bitStrings)) {
3021
+                bitStrings[2:nrow(bitStrings), ] <-
3022
+                    seed.cube[seq_len(nrow(bitStrings)-1),]
3023
+            } else {
3024
+                bitStrings[2:(nrow(seed.cube)+1), ] <- seed.cube
3025
+            }
3020 3026
         }
3021 3027
         bitStringsMem <- numeric()
3022 3028
         bitStringsScores <- numeric()
... ...
@@ -3045,9 +3051,9 @@ localSearch <-
3045 3051
                                 NEMlist = NEMlist, parameters, tellme = 0,
3046 3052
                                 relFit = relFit, method = method,
3047 3053
                                 max.steps = max.steps, node = node, ...) {
3048
-            stimuli <- colnames(CNOlist@stimuli)
3049
-            inhibitors <- colnames(CNOlist@inhibitors)
3050
-            signals <- colnames(CNOlist@signals[[1]])
3054
+            stimuli <- colnames(getStimuli(CNOlist))
3055
+            inhibitors <- colnames(getInhibitors(CNOlist))
3056
+            signals <- colnames(getSignals(CNOlist)[[1]])
3051 3057
             step.count <- 0
3052 3058
             row <- i
3053 3059
             new <- FALSE
... ...
@@ -3068,7 +3074,6 @@ localSearch <-
3068 3074
                         new <- TRUE
3069 3075
                     }
3070 3076
                 }
3071
-                print(safeNumber)
3072 3077
             }
3073 3078
             fullScore <- computeScoreNemT1(CNOlist=CNOlist, model=model,
3074 3079
                                            bString=bitString, sizeFac=sizeFac,
... ...
@@ -3078,14 +3083,14 @@ localSearch <-
3078 3083
                                            relFit = relFit, method = method,
3079 3084
                                            ...)
3080 3085
             if (verbose) {
3081
-                print(paste("Seed Network ", row, "/", n, sep = ""))
3086
+                message("Seed Network ", row, "/", n)
3082 3087
                 if (!(verbose2 %in% "part")) {
3083
-                    print(toString(bitString))
3088
+                    message(toString(bitString))
3084 3089
                 }
3085
-                print(paste(" - Score: ", fullScore, sep = ""))
3086
-                print("--------------------------------------------------")
3090
+                message(" - Score: ", fullScore)
3091
+                message("--------------------------------------------------")
3087 3092
                 if (any(bitString != 0) & draw) {
3088
-                    plotDnf(model$reacID[which(bitString == 1)],
3093
+                    plotDnf(model$reacID[bitString == 1],
3089 3094
                             CNOlist = CNOlist)
3090 3095
                 }
3091 3096
             }
... ...
@@ -3154,8 +3159,7 @@ localSearch <-
3154 3159
                                 length(
3155 3160
                                     unlist(
3156 3161
                                         strsplit(
3157
-                                            model$reacID[
3158
-                                                      which(bitStringTmp == 1)],
3162
+                                            model$reacID[bitStringTmp == 1],
3159 3163
                                             "\\+")))
3160 3164
                             return(c(computeScoreNemT1(CNOlist=CNOlist,
3161 3165
                                                        model=model,
... ...
@@ -3187,7 +3191,7 @@ localSearch <-
3187 3191
                 }
3188 3192
                 edge.matrix <- as.matrix(seq_len(bLength))
3189 3193
                 if (sum(prior != 0) > 0) {
3190
-                    edge.matrix <- as.matrix(edge.matrix[-which(prior != 0), ])
3194
+                    edge.matrix <- as.matrix(edge.matrix[!prior != 0, ])
3191 3195
                 }
3192 3196
                 if (parallel2 == 1 & !is.null(parallel)) {
3193 3197
                     scores <- sfApply(edge.matrix, 1, scoreThem, CNOlist, model,
... ...
@@ -3208,11 +3212,11 @@ localSearch <-
3208 3212
                     size <-
3209 3213
                         length(
3210 3214
                             unlist(
3211
-                                strsplit(model$reacID[which(bitString == 1)],
3215
+                                strsplit(model$reacID[bitString == 1],
3212 3216
                                          "\\+")))
3213 3217
                     check.size <- FALSE
3214 3218
                     if (any(scores == score) & all(scores >= score)) {
3215
-                        if (any(sizes[which(scores == score)] < size)) {
3219
+                        if (any(sizes[scores == score] < size)) {
3216 3220
                             check.size <- TRUE
3217 3221
                         }
3218 3222
                     }
... ...
@@ -3222,8 +3226,8 @@ localSearch <-
3222 3226
                 if (sum(prior != 0) > 0) {
3223 3227
                     scores.tmp <- scores
3224 3228
                     scores <- numeric(length(model$reacID))
3225
-                    scores[which(prior == 0)] <- scores.tmp
3226
-                    scores[which(prior != 0)] <- Inf
3229
+                    scores[prior == 0] <- scores.tmp
3230
+                    scores[prior != 0] <- Inf
3227 3231
                 }
3228 3232
                 timePassed <- as.numeric(Sys.time() - timeMark, unit = "secs")
3229 3233
                 if (sum(scores < score) > 0 | check.size) {
... ...
@@ -3235,7 +3239,7 @@ localSearch <-
3235 3239
                         minPvalue <- min(topPvalues)
3236 3240
                         topGate <- which(topPvalues == minPvalue)
3237 3241
                         topGate <- topGate[which(sizes[topGate] ==
3238
-                                                 min(sizes[topGate]))[1]]
3242
+                                                     min(sizes[topGate]))[1]]
3239 3243
                         topScore <- topScores[topGate]
3240 3244
                         whichGate <- which(sizes < size & scores == score)[1]
3241 3245
                         bitStringTmp <- bitString
... ...
@@ -3253,13 +3257,13 @@ localSearch <-
3253 3257
                                 if (bitStringTmp[whichGate] == 0 &
3254 3258
                                     length(deleted) > 1) {
3255 3259
                                     deleted <-
3256
-                                        deleted[-which(deleted == whichGate)]
3260
+                                        deleted[!deleted == whichGate]
3257 3261
                                 }
3258
-                                print(paste("Edges changed: ", edges, sep = ""))
3259
-                                print(paste("Deleted gates due to inverse ",
3260
-                                            "absorption: ",
3261
-                                            paste(model$reacID[deleted],
3262
-                                                  collapse = ", "), sep = ""))
3262
+                                message("Edges changed: ", edges)
3263
+                                message("Deleted gates due to inverse ",
3264
+                                        "absorption: ",
3265
+                                        paste(model$reacID[deleted],
3266
+                                              collapse = ", "))
3263 3267
                             }
3264 3268
                         } else {
3265 3269
                             bitStringTmp2 <- bitString
... ...
@@ -3271,10 +3275,10 @@ localSearch <-
3271 3275
                             if (verbose & (length(deleted) > 1 |
3272 3276
                                            (length(deleted) > 0 &
3273 3277
                                             bitString[whichGate] == 1))) {
3274
-                                print(paste("Edges changed: ", edges, sep = ""))
3275
-                                print(paste("Deleted gates due to absorption: ",
3276
-                                            paste(model$reacID[deleted],
3277
-                                                  collapse = ", "), sep = ""))
3278
+                                message("Edges changed: ", edges)
3279
+                                message("Deleted gates due to absorption: ",
3280
+                                        paste(model$reacID[deleted],
3281
+                                              collapse = ", "))
3278 3282
                             }
3279 3283
                         }
3280 3284
                         bitStringsMem <- rbind(bitStringsMem, bitString)
... ...
@@ -3284,29 +3288,29 @@ localSearch <-
3284 3288
                         }
3285 3289
                         if (verbose) {
3286 3290
                             counter <- counter + 1
3287
-                            print(paste("Iter step: ", counter, sep = ""))
3291
+                            message("Iter step: ", counter)
3288 3292
                             if (bitString[whichGate] == 1) {
3289
-                                print(paste("Added gate ",
3290
-                                            model$reacID[whichGate], sep = ""))
3293
+                                message("Added gate ",
3294
+                                        model$reacID[whichGate])
3291 3295
                             } else {
3292
-                                print(paste("Deleted gate ",
3293
-                                            model$reacID[whichGate], sep = ""))
3296
+                                message("Deleted gate ",
3297
+                                        model$reacID[whichGate])
3294 3298
                             }
3295 3299
                             if (!(verbose2 %in% "part")) {
3296
-                                print(toString(bitString))
3300
+                                message(toString(bitString))
3297 3301
                             }
3298
-                            print(paste(" - Score: ", topScore, sep = ""))
3299
-                            print(paste(" - Iter_time: ", timePassed, " @ ",
3300
-                                        Sys.time(), sep = ""))
3301
-                            print("-----------------------------------")
3302
+                            message(" - Score: ", topScore)
3303
+                            message(" - Iter_time: ", timePassed, " @ ",
3304
+                                    Sys.time())
3305
+                            message("-----------------------------------")
3302 3306
                             if (any(bitString != 0) & draw) {
3303
-                                plotDnf(model$reacID[which(bitString == 1)],
3307
+                                plotDnf(model$reacID[bitString == 1],
3304 3308
                                         CNOlist = CNOlist)
3305 3309
                             }
3306 3310
                         }
3307 3311
                         step.count <- step.count + 1
3308 3312
                         if (step.count >= max.steps) {
3309
-                            if (verbose) print("no more steps")
3313
+                            if (verbose) message("no more steps")
3310 3314
                             stop <- TRUE
3311 3315
                         }
3312 3316
                     } else {
... ...
@@ -3334,13 +3338,13 @@ localSearch <-
3334 3338
                                 if (bitStringTmp[whichGate] == 0 &
3335 3339
                                     length(deleted) > 1) {
3336 3340
                                     deleted <-
3337
-                                        deleted[-which(deleted == whichGate)]
3341
+                                        deleted[!deleted == whichGate]
3338 3342
                                 }
3339
-                                print(paste("Edges changed: ", edges, sep = ""))
3340
-                                print(paste("Deleted gates due to inverse ",
3341
-                                            "absorption: ",
3342
-                                            paste(model$reacID[deleted],
3343
-                                                  collapse = ", "), sep = ""))
3343
+                                message("Edges changed: ", edges)
3344
+                                message("Deleted gates due to inverse ",
3345
+                                        "absorption: ",
3346
+                                        paste(model$reacID[deleted],
3347
+                                              collapse = ", "))
3344 3348
                             }
3345 3349
                         } else {
3346 3350
                             bitStringTmp2 <- bitString
... ...
@@ -3352,10 +3356,10 @@ localSearch <-
3352 3356
                             if (verbose & (length(deleted) > 1 |
3353 3357
                                            (length(deleted) > 0 &
3354 3358
                                             bitString[whichGate] == 1))) {
3355
-                                print(paste("Edges changed: ", edges, sep = ""))
3356
-                                print(paste("Deleted gates due to absorption: ",
3357
-                                            paste(model$reacID[deleted],
3358
-                                                  collapse = ", "), sep = ""))
3359
+                                message("Edges changed: ", edges)
3360
+                                message("Deleted gates due to absorption: ",
3361
+                                        paste(model$reacID[deleted],
3362
+                                              collapse = ", "))
3359 3363
                             }
3360 3364
                         }
3361 3365
                         bitStringsMem <- rbind(bitStringsMem, bitString)
... ...
@@ -3365,47 +3369,47 @@ localSearch <-
3365 3369
                         }
3366 3370
                         if (verbose) {
3367 3371
                             counter <- counter + 1
3368
-                            print(paste("Iter step: ", counter, sep = ""))
3372
+                            message("Iter step: ", counter)
3369 3373
                             if (bitString[whichGate] == 1) {
3370
-                                print(paste("Added gate ",
3371
-                                            model$reacID[whichGate], sep = ""))
3374
+                                message("Added gate ",
3375
+                                        model$reacID[whichGate])
3372 3376
                                 if (!(verbose2 %in% "part")) {
3373
-                                    print(toString(bitString))
3377
+                                    message(toString(bitString))
3374 3378
                                 }
3375
-                                print(paste(" - Score: ", topScore, sep = ""))
3376
-                                print(paste(" - Iter_time: ", timePassed, " @ ",
3377
-                                            Sys.time(), sep = ""))
3378
-                                print("---------------------------------------
3379
+                                message(" - Score: ", topScore)
3380
+                                message(" - Iter_time: ", timePassed, " @ ",
3381
+                                        Sys.time())
3382
+                                message("---------------------------------------
3379 3383
 -----------")
3380 3384
                             } else {
3381
-                                print(paste("Deleted gate ",
3382
-                                            model$reacID[whichGate], sep = ""))
3385
+                                message("Deleted gate ",
3386
+                                        model$reacID[whichGate])
3383 3387
                                 if (!(verbose2 %in% "part")) {
3384
-                                    print(toString(bitString))
3388
+                                    message(toString(bitString))
3385 3389
                                 }
3386
-                                print(paste(" - Score: ", topScore, sep = ""))
3387
-                                print(paste(" - Iter_time: ", timePassed, " @ ",
3388
-                                            Sys.time(), sep = ""))
3389
-                                print("---------------------------------------
3390
+                                message(" - Score: ", topScore)
3391
+                                message(" - Iter_time: ", timePassed, " @ ",
3392
+                                        Sys.time())
3393
+                                message("---------------------------------------
3390 3394
 -----------")
3391 3395
                             }
3392 3396
                             if (any(bitString != 0) & draw) {
3393
-                                plotDnf(model$reacID[which(bitString == 1)],
3397
+                                plotDnf(model$reacID[bitString == 1],
3394 3398
                                         CNOlist = CNOlist)
3395 3399
                             }
3396 3400
                         }
3397 3401
                         step.count <- step.count + 1
3398 3402
                         if (step.count >= max.steps) {
3399
-                            if (verbose) print("no more steps")
3403
+                            if (verbose) message("no more steps")
3400 3404
                             stop <- TRUE
3401 3405
                         }
3402 3406
                     }
3403 3407
                 } else {
3404
-                    if (verbose) print("no further improvement")
3408
+                    if (verbose) message("no further improvement")
3405 3409
                     stop <- TRUE
3406 3410
                 }
3407 3411
                 if (Sys.time() - start.time > max.time) {
3408
-                    if (verbose) print("no more time")
3412
+                    if (verbose) message("no more time")
3409 3413
                     stop <- TRUE
3410 3414
                 }
3411 3415
             }
... ...
@@ -3451,11 +3455,6 @@ makeDesignFull <-
3451 3455
              method = "raw") {
3452 3456
         design0 <- makeDesign(x, stimuli, inhibitors, c(batches, runs))
3453 3457
         design <- design0
3454
-
3455
-        ctrlsSum <- apply(design[, -grep(paste(c(runs, batches),
3456
-                                               collapse = "|"),
3457
-                                         colnames(design))], 1, sum)
3458
-        ctrlsSum <- which(ctrlsSum == 0)
3459 3458
         stimuliDesign <- design[, grep(paste(stimuli, collapse = "|"),
3460 3459
                                        colnames(design))]
3461 3460
         inhibitorsDesign <- design[, grep(paste(inhibitors, collapse = "|"),
... ...
@@ -3478,7 +3477,7 @@ makeDesignFull <-
3478 3477
             if (length(stimuli) == 1) {
3479 3478
                 stimuliSum <- stimuliDesign
3480 3479
             } else {
3481
-                stimuliSum <- apply(stimuliDesign, 1, sum)
3480
+                stimuliSum <- rowSums(stimuliDesign)
3482 3481
             }
3483 3482
         }
3484 3483
         if (is.null(inhibitors) == TRUE) {
... ...
@@ -3487,16 +3486,16 @@ makeDesignFull <-
3487 3486
             if (length(inhibitors) == 1) {
3488 3487
                 inhibitorsSum <- inhibitorsDesign
3489 3488
             } else {
3490
-                inhibitorsSum <- apply(inhibitorsDesign, 1, sum)
3489
+                inhibitorsSum <- rowSums(inhibitorsDesign)
3491 3490
             }
3492 3491
         }
3493
-        cuesSum <- apply(design[, grep(paste(c(stimuli, inhibitors),
3494
-                                             collapse = "|"),
3495
-                                       colnames(design))], 1, sum)
3492
+        cuesSum <- rowSums(design[, grep(paste(c(stimuli, inhibitors),
3493
+                                               collapse = "|"),
3494
+                                         colnames(design))])
3496 3495
         maxStim <- max(stimuliSum)
3497 3496
         maxKd <- max(inhibitorsSum)
3498 3497
         maxCue <- max(cuesSum)
3499
-
3498
+        
3500 3499
         grepCtrl <- which(cuesSum == 0)
3501 3500
         grepStims <- intersect(which(stimuliSum != 0),
3502 3501
                                which(inhibitorsSum == 0))
... ...
@@ -3504,50 +3503,50 @@ makeDesignFull <-
3504 3503
                              which(inhibitorsSum != 0))
3505 3504
         grepStimsKds <- intersect(which(stimuliSum != 0),
3506 3505
                                   which(inhibitorsSum != 0))
3507
-
3506
+        
3508 3507
         design <- numeric()
3509 3508
         designNames <- character()
3510 3509
         design <- rep(0, ncol(x))
3511 3510
         design[grepCtrl] <- 1
3512 3511
         designNames <- "Ctrl"
3513
-
3512
+        
3514 3513
         for (i in grepStims) {
3515 3514
             stimNames <- paste(sort(names(which(stimuliDesign[i, ] >= 1))),
3516 3515
                                collapse = "_")
3517 3516
             if (stimNames %in% designNames) {
3518
-                design[i, which(designNames %in% stimNames)] <- 1
3517
+                design[i, designNames %in% stimNames] <- 1
3519 3518
             } else {
3520 3519
                 design <- cbind(design, rep(0, ncol(x)))
3521 3520
                 designNames <- c(designNames, stimNames)
3522
-                design[i, which(designNames %in% stimNames)] <- 1
3521
+                design[i, designNames %in% stimNames] <- 1
3523 3522
             }
3524 3523
         }
3525
-
3524
+        
3526 3525
         for (i in grepKds) {
3527 3526
             stimNames <- paste(sort(names(which(inhibitorsDesign[i, ] >= 1))),
3528 3527
                                collapse = "_")
3529 3528
             if (stimNames %in% designNames) {
3530
-                design[i, which(designNames %in% stimNames)] <- 1
3529
+                design[i, designNames %in% stimNames] <- 1
3531 3530
             } else {
3532 3531
                 design <- cbind(design, rep(0, ncol(x)))
3533 3532
                 designNames <- c(designNames, stimNames)
3534
-                design[i, which(designNames %in% stimNames)] <- 1
3533
+                design[i, designNames %in% stimNames] <- 1
3535 3534
             }
3536 3535
         }
3537
-
3536
+        
3538 3537
         for (i in grepStimsKds) {
3539 3538
             stimNames <- paste(c(sort(names(which(inhibitorsDesign[i, ] >= 1))),
3540 3539
                                  sort(names(which(stimuliDesign[i, ] >= 1)))),
3541 3540
                                collapse = "_")
3542 3541
             if (stimNames %in% designNames) {
3543
-                design[i, which(designNames %in% stimNames)] <- 1
3542
+                design[i, designNames %in% stimNames] <- 1
3544 3543
             } else {
3545 3544
                 design <- cbind(design, rep(0, ncol(x)))
3546 3545
                 designNames <- c(designNames, stimNames)
3547
-                design[i, which(designNames %in% stimNames)] <- 1
3546
+                design[i, designNames %in% stimNames] <- 1
3548 3547
             }
3549 3548
         }
3550
-
3549
+        
3551 3550
         if (!is.null(batches))  {
3552 3551
             for (i in batches) {
3553 3552
                 if (!is.null(runs)) {
... ...
@@ -3589,112 +3588,6 @@ makeDesign <-
3589 3588
         return(design)
3590 3589
     }
3591 3590
 #' @noRd
3592
-#' @import snowfall
3593
-myGsea <-
3594
-    function(testList, goList, parallel = NULL, adjust.method = "FDR",
3595
-             conservative = TRUE) {
3596
-        if (!is.null(parallel)) {
3597
-            if (is.list(parallel)) {
3598
-                if (length(parallel[[1]]) != length(parallel[[2]])) {
3599
-                    stop("The nodes (second list object in parallel) and the
3600
-number of cores used on every node (first list object in parallel) must be
3601
-the same.") }
3602
-                hosts <- character()
3603
-                for (i in seq_len(length(parallel[[1]]))) {
3604
-                    hosts <- c(hosts, rep(parallel[[2]][i], parallel[[1]][i]))
3605
-                }
3606
-                hosts <- as.list(hosts)
3607
-                sfInit(parallel=TRUE, socketHosts=hosts)
3608
-            } else {
3609
-                sfInit(parallel=TRUE, cpus=parallel)
3610
-            }
3611
-            sfExport("testList", "goList")
3612
-        }
3613
-
3614
-        startTime <- Sys.time()
3615
-
3616
-        if (conservative) {
3617
-            Complete <- unique(intersect(unlist(testList),unlist(goList)))
3618
-        } else {
3619
-            Complete <- unique(c(unlist(testList),unlist(goList)))
3620
-        }
3621
-        N <- length(Complete)
3622
-
3623
-        checkGeneCluster <- function(j,i) {
3624
-
3625
-            resDf <- data.frame()
3626
-            genelist <- unique(intersect(testList[[i]],Complete))
3627
-
3628
-            if (!is.null(genelist)) {
3629
-                targetlist <- intersect(goList[[j]],Complete)
3630
-                n <- length(targetlist)
3631
-                D <- length(genelist)
3632
-                AinB <- length(intersect(targetlist, genelist))
3633
-                fisherMat <- cbind(c(AinB,D-AinB),c(n-AinB,N-n-D+AinB))
3634
-                fisherTest <- fisher.test(fisherMat, alternative = "greater")
3635
-                ABpval <- fisherTest$p.value
3636
-                resDf <- rbind(resDf, data.frame(test = names(testList)[i],
3637
-                                                 go = names(goList)[j],
3638
-                                                 pval = ABpval, overlap = AinB,
3639
-                                                 targetset = n, testset = D))
3640
-            }
3641
-
3642
-            return(resDf)
3643
-        }
3644
-
3645
-        dfList <- NULL
3646
-        if (is.null(parallel)) {
3647
-            for (i in seq_len(length(testList))) {
3648
-                cat(".")
3649
-                dfList <- c(dfList, lapply(seq_len(length(goList)),
3650
-                                           checkGeneCluster, i))
3651
-            }
3652
-        } else {
3653
-            for (i in seq_len(length(testList))) {
3654
-                dfList <- c(dfList, sfLapply(seq_len(length(goList)),
3655
-                                             checkGeneCluster, i))
3656
-            }
3657
-        }
3658
-
3659
-        cat("\n")
3660
-        print(Sys.time() - startTime)
3661
-        print("all hypergeometric tests (=fisher tests with 'greater')
3662
- completed...")
3663
-        print("preparing data...")
3664
-
3665
-        bigDf <- do.call("rbind", dfList)
3666
-
3667
-        bigDf <- bigDf[order(bigDf[, 3]), ]
3668
-
3669
-        if (adjust.method %in% "FDR") {
3670
-
3671
-            qvals <- (nrow(bigDf)*bigDf[, 3])/(seq_len(nrow(bigDf)))
3672
-
3673
-            for (i in (length(qvals)-1):1) {
3674
-
3675
-                qvals[i] <- min(qvals[i], qvals[i+1])
3676
-
3677
-            }
3678
-
3679
-            qvals[which(qvals > 1)] <- 1
3680
-
3681
-        } else {
3682
-
3683
-            qvals <- p.adjust(bigDf[, 3], method = adjust.method)
3684
-
3685
-        }
3686
-
3687
-        bigDf <- cbind(bigDf, qvals = qvals)
3688
-
3689
-        bigDf <- bigDf[order(bigDf[, 7]), ]
3690
-
3691
-        if (!is.null(parallel)) {
3692
-            sfStop()
3693
-        }
3694
-
3695
-        return(bigDf)
3696
-    }
3697
-#' @noRd
3698 3591
 #' @import cluster
3699 3592
 pamNorm <-
3700 3593
     function(x, method = "euclidean") {
... ...
@@ -3704,21 +3597,21 @@ pamNorm <-
3704 3597
                 clust.nums <- clust$clustering
3705 3598
                 dist <- dist(x[i, ], method = method)
3706 3599
                 sil <- silhouette(clust.nums, dist=dist)
3707
-                max <- which(x[i, ] == max(x[i, ]))
3708
-                cluster.one <- sil[max, 1]
3600
+                cluster.one <- sil[x[i, ] == max(x[i, ]), 1]
3709 3601
                 cluster.zero <- c(1,2)[-cluster.one]
3710
-                min <- which(x[i, ] == min(x[i, ]))
3711
-                sil[which(sil[, 1] == cluster.zero), 3] <-
3712
-                    sil[which(sil[, 1] == cluster.zero), 3]*(-1)
3602
+                sil[sil[, 1] == cluster.zero, 3] <-
3603
+                    sil[sil[, 1] == cluster.zero, 3]*(-1)
3713 3604
                 sil[, 3] <- (sil[, 3] + 1)/2
3714
-                sil[which(x[i, ] >= x[i, which(sil[, 3] ==
3715
-                                               max(sil[, 3]))[1]]), 3] <-
3605
+                sil[x[i, ] >= x[i, which(sil[, 3] ==
3606
+                                             max(sil[, 3]))[1]], 3] <-
3716 3607
                     sil[which(x[i, ] == x[i, which(sil[, 3] ==
3717
-                                                   max(sil[, 3]))[1]])[1], 3]
3718
-                sil[which(x[i, ] <= x[i, which(sil[, 3] ==
3719
-                                               min(sil[, 3]))[1]]), 3] <-
3608
+                                                       max(sil[, 3]))[1]])[1],
3609
+                        3]
3610
+                sil[x[i, ] <= x[i, which(sil[, 3] ==
3611
+                                             min(sil[, 3]))[1]], 3] <-
3720 3612
                     sil[which(x[i, ] == x[i, which(sil[, 3] ==
3721
-                                                   min(sil[, 3]))[1]])[1], 3]
3613
+                                                       min(sil[, 3]))[1]])[1],
3614
+                        3]
3722 3615
                 sil[, 3] <- sil[, 3] - min(sil[, 3])
3723 3616
                 sil[, 3] <- sil[, 3]/max(sil[, 3])
3724 3617
                 x[i, ] <- sil[, 3]
... ...
@@ -3728,16 +3621,14 @@ pamNorm <-
3728 3621
             clust.nums <- clust$clustering
3729 3622
             dist <- dist(x, method = method)
3730 3623
             sil <- silhouette(clust.nums, dist=dist)
3731
-            max <- which(x == max(x))
3732
-            cluster.one <- sil[max, 1]
3624
+            cluster.one <- sil[x == max(x), 1]
3733 3625
             cluster.zero <- c(1,2)[-cluster.one]
3734
-            min <- which(x == min(x))
3735
-            sil[which(sil[, 1] == cluster.zero), 3] <-
3736
-                sil[which(sil[, 1] == cluster.zero), 3]*(-1)
3626
+            sil[sil[, 1] == cluster.zero, 3] <-
3627
+                sil[sil[, 1] == cluster.zero, 3]*(-1)
3737 3628
             sil[, 3] <- (sil[, 3] + 1)/2
3738
-            sil[which(x >= x[which(sil[, 3] == max(sil[, 3]))[1]]), 3] <-
3629
+            sil[x >= x[which(sil[, 3] == max(sil[, 3]))[1]], 3] <-
3739 3630
                 sil[which(x == x[which(sil[, 3] == max(sil[, 3]))[1]])[1], 3]
3740
-            sil[which(x <= x[which(sil[, 3] == min(sil[, 3]))[1]]), 3] <-
3631
+            sil[x <= x[which(sil[, 3] == min(sil[, 3]))[1]], 3] <-
3741 3632
                 sil[which(x == x[which(sil[, 3] == min(sil[, 3]))[1]])[1], 3]
3742 3633
             sil[, 3] <- sil[, 3] - min(sil[, 3])
3743 3634
             sil[, 3] <- sil[, 3]/max(sil[, 3])
... ...
@@ -3750,14 +3641,14 @@ removeCycles <-
3750 3641
     function(bString, model, dnf = NULL) {
3751 3642
         if (is.null(dnf)) {
3752 3643
             if (any(bString != 0)) {
3753
-                graph <- model$reacID[which(bString == 1)]
3644
+                graph <- model$reacID[bString == 1]
3754 3645
                 adjmat <- abs(dnf2adj(graph))
3755
-                get.order <- apply(adjmat, 2, sum)
3646
+                get.order <- colSums(adjmat)
3756 3647
                 adjmat <- adjmat[order(get.order), order(get.order)]
3757 3648
                 cycles <- which(lower.tri(adjmat) == TRUE & adjmat == 1,
3758 3649
                                 arr.ind = TRUE)
3759 3650
                 while(any(adjmat[lower.tri(adjmat)] == 1) &
3760
-                      dim(cycles)[1] > 0) {
3651
+                      nrow(cycles) > 0) {
3761 3652
                     for (i in seq_len(nrow(cycles))) {
3762 3653
                         bad.cycles <-
3763 3654
                             grep(paste(".*", rownames(adjmat)[cycles[i, 1]],
... ...
@@ -3766,12 +3657,12 @@ removeCycles <-
3766 3657
                         if (length(bad.cycles) > 0 &
3767 3658
                             any(bString[bad.cycles] == 1)) {
3768 3659
                             bString[bad.cycles] <- 0
3769
-                            graph <- model$reacID[which(bString == 1)]
3660
+                            graph <- model$reacID[bString == 1]
3770 3661
                             break()
3771 3662
                         }
3772 3663
                     }
3773 3664
                     adjmat <- abs(dnf2adj(graph))
3774
-                    get.order <- apply(adjmat, 2, sum)
3665
+                    get.order <- colSums(adjmat)
3775 3666
                     adjmat <- adjmat[order(get.order), order(get.order)]
3776 3667
                     cycles <- which(lower.tri(adjmat) == TRUE & adjmat == 1,
3777 3668
                                     arr.ind = TRUE)
... ...
@@ -3783,11 +3674,11 @@ removeCycles <-
3783 3674
         } else {
3784 3675
             graph <- dnf
3785 3676
             adjmat <- abs(dnf2adj(graph))
3786
-            get.order <- apply(adjmat, 2, sum)
3677
+            get.order <- colSums(adjmat)
3787 3678
             adjmat <- adjmat[order(get.order), order(get.order)]
3788 3679
             cycles <- which(lower.tri(adjmat) == TRUE & adjmat == 1,
3789 3680
                             arr.ind = TRUE)
3790
-            while(any(adjmat[lower.tri(adjmat)] == 1) & dim(cycles)[1] > 0) {
3681
+            while(any(adjmat[lower.tri(adjmat)] == 1) & nrow(cycles) > 0) {
3791 3682
                 for (i in seq_len(nrow(cycles))) {
3792 3683
                     bad.cycles <-
3793 3684
                         grep(paste(".*",
... ...
@@ -3801,7 +3692,7 @@ removeCycles <-
3801 3692
                     }
3802 3693
                 }
3803 3694
                 adjmat <- abs(dnf2adj(graph))
3804
-                get.order <- apply(adjmat, 2, sum)
3695
+                get.order <- colSums(adjmat)
3805 3696
                 adjmat <- adjmat[order(get.order), order(get.order)]
3806 3697
                 cycles <- which(lower.tri(adjmat) == TRUE & adjmat == 1,
3807 3698
                                 arr.ind = TRUE)
... ...
@@ -3818,9 +3709,9 @@ simpleNorm <-
3818 3709
             genes.max <- max(x)
3819 3710
             x <- x/genes.max
3820 3711
         } else {
3821
-            genes.min <- apply(x, 1, min)
3712
+            genes.min <- rowMins(x)
3822 3713
             x <- (x - genes.min)
3823
-            genes.max <- apply(x, 1, max)
3714
+            genes.max <- rowMaxs(x)
3824 3715
             x <- x/genes.max
3825 3716
         }
3826 3717
         x[is.na(x)] <- 0
... ...
@@ -3862,21 +3753,24 @@ simulateDnf <-
3862 3753
                                                 graph = subGraph,
3863 3754
                                                 children = NULL)
3864 3755
                                 if (
3865
-                                (length(
3866
-                                    grep(
3867
-                                        "!",
3868
-                                        children[which(children2 %in%
3869
-                                                       j2):
3870
-                                                 length(
3871
-                                                     children2)]))+add1)/2 !=
3872
-                                ceiling(
3873
-                                (
3874
-                                    length(
3875
-                                        grep("!",
3876
-                                             children[which(children2 %in%
3877
-                                                            j2):
3878
-                                                      length(children2)]))+
3879
-                                    add1)/2)) {
3756
+                                    (length(
3757
+                                        grep(
3758
+                                            "!",
3759
+                                            children[which(children2 %in%
3760
+                                                           j2):
3761
+                                                     length(
3762
+                                                         children2)]))+add1)/2
3763
+                                    !=
3764
+                                    ceiling(
3765
+                                        (
3766
+                                            length(
3767
+                                                grep("!",
3768
+                                                     children[which(children2
3769
+                                                                    %in%
3770
+                                                                    j2):
3771
+                                                              length(children2)]
3772
+                                                     ))+
3773
+                                            add1)/2)) {
3880 3774
                                     ## negative feedback loop calculation does
3881 3775
                                     ## not seem to be general enough and also
3882 3776
                                     ## not feasible:
... ...
@@ -3938,7 +3832,7 @@ simulateDnf <-
3938 3832
         rownames(signalStates) <- paste(c("stimuli:", stimuli, "inhibitors:",
3939 3833
                                           inhibitors), collapse = " ")
3940 3834
         colnames(signalStates) <- signals
3941
-        signalStates[which(signals %in% stimuli)] <- 1
3835
+        signalStates[signals %in% stimuli] <- 1
3942 3836
         for (k in signals) {
3943 3837
             if (is.na(signalStates[, k]) == TRUE) {
3944 3838
                 signalStates <- getStateDnf(node = k,
... ...
@@ -3961,8 +3855,8 @@ simulateStatesRecursiveAdd <-
3961 3855
                                 children = NULL, NEMlist = NULL) {
3962 3856
             graphCut <- graph[grep(paste("=", node, sep = ""), graph)]
3963 3857
             if (length(graphCut) == 0) {
3964
-                if (node %in% colnames(CNOlist@inhibitors)) {
3965
-                    signalStates[, node] <- 0 - CNOlist@inhibitors[, node]
3858
+                if (node %in% colnames(getInhibitors(CNOlist))) {
3859
+                    signalStates[, node] <- 0 - getInhibitors(CNOlist)[, node]
3966 3860
                 } else {
3967 3861
                     signalStates[, node] <- 0
3968 3862
                 }
... ...
@@ -3985,23 +3879,24 @@ simulateStatesRecursiveAdd <-
3985 3879
                                     add1 <- 1
3986 3880
                                 }
3987 3881
                                 if (
3988
-                                (length(
3989
-                                    grep(
3990
-                                        "!",
3991
-                                        children[
3992
-                                            which(
3993
-                                                children2 %in%
3994
-                                                j2):length(children2)]))+
3995
-                                 add1)/2 !=
3996
-                                ceiling((
3997
-                                    length(
3882
+                                    (length(
3998 3883
                                         grep(
3999 3884
                                             "!",
4000 3885
                                             children[
4001 3886
                                                 which(
4002
-                                                    children2 %in% j2):
4003
-                                                length(
4004
-                                                    children2)]))+add1)/2)) {
3887
+                                                    children2 %in%
3888
+                                                    j2):length(children2)]))+
3889
+                                     add1)/2 !=
3890
+                                    ceiling((
3891
+                                        length(
3892
+                                            grep(
3893
+                                                "!",
3894
+                                                children[
3895
+                                                    which(
3896
+                                                        children2 %in% j2):
3897
+                                                    length(
3898
+                                                        children2)]))+add1)/2)
3899
+                                    ) {
4005 3900
                                     subGraph <-
4006 3901
                                         graph[
4007 3902
                                             -grep(paste(".*",
... ...
@@ -4019,7 +3914,7 @@ simulateStatesRecursiveAdd <-
4019 3914
                                     pobMult <- subResult[, node]
4020 3915
                                     subResult <- signalStates
4021 3916
                                     subResult[, node] <- pobMult
4022
-                                    subGraph2 <- graph[-which(graph %in% i)]
3917
+                                    subGraph2 <- graph[!graph %in% i]
4023 3918
                                     subResult2 <-
4024 3919
                                         getStateAdd(CNOlist = CNOlist,
4025 3920
                                                     node = j2,
... ...
@@ -4032,40 +3927,40 @@ simulateStatesRecursiveAdd <-
4032 3927
                                         pobMult2 <- add1 - subResult2[, j2]
4033 3928
                                     }
4034 3929
                                     pobMult2[pobMult2 == 2] <- 1
4035
-
3930
+                                    
4036 3931
                                     pobNA <- numeric(length(pob))
4037 3932
                                     pobNA[is.na(pob)] <- 1
4038 3933
                                     pobNA[is.na(pobMult)] <- 1
4039
-                                    pobNA[which(pobMult != pobMult2)] <- 1
3934
+                                    pobNA[pobMult != pobMult2] <- 1
4040 3935
                                     pobMult[is.na(pobMult)] <- 1
4041
-                                    pobMult[which(pobMult != pobMult2)] <- 1
3936
+                                    pobMult[pobMult != pobMult2] <- 1
4042 3937
                                     pob[is.na(pob)] <- 1
4043
-
3938
+                                    
4044 3939
                                     ##pobMult[pobMult == -1] <- 0
4045 3940
                                     pob <- rowMin(cbind(pob,pobMult))
4046
-
4047
-                                    pobNA[which(pob == 0)] <- 0
4048
-                                    pob[which(pobNA > 0)] <- NA
3941
+                                    
3942
+                                    pobNA[pob == 0] <- 0
3943
+                                    pob[pobNA > 0] <- NA
4049 3944
                                 } else {
4050 3945
                                     signalStatesTemp <- signalStates
4051 3946
                                     if (!(j %in% j2)) {
4052 3947
                                         if (j2 %in%
4053
-                                            colnames(CNOlist@inhibitors)) {
3948
+                                            colnames(getInhibitors(CNOlist))) {
4054 3949
                                             signalStatesTemp[, node] <-
4055
-                                                1 - CNOlist@inhibitors[, j2]
3950
+                                                1 - getInhibitors(CNOlist)[, j2]
4056 3951
                                         } else {
4057 3952
                                             signalStatesTemp[, node] <- 1
4058 3953
                                         }
4059 3954
                                     } else {
4060 3955
                                         if (j2 %in%
4061
-                                            colnames(CNOlist@inhibitors)) {
3956
+                                            colnames(getInhibitors(CNOlist))) {
4062 3957
                                             signalStatesTemp[, node] <-
4063
-                                                0 - CNOlist@inhibitors[, j2]
3958
+                                                0 - getInhibitors(CNOlist)[, j2]
4064 3959
                                         } else {
4065 3960
                                             signalStatesTemp[, node] <- 0
4066 3961
                                         }
4067 3962
                                     }
4068
-                                    subGraph <- graph[-which(graph %in% i)]
3963
+                                    subGraph <- graph[!graph %in% i]
4069 3964
                                     subResult <-
4070 3965
                                         getStateAdd(CNOlist = CNOlist,
4071 3966
                                                     node = j2,
... ...
@@ -4073,25 +3968,25 @@ simulateStatesRecursiveAdd <-
4073 3968
                                                         signalStatesTemp,
4074 3969
                                                     graph = subGraph,
4075 3970
                                                     children = NULL, NEMlist)
4076
-
3971
+                                    
4077 3972
                                     if (add1 == 0) {
4078 3973
                                         pobMult <- subResult[, j2]
4079 3974
                                     } else {
4080 3975
                                         pobMult <- add1 - subResult[, j2]
4081 3976
                                     }
4082 3977
                                     pobMult[pobMult == 2] <- 1
4083
-
3978
+                                    
4084 3979
                                     pobNA <- numeric(length(pob))
4085 3980
                                     pobNA[is.na(pob)] <- 1
4086 3981
                                     pobNA[is.na(pobMult)] <- 1
4087 3982
                                     pobMult[is.na(pobMult)] <- 1
4088 3983
                                     pob[is.na(pob)] <- 1
4089
-
3984
+                                    
4090 3985
                                     ##pobMult[pobMult == -1] <- 0
4091 3986
                                     pob <- rowMin(cbind(pob,pobMult))
4092
-
4093
-                                    pobNA[which(pob == 0)] <- 0
4094
-                                    pob[which(pobNA > 0)] <- NA
3987
+                                    
3988
+                                    pobNA[pob == 0] <- 0
3989
+                                    pob[pobNA > 0] <- NA
4095 3990
                                 }
4096 3991
                             } else {
4097 3992
                                 if (j %in% j2) {
... ...
@@ -4108,25 +4003,25 @@ simulateStatesRecursiveAdd <-
4108 4003
                                                 children =
4109 4004
                                                     unique(c(children, node2)),
4110 4005
                                                 NEMlist)
4111
-
4006
+                                
4112 4007
                                 if (add1 == 0) {
4113 4008
                                     pobMult <- signalStates[, j2]
4114 4009
                                 } else {
4115 4010
                                     pobMult <- add1 - signalStates[, j2]
4116 4011
                                 }
4117 4012
                                 pobMult[pobMult == 2] <- 1
4118
-
4013
+                                
4119 4014
                                 pobNA <- numeric(length(pob))
4120 4015
                                 pobNA[is.na(pob)] <- 1
4121 4016
                                 pobNA[is.na(pobMult)] <- 1
4122 4017
                                 pobMult[is.na(pobMult)] <- 1
4123 4018
                                 pob[is.na(pob)] <- 1
4124
-
4019
+                                
4125 4020
                                 ##pobMult[pobMult == -1] <- 0
4126 4021
                                 pob <- rowMin(cbind(pob,pobMult))
4127
-
4128
-                                pobNA[which(pob == 0)] <- 0
4129
-                                pob[which(pobNA > 0)] <- NA
4022
+                                
4023
+                                pobNA[pob == 0] <- 0
4024
+                                pob[pobNA > 0] <- NA
4130 4025
                             }
4131 4026
                         } else {
4132 4027
                             if (j %in% j2) {
... ...
@@ -4134,23 +4029,23 @@ simulateStatesRecursiveAdd <-
4134 4029
                             } else {
4135 4030
                                 add1 <- 1
4136 4031
                             }
4137
-
4032
+                            
4138 4033
                             if (add1 == 0) {
4139 4034
                                 pobMult <- signalStates[, j2]
4140 4035
                             } else {
4141 4036
                                 pobMult <- add1 - signalStates[, j2]
4142 4037
                             }
4143 4038
                             pobMult[pobMult == 2] <- 1
4144
-
4039
+                            
4145 4040
                             pobNA <- numeric(length(pob))
4146 4041
                             pobNA[is.na(pob)] <- 1
4147 4042
                             pobNA[is.na(pobMult)] <- 1
4148 4043
                             pobMult[is.na(pobMult)] <- 1
4149 4044
                             pob[is.na(pob)] <- 1
4150 4045
                             pob <- rowMin(cbind(pob,pobMult))
4151
-
4152
-                            pobNA[which(pob == 0)] <- 0
4153
-                            pob[which(pobNA > 0)] <- NA
4046
+                            
4047
+                            pobNA[pob == 0] <- 0
4048
+                            pob[pobNA > 0] <- NA
4154 4049
                         }
4155 4050
                         if (max(pob, na.rm = TRUE) == 0) { break() }
4156 4051
                     }
... ...
@@ -4160,36 +4055,36 @@ simulateStatesRecursiveAdd <-
4160 4055
                     pob[is.na(pob)] <- 0
4161 4056
                     sop[is.na(sop)] <- 0
4162 4057
                     sop <- rowMax(cbind(sop,pob))
4163
-                    pobNA[which(sop > 0)] <- 0
4164
-                    sop[which(pobNA > 0)] <- NA
4058
+                    pobNA[sop > 0] <- 0
4059
+                    sop[pobNA > 0] <- NA
4165 4060
                     if (min(sop, na.rm = TRUE) > 0) { break() }
4166 4061
                 }
4167 4062
                 ##sop[sop > 0] <- 1
4168
-                if (node %in% colnames(CNOlist@inhibitors)) {
4169
-                    sop <- sop - CNOlist@inhibitors[, node]
4063
+                if (node %in% colnames(getInhibitors(CNOlist))) {
4064
+                    sop <- sop - getInhibitors(CNOlist)[, node]
4170 4065
                 }
4171
-                if (node %in% colnames(CNOlist@stimuli)) {
4172
-                    sop <- sop + CNOlist@stimuli[, node]
4066
+                if (node %in% colnames(getStimuli(CNOlist))) {
4067
+                    sop <- sop + getStimuli(CNOlist)[, node]
4173 4068
                 }
4174 4069
                 signalStates[, node] <- sop
4175 4070
             }
4176 4071
             return(signalStates)
4177 4072
         }
4178 4073
         bString <- reduceGraph(bString, CNOlist, model)
4179
-        stimuli <- colnames(CNOlist@stimuli)
4074
+        stimuli <- colnames(getStimuli(CNOlist))
4180 4075
         inhibitors <-
4181
-            c(colnames(CNOlist@inhibitors),
4182
-              model$namesSpecies[-which(model$namesSpecies %in%
4183
-                                        c(stimuli,
4184
-                                          colnames(CNOlist@inhibitors)))])
4185
-        graph <- model$reacID[which(bString == 1)]
4186
-        stimuliStates <- CNOlist@stimuli
4076
+            c(colnames(getInhibitors(CNOlist)),
4077
+              model$namesSpecies[!model$namesSpecies %in%
4078
+                                     c(stimuli,
4079
+                                       colnames(getInhibitors(CNOlist)))])
4080
+        graph <- model$reacID[bString == 1]
4081
+        stimuliStates <- getStimuli(CNOlist)
4187 4082
         if (!is.null(NEMlist$signalStates)) {
4188 4083
             signalStates <- NEMlist$signalStates
4189 4084
         } else {
4190
-            signalStates <- matrix(NA, nrow = nrow(CNOlist@signals[[2]]),
4085
+            signalStates <- matrix(NA, nrow = nrow(getSignals(CNOlist)[[2]]),
4191 4086
                                    ncol = length(inhibitors))
4192
-            rownames(signalStates) <- rownames(CNOlist@signals[[2]])
4087
+            rownames(signalStates) <- rownames(getSignals(CNOlist)[[2]])
4193 4088
             colnames(signalStates) <- inhibitors
4194 4089
             signalStates <- cbind(stimuliStates, signalStates)
4195 4090
         }
... ...
@@ -4206,14 +4101,11 @@ simulateStatesRecursiveAdd <-
4206 4101
     }
4207 4102
 #' @noRd
4208 4103
 smoothMatrix <-
4209
-    function(M, n=1, direction = 0, torus = FALSE) {
4104
+    function(M, n=1, direction = 0, torus = FALSE, verbose = FALSE) {
4210 4105
         Msmooth <- M
4211 4106
         if (n > 0) {
4212 4107
             for (i in seq_len(n)) {
4213
-
4214 4108
                 cat('\r', i)
4215
-                flush.console()
4216
-
4217 4109
                 Mtmp <- Msmooth
4218 4110
                 M1 <- M2 <- M3 <- M4 <- M5 <- M6 <- M7 <- M8 <- M*0
4219 4111
                 if (torus) {
... ...
@@ -4230,11 +4122,12 @@ smoothMatrix <-
4230 4122
                     if (any(direction %in% c(0,3))) {
4231 4123
                         M2 <- rbind(cbind(Msmooth[, ncol(M)],
4232 4124
                                           Msmooth[
4233
-                                            , seq_len((ncol(M)-1))])[nrow(M), ],
4125
+                                              , seq_len((ncol(M)-1))])[nrow(M),
4126
+                                                                       ],
4234 4127
                                     cbind(Msmooth[, ncol(M)],
4235 4128
                                           Msmooth[
4236
-                                            , seq_len((ncol(M)-1))])[
4237
-                                        seq_len((nrow(M)-1)), ])
4129
+                                              , seq_len((ncol(M)-1))])[
4130
+                                                  seq_len((nrow(M)-1)), ])
4238 4131
                         M6 <- rbind(cbind(Msmooth[, 2:ncol(M)],
4239 4132
                                           Msmooth[, 1])[2:nrow(M), ],
4240 4133
                                     cbind(Msmooth[, 2:ncol(M)],
... ...
@@ -4264,23 +4157,23 @@ smoothMatrix <-
4264 4157
                             rbind(0,
4265 4158
                                   cbind(0,
4266 4159
                                         Msmooth[
4267
-                                          , seq_len((ncol(M)-1))])[
4268
-                                      seq_len((nrow(M)-1)), ])
4160
+                                            , seq_len((ncol(M)-1))])[
4161
+                                                seq_len((nrow(M)-1)), ])
4269 4162
                         M6 <- rbind(cbind(Msmooth[, 2:ncol(M)], 0)[2:nrow(M), ]
4270
-                                  , 0)
4163
+                                    , 0)
4271 4164
                     }
4272 4165
                     if (any(direction %in% c(0,4))) {
4273 4166
                         M4 <- rbind(0, cbind(Msmooth[, 2:ncol(M)], 0)[
4274
-                                           seq_len((nrow(M)-1)), ])
4167
+                            seq_len((nrow(M)-1)), ])
4275 4168
                         M8 <- cbind(0, rbind(Msmooth[2:nrow(M), ], 0)[
4276
-                                         , seq_len((ncol(M)-1))])
4169
+                            , seq_len((ncol(M)-1))])
4277 4170
                     }
4278 4171
                 }
4279 4172
                 denom <- matrix(9, nrow(M), ncol(M))
4280 4173
                 Msmooth <- Mtmp+M1+M2+M3+M4+M5+M6+M7+M8
4281 4174
                 Msmooth <- Msmooth/denom
4282 4175
                 if (all(Mtmp == Msmooth)) {
4283
-                    print("convergence")
4176
+                    if (verbose) message("convergence")
4284 4177
                     break()
4285 4178
                 }
4286 4179
             }
... ...
@@ -1,3 +1,24 @@
1
+#' Add noise
2
+#'
3
+#' Adds noise to simulated data
4
+#' @param sim bnemsim object from simBoolGtn
5
+#' @param sd standard deviation for the rnorm function
6
+#' @author Martin Pirkl
7
+#' @return noisy fold-change matrix
8
+#' @export
9
+#' @examples
10
+#' sim <- simBoolGtn(Sgenes = 10, maxEdges = 10, negation=0.1,layer=1)
11
+#' fc <- addNoise(sim,sd=1)
12
+addNoise <- function(sim,sd=1) {
13
+    fc <- sim$fc
14
+    pos <- which(fc == 1)
15
+    neg <- which(fc == -1)
16
+    zero <- which(fc == 0)
17
+    fc[pos] <- rnorm(length(pos),1,1)
18
+    fc[neg] <- rnorm(length(neg),-1,1)
19
+    fc[zero] <- rnorm(length(zero),0,1)
20
+    return(fc)
21
+}
1 22
 #' BCR perturbation reproduction
2 23
 #'
3 24
 #' Produce the application data from the BCR paper
... ...
@@ -29,10 +50,9 @@ processDataBCR <- function(path = "", combsign = FALSE) {
29 50
     ev <- vsn::vsnrma(ab)
30 51
     data <- exprs(ev)
31 52
     colnames(data) <- gsub("GSM16808[0-9][0-9]_|\\.CEL\\.gz", "",
32
-                          colnames(data))
33
-
53
+                           colnames(data))
34 54
     batch <- gsub(".*_", "", colnames(data))
35
-    batch[which(batch == "Batch")] <- "Batch3"
55
+    batch[batch == "Batch"] <- "Batch3"
36 56
     colnames(data) <- gsub("SP600125", "Jnk", colnames(data))
37 57
     colnames(data) <- gsub("SB203580", "p38", colnames(data))
38 58
     colnames(data) <- gsub("10058F4", "Myc", colnames(data))
... ...
@@ -46,7 +66,7 @@ processDataBCR <- function(path = "", combsign = FALSE) {
46 66
     vars <- unique(unlist(strsplit(gsub("_Batch.*", "", colnames(data)),
47 67
                                    "_")))
48 68
     vars <- sort(vars[-grep("\\+", vars)])
49
-    vars <- vars[-which(vars %in% c("KO"))]
69
+    vars <- vars[!vars %in% c("KO")]
50 70
     design <- matrix(0, ncol(data), length(vars))
51 71
     colnames(design) <- vars
52 72
     rownames(design) <- colnames(data)
... ...
@@ -54,34 +74,31 @@ processDataBCR <- function(path = "", combsign = FALSE) {
54 74
         design[grep(i, colnames(data)), i] <- 1
55 75
     }
56 76
     combos <- NULL
57
-    for (i in which(apply(design, 1, sum) > 1)) {
77
+    for (i in which(rowSums(design) > 1)) {
58 78
         combos <- c(combos,
59
-                    paste(sort(colnames(design)[which(design[i, ] > 0)]),
79
+                    paste(sort(colnames(design)[design[i, ] > 0]),
60 80
                           collapse = "_"))
61 81
     }
62 82
     combos <- sort(unique(combos))
63 83
     design2 <- design
64
-    design2[which(apply(design, 1, sum) > 1), ] <- 0
84
+    design2[rowSums(design) > 1, ] <- 0
65 85
     for (i in combos) {
66 86
         comb <- unlist(strsplit(i, "_"))
67 87
         tmp2 <- numeric(nrow(design))
68
-        tmp2[which(apply(design[, comb], 1, sum) == length(comb) &
69
-                  apply(design, 1, sum) == length(comb))] <- 1
88
+        tmp2[rowSums(design[, comb]) == length(comb) &
89
+                 rowSums(design) == length(comb)] <- 1
70 90
         design2 <- cbind(design2, tmp2)
71 91
         colnames(design2)[ncol(design2)] <- i
72 92
     }
73
-    design2 <- design2[, -which(colnames(design2) %in% "BCR")]
74
-    colnames(design2)[which(colnames(design2) %in% "BCR_Ctrl")] <- "BCR"
75
-
93
+    design2 <- design2[, !colnames(design2) %in% "BCR"]
94
+    colnames(design2)[colnames(design2) %in% "BCR_Ctrl"] <- "BCR"
76 95
     if (combsign) {
77 96
         dataCB <- sva::ComBat(data, batch,
78 97
                               design2[, -grep("Ctrl", colnames(design2))])
79 98
     } else {
80 99
         dataCB <- sva::ComBat(data, batch)
81 100
     }
82
-
83 101
     fit <- limma::lmFit(dataCB, design2)
84
-
85 102
     fc <- matrix(0, nrow(dataCB), (ncol(design2)-2)*2 + 1)
86 103
     colnames(fc) <- seq_len(ncol(fc))
87 104
     contmat <- limma::makeContrasts(Ctrl_vs_BCR="BCR-Ctrl", levels=design2)
... ...
@@ -90,46 +107,45 @@ processDataBCR <- function(path = "", combsign = FALSE) {
90 107
     fc[, 1] <- fit2$coefficients
91 108
     colnames(fc)[1] <- "Ctrl_vs_BCR"
92 109
     colnames(fc)[-1] <- c(paste("Ctrl_vs",
93
-                                colnames(design2)[-which(colnames(design2) %in%
94
-                                                         c("Ctrl", "BCR"))],
110
+                                colnames(design2)[!colnames(design2) %in%
111
+                                                      c("Ctrl", "BCR")],
95 112
                                 sep = "_"),
96 113
                           paste("BCR_vs",
97
-                                colnames(design2)[-which(colnames(design2) %in%
98
-                                                         c("Ctrl", "BCR"))],
114
+                                colnames(design2)[!colnames(design2) %in%
115
+                                                      c("Ctrl", "BCR")],
99 116
                                 sep = "_"))
100 117
     for (i in colnames(design2)) {
101 118
         if (i %in% c("Ctrl", "BCR")) { next() }
102 119
         contmat <- contmat*0
103
-        contmat[which(colnames(design2) %in% "Ctrl")] <- -1
120
+        contmat[colnames(design2) %in% "Ctrl"] <- -1
104 121
         contmat[i, ] <- 1
105 122
         fit2 <- limma::contrasts.fit(fit, contmat)
106 123
         fit2 <- limma::eBayes(fit2)
107 124
         fc[, paste0("Ctrl_vs_", i)] <- fit2$coefficients
108 125
         contmat <- contmat*0
109
-        contmat[which(colnames(design2) %in% "BCR")] <- -1
126
+        contmat[colnames(design2) %in% "BCR"] <- -1
110 127
         contmat[i, ] <- 1
111 128
         fit2 <- limma::contrasts.fit(fit, contmat)
112 129
         fit2 <- limma::eBayes(fit2)
113 130
         fc[, paste0("BCR_vs_", i)] <- fit2$coefficients
114 131
     }
115 132
     targets <- paste("BCR_vs_BCR",
116
-                                colnames(design2)[-which(colnames(design2) %in%
117
-                                                         c("DMSO", "BCR"))],
118
-                                sep = "_")
133
+                     colnames(design2)[!colnames(design2) %in%
134
+                                           c("DMSO", "BCR")],
135
+                     sep = "_")
119 136
     targets <- targets[-grep("Myc|LY294|U0126|Vivit|BCR_BCR|BCR_Ctrl", targets)]
120 137
     fc2 <- fc[, c("Ctrl_vs_BCR", targets)]
121 138
     rownames(fc) <- rownames(data)
122
-
123
-    fc2 <- fc2[which(abs(fc2[, "Ctrl_vs_BCR"]) > 1 &
124
-                   apply(abs(fc2[, -which(colnames(fc2) %in%
125
-                                         "Ctrl_vs_BCR")]), 1, max) >
126
-                   log2(1.5)), ]
127
-    fci <- fc2[, -which(colnames(fc2) %in%
128
-                        "Ctrl_vs_BCR")]*sign(fc2[, "Ctrl_vs_BCR"])
129
-    argl <- apply(fci, 1, min)
130
-    fc2 <- fc2[which(argl < 0), ]
131
-
132
-    bcr <- list(exprs = fit$coefficients%*%t(design2), fc = fc2, full = fc,
139
+    
140
+    fc2 <- fc2[abs(fc2[, "Ctrl_vs_BCR"]) > 1 &
141
+                   rowMaxs(abs(fc2[, !colnames(fc2) %in%
142
+                                       "Ctrl_vs_BCR"])) >
143
+                   log2(1.5), ]
144
+    fci <- fc2[, !colnames(fc2) %in%
145
+                   "Ctrl_vs_BCR"]*sign(fc2[, "Ctrl_vs_BCR"])
146
+    argl <- rowMins(fci)
147
+    fc2 <- fc2[argl < 0, ]
148
+    bcr <- list(expression = fit$coefficients%*%t(design2), fc = fc2, full = fc,
133 149
                 design = design2)
134 150
     return(bcr)
135 151
 }
... ...
@@ -137,7 +153,7 @@ processDataBCR <- function(path = "", combsign = FALSE) {
137 153
 #'
138 154
 #' Shows the result of a Boostrap with either edge frequencies
139 155
 #' or confidence intervals
140
-#' @param x bnembs object
156
+#' @param x bnemBs object
141 157
 #' @param scale numeric value for scaling the edgewidth
142 158
 #' @param shift numeric value for shifting the edgewidth
143 159
 #' @param cut shows only edges with a fraction larger than cut
... ...
@@ -149,30 +165,30 @@ processDataBCR <- function(path = "", combsign = FALSE) {
149 165
 #' @param ... additional parameters for the function mnem::plotDnf
150 166
 #' @author Martin Pirkl
151 167
 #' @return plot of the network from the bootstrap
152
-#' @method plot bnembs
168
+#' @method plot bnemBs
153 169
 #' @export
154 170
 #' @importFrom mnem plotDnf
155 171
 #' @importFrom binom binom.confint
156 172
 #' @examples
157 173
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
158 174
 #' c("C", 1, "D"))
159
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t",
175
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
176
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
160 177
 #' row.names = FALSE, col.names = FALSE,
161 178
 #' quote = FALSE)
162
-#' PKN <- CellNOptR::readSIF("temp.sif")
163
-#' unlink('temp.sif')
179
+#' PKN <- CellNOptR::readSIF(temp.file)
164 180
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
165 181
 #' maxInhibit = 2, signals = c("A", "B","C","D"))
166 182
 #' model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
167
-#' exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
183
+#' expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
168 184
 #' nrow(slot(CNOlist, "cues")))
169
-#' fc <- computeFc(CNOlist, exprs)
185
+#' fc <- computeFc(CNOlist, expression)
170 186
 #' initBstring <- rep(0, length(model$reacID))
171 187
 #' res <- bnemBs(search = "greedy", model = model, CNOlist = CNOlist,
172 188
 #' fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
173 189
 #' parallel = NULL, initBstring = initBstring, draw = FALSE, verbose = FALSE,
174 190
 #' maxSteps = Inf)
175
-plot.bnembs <- function(x, scale = 3, shift = 0.1, cut = 0.5, dec = 2,
191
+plot.bnemBs <- function(x, scale = 3, shift = 0.1, cut = 0.5, dec = 2,
176 192
                         ci = 0, cip = 0.95, method = "exact", ...) {
177 193
     y <- x$x
178 194
     n <- x$n
... ...
@@ -182,8 +198,8 @@ plot.bnembs <- function(x, scale = 3, shift = 0.1, cut = 0.5, dec = 2,
182 198
     x$freq <- x$freq[order(names(x$freq))]/n
183 199
     graph <- x$graph
184 200
     freq <- x$freq
185
-    graph <- graph[which(freq >= cut)]
186
-    freq <- freq[which(freq >= cut)]
201
+    graph <- graph[freq >= cut]
202
+    freq <- freq[freq >= cut]
187 203
     freq2 <- NULL
188 204
     for (i in seq_len(length(graph))) {
189 205
         tmp <- rep(freq[i], length(unlist(strsplit(graph[i], "\\+"))))
... ...
@@ -227,17 +243,17 @@ plot.bnembs <- function(x, scale = 3, shift = 0.1, cut = 0.5, dec = 2,
227 243
 #' @examples
228 244
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
229 245
 #' c("C", 1, "D"))
230
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t",
246
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
247
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
231 248
 #' row.names = FALSE, col.names = FALSE,
232 249
 #' quote = FALSE)
233
-#' PKN <- CellNOptR::readSIF("temp.sif")
234
-#' unlink('temp.sif')
250
+#' PKN <- CellNOptR::readSIF(temp.file)
235 251
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
236 252
 #' maxInhibit = 2, signals = c("A", "B","C","D"))
237 253
 #' model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
238
-#' exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
254
+#' expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
239 255
 #' nrow(slot(CNOlist, "cues")))
240
-#' fc <- computeFc(CNOlist, exprs)
256
+#' fc <- computeFc(CNOlist, expression)
241 257
 #' initBstring <- rep(0, length(model$reacID))
242 258
 #' res <- bnemBs(search = "greedy", model = model, CNOlist = CNOlist,
243 259
 #' fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
... ...
@@ -267,7 +283,7 @@ bnemBs <- function(fc, x = 10, f = 0.5, replace = TRUE, startString = NULL,
267 283
         accum <- c(accum, tmp$graph)
268 284
     }
269 285
     accum <- list(x = accum, n = x)
270
-    class(accum) <- "bnembs"
286
+    class(accum) <- "bnemBs"
271 287
     return(accum)
272 288
 }
273 289
 #' B-Cell receptor signalling perturbations
... ...
@@ -326,6 +342,7 @@ NA
326 342
 #' data
327 343
 #' @export
328 344
 #' @importFrom mnem plotDnf
345
+#' @import CellNOptR
329 346
 #' @examples
330 347
 #' sim <- simBoolGtn()
331 348
 #' plot(sim)
... ...
@@ -351,11 +368,11 @@ simBoolGtn <-
351 368
                                                      "\\+")))))
352 369
             inputs <-
353 370
                 unique(unlist(strsplit(gsub("!", "", gsub("=.*", "", dnf)),
354
-                                             "=")))
371
+                                       "=")))
355 372
             outputs <- unique(gsub(".*=", "", dnf))
356 373
             stimuli <- cues
357 374
             inhibitors <- cues
358
-            both <- stimuli[which(stimuli %in% inhibitors)]
375
+            both <- stimuli[stimuli %in% inhibitors]
359 376
             for (i in both) {
360 377
                 dnf <- gsub(i, paste(i, "inhibit", sep = ""), dnf)
361 378
                 dnf <- c(dnf, paste(i, "stim=", i, "inhibit", sep = ""))
... ...
@@ -368,7 +385,7 @@ simBoolGtn <-
368 385
             Sgenes <- paste0("S", seq_len(n)-1, "g")
369 386
             layers <- list()
370 387
             layers[[1]] <- stimuli <- prev <- Sgenes[seq_len(s)]
371
-            Sgenes <- inhibitors <- Sgenes[which(!(Sgenes %in% stimuli))]
388
+            Sgenes <- inhibitors <- Sgenes[!(Sgenes %in% stimuli)]
372 389
             pkn <- NULL
373 390
             enew <- 0
374 391
             count <- 1
... ...
@@ -378,7 +395,7 @@ simBoolGtn <-
378 395
                 layers[[count]] <- layer <- sample(Sgenes,
379 396
                                                    ceiling(length(Sgenes)*pp))
380 397
                 enew <- enew + length(prev)*length(layer)
381
-                Sgenes <- Sgenes[which(!(Sgenes %in% layer))]
398
+                Sgenes <- Sgenes[!(Sgenes %in% layer)]
382 399
                 for (i in seq_len(length(prev))) {
383 400
                     for (j in layer) {
384 401
                         if (negation > 0 & (!positive | count > 2)) {
... ...
@@ -461,7 +478,7 @@ simBoolGtn <-
461 478
                 }
462 479
             }
463 480
             toomany <- table(gsub(".*=", "", model$reacID[as.logical(bString)]))
464
-            toomany <- toomany[which(toomany > maxInDeg)]
481
+            toomany <- toomany[toomany > maxInDeg]
465 482
             for (i in seq_len(length(toomany))) {
466 483
                 manyIn <- intersect(which(bString == 1),
467 484
                                     grep(paste0("=", names(toomany)[i]),
... ...
@@ -474,8 +491,8 @@ simBoolGtn <-
474 491
         steadyState <- steadyState2 <- simulateStatesRecursive(CNOlist, model,
475 492
                                                                bString)
476 493
         ind <- grep(paste(inhibitors, collapse = "|"), colnames(steadyState2))
477
-        steadyState2[, ind] <- steadyState2[, ind] + CNOlist@inhibitors
478
-        exprs <- t(steadyState)[rep(seq_len(ncol(steadyState)), m),
494
+        steadyState2[, ind] <- steadyState2[, ind] + getInhibitors(CNOlist)
495
+        expression <- t(steadyState)[rep(seq_len(ncol(steadyState)), m),
479 496
                                 rep(seq_len(nrow(steadyState)), r)]
480 497
         ERS <- computeFc(CNOlist, t(steadyState))
481 498
         stimcomb <- apply(expand.grid(stimuli, stimuli), c(1,2), as.character)
... ...
@@ -494,7 +511,8 @@ simBoolGtn <-
494 511
         fc[flip, ] <- fc[flip, ]*(-1)
495 512
         rownames(fc) <- paste(rownames(fc), seq_len(nrow(fc)), sep = "_")
496 513
         sim <- list(PKN = PKN, CNOlist = CNOlist, model = model,
497
-                    bString = bString, fc = fc, exprs = exprs, ERS = ERS)
514
+                    bString = bString, fc = fc, expression = expression,
515
+                    ERS = ERS)
498 516
         class(sim) <- "bnemsim"
499 517
         return(sim)
500 518
     }
... ...
@@ -520,13 +538,13 @@ absorptionII <-
520 538
                             unlist(strsplit(unlist(strsplit(graph, "=")),
521 539
                                             "\\+"))))
522 540
         } else {
523
-            graph <- model$reacID[which(bString == 1)]
541
+            graph <- model$reacID[bString == 1]
524 542
             nodes <- model$namesSpecies
525 543
         }
526 544
         for (i in graph) {
527 545
             players <- unlist(strsplit(gsub("=.*", "", i), "\\+"))
528 546
             target <- gsub(".*=", "", i)
529
-            others <- nodes[-which(nodes %in% c(players, target))]
547
+            others <- nodes[!nodes %in% c(players, target)]
530 548
             players2 <- gsub("!", "", players)
531 549
             change1 <- which(players == players2)
532 550
             change2 <- which(!(players == players2))
... ...
@@ -535,7 +553,7 @@ absorptionII <-
535 553
                                           sep = ""))
536 554
             }
537 555
             if (length(change2) > 0) {
538
-                others <- c(others[-which(others %in% players2[change2])],
556
+                others <- c(others[!others %in% players2[change2]],
539 557
                             paste("\\+", players2[change2], sep = ""),
540 558
                             paste("^", players2[change2], sep = ""))
541 559
             }
... ...
@@ -551,13 +569,13 @@ absorptionII <-
551 569
                 targets <- targets[-toomuch]
552 570
             }
553 571
             if (length(targets) > 1) {
554
-                targets <- targets[-which(targets %in% which(graph %in% i))]
572
+                targets <- targets[!targets %in% which(graph %in% i)]
555 573
                 if (is.null(model)) {
556 574
                     if (sum(bString %in% graph[targets]) > 0) {
557
-                        bString <- bString[-which(bString %in% graph[targets])]
575
+                        bString <- bString[!bString %in% graph[targets]]
558 576
                     }
559 577
                 } else {
560
-                    bString[which(model$reacID %in% graph[targets])] <- 0
578
+                    bString[model$reacID %in% graph[targets]] <- 0
561 579
                 }
562 580
             }
563 581
         }
... ...
@@ -580,7 +598,7 @@ absorption <-
580 598
         if (is.null(model)) {
581 599
             graph <- bString
582 600
         } else {
583
-            graph <- model$reacID[which(bString == 1)]
601
+            graph <- model$reacID[bString == 1]
584 602
         }
585 603
         for (i in graph) {
586 604
             targets <-
... ...
@@ -598,13 +616,13 @@ absorption <-
598 616
                                         sep = ""), graph[targets])]
599 617
             }
600 618
             if (length(targets) > 1) {
601
-                targets <- targets[-which(targets == which(graph %in% i))]
619
+                targets <- targets[!targets == which(graph %in% i)]
602 620
                 if (is.null(model)) {
603 621
                     if (sum(bString %in% graph[targets]) > 0) {
604
-                        bString <- bString[-which(bString %in% graph[targets])]
622
+                        bString <- bString[!bString %in% graph[targets]]
605 623
                     }
606 624
                 } else {
607
-                    bString[which(model$reacID %in% graph[targets])] <- 0
625
+                    bString[model$reacID %in% graph[targets]] <- 0
608 626
                 }
609 627
             }
610 628
         }
... ...
@@ -624,7 +642,7 @@ absorption <-
624 642
 #' (normalized pvalues, logodds, ...) for m E-genes and l contrasts. If left 
625 643
 #' NULL, the gene expression
626 644
 #' data is used to calculate naive foldchanges.
627
-#' @param exprs Optional normalized m x l matrix of gene expression data 
645
+#' @param expression Optional normalized m x l matrix of gene expression data 
628 646
 #' for m E-genes and l experiments.
629 647
 #' @param egenes list object; each list entry is named after an S-gene and
630 648
 #' contains the names of egenes which are potential children
... ...
@@ -717,17 +735,17 @@ absorption <-
717 735
 #' @examples
718 736
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
719 737
 #' c("C", 1, "D"))
720
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t",
738
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
739
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
721 740
 #' row.names = FALSE, col.names = FALSE,
722 741
 #' quote = FALSE)
723
-#' PKN <- CellNOptR::readSIF("temp.sif")
724
-#' unlink('temp.sif')
742
+#' PKN <- CellNOptR::readSIF(temp.file)
725 743
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
726 744
 #' maxInhibit = 2, signals = c("A", "B","C","D"))
727 745
 #' model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
728
-#' exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
746
+#' expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
729 747
 #' nrow(slot(CNOlist, "cues")))
730
-#' fc <- computeFc(CNOlist, exprs)
748
+#' fc <- computeFc(CNOlist, expression)
731 749
 #' initBstring <- rep(0, length(model$reacID))
732 750
 #' res <- bnem(search = "greedy", model = model, CNOlist = CNOlist,
733 751
 #' fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
... ...
@@ -735,9 +753,9 @@ absorption <-
735 753
 #' maxSteps = Inf)
736 754
 bnem <-
737 755
     function(search = "greedy",
738
-
756
+             
739 757
              fc=NULL,
740
-             exprs=NULL,
758
+             expression=NULL,
741 759
              egenes=NULL,
742 760
              pkn=NULL,
743 761
              design=NULL,
... ...
@@ -755,7 +773,7 @@ bnem <-
755 773
              verbose = TRUE,
756 774
              reduce = TRUE,
757 775
              parallel2 = 1,
758
-
776
+             
759 777
              initBstring = NULL,
760 778
              popSize = 100,
761 779
              pMutation = 0.5,
... ...
@@ -773,7 +791,7 @@ bnem <-
773 791
              type = "SOCK",
774 792
              exhaustive = FALSE,
775 793
              delcyc = FALSE,
776
-
794
+             
777 795
              seeds = 1,
778 796
              maxSteps = Inf,
779 797
              node = NULL,
... ...
@@ -781,26 +799,27 @@ bnem <-
781 799
              draw = TRUE,
782 800
              prior = NULL,
783 801
              maxInputsPerGate = 2
784
-             ) {
802
+    ) {
785 803
         approach <- "fc"
786 804
         if (is.null(fc)) { approach <- "abs" }
787
-        if (is.null(fc) & is.null(exprs)) {
788
-            stop(paste0("please either provide a matrix of foldchanges 'fc' ",
789
-            "or a matrix of expression values 'exprs'"))
805
+        if (is.null(fc) & is.null(expression)) {
806
+            stop("please either provide a matrix of foldchanges 'fc' ",
807
+                 "or a matrix of expression values 'expression'")
790 808
         }
791 809
         if (is.null(model) | is.null(CNOlist)) {
792 810
             tmp <- preprocessInput(stimuli=stimuli,inhibitors=inhibitors,
793
-                                   signals=signals,design=design,exprs=exprs,
811
+                                   signals=signals,design=design,
812
+                                   expression=expression,
794 813
                                    fc=fc,pkn=pkn,
795 814
                                    maxInputsPerGate=maxInputsPerGate)
796
-
815
+            
797 816
             CNOlist <- tmp$CNOlist
798 817
             NEMlist <- tmp$NEMlist
799 818
             model <- tmp$model
800 819
         } else {
801 820
             NEMlist <- list()
802 821
             NEMlist$fc <- fc
803
-            NEMlist$exprs <- exprs
822
+            NEMlist$expression <- expression
804 823
             NEMlist$egenes <- egenes
805 824
         }
806 825
         CNOlist <- checkCNOlist(CNOlist)
... ...
@@ -809,7 +828,7 @@ bnem <-
809 828
                                 parameters = parameters, approach = approach,
810 829
                                 method)
811 830
         if (search %in% c("greedy", "genetic", "exhaustive")) {
812
-
831
+            
813 832
             if (search %in% "greedy") {
814 833
                 res <- localSearch(CNOlist=CNOlist, NEMlist=NEMlist,
815 834
                                    model=model,
... ...
@@ -855,7 +874,7 @@ bnem <-
855 874
                                      selection = selection,relFit = relFit,
856 875
                                      method = method,type = type,
857 876
                                      exhaustive = exhaustive,delcyc = delcyc
858
-                                     )
877
+                )
859 878
                 result <- list(graph = model$reacID[as.logical(res$bString)],
860 879
                                bString = res$bString, bStrings = res$stringsTol,
861 880
                                scores = res$stringsTolScores)
... ...
@@ -890,25 +909,25 @@ bnem <-
890 909
 #' @examples
891 910
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
892 911
 #' c("C", 1, "D"))
893
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
894
-#' col.names = FALSE,
912
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
913
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
914
+#' row.names = FALSE, col.names = FALSE,
895 915
 #' quote = FALSE)
896
-#' PKN <- CellNOptR::readSIF("temp.sif")
897
-#' unlink('temp.sif')
916
+#' PKN <- CellNOptR::readSIF(temp.file)
898 917
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
899 918
 #' signals = c("A", "B","C","D"))
900 919
 #' model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
901
-#' exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
920
+#' expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
902 921
 #' nrow(slot(CNOlist, "cues")))
903
-#' fc <- computeFc(CNOlist, exprs)
922
+#' fc <- computeFc(CNOlist, expression)
904 923
 computeFc <-
905 924
     function (CNOlist, y) {
906 925
         test <- 0 # for debugging DONT FORGET TO SET TO 0!!!
907 926
         CompMat <- numeric()
908 927
         CompMatNames <- character()
909
-        cnolistStimuli <- apply(CNOlist@stimuli, 1, sum)
910
-        cnolistInhibitors <- apply(CNOlist@inhibitors, 1, sum)
911
-        cnolistCues <- apply(CNOlist@cues, 1, sum)
928
+        cnolistStimuli <- rowSums(getStimuli(CNOlist))
929
+        cnolistInhibitors <- rowSums(getInhibitors(CNOlist))
930
+        cnolistCues <- rowSums(getCues(CNOlist))
912 931
         maxStim <- max(cnolistStimuli)
913 932
         maxKd <- max(cnolistInhibitors)
914 933
         grepCtrl <- which(cnolistCues == 0)[1]
... ...
@@ -918,15 +937,15 @@ computeFc <-
918 937
                              which(cnolistInhibitors != 0))
919 938
         grepStimsKds <- intersect(which(cnolistStimuli != 0),
920 939
                                   which(cnolistInhibitors != 0))
921
-        stimsKdsCbind <- cbind(CNOlist@stimuli, CNOlist@inhibitors)
940
+        stimsKdsCbind <- cbind(getStimuli(CNOlist), getInhibitors(CNOlist))
922 941
         ## get ctrl_vs_kd:
923 942
         inhibitorsNames <- NULL
924 943
         for (i in grepKds) {
925 944
             inhibitorsNames <-
926 945
                 c(inhibitorsNames,
927
-                  paste(colnames(CNOlist@inhibitors)[which(
928
-                                    CNOlist@inhibitors[i, ] >= 1)],
929
-                        collapse = "_"))
946
+                  paste(colnames(getInhibitors(CNOlist))[
947
+                      getInhibitors(CNOlist)[i, ] >= 1],
948
+                      collapse = "_"))
930 949
         }
931 950
         if (length(grepKds) > 0) {
932 951
             CompMat <- cbind(CompMat, y[, grepKds] - y[, grepCtrl])
... ...
@@ -937,16 +956,16 @@ computeFc <-
937 956
         ## get ctrl_vs_stim:
938 957
         stimuliNames <- NULL
939 958
         for (i in grepStims) {
940
-            if (sum(CNOlist@stimuli[i, ] >= 1) > 1) {
959
+            if (sum(getStimuli(CNOlist)[i, ] >= 1) > 1) {
941 960
                 stimuliNames <-
942 961
                     c(stimuliNames,
943
-                      paste(names(which(CNOlist@stimuli[i, ] >= 1)),
962
+                      paste(names(which(getStimuli(CNOlist)[i, ] >= 1)),
944 963
                             collapse = "_"))
945 964
             } else {
946 965
                 stimuliNames <-
947 966
                     c(stimuliNames,
948
-                      colnames(CNOlist@stimuli)[
949
-                          which(CNOlist@stimuli[i, ] >= 1)])
967
+                      colnames(getStimuli(CNOlist))[
968
+                          getStimuli(CNOlist)[i, ] >= 1])
950 969
             }
951 970
         }
952 971
         if (length(grepStims) > 0) {
... ...
@@ -962,12 +981,12 @@ computeFc <-
962 981
         ##           paste(names(which(stimsKdsCbind[i, ] >= 1)),
963 982
         ##                 collapse = "_"))
964 983
         ## }
965
-        combiNames <- rownames(CNOlist@cues)[grepStimsKds]
984
+        combiNames <- rownames(getCues(CNOlist))[grepStimsKds]
966 985
         if (length(grepStimsKds) > 0 & length(grepStims) > 0) {
967 986
             CompMat <-
968 987
                 cbind(CompMat,
969 988
                       y[, rep(grepStimsKds, length(grepStims))] -
970
-                      y[, sort(rep(grepStims, length(grepStimsKds)))])
989
+                          y[, sort(rep(grepStims, length(grepStimsKds)))])
971 990
             orderStims <- order(rep(grepStims, length(grepStimsKds)))
972 991
             CompMatNames <-
973 992
                 c(CompMatNames,
... ...
@@ -979,7 +998,7 @@ computeFc <-
979 998
         colnames(CompMat) <- CompMatNames
980 999
         if (sum(duplicated(colnames(CompMat)) == TRUE)) {
981 1000
             CompMat <-
982
-                CompMat[, -which(duplicated(colnames(CompMat)) == TRUE)]
1001
+                CompMat[, !duplicated(colnames(CompMat))]
983 1002
         }
984 1003
         if (test == 1) {
985 1004
             ## get stim_vs_stim:
... ...
@@ -987,13 +1006,13 @@ computeFc <-
987 1006
             for (i in grepStims) {
988 1007
                 combiNames2 <-
989 1008
                     c(combiNames2,
990
-                      paste(names(which(CNOlist@stimuli[i, ] >= 1)),
1009
+                      paste(names(which(getStimuli(CNOlist)[i, ] >= 1)),
991 1010
                             collapse = "_"))
992 1011
             }
993 1012
             if (length(grepStims) > 0) {
994 1013
                 CompMat <-
995 1014
                     cbind(CompMat, y[, rep(grepStims, length(grepStims))] -
996
-                                   y[, sort(rep(grepStims, length(grepStims)))])
1015
+                              y[, sort(rep(grepStims, length(grepStims)))])
997 1016
                 orderStims2 <- order(rep(grepStims, length(grepStims)))
998 1017
                 CompMatNames <-
999 1018
                     c(CompMatNames,
... ...
@@ -1012,8 +1031,8 @@ computeFc <-
1012 1031
             if (length(grepStimsKds) > 0 & length(grepKds) > 0) {
1013 1032
                 CompMat <-
1014 1033
                     cbind(CompMat, y[, rep(grepStimsKds, length(grepKds))] -
1015
-                                   y[, sort(rep(grepKds,
1016
-                                                length(grepStimsKds)))])
1034
+                              y[, sort(rep(grepKds,
1035
+                                           length(grepStimsKds)))])
1017 1036
                 orderKds <- order(rep(grepKds, length(grepStimsKds)))
1018 1037
                 CompMatNames <-
1019 1038
                     c(CompMatNames,
... ...
@@ -1039,7 +1058,7 @@ computeFc <-
1039 1058
         colnames(CompMat) <- CompMatNames
1040 1059
         if (sum(duplicated(colnames(CompMat)) == TRUE)) {
1041 1060
             CompMat <-
1042
-                CompMat[, -which(duplicated(colnames(CompMat)) == TRUE)]
1061
+                CompMat[, !duplicated(colnames(CompMat))]
1043 1062
         }
1044 1063
         return(CompMat)
1045 1064
     }
... ...
@@ -1072,7 +1091,7 @@ convertGraph <-
1072 1091
             }
1073 1092
             cnf <- expand.grid(dnf)
1074 1093
             dnf <- NULL
1075
-            for (j in seq_len(dim(cnf)[1])) {
1094
+            for (j in seq_len(nrow(cnf))) {
1076 1095
                 dnf <- c(dnf, paste(sort(unique(unlist(cnf[j, ]))),
1077 1096
                                     collapse = "+"))
1078 1097
             }
... ...
@@ -1105,11 +1124,11 @@ convertGraph <-
1105 1124
 #' @examples
1106 1125
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
1107 1126
 #' c("C", 1, "D"))
1108
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
1109
-#' col.names = FALSE,
1127
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
1128
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
1129
+#' row.names = FALSE, col.names = FALSE,
1110 1130
 #' quote = FALSE)
1111
-#' PKN <- CellNOptR::readSIF("temp.sif")
1112
-#' unlink('temp.sif')
1131
+#' PKN <- CellNOptR::readSIF(temp.file)
1113 1132
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
1114 1133
 #' signals = c("A", "B","C","D"))
1115 1134
 dummyCNOlist <-
... ...
@@ -1180,7 +1199,7 @@ dummyCNOlist <-
1180 1199
                                  stimn+inhibn)
1181 1200
                 for (i in seq_len(nrow(stimDesign))) {
1182 1201
                     design[((i-1)*nrow(inhibDesign) + 1):
1183
-                           (i*nrow(inhibDesign)), ] <-
1202
+                               (i*nrow(inhibDesign)), ] <-
1184 1203
                         cbind(stimDesign[rep(i, nrow(inhibDesign)), ,
1185 1204
                                          drop = FALSE],
1186 1205
                               inhibDesign)
... ...
@@ -1208,9 +1227,12 @@ dummyCNOlist <-
1208 1227
             colnames(design) <- c(stimuli, inhibitors)
1209 1228
         }
1210 1229
         colnamesdesign <- colnames(design)
1211
-        design <- rbind(cbind(stimDesign, matrix(0, nrow(stimDesign),
1212
-        (ncol(design) - ncol(stimDesign)))), cbind(matrix(0, nrow(inhibDesign),
1213
-        (ncol(design) - ncol(inhibDesign))), inhibDesign), design)
1230
+        design <- rbind(cbind(stimDesign,
1231
+                              matrix(0, nrow(stimDesign),
1232
+                                     (ncol(design) - ncol(stimDesign)))),
1233
+                        cbind(matrix(0, nrow(inhibDesign),
1234
+                                     (ncol(design) - ncol(inhibDesign))), 
1235
+                              inhibDesign), design)
1214 1236
         colnames(design) <- colnamesdesign
1215 1237
         ## make signalmatrix:
1216 1238
         signaln <- length(signals)
... ...
@@ -1228,7 +1250,7 @@ dummyCNOlist <-
1228 1250
         rownames(design) <- rownames(inhibDesign) <- rownames(stimDesign) <-
1229 1251
             rownames(signalData) <- c("Ctrl", 2:nrow(design))
1230 1252
         getRowname <- function(i, M) {
1231
-            r <- paste(colnames(M)[which(M[i, ] == 1)], collapse = "_")
1253
+            r <- paste(colnames(M)[M[i, ] == 1], collapse = "_")
1232 1254
             return(r)
1233 1255
         }
1234 1256
         rownames(design)[2:nrow(design)] <-
... ...
@@ -1271,14 +1293,14 @@ epiNEM2Bg <- function(t) {
1271 1293
                              sep = "")
1272 1294
         return(t)
1273 1295
     } else {
1274
-        tmp <- apply(t$origModel, 2, sum)
1275
-        stim <- rownames(t$origModel)[which(tmp == min(tmp))]
1296
+        tmp <- rowSums(t$origModel)
1297
+        stim <- rownames(t$origModel)[tmp == min(tmp)]
1276 1298
         graph <- NULL
1277
-
1299
+        
1278 1300
         for (i in seq_len(length(t$column))) {
1279 1301
             parents <-
1280
-                sort(rownames(t$origModel)[which(t$origModel[
1281
-                                                     , t$column[i]] == 1)])
1302
+                sort(rownames(t$origModel)[t$origModel[
1303
+                    , t$column[i]] == 1])
1282 1304
             child <- colnames(t$origModel)[t$column[i]]
1283 1305
             if (length(parents) == 2) {
1284 1306
                 if (t$logics[i] %in% "OR") {
... ...
@@ -1378,7 +1400,7 @@ epiNEM2Bg <- function(t) {
1378 1400
         all <- rownames(t$origModel)
1379 1401
         children2 <- unique(gsub(".*=", "", graph))
1380 1402
         if (sum(!(all %in% children2)) > 0) {
1381
-            graph <- c(graph, paste("S", all[which(!(all %in% children2))],
1403
+            graph <- c(graph, paste("S", all[!(all %in% children2)],
1382 1404
                                     sep = "="))
1383 1405
         }
1384 1406
         return(unique(graph))
... ...
@@ -1397,7 +1419,7 @@ epiNEM2Bg <- function(t) {
1397 1419
 #' (normalized pvalues, logodds, ...) for m E-genes and l contrasts. If left 
1398 1420
 #' NULL, the gene expression
1399 1421
 #' data is used to calculate naive foldchanges.
1400
-#' @param exprs Optional normalized m x l matrix of gene expression data 
1422
+#' @param expression Optional normalized m x l matrix of gene expression data 
1401 1423
 #' for m E-genes and l experiments.
1402 1424
 #' @param egenes list object; each list entry is named after an S-gene and
1403 1425
 #' contains the names of egenes which are potential children
... ...
@@ -1435,17 +1457,17 @@ epiNEM2Bg <- function(t) {
1435 1457
 #' @examples
1436 1458
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
1437 1459
 #' c("C", 1, "D"))
1438
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
1439
-#' col.names = FALSE,
1460
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
1461
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
1462
+#' row.names = FALSE, col.names = FALSE,
1440 1463
 #' quote = FALSE)
1441
-#' PKN <- CellNOptR::readSIF("temp.sif")
1442
-#' unlink('temp.sif')
1464
+#' PKN <- CellNOptR::readSIF(temp.file)
1443 1465
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
1444 1466
 #' signal = c("A", "B","C","D"))
1445 1467
 #' model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
1446
-#' exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
1468
+#' expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
1447 1469
 #' nrow(slot(CNOlist, "cues")))
1448
-#' fc <- computeFc(CNOlist, exprs)
1470
+#' fc <- computeFc(CNOlist, expression)
1449 1471
 #' initBstring <- rep(0, length(model$reacID))
1450 1472
 #' res <- bnem(search = "greedy", CNOlist = CNOlist, fc = fc, model = model,
1451 1473
 #' parallel = NULL, initBstring = initBstring, draw = FALSE, verbose = FALSE,
... ...
@@ -1455,57 +1477,57 @@ epiNEM2Bg <- function(t) {
1455 1477
 #' ## bString = res$bString, Egenes = 10, Sgene = 4)
1456 1478
 #' residuals <- findResiduals(res$bString, CNOlist, model, fc = fc)
1457 1479
 findResiduals <-
1458
-    function(bString, CNOlist, model, fc=NULL, exprs=NULL, egenes=NULL,
1480
+    function(bString, CNOlist, model, fc=NULL, expression=NULL, egenes=NULL,
1459 1481
              parameters = list(cutOffs = c(0,1,0),
1460
-                                             scoring = c(0.1,0.2,0.9)),
1482
+                               scoring = c(0.1,0.2,0.9)),
1461 1483
              method = "s", sizeFac = 10^-10,
1462 1484
              main = "residuals for decoupled vertices",
1463 1485
              sub = paste0("green residuals are added effects (left positive,",
1464 1486
                           " right negative) and red residuals are deleted ",
1465 1487
                           "effects"),
1466
-cut = TRUE, parallel = NULL, verbose = TRUE, ...) {
1488
+             cut = TRUE, parallel = NULL, verbose = TRUE, ...) {
1467 1489
         approach <- "fc"
1468 1490
         if (is.null(fc)) { approach <- "abs" }
1469
-        if (is.null(fc) & is.null(exprs)) {
1470
-            stop(paste0("please either provide a matrix of foldchanges 'fc' ",
1471
-                        "or a matrix of expression values 'exprs'"))
1491
+        if (is.null(fc) & is.null(expression)) {
1492
+            stop("please either provide a matrix of foldchanges 'fc' ",
1493
+                 "or a matrix of expression values 'expression'")
1472 1494
         }
1473 1495
         NEMlist <- list()
1474 1496
         NEMlist$fc <- fc
1475 1497
         NEMlist$egenes <- egenes
1476
-        NEMlist$exprs <- exprs
1498
+        NEMlist$expression <- expression
1477 1499
         CNOlist <- checkCNOlist(CNOlist)
1478 1500
         method <- checkMethod(method)[1]
1479 1501
         NEMlist <- checkNEMlist(NEMlist, CNOlist, parameters, approach, method)
1480 1502
         simResults <- simulateStatesRecursive(CNOlist = CNOlist, model = model,
1481 1503
                                               bString = bString)
1482 1504
         SCompMat <- computeFc(CNOlist, t(simResults))
1483
-        SCompMat <- SCompMat[, which(colnames(SCompMat) %in%
1484
-                                     colnames(NEMlist$fc))]
1505
+        SCompMat <- SCompMat[, colnames(SCompMat) %in%
1506
+                                 colnames(NEMlist$fc)]
1485 1507
         NEMlist$fc <- NEMlist$fc[, order(colnames(NEMlist$fc))]
1486 1508
         SCompMat <- SCompMat[, order(colnames(SCompMat))]
1487 1509
         SCompMat <- SCompMat[, colnames(NEMlist$fc)]
1488
-        stimuli <- colnames(CNOlist@stimuli)
1489
-        inhibitors <- colnames(CNOlist@inhibitors)
1510
+        stimuli <- colnames(getStimuli(CNOlist))
1511
+        inhibitors <- colnames(getInhibitors(CNOlist))
1490 1512
         tmp <- computeScoreNemT1(CNOlist, model = model, bString,
1491 1513
                                  NEMlist = NEMlist, tellme = 1,
1492 1514
                                  parameters = parameters, method = method,
1493 1515
                                  verbose = verbose, sizeFac = sizeFac)
1494 1516
         EtoS <- tmp$EtoS
1495
-
1517
+        
1496 1518
         if (verbose) {
1497
-            print(paste("calculating residuals for ",
1498
-                        ncol(CNOlist@signals[[1]]),
1499
-                        " S-genes based on ", length(unique(EtoS[, 1])),
1500
-                        " E-genes.", sep = ""))
1519
+            message("calculating residuals for ",
1520
+                    ncol(getSignals(CNOlist)[[1]]),
1521
+                    " S-genes based on ", length(unique(EtoS[, 1])),
1522
+                    " E-genes.")
1501 1523
         }
1502
-
1503
-        resMat <- matrix(0, nrow = ncol(CNOlist@signals[[1]]),
1524
+        
1525
+        resMat <- matrix(0, nrow = ncol(getSignals(CNOlist)[[1]]),
1504 1526
                          ncol = 2*ncol(NEMlist$fc))
1505
-        resVec <- numeric(ncol(CNOlist@signals[[1]]))
1506
-        resType <- matrix(0, nrow = ncol(CNOlist@signals[[1]]),
1527
+        resVec <- numeric(ncol(getSignals(CNOlist)[[1]]))
1528
+        resType <- matrix(0, nrow = ncol(getSignals(CNOlist)[[1]]),
1507 1529
                           ncol = 2*ncol(NEMlist$fc))
1508
-
1530
+        
1509 1531
         checkSgene <- function(i) {
1510 1532
             resType <- numeric(2*ncol(NEMlist$fc))
1511 1533
             resMat <- numeric(2*ncol(NEMlist$fc))
... ...
@@ -1517,30 +1539,29 @@ cut = TRUE, parallel = NULL, verbose = TRUE, ...) {
1517 1539
                         names(which(EtoS[, 2] == i))) == 1) {
1518 1540
                     data.tmp <-
1519 1541
                         t(as.matrix(
1520
-                            NEMlist$fc[which(rownames(NEMlist$fc) %in%
1521
-                                             names(which(EtoS[, 2] == i))), ]))
1542
+                            NEMlist$fc[rownames(NEMlist$fc) %in%
1543
+                                           names(which(EtoS[, 2] == i)), ]))
1522 1544
                     rownames(data.tmp) <-
1523 1545
                         rownames(NEMlist$fc)[
1524
-                            which(rownames(NEMlist$fc) %in%
1525
-                                  names(which(EtoS[, 2] == i)))]
1546
+                            rownames(NEMlist$fc) %in%
1547
+                                names(which(EtoS[, 2] == i))]
1526 1548
                 } else {
1527 1549
                     data.tmp <-
1528
-                        NEMlist$fc[which(rownames(NEMlist$fc) %in%
1529
-                                         names(which(EtoS[, 2] == i))), ]
1550
+                        NEMlist$fc[rownames(NEMlist$fc) %in%
1551
+                                       names(which(EtoS[, 2] == i)), ]
1530 1552
                 }
1531 1553
                 resVec <- sum(abs(cor(SCompMat[i, ], t(data.tmp),
1532 1554
                                       method = method)))
1533 1555
                 for (j in seq_len(ncol(data.tmp))) { # parallel this!
1534
-
1556
+                    
1535 1557
                     if (verbose) {
1536 1558
                         cat('\r',
1537 1559
                             paste(floor(((i-1)*ncol(data.tmp) + j)/
1538
-                                        (ncol(CNOlist@signals[[1]])*
1539
-                                         ncol(data.tmp))*100), "%",
1560
+                                            (ncol(getSignals(CNOlist)[[1]])*
1561
+                                                 ncol(data.tmp))*100), "%",
1540 1562
                                   sep = ""))
1541
-                        flush.console()
1542 1563
                     }
1543
-
1564
+                    
1544 1565
                     sgene <- SCompMat[i, ]
1545 1566
                     mem <- sgene[j]
1546 1567
                     if (mem == 0) {
... ...
@@ -1581,7 +1602,7 @@ cut = TRUE, parallel = NULL, verbose = TRUE, ...) {
1581 1602
             }
1582 1603
             return(list(resMat = resMat, resType = resType, resVec = resVec))
1583 1604
         }
1584
-
1605
+        
1585 1606
         if (!is.null(parallel)) {
1586 1607
             if (is.list(parallel)) {
1587 1608
                 if (length(parallel[[1]]) != length(parallel[[2]])) {
... ...
@@ -1599,14 +1620,14 @@ same.") }
1599 1620
             }
1600 1621
             sfLibrary("CellNOptR")
1601 1622
         }
1602
-
1623
+        
1603 1624
         if (!is.null(parallel)) {
1604 1625
             resTmp <- sfLapply(as.list(seq_len(nrow(resMat))), checkSgene)
1605 1626
             sfStop()
1606 1627
         } else {
1607 1628
             resTmp <- lapply(as.list(seq_len(nrow(resMat))), checkSgene)
1608 1629
         }
1609
-
1630
+        
1610 1631
         for (i in seq_len(nrow(resMat))) {
1611 1632
             resMat[i, ] <- resTmp[[i]]$resMat
1612 1633
             resType[i, ] <- resTmp[[i]]$resType
... ...
@@ -1615,24 +1636,24 @@ same.") }
1615 1636
         resType <- resType*(-1)
1616 1637
         resDiff <- (resVec - resMat)/nrow(NEMlist$fc)
1617 1638
         colnames(resDiff) <- c(colnames(NEMlist$fc), colnames(NEMlist$fc))
1618
-        rownames(resDiff) <- colnames(CNOlist@signals[[1]])
1639
+        rownames(resDiff) <- colnames(getSignals(CNOlist)[[1]])
1619 1640
         resDiff1 <- cbind(resDiff[, seq_len(ncol(NEMlist$fc))], max(resDiff),
1620 1641
                           resDiff[, (ncol(NEMlist$fc)+1):(2*ncol(NEMlist$fc))])
1621
-
1642
+        
1622 1643
         p1 <- HeatmapOP(resDiff1, Rowv = FALSE, Colv = FALSE, main = main,
1623 1644
                         sub = sub, bordercol = "grey", ...)
1624
-
1645
+        
1625 1646
         resDiff2 <- cbind(resDiff[, seq_len(ncol(NEMlist$fc))], min(resDiff),
1626 1647
                           resDiff[, (ncol(NEMlist$fc)+1):(2*ncol(NEMlist$fc))])
1627 1648
         resType2 <- cbind(resType[, seq_len(ncol(NEMlist$fc))], min(resType),
1628 1649
                           resType[, (ncol(NEMlist$fc)+1):(2*ncol(NEMlist$fc))])
1629
-        resDiff2[which(resDiff2 > 0)] <- 0
1630
-
1650
+        resDiff2[resDiff2 > 0] <- 0
1651
+        
1631 1652
         p2 <- HeatmapOP(resDiff2, Colv = FALSE, Rowv = FALSE, main = main,
1632 1653
                         sub = sub, bordercol = "grey", ...)
1633
-
1654
+        
1634 1655
         resDiff3 <- resDiff2*resType2
1635
-
1656
+        
1636 1657
         p3 <- HeatmapOP(resDiff3, Colv = FALSE, Rowv = FALSE, main = main,
1637 1658
                         sub = sub, bordercol = "grey", ...)
1638 1659
         res.breaks <-
... ...
@@ -1642,48 +1663,48 @@ same.") }
1642 1663
                                                               na.rm = TRUE))),
1643 1664
                 (max(abs(min(resDiff3, na.rm = TRUE)), abs(max(resDiff3,
1644 1665
                                                                na.rm = TRUE))) -
1645
-                 -max(abs(min(resDiff3, na.rm = TRUE)),
1646
-                      abs(max(resDiff3,
1647
-                              na.rm = TRUE))))/100)
1648
-
1666
+                     -max(abs(min(resDiff3, na.rm = TRUE)),
1667
+                          abs(max(resDiff3,
1668
+                                  na.rm = TRUE))))/100)
1669
+        
1649 1670
         p1 <- HeatmapOP(resDiff3[, seq_len(ncol(NEMlist$fc))],
1650 1671
                         bordercol = "grey", Colv = FALSE, Rowv = FALSE,
1651 1672
                         main = "residuals (positive effects)", sub = "",
1652 1673
                         xrot = "60", breaks = res.breaks, colorkey = FALSE)
1653
-
1674
+        
1654 1675
         p2 <- HeatmapOP(resDiff3[, (ncol(NEMlist$fc)+2):(2*ncol(NEMlist$fc)+1)],
1655 1676
                         bordercol = "grey", Colv = FALSE, Rowv = FALSE,
1656 1677
                         main = "residuals (negative effects)", sub = "",
1657 1678
                         xrot = "60", breaks = res.breaks, colorkey = TRUE)
1658
-
1679
+        
1659 1680
         if (verbose) {
1660 1681
             print(p1, position=c(0, 0, .48, 1), more=TRUE)
1661 1682
             print(p2, position=c(.48, 0, 1, 1))
1662 1683
         }
1663 1684
         if (cut & all(is.na(resDiff) == FALSE)) {
1664
-            if (sum(apply(abs(resDiff1), 1, sum) == 0) > 0) {
1685
+            if (sum(rowSums(abs(resDiff1)) == 0) > 0) {
1665 1686
                 resDiff1 <-
1666
-                    resDiff1[-which(apply(abs(resDiff1), 1, sum) == 0), ]
1687
+                    resDiff1[!rowSums(abs(resDiff1)) == 0, ]
1667 1688
             }
1668
-            if (sum(apply(abs(resDiff1), 2, sum) == 0) > 0) {
1689
+            if (sum(colSums(abs(resDiff1)) == 0) > 0) {
1669 1690
                 resDiff1 <-
1670
-                    resDiff1[, -which(apply(abs(resDiff1), 2, sum) == 0)]
1691
+                    resDiff1[, !colSums(abs(resDiff1)) == 0]
1671 1692
             }
1672
-            if (sum(apply(abs(resDiff2), 1, sum) == 0) > 0) {
1693
+            if (sum(rowSums(abs(resDiff2)) == 0) > 0) {
1673 1694
                 resDiff2 <-
1674
-                    resDiff2[-which(apply(abs(resDiff2), 1, sum) == 0), ]
1695
+                    resDiff2[!rowSums(abs(resDiff2)) == 0, ]
1675 1696
             }
1676
-            if (sum(apply(abs(resDiff2), 2, sum) == 0) > 0) {
1697
+            if (sum(colSums(abs(resDiff2)) == 0) > 0) {
1677 1698
                 resDiff2 <-
1678
-                    resDiff2[, -which(apply(abs(resDiff2), 2, sum) == 0)]
1699
+                    resDiff2[, !colSums(abs(resDiff2)) == 0]
1679 1700
             }
1680
-            if (sum(apply(abs(resDiff3), 1, sum) == 0) > 0) {
1701
+            if (sum(rowSums(abs(resDiff3)) == 0) > 0) {
1681 1702
                 resDiff3 <-
1682
-                    resDiff3[-which(apply(abs(resDiff3), 1, sum) == 0), ]
1703
+                    resDiff3[!rowSums(abs(resDiff3)) == 0, ]
1683 1704
             }
1684
-            if (sum(apply(abs(resDiff3), 2, sum) == 0) > 0) {
1705
+            if (sum(colSums(abs(resDiff3)) == 0) > 0) {
1685 1706
                 resDiff3 <-
1686
-                    resDiff3[, -which(apply(abs(resDiff3), 2, sum) == 0)]
1707
+                    resDiff3[, !colSums(abs(resDiff3)) == 0]
1687 1708
             }
1688 1709
         }
1689 1710
         return(list(resDiff1 = resDiff1, resDiff2 = resDiff2,
... ...
@@ -1702,11 +1723,11 @@ same.") }
1702 1723
 #' @examples
1703 1724
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
1704 1725
 #' c("C", 1, "D"))
1705
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
1706
-#' col.names = FALSE,
1726
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
1727
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
1728
+#' row.names = FALSE, col.names = FALSE,
1707 1729
 #' quote = FALSE)
1708
-#' PKN <- CellNOptR::readSIF("temp.sif")
1709
-#' unlink('temp.sif')
1730
+#' PKN <- CellNOptR::readSIF(temp.file)
1710 1731
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
1711 1732
 #' signal = c("A", "B","C","D"))
1712 1733
 #' model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
... ...
@@ -1714,8 +1735,8 @@ same.") }
1714 1735
 reduceGraph <-
1715 1736
     function(bString, model, CNOlist) {
1716 1737
         if (any(bString != 0)) {
1717
-            stimuli <- colnames(CNOlist@stimuli)
1718
-            graph <- model$reacID[which(bString == 1)]
1738
+            stimuli <- colnames(getStimuli(CNOlist))
1739
+            graph <- model$reacID[bString == 1]
1719 1740
             tmp <- unlist(strsplit(graph, "="))
1720 1741
             tmp <- unlist(strsplit(tmp, "\\+"))
1721 1742
             tmp <- unique(gsub("!", "", tmp))
... ...
@@ -1729,7 +1750,7 @@ reduceGraph <-
1729 1750
                 }
1730 1751
             }
1731 1752
             bString <- numeric(length(bString))
1732
-            bString[which(model$reacID %in% graph)] <- 1
1753
+            bString[model$reacID %in% graph] <- 1
1733 1754
         }
1734 1755
         bString <- absorption(bString, model)
1735 1756
         return(bString)
... ...
@@ -1753,11 +1774,11 @@ reduceGraph <-
1753 1774
 #' @examples
1754 1775
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
1755 1776
 #' c("C", 1, "D"))
1756
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
1757
-#' col.names = FALSE,
1777
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
1778
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
1779
+#' row.names = FALSE, col.names = FALSE,
1758 1780
 #' quote = FALSE)
1759
-#' PKN <- CellNOptR::readSIF("temp.sif")
1760
-#' unlink('temp.sif')
1781
+#' PKN <- CellNOptR::readSIF(temp.file)
1761 1782
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
1762 1783
 #' signal = c("A", "B","C","D"))
1763 1784
 #' model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
... ...
@@ -1804,7 +1825,7 @@ simulateStatesRecursive <-
1804 1825
                                              signalStates = signalStates,
1805 1826
                                              graph = subGraph,
1806 1827
                                              children = children2[
1807
-                                                 -which(children2 %in% node)],
1828
+                                                 !children2 %in% node],
1808 1829
                                              NEMlist)
1809 1830
                                 if (add1 == 0) {
1810 1831
                                     pobMult <- signalStatesTmp[, j2]
... ...
@@ -1845,32 +1866,32 @@ simulateStatesRecursive <-
1845 1866
                     if (min(sop, na.rm = TRUE) > 0) { break() }
1846 1867
                 }
1847 1868
                 sop[sop > 0] <- 1
1848
-                if (node %in% colnames(CNOlist@inhibitors)) {
1849
-                    sop <- sop*(1 - CNOlist@inhibitors[, node])
1869
+                if (node %in% colnames(getInhibitors(CNOlist))) {
1870
+                    sop <- sop*(1 - getInhibitors(CNOlist)[, node])
1850 1871
                 }
1851
-                if (node %in% colnames(CNOlist@stimuli)) {
1852
-                    sop <- max(sop, CNOlist@stimuli[, node])
1872
+                if (node %in% colnames(getStimuli(CNOlist))) {
1873
+                    sop <- max(sop, getStimuli(CNOlist)[, node])
1853 1874
                 }
1854 1875
                 signalStates[, node] <- sop
1855 1876
             }
1856 1877
             return(signalStates)
1857 1878
         }
1858 1879
         bString <- reduceGraph(bString, model, CNOlist)
1859
-        stimuli <- colnames(CNOlist@stimuli)
1880
+        stimuli <- colnames(getStimuli(CNOlist))
1860 1881
         signals <-
1861
-            sort(c(colnames(CNOlist@inhibitors),
1882
+            sort(c(colnames(getInhibitors(CNOlist)),
1862 1883
                    model$namesSpecies[
1863
-                             -which(model$namesSpecies %in%
1864
-                                    c(stimuli,
1865
-                                      colnames(CNOlist@inhibitors)))]))
1866
-        graph0 <- model$reacID[which(bString == 1)]
1867
-        stimuliStates <- CNOlist@stimuli
1884
+                       !model$namesSpecies %in%
1885
+                           c(stimuli,
1886
+                             colnames(getInhibitors(CNOlist)))]))
1887
+        graph0 <- model$reacID[bString == 1]
1888
+        stimuliStates <- getStimuli(CNOlist)
1868 1889
         if (!is.null(NEMlist$signalStates)) {
1869 1890
             signalStates <- NEMlist$signalStates
1870 1891
         } else {
1871
-            signalStates <- matrix(NA, nrow = nrow(CNOlist@signals[[2]]),
1892
+            signalStates <- matrix(NA, nrow = nrow(getSignals(CNOlist)[[2]]),
1872 1893
                                    ncol = length(signals))
1873
-            rownames(signalStates) <- rownames(CNOlist@signals[[2]])
1894
+            rownames(signalStates) <- rownames(getSignals(CNOlist)[[2]])
1874 1895
             colnames(signalStates) <- signals
1875 1896
             signalStates <- cbind(stimuliStates, signalStates)
1876 1897
         }
... ...
@@ -1883,13 +1904,13 @@ simulateStatesRecursive <-
1883 1904
                                          NEMlist)
1884 1905
             }
1885 1906
         }
1886
-        signalStates <- signalStates[, which(colnames(signalStates) %in%
1887
-                                             colnames(CNOlist@signals[[1]]))]
1888
-        if (ncol(CNOlist@signals[[1]]) != 1) {
1907
+        signalStates <- signalStates[, colnames(signalStates) %in%
1908
+                                         colnames(getSignals(CNOlist)[[1]])]
1909
+        if (ncol(getSignals(CNOlist)[[1]]) != 1) {
1889 1910
             signalStates <- signalStates[, order(colnames(signalStates))]
1890 1911
         } else {
1891 1912
             signalStates <- as.matrix(signalStates)
1892
-            colnames(signalStates) <- colnames(CNOlist@signals[[1]])
1913
+            colnames(signalStates) <- colnames(getSignals(CNOlist)[[1]])
1893 1914
         }
1894 1915
         return(signalStates = signalStates)
1895 1916
     }
... ...
@@ -1914,16 +1935,15 @@ transClose <-
1914 1935
             max.iter <- length(h) - 2 # should be sufficient
1915 1936
         }
1916 1937
         if (verbose) {
1917
-            print(paste("maximum iterations: ", max.iter, sep = ""))
1938
+            message("maximum iterations: ", max.iter)
1918 1939
         }
1919 1940
         g.out <- unique(gsub(".*=", "", g))
1920 1941
         g.closed <- g
1921 1942
         for (iter in seq_len(max.iter)) {
1922 1943
             g.old <- g.closed
1923
-
1944
+            
1924 1945
             if (verbose) {
1925 1946
                 cat('\r', paste("iteration: ", iter, sep = ""))
1926
-                flush.console()
1927 1947
             }
1928 1948
             for (i in g.closed) {
1929 1949
                 input <-
... ...
@@ -1967,7 +1987,7 @@ transClose <-
1967 1987
             if (all(g.closed %in% g.old)) {
1968 1988
                 if (verbose) {
1969 1989
                     cat("\n")
1970
-                    print(paste("successfull convergence", sep = ""))
1990
+                    message("successfull convergence")
1971 1991
                 }
1972 1992
                 break()
1973 1993
             }
... ...
@@ -2036,7 +2056,7 @@ transRed <-
2036 2056
         }
2037 2057
         g3 <- transClose(g2, max.iter)
2038 2058
         if (sum(g %in% g3) > 0) {
2039
-            g4 <- g[-which(g %in% g3)]
2059
+            g4 <- g[!g %in% g3]
2040 2060
         }
2041 2061
         g5 <- unique(c(g2, g4))
2042 2062
         return(g5)
... ...
@@ -2051,14 +2071,14 @@ transRed <-
2051 2071
 #' (normalized pvalues, logodds, ...) for m E-genes and l contrasts. If left 
2052 2072
 #' NULL, the gene expression
2053 2073
 #' data is used to calculate naive foldchanges.
2054
-#' @param exprs Optional normalized m x l matrix of gene expression data 
2074
+#' @param expression Optional normalized m x l matrix of gene expression data 
2055 2075
 #' for m E-genes and l experiments.
2056 2076
 #' @param model Model object including the search space, if available.
2057 2077
 #' See CellNOptR::preprocessing.
2058 2078
 #' @param bString Binary string denoting the hyper-graph.
2059 2079
 #' @param Egenes Maximal number of visualized E-genes.
2060 2080
 #' @param Sgene Integer denoting the S-gene. See
2061
-#' colnames(CNOlist@signals[[1]]) to match integer with S-gene name.
2081
+#' colnames(getSignals(CNOlist)[[1]]) to match integer with S-gene name.
2062 2082
 #' @param parameters parameters for discrete case (not recommended);
2063 2083
 #' has to be a list with entries cutOffs and scoring:
2064 2084
 #' cutOffs = c(a,b,c) with a (cutoff for real zeros),
... ...
@@ -2097,6 +2117,7 @@ transRed <-
2097 2117
 #' @author Martin Pirkl
2098 2118
 #' @return lattice object with matrix information
2099 2119
 #' @export
2120
+#' @importFrom utils glob2rx
2100 2121
 #' @import
2101 2122
 #' CellNOptR
2102 2123
 #' stats
... ...
@@ -2106,17 +2127,17 @@ transRed <-
2106 2127
 #' @examples
2107 2128
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
2108 2129
 #' c("C", 1, "D"))
2109
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
2110
-#' col.names = FALSE,
2130
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
2131
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
2132
+#' row.names = FALSE, col.names = FALSE,
2111 2133
 #' quote = FALSE)
2112
-#' PKN <- CellNOptR::readSIF("temp.sif")
2113
-#' unlink('temp.sif')
2134
+#' PKN <- CellNOptR::readSIF(temp.file)
2114 2135
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
2115 2136
 #' signal = c("A", "B","C","D"))
2116 2137
 #' model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
2117
-#' exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
2138
+#' expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
2118 2139
 #' nrow(slot(CNOlist, "cues")))
2119
-#' fc <- computeFc(CNOlist, exprs)
2140
+#' fc <- computeFc(CNOlist, expression)
2120 2141
 #' initBstring <- rep(0, length(model$reacID))
2121 2142
 #' res <- bnem(search = "greedy", CNOlist = CNOlist, fc = fc,
2122 2143
 #' model = model, parallel = NULL, initBstring = initBstring, draw = FALSE,
... ...
@@ -2125,7 +2146,7 @@ transRed <-
2125 2146
 #' val <- validateGraph(CNOlist = CNOlist, fc = fc, model = model,
2126 2147
 #' bString = res$bString, Egenes = 10, Sgene = 4)
2127 2148
 validateGraph <-
2128
-    function(CNOlist, fc=NULL, exprs=NULL, model, bString,
2149
+    function(CNOlist, fc=NULL, expression=NULL, model, bString,
2129 2150
              Egenes = 25, Sgene = 1,
2130 2151
              parameters = list(cutOffs = c(0,1,0), scoring = c(0.1,0.2,0.9)),
2131 2152
              plot = TRUE,
... ...
@@ -2137,19 +2158,19 @@ validateGraph <-
2137 2158
              order = "rank", verbose = TRUE, ...) {
2138 2159
         approach <- "fc"
2139 2160
         if (is.null(fc)) { approach <- "abs" }
2140
-        if (is.null(fc) & is.null(exprs)) {
2141
-            stop(paste0("please either provide a matrix of foldchanges 'fc' ",
2142
-                        "or a matrix of expression values 'exprs'"))
2161
+        if (is.null(fc) & is.null(expression)) {
2162
+            stop("please either provide a matrix of foldchanges 'fc' ",
2163
+                 "or a matrix of expression values 'expression'")
2143 2164
         }
2144 2165
         csc <- TRUE
2145 2166
         colnames <- "bio"
2146 2167
         complete <- FALSE
2147 2168
         sim <- 0
2148
-
2169
+        
2149 2170
         NEMlist <- list()
2150 2171
         NEMlist$fc <- fc
2151
-        NEMlist$exprs <- exprs
2152
-
2172
+        NEMlist$expression <- expression
2173
+        
2153 2174
         myCN2bioCN <- function(x, stimuli, inhibitors) {
2154 2175
             y <- gsub("_vs_", ") vs (", x)
2155 2176
             for (i in inhibitors) {
... ...
@@ -2162,43 +2183,31 @@ validateGraph <-
2162 2183
                                                sep = ""))
2163 2184
             return(y)
2164 2185
         }
2165
-
2186
+        genes.upper <- c("APC", "ATF2", "BIRC2", "BIRC3", "CASP4", "CASP8",
2187
+                         "CFLAR", "CHUK", "CTNNB1", "DKK1", "DKK4", "FLASH",
2188
+                         "IKBKB", "IKBKG", "JUN", "MAP2K1", "MAP3K14",
2189
+                         "MAP3K7", "MAPK8", "PIK3CA", "RBCK1", "RELA",
2190
+                         "RIPK1", "RIPK3", "RNF31", "SHARPIN", "TAB2",
2191
+                         "TCF4", "TCF7L2", "TNFRSF10A", "TNFRSF10B",
2192
+                         "TNFRSF1A", "TNIK", "TRAF2", "USP2", "WLS", 
2193
+                         "WNT11", "WNT5A", "TNFa", "TRAIL")
2194
+        genes.lower <- c("Apc", "Atf2", "cIap1", "cIap2", "Casp4", "Casp8",
2195
+                         "c-Flip", "Ikka", "Beta-Cat.", "Dkk1", "Dkk4",
2196
+                         "Casp8ap2", "Ikkb", "Nemo", "cJun", "Mekk", "Nik",
2197
+                         "Tak1", "Jnk", "Pi3k", "Hoil1", "RelA", "Rip1",
2198
+                         "Rip3", "Hoip", "Sharpin", "Tab2", "fake", "Tcf4",
2199
+                         "Dr4", "Dr5", "Tnfr1", "Tnik", "Traf2", "Usp2", 
2200
+                         "Evi", "Wnt11", "Wnt5A", "Tnfa", "Trail")
2166 2201
         gene2protein <- function(genes, strict = FALSE) {
2167 2202
             if (strict) {
2168 2203
                 gene2prot <- cbind(
2169
-                    c("^APC$", "^ATF2$", "^BIRC2$", "^BIRC3$", "^CASP4$",
2170
-                      "^CASP8$", "^CFLAR$", "^CHUK$", "^CTNNB1$", "^DKK1$",
2171
-                      "^DKK4$", "^FLASH$", "^IKBKB$", "^IKBKG$", "^JUN$",
2172
-                      "^MAP2K1$", "^MAP3K14$", "^MAP3K7$", "^MAPK8$",
2173
-                      "^PIK3CA$", "^RBCK1$", "^RELA$", "^RIPK1$", "^RIPK3$",
2174
-                      "^RNF31$", "^SHARPIN$", "^TAB2$", "^TCF4$", "^TCF7L2$",
2175
-                      "^TNFRSF10A$", "^TNFRSF10B$", "^TNFRSF1A$", "^TNIK$",
2176
-                      "^TRAF2$", "^USP2$", "^WLS$", "^WNT11$", "^WNT5A$",
2177
-                      "^TNFa$", "^TRAIL"),
2178
-                    c("Apc", "Atf2", "cIap1", "cIap2", "Casp4", "Casp8",
2179
-                      "c-Flip", "Ikka", "Beta-Cat.", "Dkk1", "Dkk4",
2180
-                      "Casp8ap2", "Ikkb", "Nemo", "cJun", "Mekk", "Nik",
2181
-                      "Tak1", "Jnk", "Pi3k", "Hoil1", "RelA", "Rip1",
2182
-                      "Rip3", "Hoip", "Sharpin", "Tab2", "fake", "Tcf4",
2183
-                      "Dr4", "Dr5", "Tnfr1", "Tnik", "Traf2", "Usp2", "Evi",
2184
-                      "Wnt11", "Wnt5A", "Tnfa", "Trail")
2204
+                    glob2rx(genes.upper),
2205
+                    genes.lower
2185 2206
                 )
2186 2207
             } else {
2187 2208
                 gene2prot <- cbind(
2188
-                    c("APC", "ATF2", "BIRC2", "BIRC3", "CASP4", "CASP8",
2189
-                      "CFLAR", "CHUK", "CTNNB1", "DKK1", "DKK4", "FLASH",
2190
-                      "IKBKB", "IKBKG", "JUN", "MAP2K1", "MAP3K14", "MAP3K7",
2191
-                      "MAPK8", "PIK3CA", "RBCK1", "RELA", "RIPK1", "RIPK3",
2192
-                      "RNF31", "SHARPIN", "TAB2", "TCF4", "TCF7L2",
2193
-                      "TNFRSF10A", "TNFRSF10B", "TNFRSF1A", "TNIK", "TRAF2",
2194
-                      "USP2", "WLS", "WNT11", "WNT5A", "TNFa", "TRAIL"),
2195
-                    c("Apc", "Atf2", "cIap1", "cIap2", "Casp4", "Casp8",
2196
-                      "c-Flip", "Ikka", "Beta-Cat.", "Dkk1", "Dkk4",
2197
-                      "Casp8ap2", "Ikkb", "Nemo", "cJun", "Mekk", "Nik",
2198
-                      "Tak1", "Jnk", "Pi3k", "Hoil1", "RelA", "Rip1", "Rip3",
2199
-                      "Hoip", "Sharpin", "Tab2", "fake", "Tcf4", "Dr4", "Dr5",
2200
-                      "Tnfr1", "Tnik", "Traf2", "Usp2", "Evi", "Wnt11",
2201
-                      "Wnt5A", "Tnfa", "Trail")
2209
+                    genes.upper,
2210
+                    genes.lower
2202 2211
                 )
2203 2212
             }
2204 2213
             for (i in seq_len(nrow(gene2prot))) {
... ...
@@ -2206,46 +2215,17 @@ validateGraph <-
2206 2215
             }
2207 2216
             return(genes)
2208 2217
         }
2209
-
2218
+        
2210 2219
         protein2gene <- function(proteins, strict = FALSE) {
2211 2220
             if (strict) {
2212 2221
                 gene2prot <- cbind(
2213
-                    c("APC", "ATF2", "BIRC2", "BIRC3", "CASP4", "CASP8",
2214
-                      "CFLAR", "CHUK", "CTNNB1", "DKK1", "DKK4", "FLASH",
2215
-                      "IKBKB", "IKBKG", "JUN", "MAP2K1", "MAP3K14",
2216
-                      "MAP3K7", "MAPK8", "PIK3CA", "RBCK1", "RELA",
2217
-                      "RIPK1", "RIPK3", "RNF31", "SHARPIN", "TAB2",
2218
-                      "TCF4", "TCF7L2", "TNFRSF10A", "TNFRSF10B",
2219
-                      "TNFRSF1A", "TNIK", "TRAF2", "USP2", "WLS",
2220
-                      "WNT11", "WNT5A", "TNFa", "TRAIL"),
2221
-                    c("^Apc$", "^Atf2$", "^cIap1$", "^cIap2$",
2222
-                      "^Casp4$", "^Casp8$", "^c-Flip$", "^Ikka$",
2223
-                      "^Beta-Cat.$", "^Dkk1$", "^Dkk4$", "^Casp8ap2$",
2224
-                      "^Ikkb$", "^Nemo$", "^cJun$", "^Mekk$", "^Nik$",
2225
-                      "^Tak1$", "^Jnk$", "^Pi3k$", "^Hoil1$", "^RelA$",
2226
-                      "^Rip1$", "^Rip3$", "^Hoip$", "^Sharpin$", "^Tab2$",
2227
-                      "^fake$", "^Tcf4$", "^Dr4$", "^Dr5$", "^Tnfr1$",
2228
-                      "^Tnik$", "^Traf2$", "^Usp2$", "^Evi$", "^Wnt11$",
2229
-                      "^Wnt5A$", "^Tnfa$", "^Trail$")
2222
+                    genes.upper,
2223
+                    glob2rx(genes.lower)
2230 2224
                 )
2231 2225
             } else {
2232 2226
                 gene2prot <- cbind(
2233
-                    c("APC", "ATF2", "BIRC2", "BIRC3", "CASP4", "CASP8",
2234
-                      "CFLAR", "CHUK", "CTNNB1", "DKK1", "DKK4", "FLASH",
2235
-                      "IKBKB", "IKBKG", "JUN", "MAP2K1", "MAP3K14",
2236
-                      "MAP3K7", "MAPK8", "PIK3CA", "RBCK1", "RELA",
2237
-                      "RIPK1", "RIPK3", "RNF31", "SHARPIN", "TAB2",
2238
-                      "TCF4", "TCF7L2", "TNFRSF10A", "TNFRSF10B",
2239
-                      "TNFRSF1A", "TNIK", "TRAF2", "USP2", "WLS",
2240
-                      "WNT11", "WNT5A", "TNFa", "TRAIL"),
2241
-                    c("Apc", "Atf2", "cIap1", "cIap2", "Casp4",
2242
-                      "Casp8", "c-Flip", "Ikka", "Beta-Cat.", "Dkk1",
2243
-                      "Dkk4", "Casp8ap2", "Ikkb", "Nemo", "cJun",
2244
-                      "Mekk", "Nik", "Tak1", "Jnk", "Pi3k", "Hoil1",
2245
-                      "RelA", "Rip1", "Rip3", "Hoip", "Sharpin", "Tab2",
2246
-                      "fake", "Tcf4", "Dr4", "Dr5", "Tnfr1", "Tnik",
2247
-                      "Traf2", "Usp2", "Evi", "Wnt11", "Wnt5A", "Tnfa",
2248
-                      "Trail")
2227
+                    genes.upper,
2228
+                    genes.lower
2249 2229
                 )
2250 2230
             }
2251 2231
             for (i in seq_len(nrow(gene2prot))) {
... ...
@@ -2253,7 +2233,7 @@ validateGraph <-
2253 2233
             }
2254 2234
             return(proteins)
2255 2235
         }
2256
-
2236
+        
2257 2237
         colSideColorsSave <- NULL
2258 2238
         bad.data <- FALSE
2259 2239
         errorMat <- function() {
... ...
@@ -2301,26 +2281,24 @@ validateGraph <-
2301 2281
                                  sizeFac = sizeFac, verbose = FALSE)
2302 2282
         EtoS <- tmp$EtoS
2303 2283
         if (verbose) {
2304
-            print(paste(Sgene, ".", colnames(CNOlist@signals[[1]])[Sgene],
2305
-                        ": ", sum(EtoS[, 2] == Sgene), sep = ""))
2306
-            print(paste("Activated: ", sum(EtoS[, 2] == Sgene & EtoS[, 3] == 1),
2307
-                        sep = ""))
2308
-            print(paste("Inhibited: ", sum(EtoS[, 2] == Sgene &
2309
-                                           EtoS[, 3] == -1), sep = ""))
2310
-            print("Summary Score:")
2311
-            print(summary(EtoS[which(EtoS[, 2] == Sgene), 4]))
2284
+            message(Sgene, ".", colnames(getSignals(CNOlist)[[1]])[Sgene],
2285
+                    ": ", sum(EtoS[, 2] == Sgene))
2286
+            message("Activated: ", sum(EtoS[, 2] == Sgene & EtoS[, 3] == 1))
2287
+            message("Inhibited: ", sum(EtoS[, 2] == Sgene &
2288
+                                           EtoS[, 3] == -1))
2289
+            message("Summary Score:")
2290
+            message(summary(EtoS[EtoS[, 2] == Sgene, 4]))
2312 2291
             dups <- sum(duplicated(rownames(EtoS)) == TRUE)
2313 2292
             if (dups > 0) {
2314 2293
                 used <- length(unique(rownames(EtoS)))
2315 2294
             } else {
2316 2295
                 used <- nrow(EtoS)
2317 2296
             }
2318
-            print(paste("Unique genes used: ", (used), " (",
2319
-                        round((used/nrow(NEMlist$fc))*100, 2), " %)",
2320
-                        sep = ""))
2321
-            print(paste("Duplicated genes: ", dups, sep = ""))
2322
-            print("Overall fit:")
2323
-            print(summary(EtoS[, 4]))
2297
+            message("Unique genes used: ", (used), " (",
2298
+                    round((used/nrow(NEMlist$fc))*100, 2), " %)")
2299
+            message("Duplicated genes: ", dups)
2300
+            message("Overall fit:")
2301
+            message(summary(EtoS[, 4]))
2324 2302
         }
2325 2303
         indexList <- NULL
2326 2304
         if (is.null(indexList) == TRUE) {
... ...
@@ -2333,45 +2311,46 @@ validateGraph <-
2333 2311
                                         model = modelCut,
2334 2312
                                         bString =
2335 2313
                                             (numeric(length(modelCut$reacID)) +
2336
-                                             1))
2314
+                                                 1))
2337 2315
         }
2338 2316
         if (sim == 1) {
2339 2317
             simResults <-
2340 2318
                 simulateStatesRecursiveAdd(CNOlist = CNOlist, model = modelCut,
2341 2319
                                            bString =
2342 2320
                                                (numeric(
2343
-                                               length(modelCut$reacID)) + 1))
2321
+                                                   length(modelCut$reacID)) +
2322
+                                                    1))
2344 2323
         }
2345 2324
         rownames(simResults) <- seq_len(nrow(simResults))
2346
-        simResults <- simResults[, which(colnames(simResults) %in%
2347
-                                         colnames(CNOlist@signals[[1]]))]
2325
+        simResults <- simResults[, colnames(simResults) %in%
2326
+                                     colnames(getSignals(CNOlist)[[1]])]
2348 2327
         SCompMat <- computeFc(CNOlist, t(simResults))
2349 2328
         SCompMat <- SCompMat[, colnames(NEMlist$fc)]
2350
-
2329
+        
2351 2330
         if (parameters$cutOffs[3] == -1) {
2352 2331
             method <- checkMethod(method)
2353 2332
             S.mat <- SCompMat
2354 2333
             ## do median polish over gene clusters
2355
-            data.med <- NEMlist$fc[seq_len(ncol(CNOlist@signals[[2]])), ]*0
2334
+            data.med <- NEMlist$fc[seq_len(ncol(getSignals(CNOlist)[[2]])), ]*0
2356 2335
             Epos <- EtoS[order(rownames(EtoS)), seq_len(2)]
2357
-            for (i in seq_len(ncol(CNOlist@signals[[1]]))) {
2336
+            for (i in seq_len(ncol(getSignals(CNOlist)[[1]]))) {
2358 2337
                 tmp <-
2359 2338
                     medpolish(rbind(
2360
-                        NEMlist$fc[Epos[which(Epos[, 2] == i),
2339
+                        NEMlist$fc[Epos[Epos[, 2] == i,
2361 2340
                                         1], ],
2362
-                        NEMlist$fc[Epos[which(Epos[, 2] ==
2363
-                                              (i+ncol(CNOlist@signals[[2]]))),
2341
+                        NEMlist$fc[Epos[Epos[, 2] ==
2342
+                                            (i+ncol(getSignals(CNOlist)[[2]])),
2364 2343
                                         1], ]), trace.iter=FALSE)
2365 2344
                 data.med[i, ] <- tmp$col
2366 2345
             }
2367 2346
             E.mat <- data.med
2368 2347
             E.mat[is.na(E.mat)] <- 0
2369
-            tmp <- which(apply(E.mat, 1, sum) != 0)
2370
-            E.mat <- E.mat[which(apply(E.mat, 1, sum) != 0), ]
2348
+            tmp <- which(rowSums(E.mat) != 0)
2349
+            E.mat <- E.mat[rowSums(E.mat) != 0, ]
2371 2350
             rownames(E.mat) <- rownames(S.mat)[tmp]
2372 2351
             NEMlist$fc <- E.mat
2373 2352
             if (parameters$scoring[1] == 0) {
2374
-                S.mat[which(S.mat == 0)] <- NA
2353
+                S.mat[S.mat == 0] <- NA
2375 2354
             }
2376 2355
             if ("pearson" %in% method) {
2377 2356
                 cosine.sim <- -t(cor(t(S.mat), t(E.mat), method = "p",
... ...
@@ -2389,7 +2368,7 @@ validateGraph <-
2389 2368
             R[is.na(R)] <- max(R[!is.na(R)])
2390 2369
             MSEE <- matrixStats::rowMins(R)
2391 2370
         }
2392
-
2371
+        
2393 2372
         ## matrix visualisation for egenes fitted:
2394 2373
         if ("fc" %in% approach) {
2395 2374
             check.data <- NEMlist$fc
... ...
@@ -2397,15 +2376,15 @@ validateGraph <-
2397 2376
             rownames(check.model) <- colnames(simResults)
2398 2377
         }
2399 2378
         if ("abs" %in% approach) {
2400
-            check.data <- NEMlist$exprs # here the $norm is needed
2379
+            check.data <- NEMlist$expression # here the $norm is needed
2401 2380
             check.model <- simResults
2402
-            colnames(check.model) <- colnames(CNOlist@signals[[2]])
2381
+            colnames(check.model) <- colnames(getSignals(CNOlist)[[2]])
2403 2382
         }
2404
-
2383
+        
2405 2384
         Egenes <- Egenes
2406
-
2385
+        
2407 2386
         Egenes <- min(Egenes, sum(EtoS[, 2] == Sgene))
2408
-
2387
+        
2409 2388
         if (Egenes == 0) {
2410 2389
             mainlab <- paste("Regulated by ",
2411 2390
                              rownames(check.model)[Sgene], "\n", sep = "")
... ...
@@ -2418,14 +2397,14 @@ validateGraph <-
2418 2397
             rownames(genesInfo) <- "dummy"
2419 2398
             return(list(genesInfo = genesInfo, data = genesInfo))
2420 2399
         }
2421
-
2400
+        
2422 2401
         if (complete) {
2423 2402
             egenefit <- matrix(0, nrow = (sum(EtoS[, 2] == Sgene)+1),
2424 2403
                                ncol = ncol(check.data))
2425 2404
         } else {
2426 2405
             egenefit <- matrix(0, nrow = (Egenes+1), ncol = ncol(check.data))
2427 2406
         }
2428
-
2407
+        
2429 2408
         egenefit[1,] <- check.model[Sgene, ]
2430 2409
         rownames(egenefit) <- seq_len(nrow(egenefit))
2431 2410
         rownames(egenefit)[1] <- rownames(check.model)[Sgene]
... ...
@@ -2436,13 +2415,13 @@ validateGraph <-
2436 2415
         } else {
2437 2416
             activatedEgenes <- numeric(Egenes+1)
2438 2417
         }
2439
-
2418
+        
2440 2419
         count <- 0
2441 2420
         for (i in seq_len(nrow(EtoS))) {
2442 2421
             if (EtoS[i, 2] == Sgene) {
2443 2422
                 egenefit[count+2,] <-
2444
-                    check.data[which(rownames(check.data) %in%
2445
-                                     rownames(EtoS)[i]), ]
2423
+                    check.data[rownames(check.data) %in%
2424
+                                   rownames(EtoS)[i], ]
2446 2425
                 rownames(egenefit)[count+2] <- rownames(EtoS)[i]
2447 2426
                 if (EtoS[i, 3] == 1) {
2448 2427
                     activatedEgenes[count+2] <- 1
... ...
@@ -2451,9 +2430,9 @@ validateGraph <-
2451 2430
             }
2452 2431
             if (count >= Egenes & !complete) { break() }
2453 2432
         }
2454
-
2433
+        
2455 2434
         Egenes <- count
2456
-
2435
+        
2457 2436
         if (affyIds == FALSE) {
2458 2437
             temp <-
2459 2438
                 as.vector(unlist(mget(unique(rownames(egenefit)[-1]),
... ...
@@ -2465,7 +2444,7 @@ validateGraph <-
2465 2444
             }
2466 2445
             rownames(egenefit)[-1] <- temp
2467 2446
         }
2468
-
2447
+        
2469 2448
         rownames(egenefit)[is.na(rownames(egenefit))] <- "NA"
2470 2449
         count <- 0
2471 2450
         if (min(egenefit) != max(egenefit)) {
... ...
@@ -2478,77 +2457,88 @@ validateGraph <-
2478 2457
                         real.breaks <-
2479 2458
                             seq(-max(abs(min(egenefit)),
2480 2459
                                      abs(max(egenefit))),
2481
-                                max(abs(min(egenefit)),abs(max(egenefit))),0.1)
2460
+                                max(abs(min(egenefit)),abs(max(egenefit))),
2461
+                                0.1)
2482 2462
                         if (length(real.breaks) > 101) {
2483 2463
                             real.breaks <-
2484 2464
                                 real.breaks[
2485 2465
                                     c((floor(length(
2486
-                                          real.breaks)/2)-50):
2487
-                                      floor(length(real.breaks)/2),
2488
-                                    (floor(length(real.breaks)/2)+1):
2489
-                                    (floor(length(real.breaks)/2)+50))]
2466
+                                        real.breaks)/2)-50):
2467
+                                          floor(length(real.breaks)/2),
2468
+                                      (floor(length(real.breaks)/2)+1):
2469
+                                          (floor(length(real.breaks)/2)+50))]
2490 2470
                         }
2491 2471
                     } else {
2492 2472
                         if (activatedEgenes[i] == 1) {
2493 2473
                             onePosI <-
2494 2474
                                 c(which(egenefit[1, ] == 1 & egenefit[i, ] >
2495
-                                        parameters$cutOffs[2]),
2475
+                                            parameters$cutOffs[2]),
2496 2476
                                   which(egenefit[1, ] == 0 & egenefit[i, ] >
2497
-                                        parameters$cutOffs[2]),
2477
+                                            parameters$cutOffs[2]),
2498 2478
                                   which(egenefit[1, ] == -1 & egenefit[i, ] >
2499
-                                        parameters$cutOffs[2]))
2479
+                                            parameters$cutOffs[2]))
2500 2480
                             onePosII <-
2501 2481
                                 which(egenefit[1, ] == 1 & egenefit[i, ] >
2502
-                                      parameters$cutOffs[1] & egenefit[i, ] <=
2503
-                                      parameters$cutOffs[2])
2482
+                                          parameters$cutOffs[1] & 
2483
+                                          egenefit[i, ] <=
2484
+                                          parameters$cutOffs[2])
2504 2485
                             oneNegI <-
2505 2486
                                 c(which(egenefit[1, ] == -1 & egenefit[i, ] <
2506
-                                        -parameters$cutOffs[2]),
2487
+                                            -parameters$cutOffs[2]),
2507 2488
                                   which(egenefit[1, ] == 0 & egenefit[i, ] <
2508
-                                        -parameters$cutOffs[2]),
2489
+                                            -parameters$cutOffs[2]),
2509 2490
                                   which(egenefit[1, ] == 1 & egenefit[i, ] <
2510
-                                        -parameters$cutOffs[2]))
2491
+                                            -parameters$cutOffs[2]))
2511 2492
                             oneNegII <-
2512 2493
                                 which(egenefit[1, ] == -1 & egenefit[i, ] <
2513
-                                      -parameters$cutOffs[1] & egenefit[i, ] >=
2514
-                                      -parameters$cutOffs[2])
2494
+                                          -parameters$cutOffs[1] & 
2495
+                                          egenefit[i, ] >=
2496
+                                          -parameters$cutOffs[2])
2515 2497
                             zeros <-
2516 2498
                                 c(which(egenefit[1, ] == 0 &
2517
-                                        abs(egenefit[i, ]) <=
2518
-                                        parameters$cutOffs[2]),
2499
+                                            abs(egenefit[i, ]) <=
2500
+                                            parameters$cutOffs[2]),
2519 2501
                                   which(egenefit[1, ] == 1 &
2520
-                                        egenefit[i, ] <= parameters$cutOffs[1] &
2521
-                                        egenefit[i, ] >=
2522
-                                        -parameters$cutOffs[2]),
2502
+                                            egenefit[i, ] <= 
2503
+                                            parameters$cutOffs[1] &
2504
+                                            egenefit[i, ] >=
2505
+                                            -parameters$cutOffs[2]),
2523 2506
                                   which(egenefit[1, ] == -1 &
2524
-                                        egenefit[i, ] >=
2525
-                                        -parameters$cutOffs[1] &
2526
-                                        egenefit[i, ] <= parameters$cutOffs[2]))
2507
+                                            egenefit[i, ] >=
2508
+                                            -parameters$cutOffs[1] &
2509
+                                            egenefit[i, ] <=
2510
+                                            parameters$cutOffs[2]))
2527 2511
                             zerosI <-
2528 2512
                                 c(which(egenefit[1, ] == 0 &
2529
-                                        abs(egenefit[i, ]) <=
2530
-                                        parameters$cutOffs[1]),
2513
+                                            abs(egenefit[i, ]) <=
2514
+                                            parameters$cutOffs[1]),
2531 2515
                                   which(egenefit[1, ] == 1 & egenefit[i, ] <=
2532
-                                        parameters$cutOffs[1] & egenefit[i, ] >=
2533
-                                        -parameters$cutOffs[1]),
2534
-                                  which(egenefit[1, ] == -1 & egenefit[i, ] <=
2535
-                                        parameters$cutOffs[1] & egenefit[i, ] >=
2536
-                                        -parameters$cutOffs[1]))
2516
+                                            parameters$cutOffs[1] & 
2517
+                                            egenefit[i, ] >=
2518
+                                            -parameters$cutOffs[1]),
2519
+                                  which(egenefit[1, ] == -1 & 
2520
+                                            egenefit[i, ] <=
2521
+                                            parameters$cutOffs[1] & 
2522
+                                            egenefit[i, ] >=
2523
+                                            -parameters$cutOffs[1]))
2537 2524
                             zerosII <-
2538 2525
                                 c(which(egenefit[1, ] == 0 & egenefit[i, ] <=
2539
-                                        parameters$cutOffs[2] & egenefit[i, ] >
2540
-                                        parameters$cutOffs[1]),
2526
+                                            parameters$cutOffs[2] & 
2527
+                                            egenefit[i, ] >
2528
+                                            parameters$cutOffs[1]),
2541 2529
                                   which(egenefit[1, ] == -1 & egenefit[i, ] >
2542
-                                        parameters$cutOffs[1] & egenefit[i, ] <=
2543
-                                        parameters$cutOffs[2]))
2530
+                                            parameters$cutOffs[1] & 
2531
+                                            egenefit[i, ] <=
2532
+                                            parameters$cutOffs[2]))
2544 2533
                             zerosIII <-
2545 2534
                                 c(which(egenefit[1, ] == 0 & egenefit[i, ] >=
2546
-                                        -parameters$cutOffs[2] & egenefit[i, ] <
2547
-                                        -parameters$cutOffs[1]),
2535
+                                            -parameters$cutOffs[2] & 
2536
+                                            egenefit[i, ] <
2537
+                                            -parameters$cutOffs[1]),
2548 2538
                                   which(egenefit[1, ] == 1 & egenefit[i, ] <
2549
-                                        -parameters$cutOffs[1] &
2550
-                                        egenefit[i, ] >=
2551
-                                        -parameters$cutOffs[2]))
2539
+                                            -parameters$cutOffs[1] &
2540
+                                            egenefit[i, ] >=
2541
+                                            -parameters$cutOffs[2]))
2552 2542
                             if (soft) {
2553 2543
                                 egenefit[i, onePosI] <- 3
2554 2544
                                 egenefit[i, oneNegI] <- -3
... ...
@@ -2569,51 +2559,59 @@ validateGraph <-
2569 2559
                         } else {
2570 2560
                             onePosI <-
2571 2561
                                 c(which(egenefit[1, ] == 1 & egenefit[i, ] >
2572
-                                        parameters$cutOffs[2]),
2562
+                                            parameters$cutOffs[2]),
2573 2563
                                   which(egenefit[1, ] == 0 & egenefit[i, ] >
2574
-                                        parameters$cutOffs[2]),
2564
+                                            parameters$cutOffs[2]),
2575 2565
                                   which(egenefit[1, ] == -1 & egenefit[i, ] >
2576
-                                        parameters$cutOffs[2]))
2566
+                                            parameters$cutOffs[2]))
2577 2567
                             onePosII <-
2578 2568
                                 which(egenefit[1, ] == -1 & egenefit[i, ] >
2579
-                                      parameters$cutOffs[1] & egenefit[i, ] <=
2580
-                                      parameters$cutOffs[2])
2569
+                                          parameters$cutOffs[1] & 
2570
+                                          egenefit[i, ] <=
2571
+                                          parameters$cutOffs[2])
2581 2572
                             oneNegI <-
2582 2573
                                 c(which(egenefit[1, ] == -1 & egenefit[i, ] <
2583
-                                        -parameters$cutOffs[2]),
2574
+                                            -parameters$cutOffs[2]),
2584 2575
                                   which(egenefit[1, ] == 0 & egenefit[i, ] <
2585
-                                        -parameters$cutOffs[2]),
2576
+                                            -parameters$cutOffs[2]),
2586 2577
                                   which(egenefit[1, ] == 1 & egenefit[i, ] <
2587
-                                        -parameters$cutOffs[2]))
2578
+                                            -parameters$cutOffs[2]))
2588 2579
                             oneNegII <-
2589 2580
                                 which(egenefit[1, ] == 1 & egenefit[i, ] <
2590
-                                      -parameters$cutOffs[1] & egenefit[i, ] >=
2591
-                                      -parameters$cutOffs[2])
2581
+                                          -parameters$cutOffs[1] &
2582
+                                          egenefit[i, ] >=
2583
+                                          -parameters$cutOffs[2])
2592 2584
                             zerosI <-
2593 2585
                                 c(which(egenefit[1, ] == 0 &
2594
-                                        abs(egenefit[i, ]) <=
2595
-                                        parameters$cutOffs[1]),
2586
+                                            abs(egenefit[i, ]) <=
2587
+                                            parameters$cutOffs[1]),
2596 2588
                                   which(egenefit[1, ] == 1 & egenefit[i, ] <=
2597
-                                        parameters$cutOffs[1] & egenefit[i, ] >=
2598
-                                        -parameters$cutOffs[1]),
2599
-                                  which(egenefit[1, ] == -1 & egenefit[i, ] <=
2600
-                                        parameters$cutOffs[1] & egenefit[i, ] >=
2601
-                                        -parameters$cutOffs[1]))
2589
+                                            parameters$cutOffs[1] &
2590
+                                            egenefit[i, ] >=
2591
+                                            -parameters$cutOffs[1]),
2592
+                                  which(egenefit[1, ] == -1 &
2593
+                                            egenefit[i, ] <=
2594
+                                            parameters$cutOffs[1] &
2595
+                                            egenefit[i, ] >=
2596
+                                            -parameters$cutOffs[1]))
2602 2597
                             zerosII <-
2603 2598
                                 c(which(egenefit[1, ] == 0 & egenefit[i, ] <=
2604
-                                        parameters$cutOffs[2] & egenefit[i, ] >
2605
-                                        parameters$cutOffs[1]),
2599
+                                            parameters$cutOffs[2] &
2600
+                                            egenefit[i, ] >
2601
+                                            parameters$cutOffs[1]),
2606 2602
                                   which(egenefit[1, ] == 1 & egenefit[i, ] >
2607
-                                        parameters$cutOffs[1] & egenefit[i, ] <=
2608
-                                        parameters$cutOffs[2]))
2603
+                                            parameters$cutOffs[1] &
2604
+                                            egenefit[i, ] <=
2605
+                                            parameters$cutOffs[2]))
2609 2606
                             zerosIII <-
2610 2607
                                 c(which(egenefit[1, ] == 0 & egenefit[i, ] >=
2611
-                                        -parameters$cutOffs[2] & egenefit[i, ] <
2612
-                                        -parameters$cutOffs[1]),
2608
+                                            -parameters$cutOffs[2] & 
2609
+                                            egenefit[i, ] <
2610
+                                            -parameters$cutOffs[1]),
2613 2611
                                   which(egenefit[1, ] == -1 & egenefit[i, ] <
2614
-                                        -parameters$cutOffs[1] &
2615
-                                        egenefit[i, ] >=
2616
-                                        -parameters$cutOffs[2]))
2612
+                                            -parameters$cutOffs[1] &
2613
+                                            egenefit[i, ] >=
2614
+                                            -parameters$cutOffs[2]))
2617 2615
                             if (soft) {
2618 2616
                                 egenefit[i, onePosI] <- 3
2619 2617
                                 egenefit[i, oneNegI] <- -3
... ...
@@ -2648,29 +2646,30 @@ validateGraph <-
2648 2646
                                 unlist(strsplit(colnames(egenefit)[i], "_"))
2649 2647
                             if (length(names) > 1) {
2650 2648
                                 if (names[1] %in%
2651
-                                    colnames(CNOlist@inhibitors) &
2649
+                                    colnames(getInhibitors(CNOlist)) &
2652 2650
                                     names[length(names)] %in%
2653
-                                    colnames(CNOlist@stimuli)) {
2651
+                                    colnames(getStimuli(CNOlist))) {
2654 2652
                                     colSideColors[i] <- "brown"
2655 2653
                                 }
2656 2654
                                 if (names[1] %in%
2657
-                                    colnames(CNOlist@stimuli) &
2655
+                                    colnames(getStimuli(CNOlist)) &
2658 2656
                                     names[length(names)] %in%
2659
-                                    colnames(CNOlist@inhibitors)) {
2657
+                                    colnames(getInhibitors(CNOlist))) {
2660 2658
                                     colSideColors[i] <- "orange"
2661 2659
                                 }
2662 2660
                                 if (names[1] %in% "Ctrl" &
2663 2661
                                     names[length(names)] %in%
2664
-                                    colnames(CNOlist@stimuli)) {
2662
+                                    colnames(getStimuli(CNOlist))) {
2665 2663
                                     colSideColors[i] <- "yellow"
2666 2664
                                 }
2667 2665
                                 if (names[1] %in% "Ctrl" &
2668 2666
                                     names[length(names)] %in%
2669
-                                    colnames(CNOlist@inhibitors)) {
2667
+                                    colnames(getInhibitors(CNOlist))) {
2670 2668
                                     colSideColors[i] <- "blue"
2671 2669
                                 }
2672 2670
                             } else {
2673
-                                if (names %in% colnames(CNOlist@inhibitors)) {
2671
+                                if (names %in%
2672
+                                    colnames(getInhibitors(CNOlist))) {
2674 2673
                                     colSideColors[i] <- "blue"
2675 2674
                                 } else {
2676 2675
                                     colSideColors[i] <- "yellow"
... ...
@@ -2705,8 +2704,8 @@ validateGraph <-
2705 2704
                         col.sums <- colMedians(abs(egenefit))
2706 2705
                         sig.mismatch <- which(col.sums >= 2)
2707 2706
                         sig.mismatch <-
2708
-                            sig.mismatch[-which(egenefit[nrow(egenefit), ]
2709
-                                                != 0)]
2707
+                            sig.mismatch[!egenefit[nrow(egenefit), ]
2708
+                                         != 0]
2710 2709
                         get.cols <-
2711 2710
                             unique(c(sig.mismatch,
2712 2711
                                      which(egenefit[nrow(egenefit), ]
... ...
@@ -2800,8 +2799,9 @@ validateGraph <-
2800 2799
                             colnames(egenefit) <-
2801 2800
                                 gene2protein(
2802 2801
                                     myCN2bioCN(colnames(egenefit),
2803
-                                               colnames(CNOlist@stimuli),
2804
-                                               colnames(CNOlist@inhibitors)))
2802
+                                               colnames(getStimuli(CNOlist)),
2803
+                                               colnames(
2804
+                                                   getInhibitors(CNOlist))))
2805 2805
                         }
2806 2806
                         print(HeatmapOP(egenefit, main = mainlab, xrot = xrot,
2807 2807
                                         breaks = real.breaks, coln = 11,
... ...
@@ -2810,10 +2810,10 @@ validateGraph <-
2810 2810
                                         dendrogram = dendrogram, col = col,
2811 2811
                                         clusterx = clusterdata, ...))
2812 2812
                     } else {
2813
-                        print("one effect is not a matrix")
2813
+                        stop("one effect is not a matrix")
2814 2814
                     }
2815 2815
                 } else {
2816
-                    print("min equals max in data matrix")
2816
+                    stop("min equals max in data matrix")
2817 2817
                 }
2818 2818
             } else {
2819 2819
                 if (csc) {
... ...
@@ -2821,26 +2821,26 @@ validateGraph <-
2821 2821
                     for (i in seq_len(length(colnames(egenefit)))) {
2822 2822
                         names <- unlist(strsplit(colnames(egenefit)[i], "_"))
2823 2823
                         if (length(names) > 1) {
2824
-                            if (names[1] %in% colnames(CNOlist@inhibitors) &
2824
+                            if (names[1] %in% colnames(getInhibitors(CNOlist)) &
2825 2825
                                 names[length(names)] %in%
2826
-                                colnames(CNOlist@stimuli)) {
2826
+                                colnames(getStimuli(CNOlist))) {
2827 2827
                                 colSideColors[i] <- "brown"
2828 2828
                             }
2829
-                            if (names[1] %in% colnames(CNOlist@stimuli) &
2829
+                            if (names[1] %in% colnames(getStimuli(CNOlist)) &
2830 2830
                                 names[length(names)] %in%
2831
-                                colnames(CNOlist@inhibitors)) {
2831
+                                colnames(getInhibitors(CNOlist))) {
2832 2832
                                 colSideColors[i] <- "orange"
2833 2833
                             }
2834 2834
                             if (names[1] %in% "Ctrl" & names[length(names)] %in%
2835
-                                colnames(CNOlist@stimuli)) {
2835
+                                colnames(getStimuli(CNOlist))) {
2836 2836
                                 colSideColors[i] <- "yellow"
2837 2837
                             }
2838 2838
                             if (names[1] %in% "Ctrl" & names[length(names)] %in%
2839
-                                colnames(CNOlist@inhibitors)) {
2839
+                                colnames(getInhibitors(CNOlist))) {
2840 2840
                                 colSideColors[i] <- "blue"
2841 2841
                             }
2842 2842
                         } else {
2843
-                            if (names %in% colnames(CNOlist@inhibitors)) {
2843
+                            if (names %in% colnames(getInhibitors(CNOlist))) {
2844 2844
                                 colSideColors[i] <- "blue"
2845 2845
                             } else {
2846 2846
                                 colSideColors[i] <- "yellow"
... ...
@@ -2874,7 +2874,7 @@ validateGraph <-
2874 2874
                     col.sums <- colMedians(abs(egenefit))
2875 2875
                     sig.mismatch <- which(col.sums >= 2)
2876 2876
                     sig.mismatch <-
2877
-                        sig.mismatch[-which(egenefit[nrow(egenefit), ] != 0)]
2877
+                        sig.mismatch[!egenefit[nrow(egenefit), ] != 0]
2878 2878
                     get.cols <-
2879 2879
                         unique(c(sig.mismatch,
2880 2880
                                  which(egenefit[nrow(egenefit), ] != 0)))
... ...
@@ -2924,7 +2924,7 @@ validateGraph <-
2924 2924
                     } else {
2925 2925
                         geneorder <-
2926 2926
                             rownames(EtoS)[which(EtoS[, 2] ==
2927
-                                                 Sgene)[seq_len(Egenes)]]
2927
+                                                     Sgene)[seq_len(Egenes)]]
2928 2928
                         egenefit_genes <-
2929 2929
                             egenefit_genes[order(match(rownames(egenefit_genes),
2930 2930
                                                        geneorder),
... ...
@@ -2964,21 +2964,21 @@ validateGraph <-
2964 2964
                 clusterdata <- NULL
2965 2965
                 low <-
2966 2966
                     sum(egenefit[nrow(egenefit), ] ==
2967
-                        min(egenefit[nrow(egenefit), ]))
2967
+                            min(egenefit[nrow(egenefit), ]))
2968 2968
                 high <-
2969 2969
                     sum(egenefit[nrow(egenefit), ] ==
2970
-                        max(egenefit[nrow(egenefit), ]))
2970
+                            max(egenefit[nrow(egenefit), ]))
2971 2971
                 egenefit2 <- egenefit
2972
-                egenefit2[which(rownames(egenefit2) %in%
2973
-                                rownames(EtoS)[which(EtoS[, 3] == -1)]), ] <-
2974
-                    egenefit2[which(rownames(egenefit2) %in%
2975
-                                    rownames(EtoS)[which(EtoS[, 3] ==
2976
-                                                         -1)]), ]*(-1)
2972
+                egenefit2[rownames(egenefit2) %in%
2973
+                              rownames(EtoS)[EtoS[, 3] == -1], ] <-
2974
+                    egenefit2[rownames(egenefit2) %in%
2975
+                                  rownames(EtoS)[EtoS[, 3] ==
2976
+                                                     -1], ]*(-1)
2977 2977
                 egenefit2 <- t(apply(egenefit2, 1, rank))
2978
-                high2 <- which(egenefit2 > ncol(egenefit2)-high)
2979
-                low2 <- which(egenefit2 < low)
2980
-                mid <- which(egenefit2 >= low & egenefit2 <=
2981
-                             ncol(egenefit2)-high)
2978
+                high2 <- egenefit2 > ncol(egenefit2)-high
2979
+                low2 <- egenefit2 < low
2980
+                mid <- egenefit2 >= low & egenefit2 <=
2981
+                    ncol(egenefit2)-high
2982 2982
                 egenefit2[high2] <- 1
2983 2983
                 egenefit2[low2] <- -1
2984 2984
                 egenefit2[mid] <- 0
... ...
@@ -2994,7 +2994,9 @@ validateGraph <-
2994 2994
                     breaks <-
2995 2995
                         c(0, sort(unique(egenefit[nrow(egenefit), ])),
2996 2996
                           ncol(egenefit)+1)
2997
-                    print(breaks)
2997
+                    if (verbose) {
2998
+                        message(breaks)
2999
+                    }
2998 3000
                 }
2999 3001
                 if (ranks) {
3000 3002
                     if (is.null(breaks)) {
... ...
@@ -3004,8 +3006,8 @@ validateGraph <-
3004 3006
                         colnames(egenefit2) <-
3005 3007
                             gene2protein(
3006 3008
                                 myCN2bioCN(colnames(egenefit2),
3007
-                                           colnames(CNOlist@stimuli),
3008
-                                           colnames(CNOlist@inhibitors)))
3009
+                                           colnames(getStimuli(CNOlist)),
3010
+                                           colnames(getInhibitors(CNOlist))))
3009 3011
                     }
3010 3012
                     print(HeatmapOP(egenefit2, main = mainlab, xrot = xrot,
3011 3013
                                     breaks = breaks, coln = 11, Colv = Colv,
... ...
@@ -3021,8 +3023,8 @@ validateGraph <-
3021 3023
                         colnames(egenefit) <-
3022 3024
                             gene2protein(
3023 3025
                                 myCN2bioCN(colnames(egenefit),
3024
-                                           colnames(CNOlist@stimuli),
3025
-                                           colnames(CNOlist@inhibitors)))
3026
+                                           colnames(getStimuli(CNOlist)),
3027
+                                           colnames(getInhibitors(CNOlist))))
3026 3028
                     }
3027 3029
                     print(HeatmapOP(egenefit, main = mainlab, xrot = xrot,
3028 3030
                                     breaks = breaks, coln = 11, Colv = Colv,
... ...
@@ -3040,7 +3042,7 @@ validateGraph <-
3040 3042
                                 Colv = FALSE, Rowv = FALSE, col = "RdBu",
3041 3043
                                 coln = 12, breaks = seq(0,8,0.1)), ...)
3042 3044
             }
3043
-            print("min equals max in data matrix")
3045
+            stop("min equals max in data matrix")
3044 3046
             bad.data <- TRUE
3045 3047
         }
3046 3048
         if (sum(EtoS[, 2] == Sgene) == 0) {
... ...
@@ -3056,13 +3058,13 @@ validateGraph <-
3056 3058
                 return(NULL)
3057 3059
             }
3058 3060
         } else {
3059
-            if (!is.na(rownames(as.matrix(EtoS[which(EtoS[, 2] ==
3060
-                                                     Sgene), ]))[1])) {
3061
+            if (!is.na(rownames(as.matrix(EtoS[EtoS[, 2] ==
3062
+                                               Sgene, ]))[1])) {
3061 3063
                 if (sum(EtoS[, 2] == Sgene) > 1) {
3062
-                    genesInfo <- EtoS[which(EtoS[, 2] == Sgene), ]
3064
+                    genesInfo <- EtoS[EtoS[, 2] == Sgene, ]
3063 3065
                 } else {
3064
-                    names.backup <- rownames(EtoS)[which(EtoS[, 2] == Sgene)]
3065
-                    genesInfo <- t(as.matrix(EtoS[which(EtoS[, 2] == Sgene), ]))
3066
+                    names.backup <- rownames(EtoS)[EtoS[, 2] == Sgene]
3067
+                    genesInfo <- t(as.matrix(EtoS[EtoS[, 2] == Sgene, ]))
3066 3068
                     rownames(genesInfo) <- names.backup
3067 3069
                 }
3068 3070
                 if (affyIds == FALSE) {
... ...
@@ -3144,7 +3146,7 @@ randomDnf <- function(vertices = 10, negation = TRUE, max.edge.size = NULL,
3144 3146
 #' (normalized pvalues, logodds, ...) for m E-genes and l contrasts. If left 
3145 3147
 #' NULL, the gene expression
3146 3148
 #' data is used to calculate naive foldchanges.
3147
-#' @param exprs Optional normalized m x l matrix of gene expression data 
3149
+#' @param expression Optional normalized m x l matrix of gene expression data 
3148 3150
 #' for m E-genes and l experiments.
3149 3151
 #' @param model Model object including the search space, if available.
3150 3152
 #' See CellNOptR::preprocessing.
... ...
@@ -3174,7 +3176,7 @@ randomDnf <- function(vertices = 10, negation = TRUE, max.edge.size = NULL,
3174 3176
 #' sim <- simBoolGtn()
3175 3177
 #' scoreDnf(sim$bString, sim$CNOlist, sim$fc, model=sim$model)
3176 3178
 scoreDnf <- function(bString, CNOlist, fc, 
3177
-                     exprs=NULL, model, method = "cosine",
3179
+                     expression=NULL, model, method = "cosine",
3178 3180
                      sizeFac=10^-10,NAFac=1,
3179 3181
                      parameters = list(cutOffs = c(0,1,0),
3180 3182
                                        scoring = c(0.25,0.5,2)),
... ...
@@ -3182,13 +3184,13 @@ scoreDnf <- function(bString, CNOlist, fc,
3182 3184
                      verbose = FALSE) {
3183 3185
     approach <- "fc"
3184 3186
     if (is.null(fc)) { approach <- "abs" }
3185
-    if (is.null(fc) & is.null(exprs)) {
3186
-        stop(paste0("please either provide a matrix of foldchanges 'fc' ",
3187
-                    "or a matrix of expression values 'exprs'"))
3187
+    if (is.null(fc) & is.null(expression)) {
3188
+        stop("please either provide a matrix of foldchanges 'fc' ",
3189
+             "or a matrix of expression values 'expression'")
3188 3190
     }
3189 3191
     NEMlist <- list()
3190 3192
     NEMlist$fc <- fc
3191
-    NEMlist$exprs <- exprs
3193
+    NEMlist$expression <- expression
3192 3194
     NEMlist <- checkNEMlist(NEMlist, CNOlist=CNOlist,
3193 3195
                             parameters = parameters, approach = approach,
3194 3196
                             method=method)
... ...
@@ -3229,17 +3231,17 @@ plot.bnemsim <- function(x, ...) {
3229 3231
 #' @examples
3230 3232
 #' sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
3231 3233
 #' c("C", 1, "D"))
3232
-#' write.table(sifMatrix, file = "temp.sif", sep = "\t",
3234
+#' temp.file <- tempfile(pattern="interaction",fileext=".sif")
3235
+#' write.table(sifMatrix, file = temp.file, sep = "\t",
3233 3236
 #' row.names = FALSE, col.names = FALSE,
3234 3237
 #' quote = FALSE)
3235
-#' PKN <- CellNOptR::readSIF("temp.sif")
3236
-#' unlink('temp.sif')
3238
+#' PKN <- CellNOptR::readSIF(temp.file)
3237 3239
 #' CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
3238 3240
 #' maxInhibit = 2, signals = c("A", "B","C","D"))
3239 3241
 #' model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
3240
-#' exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
3242
+#' expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
3241 3243
 #' nrow(slot(CNOlist, "cues")))
3242
-#' fc <- computeFc(CNOlist, exprs)
3244
+#' fc <- computeFc(CNOlist, expression)
3243 3245
 #' initBstring <- rep(0, length(model$reacID))
3244 3246
 #' res <- bnem(search = "greedy", model = model, CNOlist = CNOlist,
3245 3247
 #' fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
3246 3248
Binary files a/data/bcr.rda and b/data/bcr.rda differ
3247 3249
similarity index 84%
3248 3250
rename from other/bnem_app.r
3249 3251
rename to inst/scripts/bnem_app.r
... ...
@@ -106,7 +106,7 @@ if (is.na(commandArgs(TRUE)[2])) {
106 106
     verbose <- FALSE
107 107
     draw <- FALSE
108 108
     
109
-    methnames <- c("greedy", "greedy_ia", "genetic_quick", "genetic_long", "genetic_stall","random")
109
+    methnames <- c("greedy", "greedy_ia", "greedy_cor", "genetic_quick", "genetic_long", "genetic_stall","random")
110 110
     storenames <- c("time", "accracy truth table", "accuracy differential effects", "score","tp","fp","tn","fn")
111 111
     result <- array(0, c(maxrun, length(methnames), length(storenames)), list(paste0("run", seq_len(maxrun)), methnames, storenames))
112 112
     
... ...
@@ -192,62 +192,76 @@ if (is.na(commandArgs(TRUE)[2])) {
192 192
         maxTime <- result[run, 2, 1]
193 193
         
194 194
         start <- as.numeric(Sys.time())
195
-        res2 <- bnem(search = "genetic", maxTime = maxTime, fc = sim$fc, CNOlist = sim$CNOlist, model = sim$model, method = method, verbose = verbose, draw = draw,stallGenMax=Inf)
195
+        res1 <- bnem(search = "greedy", fc = sim$fc, CNOlist = sim$CNOlist, model = sim$model, method = "s", verbose = verbose, draw = draw)
196 196
         result[run, 3, 1] <- as.numeric(Sys.time()) - start
197
-        ETT2 <- t(simulateStatesRecursive(CNOlist=sim$CNOlist, model=sim$model, bString=res2$bString))
198
-        result[run, 3, 2] <- sum(ETT2 == ETT)/length(ETT)
199
-        ERS <- computeFc(CNOlist=sim$CNOlist, y = ETT2)
200
-        ERS2 <- ERS <- ERS[, which(colnames(ERS) %in% colnames(sim$ERS))]
197
+        ETT1 <- t(simulateStatesRecursive(CNOlist=sim$CNOlist, model=sim$model, bString=res1$bString))
198
+        result[run, 3, 2] <- sum(ETT1 == ETT)/length(ETT)
199
+        ERS <- computeFc(CNOlist=sim$CNOlist, y = ETT1)
200
+        ERS1 <- ERS <- ERS[, which(colnames(ERS) %in% colnames(sim$ERS))]
201 201
         result[run, 3, 3] <- sum(ERS == sim$ERS)/length(ERS)
202
-        result[run, 3, 4] <- min(res2$scores)
202
+        result[run, 3, 4] <- min(res1$scores[[1]])
203 203
         result[run, 3, 5] <- sum(ERS == 1 & sim$ERS == 1)+sum(ERS==-1 & sim$ERS == -1)
204 204
         result[run, 3, 6] <- sum(abs(ERS) == 1 & sim$ERS == 0)
205 205
         result[run, 3, 7] <- sum(ERS == 0 & sim$ERS == 0)
206 206
         result[run, 3, 8] <- sum(ERS == 0 & abs(sim$ERS) == 1)
207 207
         
208
-        maxTime <- result[run, 2, 1]*10
209
-        
210 208
         start <- as.numeric(Sys.time())
211
-        res3 <- bnem(search = "genetic", maxTime = maxTime, fc = sim$fc, CNOlist = sim$CNOlist, model = sim$model, method = method, verbose = verbose, draw = draw,stallGenMax=Inf)
209
+        res2 <- bnem(search = "genetic", maxTime = maxTime, fc = sim$fc, CNOlist = sim$CNOlist, model = sim$model, method = method, verbose = verbose, draw = draw,stallGenMax=Inf)
212 210
         result[run, 4, 1] <- as.numeric(Sys.time()) - start
213
-        ETT3 <- t(simulateStatesRecursive(CNOlist=sim$CNOlist, model=sim$model, bString=res3$bString))
214
-        result[run, 4, 2] <- sum(ETT3 == ETT)/length(ETT)
215
-        ERS <- computeFc(CNOlist=sim$CNOlist, y = ETT3)
216
-        ERS3 <- ERS <- ERS[, which(colnames(ERS) %in% colnames(sim$ERS))]
211
+        ETT2 <- t(simulateStatesRecursive(CNOlist=sim$CNOlist, model=sim$model, bString=res2$bString))
212
+        result[run, 4, 2] <- sum(ETT2 == ETT)/length(ETT)
213
+        ERS <- computeFc(CNOlist=sim$CNOlist, y = ETT2)
214
+        ERS2 <- ERS <- ERS[, which(colnames(ERS) %in% colnames(sim$ERS))]
217 215
         result[run, 4, 3] <- sum(ERS == sim$ERS)/length(ERS)
218
-        result[run, 4, 4] <- min(res3$scores)
216
+        result[run, 4, 4] <- min(res2$scores)
219 217
         result[run, 4, 5] <- sum(ERS == 1 & sim$ERS == 1)+sum(ERS==-1 & sim$ERS == -1)
220 218
         result[run, 4, 6] <- sum(abs(ERS) == 1 & sim$ERS == 0)
221 219
         result[run, 4, 7] <- sum(ERS == 0 & sim$ERS == 0)
222 220
         result[run, 4, 8] <- sum(ERS == 0 & abs(sim$ERS) == 1)
223 221
         
222
+        maxTime <- result[run, 2, 1]*10
223
+        
224 224
         start <- as.numeric(Sys.time())
225
-        res4 <- bnem(search = "genetic", fc = sim$fc, CNOlist = sim$CNOlist, model = sim$model, method = method, verbose = verbose, draw = draw)
225
+        res3 <- bnem(search = "genetic", maxTime = maxTime, fc = sim$fc, CNOlist = sim$CNOlist, model = sim$model, method = method, verbose = verbose, draw = draw,stallGenMax=Inf)
226 226
         result[run, 5, 1] <- as.numeric(Sys.time()) - start
227
-        ETT3 <- t(simulateStatesRecursive(CNOlist=sim$CNOlist, model=sim$model, bString=res4$bString))
227
+        ETT3 <- t(simulateStatesRecursive(CNOlist=sim$CNOlist, model=sim$model, bString=res3$bString))
228 228
         result[run, 5, 2] <- sum(ETT3 == ETT)/length(ETT)
229 229
         ERS <- computeFc(CNOlist=sim$CNOlist, y = ETT3)
230 230
         ERS3 <- ERS <- ERS[, which(colnames(ERS) %in% colnames(sim$ERS))]
231 231
         result[run, 5, 3] <- sum(ERS == sim$ERS)/length(ERS)
232
-        result[run, 5, 4] <- min(res4$scores)
232
+        result[run, 5, 4] <- min(res3$scores)
233 233
         result[run, 5, 5] <- sum(ERS == 1 & sim$ERS == 1)+sum(ERS==-1 & sim$ERS == -1)
234 234
         result[run, 5, 6] <- sum(abs(ERS) == 1 & sim$ERS == 0)
235 235
         result[run, 5, 7] <- sum(ERS == 0 & sim$ERS == 0)
236 236
         result[run, 5, 8] <- sum(ERS == 0 & abs(sim$ERS) == 1)
237 237
         
238 238
         start <- as.numeric(Sys.time())
239
-        rand <- sample(c(0,1), length(sim$model$reacID), replace = TRUE)
239
+        res4 <- bnem(search = "genetic", fc = sim$fc, CNOlist = sim$CNOlist, model = sim$model, method = method, verbose = verbose, draw = draw)
240 240
         result[run, 6, 1] <- as.numeric(Sys.time()) - start
241
-        ETT4 <- t(simulateStatesRecursive(CNOlist=sim$CNOlist, model=sim$model, bString=rand))
242
-        result[run, 6, 2] <- sum(ETT4 == ETT)/length(ETT)
243
-        ERS <- computeFc(CNOlist=sim$CNOlist, y = ETT4)
244
-        ERS <- ERS[, which(colnames(ERS) %in% colnames(sim$ERS))]
241
+        ETT3 <- t(simulateStatesRecursive(CNOlist=sim$CNOlist, model=sim$model, bString=res4$bString))
242
+        result[run, 6, 2] <- sum(ETT3 == ETT)/length(ETT)
243
+        ERS <- computeFc(CNOlist=sim$CNOlist, y = ETT3)
244
+        ERS3 <- ERS <- ERS[, which(colnames(ERS) %in% colnames(sim$ERS))]
245 245
         result[run, 6, 3] <- sum(ERS == sim$ERS)/length(ERS)
246
-        result[run, 6, 4] <- scoreDnf(rand, fc = sim$fc, CNOlist = sim$CNOlist, model = sim$model, method = method)
246
+        result[run, 6, 4] <- min(res4$scores)
247 247
         result[run, 6, 5] <- sum(ERS == 1 & sim$ERS == 1)+sum(ERS==-1 & sim$ERS == -1)
248 248
         result[run, 6, 6] <- sum(abs(ERS) == 1 & sim$ERS == 0)
249 249
         result[run, 6, 7] <- sum(ERS == 0 & sim$ERS == 0)
250 250
         result[run, 6, 8] <- sum(ERS == 0 & abs(sim$ERS) == 1)
251
+        
252
+        start <- as.numeric(Sys.time())
253
+        rand <- sample(c(0,1), length(sim$model$reacID), replace = TRUE)
254
+        result[run, 7, 1] <- as.numeric(Sys.time()) - start
255
+        ETT4 <- t(simulateStatesRecursive(CNOlist=sim$CNOlist, model=sim$model, bString=rand))
256
+        result[run, 7, 2] <- sum(ETT4 == ETT)/length(ETT)
257
+        ERS <- computeFc(CNOlist=sim$CNOlist, y = ETT4)
258
+        ERS <- ERS[, which(colnames(ERS) %in% colnames(sim$ERS))]
259
+        result[run, 7, 3] <- sum(ERS == sim$ERS)/length(ERS)
260
+        result[run, 7, 4] <- scoreDnf(rand, fc = sim$fc, CNOlist = sim$CNOlist, model = sim$model, method = method)
261
+        result[run, 7, 5] <- sum(ERS == 1 & sim$ERS == 1)+sum(ERS==-1 & sim$ERS == -1)
262
+        result[run, 7, 6] <- sum(abs(ERS) == 1 & sim$ERS == 0)
263
+        result[run, 7, 7] <- sum(ERS == 0 & sim$ERS == 0)
264
+        result[run, 7, 8] <- sum(ERS == 0 & abs(sim$ERS) == 1)
251 265
 
252 266
         ## result[1,,]; par(mfrow=c(1,4)); plotDnf(sim$model$reacID[as.logical(res1$bString)]); plotDnf(sim$model$reacID[as.logical(sim$bString)]); plotDnf(sim$model$reacID[as.logical(res2$bString)]); plotDnf(sim$model$reacID[as.logical(res3$bString)]);
253 267
         ## result[run,,]
... ...
@@ -260,9 +274,7 @@ if (is.na(commandArgs(TRUE)[2])) {
260 274
     
261 275
 ## general:
262 276
 
263
-system("scp ~/Documents/B-NEM/R/bnem_low.r euler:")
264
-system("scp ~/Documents/B-NEM/R/bnem_main.r euler:")
265
-system("scp ~/Documents/B-NEM/other/bnem_app.r euler:")
277
+## system("scp ~/Documents/bnem/R/bnem_low.r euler:"); system("scp ~/Documents/bnem/R/bnem_main.r euler:"); system("scp ~/Documents/bnem/other/bnem_app.r euler:")
266 278
 
267 279
 ram=1000
268 280
 rm error.txt
... ...
@@ -314,6 +326,9 @@ done
314 326
 
315 327
 ## plot sim:
316 328
 
329
+source("~/Documents/mnem/R/mnems.r")
330
+source("~/Documents/mnem/R/mnems_low.r")
331
+
317 332
 path <- "~/Mount/Eulershare/"
318 333
 n <- 20
319 334
 s <- 4
... ...
@@ -346,15 +361,21 @@ for (n in c(10,20,30)) {
346 361
     results[[count]] <- result
347 362
 }
348 363
 
349
-methods <- c("greedy","greedy\n(inverse absorption)","genetic\n(time-limit)","genetic","genetic (stall)","random")
350
-cols <- c("darkred","red","darkgreen","green","lightgreen","grey")
364
+n.meth <- dim(results[[1]])[2]
365
+if (n.meth==7) {
366
+    methods <- c("greedy","greedy\n(inverse absorption)","greedy\n(spearman)","genetic\n(time-limit)","genetic","genetic (stall)","random")
367
+    cols <- c("darkred","red","blue","darkgreen","green","lightgreen","grey")
368
+} else {
369
+    methods <- c("greedy","greedy\n(inverse absorption)","genetic\n(time-limit)","genetic","genetic (stall)","random")
370
+    cols <- c("darkred","red","darkgreen","green","lightgreen","grey")
371
+}
351 372
 
352 373
 wilcox <- array(NA,c(3,length(methods),length(methods)),list(Sgenes=c(10,20,30),methods=methods,methods2=methods))
353 374
 idx1 <- 5
354
-idx2 <- 8
375
+idx2 <- 6
355 376
 for (i in 1:3) {
356
-    for (j in 1:6) {
357
-        for (k in 1:6) {
377
+    for (j in 1:n.meth) {
378
+        for (k in 1:n.meth) {
358 379
         wilcox[i,j,k] <- wilcox.test(results[[i]][,j,idx1]/(results[[i]][,j,idx1]+results[[i]][,j,idx2]),results[[i]][,k,idx1]/(results[[i]][,k,idx1]+results[[i]][,k,idx2]),alternative="less")$p.value
359 380
         }
360 381
     }
... ...
@@ -363,7 +384,7 @@ for (i in 1:3) {
363 384
 box <- 1
364 385
 time <- 1
365 386
 if (box) {
366
-    restime <- cbind(results[[1]][,1:6,1],results[[2]][,1:6,1],results[[3]][,1:6,1])
387
+    restime <- cbind(results[[1]][,1:n.meth,1],results[[2]][,1:n.meth,1],results[[3]][,1:n.meth,1])
367 388
     if (time) {
368 389
         # pdf("temp.pdf", width = 11, height = 6)
369 390
         # laymat <- matrix(c(rep(1,50),rep(2,50),rep(3,50),rep(4,29),rep(5,21)),2,byrow=TRUE)
... ...
@@ -376,25 +397,29 @@ if (box) {
376 397
         print(apply(restime,2,mean))
377 398
     }
378 399
     layout(laymat)
379
-    v.idx <- c(6.5,12.5)
380
-    axis.idx <- c(3.5,9.5,15.5)
400
+    v.idx <- c(n.meth+0.5,n.meth*2+0.5)
401
+    #v.idx <- c(6.5,12.5)
402
+    axis.idx <- c(n.meth/2+0.5,n.meth*1.5+0.5,n.meth*2.5+0.5)
403
+    #axis.idx <- c(3.5,9.5,15.5)
381 404
     if (time) {
382 405
         myboxplot(restime, col = cols,border=cols,medcol="black",ylab = "seconds (log10-scale)", main = "Running time", box = box,dens=0,xaxt="n",bordercol=cols,log="y")
383 406
         abline(v=v.idx)
384 407
         axis(1,axis.idx,c(10,20,30))
385 408
     }
386
-    resacc <- cbind(results[[1]][,1:6,3],results[[2]][,1:6,3],results[[3]][,1:6,3])
387
-    resacc <- cbind(results[[1]][,1:6,5],results[[2]][,1:6,5],results[[3]][,1:6,5])/(cbind(results[[1]][,1:6,5],results[[2]][,1:6,5],results[[3]][,1:6,5])+cbind(results[[1]][,1:6,6],results[[2]][,1:6,6],results[[3]][,1:6,6]))
409
+    resacc <- cbind(results[[1]][,1:n.meth,3],results[[2]][,1:n.meth,3],results[[3]][,1:n.meth,3])
410
+    resacc <- cbind(results[[1]][,1:n.meth,5],results[[2]][,1:n.meth,5],results[[3]][,1:n.meth,5])/(cbind(results[[1]][,1:n.meth,5],results[[2]][,1:n.meth,5],results[[3]][,1:n.meth,5])+cbind(results[[1]][,1:n.meth,6],results[[2]][,1:n.meth,6],results[[3]][,1:n.meth,6]))
388 411
     myboxplot(resacc, col = cols,border=cols,medcol="black",ylab = "precision", main = "Precision of expected differential effects", box = box,dens=0,xaxt="n",bordercol=cols,ylim=c(0,1))
389 412
     abline(v=v.idx)
390 413
     axis(1,axis.idx,c(10,20,30))
391
-    resll <- -cbind(results[[1]][,1:6,4],results[[2]][,1:6,4],results[[3]][,1:6,4])
392
-    resll <- cbind(results[[1]][,1:6,5],results[[2]][,1:6,5],results[[3]][,1:6,5])/(cbind(results[[1]][,1:6,5],results[[2]][,1:6,5],results[[3]][,1:6,5])+cbind(results[[1]][,1:6,8],results[[2]][,1:6,8],results[[3]][,1:6,8]))
414
+    resll <- -cbind(results[[1]][,1:n.meth,4],results[[2]][,1:n.meth,4],results[[3]][,1:n.meth,4])
415
+    resll <- cbind(results[[1]][,1:n.meth,5],results[[2]][,1:n.meth,5],results[[3]][,1:n.meth,5])/(cbind(results[[1]][,1:n.meth,5],results[[2]][,1:n.meth,5],results[[3]][,1:n.meth,5])+cbind(results[[1]][,1:n.meth,8],results[[2]][,1:n.meth,8],results[[3]][,1:n.meth,8]))
393 416
     myboxplot(resll, col = cols,border=cols,medcol="black",ylab = "recall", main = "Recall of expected differential effects", box = box,dens=0,xaxt="n",bordercol=cols,ylim=c(0,1))#, ylim = c(0,1),dens=0,bordercol=cols)
394 417
     abline(v=v.idx)
395 418
     axis(1,axis.idx,c(10,20,30))
396
-    plot(1:10,col="transparent",yaxt="n",xaxt="n",bty="n",xlab="",ylab="")
397
-    legend("top",legend=methods,col=cols,fill=cols,border=FALSE,box.lwd=0,box.col="transparent",y.intersp=1.5)
419
+    op <- par(mar = rep(0, 4))
420
+    plot(1:100,col="transparent",yaxt="n",xaxt="n",bty="n",xlab="",ylab="")
421
+    legend('top',legend=methods,col=cols,fill=cols,border=FALSE,box.lwd=0,box.col="transparent",y.intersp=2)
422
+    par(op)
398 423
     dev.off()
399 424
 }
400 425
 
401 426
deleted file mode 100644
402 427
new file mode 100644
... ...
@@ -0,0 +1,19 @@
1
+sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
2
+c("C", 1, "D"))
3
+file <- tempfile("interaction",fileext=".sif")
4
+write.table(sifMatrix, file = file, sep = "\t",
5
+row.names = FALSE, col.names = FALSE,
6
+quote = FALSE)
7
+PKN <- CellNOptR::readSIF(file)
8
+CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
9
+maxInhibit = 2, signals = c("A", "B","C","D"))
10
+model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
11
+exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
12
+nrow(slot(CNOlist, "cues")))
13
+fc <- computeFc(CNOlist, exprs)
14
+initBstring <- rep(0, length(model$reacID))
15
+res <- bnem(search = "greedy", model = model, CNOlist = CNOlist,
16
+fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
17
+parallel = NULL, initBstring = initBstring, draw = FALSE, verbose = FALSE,
18
+maxSteps = Inf)
19
+checkTrue(all(res$scores[[1]][-1]-res$scores[[1]][-length(res$scores[[1]])]<=0))
0 20
new file mode 100644
... ...
@@ -0,0 +1,19 @@
1
+set.seed(8675309)
2
+sim <- simBoolGtn()
3
+PKN <- sim$PKN
4
+CNOlist <- sim$CNOlist
5
+model <- sim$model
6
+exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
7
+                nrow(slot(CNOlist, "cues")))
8
+fc <- computeFc(CNOlist, exprs)
9
+initBstring <- rep(0, length(model$reacID))
10
+res <- bnem(search = "genetic", model = model, CNOlist = CNOlist,
11
+            fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
12
+            parallel = NULL, initBstring = initBstring, draw = TRUE,
13
+            verbose = FALSE, maxSteps = Inf)
14
+all.diff <- unlist(lapply(seq_len(nrow(res$bStrings)),function(x) {
15
+    y <- x - res$bString
16
+    y <- all(y==0)
17
+    return(y)
18
+}))
19
+checkTrue(all(!all.diff))
... ...
@@ -1,10 +1,10 @@
1 1
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
2 2
 c("C", 1, "D"))
3
-write.table(sifMatrix, file = "temp.sif", sep = "\t",
3
+file <- tempfile("interaction",fileext=".sif")
4
+write.table(sifMatrix, file = file, sep = "\t",
4 5
 row.names = FALSE, col.names = FALSE,
5 6
 quote = FALSE)
6
-PKN <- CellNOptR::readSIF("temp.sif")
7
-unlink('temp.sif')
7
+PKN <- CellNOptR::readSIF(file)
8 8
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
9 9
 maxInhibit = 2, signals = c("A", "B","C","D"))
10 10
 model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
11 11
new file mode 100644
... ...
@@ -0,0 +1,26 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/bnem_main.r
3
+\name{addNoise}
4
+\alias{addNoise}
5
+\title{Add noise}
6
+\usage{
7
+addNoise(sim, sd = 1)
8
+}
9
+\arguments{
10
+\item{sim}{bnemsim object from simBoolGtn}
11
+
12
+\item{sd}{standard deviation for the rnorm function}
13
+}
14
+\value{
15
+noisy fold-change matrix
16
+}
17
+\description{
18
+Adds noise to simulated data
19
+}
20
+\examples{
21
+sim <- simBoolGtn(Sgenes = 10, maxEdges = 10, negation=0.1,layer=1)
22
+fc <- addNoise(sim,sd=1)
23
+}
24
+\author{
25
+Martin Pirkl
26
+}
... ...
@@ -7,7 +7,7 @@
7 7
 bnem(
8 8
   search = "greedy",
9 9
   fc = NULL,
10
-  exprs = NULL,
10
+  expression = NULL,
11 11
   egenes = NULL,
12 12
   pkn = NULL,
13 13
   design = NULL,
... ...
@@ -64,7 +64,7 @@ equivalent input
64 64
 NULL, the gene expression
65 65
 data is used to calculate naive foldchanges.}
66 66
 
67
-\item{exprs}{Optional normalized m x l matrix of gene expression data 
67
+\item{expression}{Optional normalized m x l matrix of gene expression data 
68 68
 for m E-genes and l experiments.}
69 69
 
70 70
 \item{egenes}{list object; each list entry is named after an S-gene and
... ...
@@ -167,7 +167,9 @@ algorithm would take longer (only "genetic").}
167 167
 
168 168
 \item{delcyc}{If TRUE deletes cycles in all hyper-graphs (not recommended).}
169 169
 
170
-\item{seeds}{how many starts for the greedy search? (default: 1)}
170
+\item{seeds}{how many starts for the greedy search? (default: 1); uses 
171
+the n-dimensional cube (n = number of S-genes) to maximize search 
172
+space coverage}
171 173
 
172 174
 \item{maxSteps}{Maximal number of steps (only "greedy").}
173 175
 
... ...
@@ -195,17 +197,17 @@ as input and trains logical functions on that prior network
195 197
 \examples{
196 198
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
197 199
 c("C", 1, "D"))
198
-write.table(sifMatrix, file = "temp.sif", sep = "\t",
200
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
201
+write.table(sifMatrix, file = temp.file, sep = "\t",
199 202
 row.names = FALSE, col.names = FALSE,
200 203
 quote = FALSE)
201
-PKN <- CellNOptR::readSIF("temp.sif")
202
-unlink('temp.sif')
204
+PKN <- CellNOptR::readSIF(temp.file)
203 205
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
204 206
 maxInhibit = 2, signals = c("A", "B","C","D"))
205 207
 model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
206
-exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
208
+expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
207 209
 nrow(slot(CNOlist, "cues")))
208
-fc <- computeFc(CNOlist, exprs)
210
+fc <- computeFc(CNOlist, expression)
209 211
 initBstring <- rep(0, length(model$reacID))
210 212
 res <- bnem(search = "greedy", model = model, CNOlist = CNOlist,
211 213
 fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
... ...
@@ -36,17 +36,17 @@ Runs Bootstraps on the data
36 36
 \examples{
37 37
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
38 38
 c("C", 1, "D"))
39
-write.table(sifMatrix, file = "temp.sif", sep = "\t",
39
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
40
+write.table(sifMatrix, file = temp.file, sep = "\t",
40 41
 row.names = FALSE, col.names = FALSE,
41 42
 quote = FALSE)
42
-PKN <- CellNOptR::readSIF("temp.sif")
43
-unlink('temp.sif')
43
+PKN <- CellNOptR::readSIF(temp.file)
44 44
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
45 45
 maxInhibit = 2, signals = c("A", "B","C","D"))
46 46
 model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
47
-exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
47
+expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
48 48
 nrow(slot(CNOlist, "cues")))
49
-fc <- computeFc(CNOlist, exprs)
49
+fc <- computeFc(CNOlist, expression)
50 50
 initBstring <- rep(0, length(model$reacID))
51 51
 res <- bnemBs(search = "greedy", model = model, CNOlist = CNOlist,
52 52
 fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
... ...
@@ -21,17 +21,17 @@ computes differential effects given an activation pattern
21 21
 \examples{
22 22
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
23 23
 c("C", 1, "D"))
24
-write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
25
-col.names = FALSE,
24
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
25
+write.table(sifMatrix, file = temp.file, sep = "\t",
26
+row.names = FALSE, col.names = FALSE,
26 27
 quote = FALSE)
27
-PKN <- CellNOptR::readSIF("temp.sif")
28
-unlink('temp.sif')
28
+PKN <- CellNOptR::readSIF(temp.file)
29 29
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
30 30
 signals = c("A", "B","C","D"))
31 31
 model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
32
-exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
32
+expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
33 33
 nrow(slot(CNOlist, "cues")))
34
-fc <- computeFc(CNOlist, exprs)
34
+fc <- computeFc(CNOlist, expression)
35 35
 }
36 36
 \author{
37 37
 Martin Pirkl
... ...
@@ -34,11 +34,11 @@ creates a general CNOlist object from meta information
34 34
 \examples{
35 35
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
36 36
 c("C", 1, "D"))
37
-write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
38
-col.names = FALSE,
37
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
38
+write.table(sifMatrix, file = temp.file, sep = "\t",
39
+row.names = FALSE, col.names = FALSE,
39 40
 quote = FALSE)
40
-PKN <- CellNOptR::readSIF("temp.sif")
41
-unlink('temp.sif')
41
+PKN <- CellNOptR::readSIF(temp.file)
42 42
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
43 43
 signals = c("A", "B","C","D"))
44 44
 }
... ...
@@ -9,7 +9,7 @@ findResiduals(
9 9
   CNOlist,
10 10
   model,
11 11
   fc = NULL,
12
-  exprs = NULL,
12
+  expression = NULL,
13 13
   egenes = NULL,
14 14
   parameters = list(cutOffs = c(0, 1, 0), scoring = c(0.1, 0.2, 0.9)),
15 15
   method = "s",
... ...
@@ -37,7 +37,7 @@ equivalent input
37 37
 NULL, the gene expression
38 38
 data is used to calculate naive foldchanges.}
39 39
 
40
-\item{exprs}{Optional normalized m x l matrix of gene expression data 
40
+\item{expression}{Optional normalized m x l matrix of gene expression data 
41 41
 for m E-genes and l experiments.}
42 42
 
43 43
 \item{egenes}{list object; each list entry is named after an S-gene and
... ...
@@ -87,17 +87,17 @@ visualizes them
87 87
 \examples{
88 88
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
89 89
 c("C", 1, "D"))
90
-write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
91
-col.names = FALSE,
90
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
91
+write.table(sifMatrix, file = temp.file, sep = "\t",
92
+row.names = FALSE, col.names = FALSE,
92 93
 quote = FALSE)
93
-PKN <- CellNOptR::readSIF("temp.sif")
94
-unlink('temp.sif')
94
+PKN <- CellNOptR::readSIF(temp.file)
95 95
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
96 96
 signal = c("A", "B","C","D"))
97 97
 model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
98
-exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
98
+expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
99 99
 nrow(slot(CNOlist, "cues")))
100
-fc <- computeFc(CNOlist, exprs)
100
+fc <- computeFc(CNOlist, expression)
101 101
 initBstring <- rep(0, length(model$reacID))
102 102
 res <- bnem(search = "greedy", CNOlist = CNOlist, fc = fc, model = model,
103 103
 parallel = NULL, initBstring = initBstring, draw = FALSE, verbose = FALSE,
... ...
@@ -18,8 +18,25 @@ plot of boolean network
18 18
 plots the boolen network as disjunctive normal form
19 19
 }
20 20
 \examples{
21
-sim <- simBoolGtn()
22
-plot(sim)
21
+sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
22
+c("C", 1, "D"))
23
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
24
+write.table(sifMatrix, file = temp.file, sep = "\t",
25
+row.names = FALSE, col.names = FALSE,
26
+quote = FALSE)
27
+PKN <- CellNOptR::readSIF(temp.file)
28
+CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
29
+maxInhibit = 2, signals = c("A", "B","C","D"))
30
+model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
31
+expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
32
+nrow(slot(CNOlist, "cues")))
33
+fc <- computeFc(CNOlist, expression)
34
+initBstring <- rep(0, length(model$reacID))
35
+res <- bnem(search = "greedy", model = model, CNOlist = CNOlist,
36
+fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
37
+parallel = NULL, initBstring = initBstring, draw = FALSE, verbose = FALSE,
38
+maxSteps = Inf, seeds = 10)
39
+plot(res)
23 40
 }
24 41
 \author{
25 42
 Martin Pirkl
... ...
@@ -1,10 +1,10 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/bnem_main.r
3
-\name{plot.bnembs}
4
-\alias{plot.bnembs}
3
+\name{plot.bnemBs}
4
+\alias{plot.bnemBs}
5 5
 \title{Plot Bootstrap result}
6 6
 \usage{
7
-\method{plot}{bnembs}(
7
+\method{plot}{bnemBs}(
8 8
   x,
9 9
   scale = 3,
10 10
   shift = 0.1,
... ...
@@ -17,7 +17,7 @@
17 17
 )
18 18
 }
19 19
 \arguments{
20
-\item{x}{bnembs object}
20
+\item{x}{bnemBs object}
21 21
 
22 22
 \item{scale}{numeric value for scaling the edgewidth}
23 23
 
... ...
@@ -46,17 +46,17 @@ or confidence intervals
46 46
 \examples{
47 47
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
48 48
 c("C", 1, "D"))
49
-write.table(sifMatrix, file = "temp.sif", sep = "\t",
49
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
50
+write.table(sifMatrix, file = temp.file, sep = "\t",
50 51
 row.names = FALSE, col.names = FALSE,
51 52
 quote = FALSE)
52
-PKN <- CellNOptR::readSIF("temp.sif")
53
-unlink('temp.sif')
53
+PKN <- CellNOptR::readSIF(temp.file)
54 54
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1,
55 55
 maxInhibit = 2, signals = c("A", "B","C","D"))
56 56
 model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
57
-exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
57
+expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
58 58
 nrow(slot(CNOlist, "cues")))
59
-fc <- computeFc(CNOlist, exprs)
59
+fc <- computeFc(CNOlist, expression)
60 60
 initBstring <- rep(0, length(model$reacID))
61 61
 res <- bnemBs(search = "greedy", model = model, CNOlist = CNOlist,
62 62
 fc = fc, pkn = PKN, stimuli = "A", inhibitors = c("B","C","D"),
... ...
@@ -23,11 +23,11 @@ reduces the size of a graph, if possible, to an equivalent sub-graph
23 23
 \examples{
24 24
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
25 25
 c("C", 1, "D"))
26
-write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
27
-col.names = FALSE,
26
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
27
+write.table(sifMatrix, file = temp.file, sep = "\t",
28
+row.names = FALSE, col.names = FALSE,
28 29
 quote = FALSE)
29
-PKN <- CellNOptR::readSIF("temp.sif")
30
-unlink('temp.sif')
30
+PKN <- CellNOptR::readSIF(temp.file)
31 31
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
32 32
 signal = c("A", "B","C","D"))
33 33
 model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
... ...
@@ -8,7 +8,7 @@ scoreDnf(
8 8
   bString,
9 9
   CNOlist,
10 10
   fc,
11
-  exprs = NULL,
11
+  expression = NULL,
12 12
   model,
13 13
   method = "cosine",
14 14
   sizeFac = 10^-10,
... ...
@@ -30,7 +30,7 @@ equivalent input
30 30
 NULL, the gene expression
31 31
 data is used to calculate naive foldchanges.}
32 32
 
33
-\item{exprs}{Optional normalized m x l matrix of gene expression data 
33
+\item{expression}{Optional normalized m x l matrix of gene expression data 
34 34
 for m E-genes and l experiments.}
35 35
 
36 36
 \item{model}{Model object including the search space, if available.
... ...
@@ -27,11 +27,11 @@ annotated perturbation experiments
27 27
 \examples{
28 28
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
29 29
 c("C", 1, "D"))
30
-write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
31
-col.names = FALSE,
30
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
31
+write.table(sifMatrix, file = temp.file, sep = "\t",
32
+row.names = FALSE, col.names = FALSE,
32 33
 quote = FALSE)
33
-PKN <- CellNOptR::readSIF("temp.sif")
34
-unlink('temp.sif')
34
+PKN <- CellNOptR::readSIF(temp.file)
35 35
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
36 36
 signal = c("A", "B","C","D"))
37 37
 model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
... ...
@@ -7,7 +7,7 @@
7 7
 validateGraph(
8 8
   CNOlist,
9 9
   fc = NULL,
10
-  exprs = NULL,
10
+  expression = NULL,
11 11
   model,
12 12
   bString,
13 13
   Egenes = 25,
... ...
@@ -43,7 +43,7 @@ equivalent input
43 43
 NULL, the gene expression
44 44
 data is used to calculate naive foldchanges.}
45 45
 
46
-\item{exprs}{Optional normalized m x l matrix of gene expression data 
46
+\item{expression}{Optional normalized m x l matrix of gene expression data 
47 47
 for m E-genes and l experiments.}
48 48
 
49 49
 \item{model}{Model object including the search space, if available.
... ...
@@ -54,7 +54,7 @@ See CellNOptR::preprocessing.}
54 54
 \item{Egenes}{Maximal number of visualized E-genes.}
55 55
 
56 56
 \item{Sgene}{Integer denoting the S-gene. See
57
-colnames(CNOlist@signals[[1]]) to match integer with S-gene name.}
57
+colnames(getSignals(CNOlist)[[1]]) to match integer with S-gene name.}
58 58
 
59 59
 \item{parameters}{parameters for discrete case (not recommended);
60 60
 has to be a list with entries cutOffs and scoring:
... ...
@@ -121,17 +121,17 @@ expected differential effects of the regulating signalling gene
121 121
 \examples{
122 122
 sifMatrix <- rbind(c("A", 1, "B"), c("A", 1, "C"), c("B", 1, "D"),
123 123
 c("C", 1, "D"))
124
-write.table(sifMatrix, file = "temp.sif", sep = "\t", row.names = FALSE,
125
-col.names = FALSE,
124
+temp.file <- tempfile(pattern="interaction",fileext=".sif")
125
+write.table(sifMatrix, file = temp.file, sep = "\t",
126
+row.names = FALSE, col.names = FALSE,
126 127
 quote = FALSE)
127
-PKN <- CellNOptR::readSIF("temp.sif")
128
-unlink('temp.sif')
128
+PKN <- CellNOptR::readSIF(temp.file)
129 129
 CNOlist <- dummyCNOlist("A", c("B","C","D"), maxStim = 1, maxInhibit = 2,
130 130
 signal = c("A", "B","C","D"))
131 131
 model <- CellNOptR::preprocessing(CNOlist, PKN, maxInputsPerGate = 100)
132
-exprs <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
132
+expression <- matrix(rnorm(nrow(slot(CNOlist, "cues"))*10), 10,
133 133
 nrow(slot(CNOlist, "cues")))
134
-fc <- computeFc(CNOlist, exprs)
134
+fc <- computeFc(CNOlist, expression)
135 135
 initBstring <- rep(0, length(model$reacID))
136 136
 res <- bnem(search = "greedy", CNOlist = CNOlist, fc = fc,
137 137
 model = model, parallel = NULL, initBstring = initBstring, draw = FALSE,
... ...
@@ -53,6 +53,7 @@ fig.cap2 <- "Expected and observed data. The expected data pattern
53 53
 E-genes attached to S1."
54 54
 fig.cap3 <- "BCR signalling. The PKN (left) and the greedy optimum 
55 55
 with an empty start network (right)."
56
+
56 57
 ```
57 58
 
58 59
 Install the package with the devtools library or via Bioconductor.
... ...
@@ -84,17 +85,10 @@ the function generates data given the ground truth.
84 85
 
85 86
 ```{r}
86 87
 set.seed(9247)
87
-
88 88
 sim <- simBoolGtn(Sgenes = 10, maxEdges = 10, keepsif = TRUE, negation=0.1,
89 89
                   layer=1)
90
-fc <- sim$fc
91
-pos <- which(fc == 1)
92
-neg <- which(fc == -1)
93
-zero <- which(fc == 0)
94
-fc[pos] <- rnorm(length(pos),1,1)
95
-fc[neg] <- rnorm(length(neg),-1,1)
96
-fc[zero] <- rnorm(length(zero),0,1)
97
-exprs <- sim$exprs
90
+fc <- addNoise(sim,sd=1)
91
+expression <- sim$expression
98 92
 CNOlist <- sim$CNOlist
99 93
 model <- sim$model
100 94
 bString <- sim$bString
... ...
@@ -149,7 +143,7 @@ parallel <- NULL # NULL for serialization
149 143
 ## greedy search:
150 144
 greedy <- bnem(search = "greedy",
151 145
                fc=fc,
152
-               exprs=exprs, # not used, if fc is defined
146
+               expression=expression, # not used, if fc is defined
153 147
                CNOlist=CNOlist,
154 148
                model=model,
155 149
                parallel=parallel,
... ...
@@ -163,7 +157,7 @@ greedy <- bnem(search = "greedy",
163 157
 
164 158
 greedy2 <- bnem(search = "greedy",
165 159
                 fc=fc,
166
-                exprs=exprs,
160
+                expression=expression,
167 161
                 CNOlist=CNOlist,
168 162
                 model=model,
169 163
                 parallel=parallel,
... ...
@@ -181,22 +175,20 @@ inferred networks. We first look at the respective scores
181 175
 specificity of the edges for both results.
182 176
 
183 177
 ```{r}
184
-print(greedy$scores) # rank correlation = normalized
185
-print(greedy2$scores) # scaled log foldchanges
186
-
187
-resString <- greedy$bString
188
-
189
-print(sum(bString == 1 & resString == 1)/
190
-      (sum(bString == 1 & resString == 1) + sum(bString == 1 & resString == 0)))
191
-print(sum(bString == 0 & resString == 0)/
192
-      (sum(bString == 0 & resString == 0) + sum(bString == 0 & resString == 1)))
178
+greedy$scores # rank correlation = normalized
179
+greedy2$scores # scaled log foldchanges
180
+
181
+accuracy <- function(gtn,inferred) {
182
+  sens <- sum(gtn == 1 & inferred == 1)/
183
+    (sum(gtn == 1 & inferred == 1) + sum(gtn == 1 & inferred == 0))
184
+  spec <- sum(gtn == 0 & inferred == 0)/
185
+      (sum(gtn == 0 & inferred == 0) + sum(gtn == 0 & inferred == 1))
186
+  return(c(sens,spec))
187
+}
193 188
 
189
+accuracy(bString,greedy$bString)
190
+accuracy(bString,greedy2$bString)
194 191
 resString <- greedy2$bString
195
-
196
-print(sum(bString == 1 & resString == 1)/
197
-      (sum(bString == 1 & resString == 1) + sum(bString == 1 & resString == 0)))
198
-print(sum(bString == 0 & resString == 0)/
199
-      (sum(bString == 0 & resString == 0) + sum(bString == 0 & resString == 1)))
200 192
 ```
201 193
 
202 194
 We take a look at the efficiency of the search algorithm with
... ...
@@ -207,20 +199,12 @@ hyper-graph can differ from the GTN and still be $100\%$ accurate.
207 199
 
208 200
 ```{r, fig.width = 15, fig.height = 5, fig.cap = fig.cap1}
209 201
 par(mfrow=c(1,2))
210
-
211 202
 ## GTN:
212 203
 plotDnf(model$reacID[as.logical(bString)], main = "GTN", stimuli = stimuli)
213
-
214 204
 ## greedy optimum:
215 205
 plotDnf(model$reacID[as.logical(resString)], main = "greedy optimum",
216 206
         stimuli = stimuli)
217 207
 
218
-## hyper-edge sensitivity and specificity:
219
-print(sum(bString == 1 & resString == 1)/
220
-      (sum(bString == 1 & resString == 1) + sum(bString == 1 & resString == 0)))
221
-print(sum(bString == 0 & resString == 0)/
222
-      (sum(bString == 0 & resString == 0) + sum(bString == 0 & resString == 1)))
223
-
224 208
 ## accuracy of the expected response scheme (can be high even, if
225 209
 ## the networks differ):
226 210
 ERS.res <- computeFc(CNOlist,
... ...
@@ -233,7 +217,7 @@ After optimization we look at the data and how well the greedy optimum
233 217
 explains the E-genes. The lower the score the better the fit.
234 218
 
235 219
 ```{r, fig.width = 15, fig.height = 10, fig.cap = fig.cap3}
236
-fitinfo <- validateGraph(CNOlist, fc=fc, exprs=exprs, model = model,
220
+fitinfo <- validateGraph(CNOlist, fc=fc, expression=expression, model = model,
237 221
                          bString = resString,
238 222
                          Sgene = 4, Egenes = 1000, cexRow = 0.8,
239 223
                          cexCol = 0.7,
... ...
@@ -255,7 +239,7 @@ recommended for search spaces with more than 20 hyper-edges.
255 239
 ## genetic algorithm:
256 240
 genetic <- bnem(search = "genetic",
257 241
            fc=fc,
258
-           exprs=exprs,
242
+           expression=expression,
259 243
            parallel = parallel,
260 244
            CNOlist=CNOlist,
261 245
            model=model,
... ...
@@ -265,7 +249,6 @@ genetic <- bnem(search = "genetic",
265 249
            draw = FALSE,
266 250
            verbose = FALSE
267 251
            )
268
-resString <- genetic$bString
269 252
 ```
270 253
 
271 254
 ```{r, eval = FALSE}
... ...
@@ -274,10 +257,9 @@ exhaustive <- bnem(search = "exhaustive",
274 257
                    parallel = parallel,
275 258
                    CNOlist=CNOlist,
276 259
                    fc=fc,
277
-                   exprs=exprs,
260
+                   expression=expression,
278 261
                    model=model
279 262
                    )
280
-resString <- exhaustive$bString
281 263
 ```
282 264
 
283 265
 # Stimulated and inhibited S-genes can overlap
... ...
@@ -298,14 +280,8 @@ is inhibited the inhibitor S-gene is set to 0.
298 280
 set.seed(9247)
299 281
 sim <- simBoolGtn(Sgenes = 4, maxEdges = 50, dag = FALSE,
300 282
                   negation = 0, allstim = TRUE,frac=0.1)
301
-fc <- sim$fc
302
-pos <- which(fc == 1)
303
-neg <- which(fc == -1)
304
-zero <- which(fc == 0)
305
-fc[pos] <- rnorm(length(pos),1,1)
306
-fc[neg] <- rnorm(length(neg),-1,1)
307
-fc[zero] <- rnorm(length(zero),0,1)
308
-exprs <- sim$exprs
283
+fc <- addNoise(sim,sd=1)
284
+expression <- sim$expression
309 285
 CNOlist <- sim$CNOlist
310 286
 model <- sim$model
311 287
 bString <- sim$bString
... ...
@@ -330,7 +306,7 @@ plotDnf(sim$model$reacID[as.logical(bString)], stimuli = stimuli)
330 306
 greedy3 <- bnem(search = "greedy",
331 307
                 CNOlist=CNOlist,
332 308
                 fc=fc,
333
-                exprs=exprs,
309
+                expression=expression,
334 310
                 model=model,
335 311
                 parallel=parallel,
336 312
                 initBstring=bString*0,
... ...
@@ -350,12 +326,7 @@ plotDnf(model$reacID[as.logical(bString)], main = "GTN", stimuli = stimuli)
350 326
 plotDnf(model$reacID[as.logical(resString2)], main = "greedy optimum",
351 327
         stimuli = stimuli)
352 328
 
353
-print(sum(bString == 1 & resString2 == 1)/
354
-      (sum(bString == 1 & resString2 == 1) + sum(bString == 1 &
355
-                                                 resString2 == 0)))
356
-print(sum(bString == 0 & resString2 == 0)/
357
-      (sum(bString == 0 & resString2 == 0) + sum(bString == 0 &
358
-                                                 resString2 == 1)))
329
+accuracy(bString,resString2)
359 330
 ERS.res <- computeFc(CNOlist, t(simulateStatesRecursive(CNOlist, model,
360 331
                                                         resString2)))
361 332
 ERS.res <- ERS.res[, which(colnames(ERS.res) %in% colnames(ERS))]
... ...
@@ -382,7 +353,7 @@ initBstring <- reduceGraph(rep(0, length(model$reacID)), model, CNOlist)
382 353
 greedy2b <- bnem(search = "greedy",
383 354
                  CNOlist=CNOlist,
384 355
                  fc=fc,
385
-                 exprs=exprs,
356
+                 expression=expression,
386 357
                  egenes=egenes,
387 358
                  model=model,
388 359
                  parallel=parallel,
... ...
@@ -403,12 +374,7 @@ just a subset of S-genes. This way S-genes, which do not have the
403 374
 E-genes included in their E-gene set are excluded as potential parents.
404 375
 
405 376
 ```{r}
406
-print(sum(bString == 1 & resString3 == 1)/
407
-      (sum(bString == 1 & resString3 == 1) + sum(bString == 1 &
408
-                                                 resString3 == 0)))
409
-print(sum(bString == 0 & resString3 == 0)/
410
-      (sum(bString == 0 & resString3 == 0) + sum(bString == 0 &
411
-                                                 resString3 == 1)))
377
+accuracy(bString,resString3)
412 378
 ERS.res <- computeFc(CNOlist,
413 379
                      t(simulateStatesRecursive(CNOlist, model, resString3)))
414 380
 ERS.res <- ERS.res[, which(colnames(ERS.res) %in% colnames(ERS))]
... ...
@@ -441,7 +407,7 @@ with up to triple inhibitions. See Pirkl et al. 2016 for more details.
441 407
 data(bcr)
442 408
 ## head(fc)
443 409
 fc <- bcr$fc
444
-exprs <- bcr$exprs
410
+expression <- bcr$expression
445 411
 ```
446 412
 
447 413
 We build a PKN to incorporate biological knowledge and account for
... ...
@@ -477,11 +443,10 @@ for (i in c("Ikk2", "p38", "Jnk")) {
477 443
         }
478 444
     }
479 445
 }
480
-
481
-write.table(sifMatrix, file = "temp.sif", sep = "\t",
446
+file <- tempfile(pattern="interaction",fileext=".sif")
447
+write.table(sifMatrix, file = file, sep = "\t",
482 448
             row.names = FALSE, col.names = FALSE, quote = FALSE)
483
-PKN <- readSIF("temp.sif")
484
-unlink("temp.sif")
449
+PKN <- readSIF(file)
485 450
 ```
486 451
 
487 452
 In the next step, we create the meta information. This ensures, that