-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApobecExp.ReplicationTime.cls
343 lines (297 loc) · 7.22 KB
/
ApobecExp.ReplicationTime.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
///
/// Class for analysis of distribution of APOBEC mutations
/// relative to replication time
///
Class ApobecExp.ReplicationTime [ Abstract ]
{
/// Function returns value of replication timing
/// for particular cell line and chromosome position
ClassMethod GetRTval(cellline As %String, chr As %String, pos As %Integer) As %Float
{
if '$data(^RT(cellline,chr,pos), list)
{
set startpos = $order(^RT(cellline,chr,pos),-1,list)
if (startpos = "") {
return "" }
else
{
if (pos > $listget(list,1)) {
return "" }
else {
return $listget(list,2) }
}
}
else {
return $listget(list,2) }
}
/// Function returns replication timing bin number
/// for particular cell line and chromosome position
ClassMethod GetRTbin(cellline As %String, chr As %String, pos As %Integer) As %Float
{
if '$data(^RT(cellline,chr,pos), list)
{
set startpos = $order(^RT(cellline,chr,pos),-1,list)
if (startpos = "") {
return 0 }
else
{
if (pos > $listget(list,1)) {
return 0 }
else {
return $listget(list,3) }
}
}
else {
return $listget(list,3) }
}
/// Function returns interval of replication timing measurment
/// for particular cell line and chromosome position
ClassMethod GetRTInterval(cellline As %String, chr As %String, pos As %Integer) As %Library.List
{
if '$data(^RT(cellline,chr,pos), list)
{
set startpos = $order(^RT(cellline,chr,pos),-1,list)
if (startpos = "") {
return "" }
else
{
if (pos > $listget(list,1)) {
return "" }
else
{
set endpos = $listget(^RT(cellline,chr,startpos),1)
return $listbuild(startpos,endpos)
}
}
}
else
{
set startpos = pos
set endpos = $listget(^RT(cellline,chr,pos),1)
return $listbuild(startpos,endpos)
}
}
/// Function returns number of TCW motifs (potential APOBEC targets)
/// for the particular chromosome and position range
ClassMethod GetTCWinRange(chr As %String, startpos As %Integer, endpos As %Integer) As %Integer
{
set cnt = 0
if ($data(^TCW(chr,startpos)) '= 0) {
set cnt = cnt + 1 }
set pos = $order(^TCW(chr,startpos))
while ((pos '= "") && (pos <= endpos))
{
set cnt = cnt + 1
set pos = $order(^TCW(chr,pos))
}
return cnt
}
/// Function divide replication timing values
/// into seven bins for all cell lines
ClassMethod CreateRTBins()
{
kill ^RTbins
for i = 1:1:^cellLinesRT
{
set cl = ^cellLinesRT(i)
write cl, !
kill ^RTval
set cnt = 0
set totalTCW = 0
set tmp1 = 0
set tmp2 = 0
set chr = $order(^RT(cl,""))
while(chr '= "")
{
write chr, !
set pos = $order(^RT(cl,chr,""))
while (pos '= "")
{
//write pos, !
set startpos = pos
set endpos = $listget(^RT(cl,chr,pos),1)
set val = $listget(^RT(cl,chr,pos),2)
set TCWcnt = ..GetTCWinRange(chr,startpos,endpos)
if ($data(^RTval(val)) = 0) {
set ^RTval(val) = TCWcnt
set tmp1 = tmp1 + 1}
else {
set ^RTval(val) = ^RTval(val) + TCWcnt
set tmp2 = tmp2 + 1}
set cnt = cnt + 1
set totalTCW = totalTCW + TCWcnt
set pos = $order(^RT(cl,chr,pos))
}
set chr = $order(^RT(cl,chr))
}
set ^RTval = $lb(cnt,totalTCW)
set binsize = totalTCW/7
write totalTCW, $c(9), binsize, $c(9), tmp1, $c(9), tmp2, !
set val = $order(^RTval(""))
set curTCW = 0
set binnum = 1
set j = 0
while (val '= "")
{
set curTCW = curTCW + ^RTval(val)
if (curTCW > (binsize*binnum))
{
set ^RTbins(cl,val) = binnum
set binnum = binnum + 1
}
set pval = val
set val = $order(^RTval(val))
set j = j + 1
}
set ^RTbins(cl,pval) = binnum
write j, $c(9), curTCW, $c(9), !
}
}
/// Function writes replication timing bins
/// into replication timimng global
ClassMethod SetRTBins()
{
for i = 1:1:^cellLinesRT
{
set cl = ^cellLinesRT(i)
write cl, !
set chr = $order(^RT(cl,""))
while(chr '= "")
{
write chr, !
set pos = $order(^RT(cl,chr,""))
while (pos '= "")
{
set val = $listget(^RT(cl,chr,pos),2)
if ($data(^RTbins(cl,val),binnum) = 0)
{
set val = $order(^RTbins(cl,val))
set binnum = ^RTbins(cl,val)
}
set ^RT(cl,chr,pos) = $listupdate(^RT(cl,chr,pos),3,binnum)
set pos = $order(^RT(cl,chr,pos))
}
set chr = $order(^RT(cl,chr))
}
}
}
/// Function calculates and writes number of TCW motifs
/// for replication timing intervals
ClassMethod GetRTNumberOfTCW()
{
set TOTALTCW = ^TCW
kill ^RTnumTCW
for i = 1:1:^cellLinesRT
{
set cl = ^cellLinesRT(i)
write cl, !
for j = 1:1:7
{
set ^RTnumTCW(cl,j) = 0
}
set chr = $order(^RT(cl,""))
while(chr '= "")
{
write chr, !
set pos = $order(^RT(cl,chr,""))
while (pos '= "")
{
set startpos = pos
set endpos = $listget(^RT(cl,chr,pos),1)
set binnum = $listget(^RT(cl,chr,pos),3)
set TCWcnt = ..GetTCWinRange(chr,startpos,endpos)
set ^RTnumTCW(cl,binnum) = ^RTnumTCW(cl,binnum) + TCWcnt
set pos = $order(^RT(cl,chr,pos))
}
set chr = $order(^RT(cl,chr))
}
set sum = 0
for j = 1:1:7
{
set sum = sum + ^RTnumTCW(cl,j)
}
set ^RTnumTCW(cl,0) = TOTALTCW - sum
}
}
/// Function calculates and writes number of bases
/// for replication timing intervals
ClassMethod GetRTNumberOfAll()
{
set TOTALDNALENGTH = 3095677412
kill ^RTnumAll
for i = 1:1:^cellLinesRT
{
set cl = ^cellLinesRT(i)
write cl, !
for j = 1:1:7
{
set ^RTnumAll(cl,j) = 0
}
set chr = $order(^RT(cl,""))
while(chr '= "")
{
write chr, !
set pos = $order(^RT(cl,chr,""))
while (pos '= "")
{
set startpos = pos
set endpos = $listget(^RT(cl,chr,pos),1)
set binnum = $listget(^RT(cl,chr,pos),3)
set len = endpos - startpos
set ^RTnumAll(cl,binnum) = ^RTnumAll(cl,binnum) + len
set pos = $order(^RT(cl,chr,pos))
}
set chr = $order(^RT(cl,chr))
}
set sum = 0
for j = 1:1:7
{
set sum = sum + ^RTnumAll(cl,j)
}
set ^RTnumAll(cl,0) = TOTALDNALENGTH - sum
}
}
/// Function calculates and saves number of APOBEC mutations
/// for each cancer type, sample and replication timing bin
ClassMethod MutationRTAnalysis()
{
kill ^RTresultsAPOBEC
kill ^RTresultsOther
set ctype = $order(^mutation(""))
while (ctype '= "")
{
write ctype, !
set cl = ^cancerTypeRTCellLines(ctype)
set sample = $order(^mutation(ctype,""))
while (sample '= "")
{
write sample, !
for i = 0:1:7
{
set ^RTresultsAPOBEC(ctype,sample,i) = 0
set ^RTresultsOther(ctype,sample,i) = 0
}
set chr = $order(^mutation(ctype,sample,""))
while (chr '= "")
{
//write chr, !
set pos = $order(^mutation(ctype,sample,chr,""))
while (pos '= "")
{
//write pos, !
set binnum = ..GetRTbin(cl,chr,pos)
set isAPOBEC = $listget(^mutation(ctype,sample,chr,pos),3)
if (isAPOBEC = 1) {
set ^RTresultsAPOBEC(ctype,sample,binnum) = ^RTresultsAPOBEC(ctype,sample,binnum) + 1 }
else {
set ^RTresultsOther(ctype,sample,binnum) = ^RTresultsOther(ctype,sample,binnum) + 1 }
set pos = $order(^mutation(ctype,sample,chr,pos))
}
set chr = $order(^mutation(ctype,sample,chr))
}
set sample = $order(^mutation(ctype,sample))
}
set ctype = $order(^mutation(ctype))
}
}
}