@@ -25,19 +25,25 @@ Type 'q()' to quit R.
25
25
>
26
26
> # Defining some odds and ends.
27
27
>
28
- > lower.left <- function(x) {
28
+ > lower.left <- function(x, exclude=0 ) {
29
29
+ out <- matrix(TRUE, nrow=nrow(x), ncol=ncol(x))
30
- + out[nrow(x),1 ] <- FALSE
30
+ + out[nrow(x)+(-exclude):0,1:(1+exclude) ] <- FALSE
31
31
+ out
32
32
+ }
33
- > all.but.middle <- function(x) {
33
+ >
34
+ > all.but.middle <- function(x, exclude=0) {
34
35
+ out <- matrix(TRUE, nrow=nrow(x), ncol=ncol(x))
35
- + out[ceiling(length(out)/2)] <- FALSE
36
+ + midrow <- ceiling(nrow(x)/2) + (-exclude):exclude
37
+ + midrow <- midrow[midrow > 0 & midrow <= nrow(x)]
38
+ + midcol <- ceiling(ncol(x)/2) + (-exclude):exclude
39
+ + midcol <- midcol[midcol > 0 & midcol <= ncol(x)]
40
+ + out[midrow, midcol] <- FALSE
36
41
+ out
37
42
+ }
38
43
>
39
- > comp <- function(npairs, chromos, flanking, prior=2) {
44
+ > comp <- function(npairs, chromos, flanking, exclude=0, prior=2) {
40
45
+ flanking <- as.integer(flanking)
46
+ + exclude <- as.integer(exclude)
41
47
+
42
48
+ nlibs <- 4L
43
49
+ lambda <- 5
@@ -56,7 +62,7 @@ Type 'q()' to quit R.
56
62
+ data@regions$nfrags <- rep(1:3, length.out=nbins)
57
63
+
58
64
+ # Computing the reference enrichment value.
59
- + bg <- enrichedPairs(data, flank=flanking, prior.count=prior)
65
+ + bg <- enrichedPairs(data, flank=flanking, prior.count=prior, exclude=exclude )
60
66
+ final.ref <- numeric(length(bg))
61
67
+
62
68
+ # Sorting them by chromosome pairs.
@@ -93,6 +99,7 @@ Type 'q()' to quit R.
93
99
+ for (pair in 1:nrow(current)) {
94
100
+ total.num <- 4L
95
101
+ collected <- numeric(total.num)
102
+ + collected.n <- numeric(total.num)
96
103
+ ax <- a.dex[pair]
97
104
+ tx <- t.dex[pair]
98
105
+
@@ -121,16 +128,22 @@ Type 'q()' to quit R.
121
128
+ out[x > alen | x < 1 | y > tlen | y < 1] <- -1
122
129
+ return(out)
123
130
+ })
124
- + indices <- indices[keep(indices)]
131
+ + indices <- indices[keep(indices, exclude )]
125
132
+ indices <- indices[indices > 0]
126
133
+ indices <- indices[valid[indices]]
127
134
+
128
135
+ # Computing the average across this quadrant.
129
136
+ relevant.rows <- inter.space[indices]
130
137
+ is.zero <- relevant.rows==0L
131
138
+ collected[quad] <- sum(rel.ab[relevant.rows[!is.zero]])/length(relevant.rows)
139
+ + collected.n[quad] <- length(relevant.rows)
132
140
+ }
133
- + # print(sprintf("%i %i %.3f", ax, tx, collected[6]))
141
+ +
142
+ + # if (exclude) { # Troubleshooting.
143
+ + # print(c(aid[pair], tid[pair]))
144
+ + # print(collected)
145
+ + # print(collected.n)
146
+ + # }
134
147
+
135
148
+ output[pair] <- log2((rel.ab[pair]+prior)/(max(collected, na.rm=TRUE)+prior))
136
149
+ }
@@ -183,6 +196,15 @@ Type 'q()' to quit R.
183
196
> comp(200, c(chrA=20, chrB=5), 1)
184
197
[1] -0.11150832 -0.49642583 0.08572987 -0.02106162 -0.36564947 0.99297957
185
198
>
199
+ > comp(200, c(chrA=10, chrB=30, chrC=20), 3, exclude=1)
200
+ [1] -0.03394733 1.53115606 1.09019781 1.51255401 -0.32192809 0.47846288
201
+ > comp(200, c(chrA=10, chrC=20), 3, exclude=1)
202
+ [1] 0.9177729 1.4823928 0.6076826 0.6100535 0.4639471 0.9855004
203
+ > comp(200, c(chrA=10, chrB=5, chrC=20), 3, exclude=1)
204
+ [1] 1.1803590 -0.3870231 1.3440294 1.4636562 1.0533811 0.8349408
205
+ > comp(200, c(chrA=20, chrB=5), 3, exclude=1)
206
+ [1] 0.49749966 0.64114534 -0.04439412 -0.07275634 0.18737014 0.46174548
207
+ >
186
208
> ###################################################################################################
187
209
> # Same sort of simulation, but direct from read data, for neighbourCounts testing.
188
210
>
@@ -193,16 +215,17 @@ Type 'q()' to quit R.
193
215
> dir1<-"temp-neighbor/1.h5"
194
216
> dir2<-"temp-neighbor/2.h5"
195
217
>
196
- > comp2 <- function(npairs1, npairs2, width, cuts, filter=1, flank=5, prior.count=2) {
218
+ > comp2 <- function(npairs1, npairs2, width, cuts, filter=1, flank=5, exclude=0, prior.count=2) {
197
219
+ simgen(dir1, npairs1, chromos)
198
220
+ simgen(dir2, npairs2, chromos)
199
221
+ param <- pairParam(fragments=cuts)
200
222
+
201
- + out <- neighbourCounts(c(dir1, dir2), param, width=width, filter=filter, flank=flank, prior.count=prior.count)
223
+ + out <- neighbourCounts(c(dir1, dir2), param, width=width, filter=filter, flank=flank, prior.count=prior.count,
224
+ + exclude=exclude)
202
225
+
203
226
+ ref <- squareCounts(c(dir1, dir2), width=width, param, filter=1)
204
227
+ keep <- rowSums(counts(ref)) >= filter
205
- + enrichment <- enrichedPairs(ref, flank=flank, prior.count=prior.count)
228
+ + enrichment <- enrichedPairs(ref, flank=flank, prior.count=prior.count, exclude=exclude )
206
229
+
207
230
+ if (!identical(ref[keep,], out$interaction)) { stop("extracted counts don't match up") }
208
231
+ if (any(abs(enrichment[keep] - out$enrichment) > 1e-6)) { stop("enrichment values don't match up") }
@@ -247,6 +270,15 @@ numeric(0)
247
270
> comp2(10, 20, 1000, cuts=simcuts(chromos), prior.count=1)
248
271
[1] 0.5556565 0.5494439 0.5123425 0.5123425 0.5659609 0.5620062
249
272
>
273
+ > comp2(10, 20, 1000, cuts=simcuts(chromos), exclude=1)
274
+ [1] 0.2333634 0.2617857 0.3156551 0.3203674 0.3071017 0.2802203
275
+ > comp2(50, 20, 1000, cuts=simcuts(chromos), exclude=1)
276
+ [1] 0.2393575 0.2314517 0.2759848 0.2487711 0.2332494 0.2502265
277
+ > comp2(100, 50, 1000, cuts=simcuts(chromos), exclude=2)
278
+ [1] 0.2782308 0.3050583 0.5465546 0.2617857 0.2036715 0.1560364
279
+ > comp2(50, 200, 1000, cuts=simcuts(chromos), exclude=2)
280
+ [1] 0.09905107 0.26167813 0.26713529 0.26081098 0.15124940 0.24708803
281
+ >
250
282
> #####################################################################################################
251
283
> # Cleaning up
252
284
>
@@ -259,4 +291,4 @@ numeric(0)
259
291
>
260
292
> proc.time()
261
293
user system elapsed
262
- 11.464 0.298 11.755
294
+ 12.418 0.362 12.783
0 commit comments