-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneticExample_tests.Rmd
365 lines (311 loc) · 6.88 KB
/
GeneticExample_tests.Rmd
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
344
345
346
347
348
349
350
351
352
353
354
---
title: "Biol 801/Evrn 420/720, Example of unit testing using fake genetic data, unit tests"
date: "March 2018"
output:
pdf_document:
highlight: tango
fontsize: 11pt
geometry: margin=1in
documentclass: article
---
# Tests for find_fixed
```{r find_fixed_source, echo=T}
source("find_fixed.R")
```
This is a low-level function, so let's start with it.
Test it can find one length-2 pattern by itself:
```{r find_fixed_test_1, echo=T}
ms<-"AT"
seq<-"CGAAGGCTATAGA"
h<-find_fixed(ms,seq)
if (length(h)==1 && h==9)
{
print("passed")
} else
{
print("failed")
}
```
Test it can find a length-4 pattern by itself:
```{r find_fixed_test_2, echo=T}
ms<-"ATGG"
seq<-"AGCTTATGGAAGGCC"
h<-find_fixed(ms,seq)
if (length(h)==1 && h==6)
{
print("passed")
} else
{
print("failed")
}
```
Test if output is appropriate if the pattern repeats:
```{r find_fixed_test_3, echo=T}
ms<-"AG"
seq<-"TGACCAGAGAGATCCGGGG"
h<-find_fixed(ms,seq)
if (length(h)==3 && sum(h==c(6,8,10))==3)
{
print("passed")
} else
{
print("failed")
}
```
What if ms itself has a repeat?
```{r find_fixed_test_4, echo=T}
ms<-"AGAG"
seq<-"ATGGCAACAGAGAGAGCCGTAGTC"
h<-find_fixed(ms,seq)
if (length(h)==3 && sum(h==c(9,11,13))==3)
{
print("passed")
} else
{
print("failed")
}
```
Note this helps us with our design - the output here is of length 3, whereas it
would have been of length 2 for a non-repeating `ms`, and we will have to be aware
of this when writing `find_repeat`.
# Tests for my_find_fixed functioin from find_fixed.R file
```{r my_find_fixed_test1}
ms<-"AG"
seq<-"TAGAGTCAGCCTAGag"
h<-my_find_fixed(ms=ms,seq=seq)
if(length(h)==4 && all(h==c(2,4,8,13))==T){
print("my_find_fixed_test1 : passed")
}else{
print("my_find_fixed_test1 : failed")
}
```
```{r my_find_fixed_test2}
ms<-"AGAG" # What if ms itself has a repeat?
seq<-"TAGAGTCAGCCTAGagAGAGTCAGAG"
h<-my_find_fixed(ms=ms,seq=seq)
if(length(h)==3 && all(h==c(2,17,23))==T){
print("my_find_fixed_test2 : passed")
}else{
print("my_find_fixed_test2 : failed")
}
```
# Tests for getseqs
```{r getseqs_source, echo=T}
source("getseqs.R")
```
This is another low-level function, so let's continue with it next.
I realized I could make my best implementation of `getseqs` using the function `dec_to_baseb` which converts a nonnegative decimal integer into its base-b equivalent. Test it for a few examples:
```{r baseb_test_1, echo=T}
h<-dec_to_baseb(12,4)
if (length(h)==2 && sum(h==c(3,0))==2)
{
print("passed")
} else
{
print("failed")
}
h<-dec_to_baseb(320,4)
if (length(h)==5 && sum(h==c(1,1,0,0,0))==5)
{
print("passed")
} else
{
print("failed")
}
```
We already thought of this one at the design stage:
```{r getseqs_test_1, echo=T}
h<-getseqs(2)
if (length(h)==4^2 && sum(h==c("AA", "AC", "AG", "AT", "CA", "CC", "CG", "CT", "GA", "GC", "GG", "GT", "TA", "TC", "TG", "TT"))==4^2)
{
print("passed")
} else
{
print("failed")
}
```
Note we also realize something here of which we should remain aware: repeating patterns are included!
Simple test for length-4 patterns, only tests the length because I do not want to type out all $4^4=256$ length-4 sequences:
```{r getseqs_test_2, echo=T}
h<-getseqs(4)
if (length(h)==4^4)
{
print("passed")
} else
{
print("failed")
}
```
# Tests for find_repeat
```{r find_repeat_source, echo=T}
source("find_repeat.R")
```
Test for one repeat of the target `ms` only:
```{r find_repeat_test_1, echo=T}
ms<-"CG"
seq<-"AATGGGCCACGCGCGCGCGCGCGCGCGCGCGACAATTCGCGCGCGGA"
#Note this has CG occuring 4 times (which should be ignored) as well as 11 times
repmin<-10
h<-find_repeat(ms,seq,repmin)
#should be one row with 11 reps at start loc 10
if(dim(h)[1]==1)
{
print("passed")
} else
{
print("failed")
}
if (h[1,1]=="CG")
{
print("passed")
} else
{
print("failed")
}
if (h[1,2]==10)
{
print("passed")
} else
{
"failed"
}
if (h[1,3]==11)
{
print("passed")
} else
{
"failed"
}
```
Test for two repeats:
```{r find_repeat_test_2, echo=T}
ms<-"CG"
seq<-"AATGGGCCACGCGCGCGCGCGCGCGCGCGCGACAATTCGCGCGCGGA"
#Note this has CG occuring 4 times (which should be ignore) as well as 11 times
repmin<-4
h<-find_repeat(ms,seq,repmin)
#should be two rows, one with 11 reps at start loc 10, one with 4 reps at loc 38
if(dim(h)[1]==2)
{
print("passed")
} else
{
print("failed")
}
if (h[1,1]=="CG" && h[2,1]=="CG")
{
print("passed")
} else
{
print("failed")
}
if (h[1,2]==10)
{
print("passed")
} else
{
"failed"
}
if (h[1,3]==11)
{
print("passed")
} else
{
"failed"
}
if (h[2,2]==38)
{
print("passed")
} else
{
"failed"
}
if (h[2,3]==4)
{
print("passed")
} else
{
"failed"
}
```
Test for the case of an `ms` that itself has repeats. This is a test written in response to something we realized
in our above unit testing. We will have to write the function to get this right.
```{r find_repeat_test_3, echo=T}
ms<-"AGAG"
seq<-"TTAGAGAGAGAGAGAGAGAGAGTTACACT"
repmin<-4
h<-find_repeat(ms,seq,repmin)
if(dim(h)[1]==1)
{
print("passed")
} else
{
print("failed")
}
if (h[1,1]=="AGAG")
{
print("passed")
} else
{
print("failed")
}
if (h[1,2]==3)
{
print("passed")
} else
{
"failed"
}
if (h[1,3]==5)
{
print("passed")
} else
{
"failed"
}
```
# Tests for find_microsats
```{r find_microsats_source, echo=T}
source("find_microsats.R")
```
Test for an example with various features but little else between the features:
```{r }
seq<-paste0("T", #pos 1
"AGAGAGAG", #pos 2 to 9, 4 reps of AG, 3 reps of GA
"T", #pos 10
"CATCATCATCATCAT", #pos 11 to 25, 5 reps of CAT, 5 reps of ATC, 5 reps of TCA
"CTT", #pos 26 to 28
"AGAGAGAGAGAGAGAG", #pos 29 to 44, 8 reps of AG, 8 reps of GA (including subsequent A)
"ATC", #pos 45 to 47
"AAAAAAAA", #pos 48 to 55, 4 reps of AA,
"TTA")
h<-find_microsats(seq=seq,lenmin=2,lenmax=6,repmin=4)
h
```
The result should show:
- 4 reps of "AG" starting at pos 2
- 5 reps of "CAT" starting at pos 11
- 5 reps of "ATC" starting at 12
- 5 reps of "TCA" starting at 10
- 8 reps of "AG" starting at pos 29
- 8 reps of "GA" starting at pos 30
- 4 reps of "AA" starting at pos 48
- 4 reps of "AGAG" starting at pos 29
- 4 reps of "GAGA" starting at pos 30
I don't care what order these appear in.
We should get the abovesaid result if my written function is correct. To test that:
```{r }
seq<-paste0("T", #pos 1
"AGAGAGAG", #pos 2 to 9, 4 reps of AG, 3 reps of GA
"T", #pos 10
"CATCATCATCATCAT", #pos 11 to 25, 5 reps of CAT, 5 reps of ATC, 5 reps of TCA
"CTT", #pos 26 to 28
"AGAGAGAGAGAGAGAG", #pos 29 to 44, 8 reps of AG, 8 reps of GA (including subsequent A)
"ATC", #pos 45 to 47
"AAAAAAAA", #pos 48 to 55, 4 reps of AA,
"TTA")
h<-my_find_microsats(seq=seq,lenmin=2,lenmax=6,repmin=4) # it's a data-frame
h_mat<-as.matrix(h)
h_mat <- h_mat[order(h_mat[,1]),] # it's a matrix now : sorted as alphabetically ms in 1st column
h_mat
```