-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_dnds.py
96 lines (66 loc) · 3.08 KB
/
test_dnds.py
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
from __future__ import division
from fractions import Fraction
from nose.tools import assert_equal, assert_almost_equal
from dnds import dnds, pnps, substitutions, dnds_codon, dnds_codon_pair, syn_sum, translate
# From Canvas practice problem
TEST_SEQ1 = 'ACTCCGAACGGGGCGTTAGAGTTGAAACCCGTTAGA'
TEST_SEQ2 = 'ACGCCGATCGGCGCGATAGGGTTCAAGCTCGTACGA'
# From in-class problem set
TEST_SEQ3 = 'ATGCTTTTGAAATCGATCGTTCGTTCACATCGATGGATC'
TEST_SEQ4 = 'ATGCGTTCGAAGTCGATCGATCGCTCAGATCGATCGATC'
# From http://bioinformatics.cvr.ac.uk/blog/calculating-dnds-for-ngs-datasets/
TEST_SEQ5 = 'ATGAAACCCGGGTTTTAA'
TEST_SEQ6 = 'ATGAAACGCGGCTACTAA'
def test_translate():
assert_equal(translate(TEST_SEQ1), 'TPNGALELKPVR')
assert_equal(translate(TEST_SEQ2), 'TPIGAIGFKLVR')
assert_equal(translate(TEST_SEQ3), 'MLLKSIVRSHRWI')
def test_dnds_codon_easy():
assert_equal([0, 0, 1], dnds_codon('ACC'))
def test_dnds_codon_harder1():
assert_equal([0, 0, Fraction(1, 3)], dnds_codon('AAC'))
assert_equal([0, 0, Fraction(2, 3)], dnds_codon('ATC'))
def test_dnds_codon_harder2():
assert_equal([Fraction(1, 3), 0, Fraction(1, 3)], dnds_codon('AGA'))
assert_equal([Fraction(1, 3), 0, 1], dnds_codon('CGA'))
def test_dnds_codon_ngs():
assert_equal([0, 0, 0], dnds_codon('TGG'))
assert_equal([Fraction(1, 3), 0, 1], dnds_codon('CGG'))
def test_dnds_codon_ngs_sums():
assert_equal(sum(dnds_codon('ATG')), 0)
assert_equal(sum(dnds_codon('AAA')), Fraction(1, 3))
assert_equal(sum(dnds_codon('CCC')), 1)
assert_equal(sum(dnds_codon('GGG')), 1)
assert_equal(sum(dnds_codon('TTT')), Fraction(1, 3))
assert_equal(sum(dnds_codon('TAA')), Fraction(2, 3))
def test_dnds_codon_ps():
assert_equal(dnds_codon('CTT'), [0, 0, 1])
assert_equal(dnds_codon('CGT'), [0, 0, 1])
def test_dnds_codon_pair():
assert_equal([Fraction(1, 3), 0, Fraction(2, 3)],
dnds_codon_pair('AGA', 'CGA'))
def test_dnds_codon_pair_harder1():
assert_equal([Fraction(1, 6), 0, Fraction(1, 3)],
dnds_codon_pair('TTG', 'TTC'))
def test_dnds_codon_pair_harder2():
assert_equal([Fraction(1, 6), 0, Fraction(1, 2)],
dnds_codon_pair('TTA', 'ATA'))
def test_syn_sum_ps():
assert_almost_equal(syn_sum(TEST_SEQ3, TEST_SEQ4), 10, delta=1)
def test_syn_subs():
assert_equal(substitutions(TEST_SEQ1, TEST_SEQ2), (5, 5))
assert_equal(substitutions(TEST_SEQ3, TEST_SEQ4), (2, 5))
assert_equal(substitutions("ACCGGA", "ACAAGA"), (1, 1))
assert_equal(substitutions("TGC", "TAT"), (1, 1))
assert_equal(substitutions("ACC", "AAA"), (0.5, 1.5))
assert_equal(substitutions("CCC", "AAC"), (0, 2))
def test_pnps():
assert_almost_equal(pnps(TEST_SEQ1, TEST_SEQ2), 0.269, delta=0.1)
assert_almost_equal(pnps(TEST_SEQ3, TEST_SEQ4), 0.86, delta=0.1)
assert_almost_equal(pnps(TEST_SEQ5, TEST_SEQ6), 0.1364 / 0.6001, delta=1e-4)
def test_dnds():
assert_almost_equal(dnds(TEST_SEQ5, TEST_SEQ6), 0.1247, delta=1e-4)
# DNDS.pdf - wrong based on email conversation with Sean
#
# def test_syn_sum():
# assert_close(syn_sum(TEST_SEQ1, TEST_SEQ2), 7.5833)