-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprimer_test.go
690 lines (653 loc) Β· 18.2 KB
/
primer_test.go
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
package cloningprimer
import (
"errors"
"testing"
)
// test case struct for functions that compute primers
type testCasePrimer struct {
in inputForPrimer
want string
err error
}
// struct that is used in primer test case struct and that holds
// input for functions that compute primers
type inputForPrimer struct {
seq string
restrict string
seqStart int
length int
random int
addCodon bool
}
// test case struct for functions that do computations on codons
type testCaseCodon struct {
in hasCodon
want bool
}
// struct that is used in codon test case struct and that holds
// input for respective functions
type hasCodon struct {
in string
exact bool
}
type testCaseComplement struct {
in byte
want byte
err error
}
func TestFindForward(t *testing.T) {
cases := []testCasePrimer{
// test invalid input
// test `seq' with non-nucleotide letters
{
in: inputForPrimer{
seq: "QVDASTGASD", /* first invalid letter should result in an error */
restrict: "GAATTC",
seqStart: 3,
length: 3,
random: 4,
addCodon: true,
},
want: "",
err: errors.New("invalid input Q at position 1, expected sequence of lower or upper case A,T,C,G"),
},
{
in: inputForPrimer{
seq: "ATGCCGVDASTGASD", /* first invalid letter should result in an error */
restrict: "GAATTC",
seqStart: 3,
length: 3,
random: 4,
addCodon: true,
},
want: "",
err: errors.New("invalid input V at position 7, expected sequence of lower or upper case A,T,C,G"),
},
// test `seq' that is exactly of length (`length' + `seqStart' - 1)
{
in: inputForPrimer{
seq: "ATGCCGTCGCATTCTG",
restrict: "GAATTC",
seqStart: 1,
length: 16,
random: 4,
addCodon: true,
},
want: "AGCTGAATTCATGCCGTCGCATTCTG", /* the expected output is the entire sequence plus overhang */
err: nil,
},
// test `seq' that is shorter than (`length' + `seqStart' - 1)
{
in: inputForPrimer{
seq: "ATGCCGTCGCATTGTCCATCT",
restrict: "GAATTC",
seqStart: 10,
length: 16,
random: 4,
addCodon: true,
},
want: "",
err: errors.New("invalid input, the given sequence (21 nucleotides) is not long enough for a primer of length = 16 starting at nucleotide 10 (25 > 21)"),
},
// test valid input for `random'
{
in: inputForPrimer{
seq: "ATGCCGTCGCATTGTCCATCT",
restrict: "GAATTC",
seqStart: 10,
length: 16,
random: 1,
addCodon: true,
},
want: "",
err: errors.New("invalid input random = 1, expected integer value between 2 and 10"),
},
{
in: inputForPrimer{
seq: "ATGCCGTCGCATTGTCCATCT",
restrict: "GAATTC",
seqStart: 10,
length: 16,
random: 22,
addCodon: true,
},
want: "",
err: errors.New("invalid input random = 22, expected integer value between 2 and 10"),
},
// sequence does not start with an 'ATG' (start codon) and `startCodon' is false
{
in: inputForPrimer{
seq: "CTGCCGTCGCATTGTCCATCTTACTGACCTGATGTGCCA",
restrict: "GAATTC",
seqStart: 10,
length: 16,
random: 8,
addCodon: false,
},
want: "",
err: errors.New("input sequence does not begin with a start codon ('ATG')\nmake sure to automatically add a start codon by setting `startCodon' to `true'"),
},
// addition of 'ATG' start codon
{
in: inputForPrimer{
seq: "CTGCCGTCGCATTGTCCATCTTACTGACCTGATGTGCCA",
restrict: "GAATTC",
seqStart: 8,
length: 16,
random: 3,
addCodon: true,
},
want: "GCTGAATTCATGCGCATTGTCCATCTTA", /* start codon should be inserted right after recognition sequence */
err: nil,
},
// invalid `seqStart'
{
in: inputForPrimer{
seq: "CTGCCGTCGCATTGTCCATCTTACTGACCTGATGTGCCA",
restrict: "GAATTC",
seqStart: 0,
length: 16,
random: 3,
addCodon: true,
},
want: "",
err: errors.New("invalid input: primer start point must be an integer > 0 (not 0)"),
},
// experimentally validated primer
{
in: inputForPrimer{
seq: "ATGGACTCCAACACTGCTCCGCTGGGCCCCTCCTGCCCACAGCCCCCGCCAGCACCGCAGCCCCAGGCGCGTTCCCGACTCAATGCCAC",
restrict: "GGATCC",
seqStart: 1,
length: 18,
random: 4,
addCodon: false,
},
want: "AGCTGGATCCATGGACTCCAACACTGCT",
err: nil,
},
// length of primer shorter than `MinimumPrimerLength'
{
in: inputForPrimer{
seq: "ATGGACTCCAACACTGCTCCGCTGGGCCCCTCCTGCCC",
restrict: "GGATTC",
seqStart: 1,
length: 8,
random: 4,
addCodon: false,
},
want: "",
err: errors.New("invalid input length = 8, must be an integer value >= 10 and smaller than the length of the given sequence (as well as <= the maximum primer length of 30)"),
},
// length of primer larger than `MaximumPrimerLength'
{
in: inputForPrimer{
seq: "ATGGACTCCAACACTGCTCCGCTGGGCCCCTCCTGCCC",
restrict: "GGATTC",
seqStart: 1,
length: 32,
random: 4,
addCodon: false,
},
want: "",
err: errors.New("invalid input length = 32, must be an integer value >= 10 and smaller than the length of the given sequence (as well as <= the maximum primer length of 30)"),
},
}
// loop over test cases
for _, c := range cases {
got, err := FindForward(c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon)
// test similarity of expected and received value
if got != c.want {
t.Errorf("FindForward(%v, %v, %v, %v, %v, %v) == %v, want %v\n", c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon, got, c.want)
}
// if no error is returned, test if none is expected
if err == nil && c.err != nil {
t.Errorf("FindForward(%v, %v, %v, %v, %v, %v) == %v, want %v\n", c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon, err, c.err)
}
// if error is returned, test if an error is expected
if err != nil {
// if c.err is nil, print wanted and received error
// else if an error is wanted and received but error messages are not the same
// print wanted and received error
if c.err == nil {
t.Errorf("FindForward(%v, %v, %v, %v, %v, %v) == %v, want %v\n", c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon, err, c.err)
} else if err.Error() != c.err.Error() {
t.Errorf("FindForward(%v, %v, %v, %v, %v, %v) == %v, want %v\n", c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon, err, c.err)
}
}
}
}
func TestFindReverse(t *testing.T) {
cases := []testCasePrimer{
// test invalid input
// test `seq' with non-nucleotide letters
{
in: inputForPrimer{
seq: "QVDASTGASD", /* first invalid letter should result in an error */
restrict: "GAATTC",
seqStart: 3,
length: 3,
random: 4,
addCodon: true,
},
want: "",
err: errors.New("invalid input Q at position 1, expected sequence of lower or upper case A,T,C,G"),
},
{
in: inputForPrimer{
seq: "ATGCCGVDASTGASD", /* first invalid letter should result in an error */
restrict: "GAATTC",
seqStart: 3,
length: 3,
random: 4,
addCodon: true,
},
want: "",
err: errors.New("invalid input V at position 7, expected sequence of lower or upper case A,T,C,G"),
},
// test `seq' that is exactly of length (`length' + `seqStart' - 1)
{
in: inputForPrimer{
seq: "ATGCCGTCGCATTCTG",
restrict: "GAATTC",
seqStart: 1,
length: 16,
random: 4,
addCodon: true,
},
want: "AGCTGAATTCTTACAGAATGCGACGGCAT", /* the expected output is the entire sequence plus overhang */
err: nil,
},
// test `seq' that is shorter than (`length' + `seqStart' - 1)
{
in: inputForPrimer{
seq: "ATGCCGTCGCATTGTCCATCT",
restrict: "GAATTC",
seqStart: 10,
length: 16,
random: 4,
addCodon: true,
},
want: "",
err: errors.New("invalid input, the given sequence (21 nucleotides) is not long enough for a primer of length = 16 starting at nucleotide 10 (25 > 21)"),
},
// test valid input for `random'
{
in: inputForPrimer{
seq: "ATGCCGTCGCATTGTCCATCT",
restrict: "GAATTC",
seqStart: 10,
length: 16,
random: 1,
addCodon: true,
},
want: "",
err: errors.New("invalid input random = 1, expected integer value between 2 and 10"),
},
{
in: inputForPrimer{
seq: "ATGCCGTCGCATTGTCCATCT",
restrict: "GAATTC",
seqStart: 10,
length: 16,
random: 22,
addCodon: true,
},
want: "",
err: errors.New("invalid input random = 22, expected integer value between 2 and 10"),
},
// sequence does not start with an 'ATG' (start codon) and `startCodon' is false
{
in: inputForPrimer{
seq: "CTGCCGTCGCATTGTCCATCTTACTGACCTGATGTGCCA",
restrict: "GAATTC",
seqStart: 10,
length: 16,
random: 8,
addCodon: false,
},
want: "",
err: errors.New("input sequence does not begin with a stop codon ('TAA', 'TAG', 'TGA')\nmake sure to automatically add a start codon by setting `startCodon' to `true'"),
},
// recognition of valid 'TGA' stop codon at position 8 from 3' end
{
in: inputForPrimer{
seq: "CTGCCGTCGCATTGTCCATCTTACTGACCTGATGTGCCA",
restrict: "GAATTC",
seqStart: 8,
length: 16,
random: 3,
addCodon: true,
},
want: "GCTGAATTCTCAGGTCAGTAAGATG", /* stop codon should be correctly recognized and inserted */
err: nil,
},
{
in: inputForPrimer{
seq: "AAAAATTTTTTTCCATCAGGCGCTGATGGCGAAGTTAGCGTAG", /* has 'TAG' stop codon */
restrict: "GAATTC",
seqStart: 1,
length: 20,
random: 3,
addCodon: true,
},
want: "GCTGAATTCCTACGCTAACTTCGCCATCA",
err: nil,
},
// insertion of 'TAA' stop codon
{
in: inputForPrimer{
seq: "AAAAATTTTTTTCCATCAGGCGCTGATGGCGAAGTTAGCG", /* same `seq' as previous example, but w/o stop */
restrict: "GAATTC",
seqStart: 1,
length: 20,
random: 3,
addCodon: true,
},
want: "GCTGAATTCTTACGCTAACTTCGCCATCAGCG",
err: nil,
},
// invalid `seqStart'
{
in: inputForPrimer{
seq: "CTGCCGTCGCATTGTCCATCTTACTGACCTGATGTGCCA",
restrict: "GAATTC",
seqStart: 0,
length: 16,
random: 3,
addCodon: true,
},
want: "",
err: errors.New("invalid input: primer start point must be an integer > 0 (not 0)"),
},
// experimentally validated primer
{
in: inputForPrimer{
seq: "CGTCATCCCCAGCAGCCTGTTCCTGCAGGACGACGAAGATGATGACGAGCTGGCGGGGAAGAGCCCTGAGGACCTGCCACTGCGT",
restrict: "GAATTC",
seqStart: 1,
length: 18,
random: 4,
addCodon: true,
},
want: "AGCTGAATTCTTAACGCAGTGGCAGGTCCTC",
err: nil,
},
// length of primer shorter than `MinimumPrimerLength'
{
in: inputForPrimer{
seq: "ATGGACTCCAACACTGCTCCGCTGGGCCCCTCCTGCCC",
restrict: "GGATTC",
seqStart: 1,
length: 8,
random: 4,
addCodon: false,
},
want: "",
err: errors.New("invalid input length = 8, must be an integer value >= 10 and smaller than the length of the given sequence (as well as <= the maximum primer length of 30)"),
},
// length of primer larger than `MaximumPrimerLength'
{
in: inputForPrimer{
seq: "ATGGACTCCAACACTGCTCCGCTGGGCCCCTCCTGCCC",
restrict: "GGATTC",
seqStart: 1,
length: 32,
random: 4,
addCodon: false,
},
want: "",
err: errors.New("invalid input length = 32, must be an integer value >= 10 and smaller than the length of the given sequence (as well as <= the maximum primer length of 30)"),
},
}
// loop over test cases
for _, c := range cases {
got, err := FindReverse(c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon)
// test similarity of expected and received value
if got != c.want {
t.Errorf("FindReverse(%v, %v, %v, %v, %v, %v) == %v, want %v\n", c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon, got, c.want)
}
// if no error is returned, test if none is expected
if err == nil && c.err != nil {
t.Errorf("FindReverse(%v, %v, %v, %v, %v, %v) == %v, want %v\n", c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon, err, c.err)
}
// if error is returned, test if an error is expected
if err != nil {
// if c.err is nil, print wanted and received error
// else if an error is wanted and received but error messages are not the same
// print wanted and received error
if c.err == nil {
t.Errorf("FindReverse(%v, %v, %v, %v, %v, %v) == %v, want %v\n", c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon, err, c.err)
} else if err.Error() != c.err.Error() {
t.Errorf("FindReverse(%v, %v, %v, %v, %v, %v) == %v, want %v\n", c.in.seq, c.in.restrict, c.in.seqStart, c.in.length, c.in.random, c.in.addCodon, err, c.err)
}
}
}
}
func TestHasStartCodon(t *testing.T) {
cases := []testCaseCodon{
// test just a start codon
{
in: hasCodon{"ATG", true},
want: true,
},
// test start codon at beginning of a sequence
{
in: hasCodon{"ATGCCGAGACAGT", true},
want: true,
},
// test start codon at end of a sequence (in this case, `exact' must be false)
{
in: hasCodon{"GAGAGCCCACGCGAGATG", false},
want: true,
},
// test sequences without a start codon (no 'A', 'T', or 'G')
{
in: hasCodon{"GAGAGCCACGAGCAGCG", true},
want: false,
},
// test sequences without a start codon (has 'A' but no 'T' or 'G')
{
in: hasCodon{"AAGAGCCACGAGCAGCG", true},
want: false,
},
// test sequences without a start codon (has 'A' and 'T' but no 'G')
{
in: hasCodon{"ATCAGCCACGAGCAGCG", true},
want: false,
},
// if the length of the input is < 3, false should always be returned
{
in: hasCodon{"AT", true},
want: false,
},
}
// loop over test cases
for _, c := range cases {
got := HasStartCodon(c.in.in, c.in.exact)
// test similarity of expected and received value
if got != c.want {
t.Errorf("HasStartCodon(%v, %v) == %v, want %v\n", c.in.in, c.in.exact, got, c.want)
}
}
}
func TestHasStopCodon1(t *testing.T) {
cases := []testCaseCodon{
// test just a stop codon
{
in: hasCodon{"TTA", true},
want: true,
},
// test stop codon at beginning of a sequence
{
in: hasCodon{"TTACCGAGACAGT", true},
want: true,
},
// test stop codon at end of a sequence (in this case, `exact' must be false)
{
in: hasCodon{"GAGAGCCCACGCGAGTTA", false},
want: true,
},
// test sequence without a stop codon
{
in: hasCodon{"GAGAGCCACGAGCAGCG", true},
want: false,
},
// if the length of the input is < 3, false should always be returned
{
in: hasCodon{"AT", true},
want: false,
},
}
// loop over test cases
for _, c := range cases {
got := HasStopCodon1(c.in.in, c.in.exact)
// test similarity of expected and received value
if got != c.want {
t.Errorf("HasStopCodon1(%v, %v) == %v, want %v\n", c.in.in, c.in.exact, got, c.want)
}
}
}
func TestHasStopCodon2(t *testing.T) {
cases := []testCaseCodon{
// test just a stop codon
{
in: hasCodon{"CTA", true},
want: true,
},
// test stop codon at beginning of a sequence
{
in: hasCodon{"CTACCGAGACAGT", true},
want: true,
},
// test stop codon at end of a sequence (in this case, `exact' must be false)
{
in: hasCodon{"GAGAGCCCACGCGAGCTA", false},
want: true,
},
// test sequence without a stop codon
{
in: hasCodon{"GAGAGCCACGAGCAGCG", true},
want: false,
},
// if the length of the input is < 3, false should always be returned
{
in: hasCodon{"AT", true},
want: false,
},
}
// loop over test cases
for _, c := range cases {
got := HasStopCodon2(c.in.in, c.in.exact)
// test similarity of expected and received value
if got != c.want {
t.Errorf("HasStopCodon2(%v, %v) == %v, want %v\n", c.in.in, c.in.exact, got, c.want)
}
}
}
func TestHasStopCodon3(t *testing.T) {
cases := []testCaseCodon{
// test just a stop codon
{
in: hasCodon{"TCA", true},
want: true,
},
// test stop codon at beginning of a sequence
{
in: hasCodon{"TCACCGAGACAGT", true},
want: true,
},
// test stop codon at end of a sequence (in this case, `exact' must be false)
{
in: hasCodon{"GAGAGCCCACGCGAGTCA", false},
want: true,
},
// test sequence without a stop codon
{
in: hasCodon{"GAGAGCCACGAGCAGCG", true},
want: false,
},
// if the length of the input is < 3, false should always be returned
{
in: hasCodon{"AT", true},
want: false,
},
}
// loop over test cases
for _, c := range cases {
got := HasStopCodon3(c.in.in, c.in.exact)
// test similarity of expected and received value
if got != c.want {
t.Errorf("HasStopCodon3(%v, %v) == %v, want %v\n", c.in.in, c.in.exact, got, c.want)
}
}
}
func TestComplement(t *testing.T) {
cases := []testCaseComplement{
// test nucleotide 'A'
{
in: 'A',
want: 'T',
err: nil,
},
// test nucleotide 'T'
{
in: 'T',
want: 'A',
err: nil,
},
// test nucleotide 'G'
{
in: 'G',
want: 'C',
err: nil,
},
// test nucleotide 'C'
{
in: 'C',
want: 'G',
err: nil,
},
// test invalid nucleotide
{
in: 'Q',
want: 0,
err: errors.New("invalid input: Q is not a nucleotide"),
},
}
// loop over test cases
for _, c := range cases {
got, err := Complement(c.in)
// test similarity of expected and received value
if got != c.want {
t.Errorf("Complement(%v) == %v, want %v\n", c.in, got, c.want)
}
// if no error is returned, test if none is expected
if err == nil && c.err != nil {
t.Errorf("Complement(%v) == %v, want %v\n", c.in, err, c.err)
}
// if error is returned, test if an error is expected
if err != nil {
// if c.err is nil, print wanted and received error
// else if an error is wanted and received but error messages are not the same
// print wanted and received error
if c.err == nil {
t.Errorf("Complement(%v) == %v, want %v\n", c.in, err, c.err)
} else if err.Error() != c.err.Error() {
t.Errorf("Complement(%v) == %v, want %v\n", c.in, err, c.err)
}
}
}
}
func TestReverse(t *testing.T) {
// TODO: implement unit tests
}
func TestIsNucleotide(t *testing.T) {
// TODO: implement unit tests
}
func TestAddOverhang(t *testing.T) {
// TODO: implement unit tests
}
func TestValidateSequence(t *testing.T) {
// TODO: implement unit tests
}