Back to index

python-biopython  1.60
Public Member Functions
test_MarkovModel.TestMarkovModel Class Reference

List of all members.

Public Member Functions

def test_train_visible
def test_baum_welch
def test_topcoder1
def test_topcoder2
def test_topcoder3
def test_topcoder4
def test_topcoder5

Detailed Description

Definition at line 23 of file test_MarkovModel.py.


Member Function Documentation

Definition at line 106 of file test_MarkovModel.py.

00106 
00107     def test_baum_welch(self):
00108         states = ["CP", "IP"]
00109         alphabet = ["cola", "ice_t", "lem"]
00110         outputs = [
00111             (2, 1, 0)
00112             ]
00113         p_initial = [1.0, 0.0000001]
00114         p_transition = [[0.7, 0.3],
00115                         [0.5, 0.5]]
00116         p_emission = [[0.6, 0.1, 0.3],
00117                       [0.1, 0.7, 0.2]]
00118         N, M = len(states), len(alphabet)
00119         x = MarkovModel._baum_welch(N, M, outputs,
00120                                     p_initial=p_initial,
00121                                     p_transition=p_transition,
00122                                     p_emission=p_emission
00123                                     )
00124         p_initial, p_transition, p_emission = x
00125         markov_model = MarkovModel.MarkovModel(states, alphabet,
00126                                      p_initial, p_transition, p_emission)
00127         self.assertEqual(markov_model.states, ['CP', 'IP'])
00128         self.assertEqual(markov_model.alphabet, ['cola', 'ice_t', 'lem'])
00129         self.assertEqual(len(markov_model.p_initial), 2)
00130         self.assertAlmostEqual(markov_model.p_initial[0], 1.0,
00131                                places=4)
00132         self.assertAlmostEqual(markov_model.p_initial[1], 0.0,
00133                                places=4)
00134         self.assertEqual(len(markov_model.p_transition), 2)
00135         self.assertEqual(len(markov_model.p_transition[0]), 2)
00136         self.assertEqual(len(markov_model.p_transition[1]), 2)
00137         self.assertAlmostEqual(markov_model.p_transition[0][0], 0.02460365,
00138                                places=4)
00139         self.assertAlmostEqual(markov_model.p_transition[0][1], 0.97539634,
00140                                places=4)
00141         self.assertAlmostEqual(markov_model.p_transition[1][0], 1.0,
00142                                places=4)
00143         self.assertAlmostEqual(markov_model.p_transition[1][1], 0.0,
00144                                places=4)
00145         self.assertEqual(len(markov_model.p_emission), 2)
00146         self.assertEqual(len(markov_model.p_emission[0]), 3)
00147         self.assertEqual(len(markov_model.p_emission[1]), 3)
00148         self.assertAlmostEqual(markov_model.p_emission[0][0], 0.5)
00149         self.assertAlmostEqual(markov_model.p_emission[0][1], 0.0)
00150         self.assertAlmostEqual(markov_model.p_emission[0][2], 0.5)
00151         self.assertAlmostEqual(markov_model.p_emission[1][0], 0.0)
00152         self.assertAlmostEqual(markov_model.p_emission[1][1], 1.0)
00153         self.assertAlmostEqual(markov_model.p_emission[1][2], 0.0)

Definition at line 156 of file test_MarkovModel.py.

00156 
00157     def test_topcoder1(self):
00158         # NNNN
00159         states = "NR"
00160         alphabet = "AGTC"
00161         p_initial = array([1.0, 0.0])
00162         p_transition = array([[0.90, 0.10],
00163                               [0.20, 0.80]])
00164         p_emission = array([[0.30, 0.20, 0.30, 0.20],
00165                             [0.10, 0.40, 0.10, 0.40]])
00166         markov_model = MarkovModel.MarkovModel(
00167             states, alphabet, p_initial, p_transition, p_emission)
00168         states = MarkovModel.find_states(markov_model, "TGCC")
00169         self.assertEqual(len(states), 1)
00170         state_list, state_float = states[0]
00171         self.assertEqual(state_list, ['N', 'N', 'N', 'N'])

Definition at line 172 of file test_MarkovModel.py.

00172 
00173     def test_topcoder2(self):
00174         # NNNRRRNNRRNRRN
00175         states = "NR"
00176         alphabet = "AGTC"
00177         p_initial = array([1.0, 0.0])
00178         p_transition = array([[0.56, 0.44],
00179                               [0.25, 0.75]])
00180         p_emission = array([[0.04, 0.14, 0.62, 0.20],
00181                             [0.39, 0.15, 0.04, 0.42]])
00182         markov_model = MarkovModel.MarkovModel(
00183             states, alphabet, p_initial, p_transition, p_emission)
00184         states = MarkovModel.find_states(markov_model, "CCTGAGTTAGTCGT")
00185         self.assertEqual(len(states), 1)
00186         state_list, state_float = states[0]
00187         self.assertEqual(state_list, ['N', 'N', 'N', 'R', 'R', 'R', 'N', 'N', 'R', 'R', 'N', 'R', 'R', 'N'])

Definition at line 188 of file test_MarkovModel.py.

00188 
00189     def test_topcoder3(self):
00190         # NRRRRRRRRRRRNNNNRRRRRRRRR
00191         states = "NR"
00192         alphabet = "AGTC"
00193         p_initial = array([1.0, 0.0])
00194         p_transition = array([[0.75, 0.25],
00195                               [0.25, 0.75]])
00196         p_emission = array([[0.45, 0.36, 0.06, 0.13],
00197                             [0.24, 0.18, 0.12, 0.46]])
00198         markov_model = MarkovModel.MarkovModel(
00199             states, alphabet, p_initial, p_transition, p_emission)
00200         states = MarkovModel.find_states(markov_model, "CCGTACTTACCCAGGACCGCAGTCC")
00201         self.assertEqual(len(states), 1)
00202         state_list, state_float = states[0]
00203         self.assertEqual(state_list, ['N', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'N', 'N', 'N', 'N', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R'])

Definition at line 204 of file test_MarkovModel.py.

00204 
00205     def test_topcoder4(self):
00206         # NRRRRRRRRRR
00207         states = "NR"
00208         alphabet = "AGTC"
00209         p_initial = array([1.0, 0.0])
00210         p_transition = array([[0.55, 0.45],
00211                               [0.15, 0.85]])
00212         p_emission = array([[0.75, 0.03, 0.01, 0.21],
00213                             [0.34, 0.11, 0.39, 0.16]])
00214         markov_model = MarkovModel.MarkovModel(
00215             states, alphabet, p_initial, p_transition, p_emission)
00216         states = MarkovModel.find_states(markov_model, "TTAGCAGTGCG")
00217         self.assertEqual(len(states), 1)
00218         state_list, state_float = states[0]
00219         self.assertEqual(state_list, ['N','R','R','R','R','R','R','R','R','R','R'])

Definition at line 220 of file test_MarkovModel.py.

00220 
00221     def test_topcoder5(self):
00222         # N
00223         states = "NR"
00224         alphabet = "AGTC"
00225         p_initial = array([1.0, 0.0])
00226         p_transition = array([[0.84, 0.16],
00227                               [0.25, 0.75]])
00228         p_emission = array([[0.26, 0.37, 0.08, 0.29],
00229                             [0.31, 0.13, 0.33, 0.23]])
00230         markov_model = MarkovModel.MarkovModel(
00231             states, alphabet, p_initial, p_transition, p_emission)
00232         states = MarkovModel.find_states(markov_model, "T")
00233         self.assertEqual(len(states), 1)
00234         state_list, state_float = states[0]
00235         self.assertEqual(state_list, ["N"])
00236 

Definition at line 25 of file test_MarkovModel.py.

00025 
00026     def test_train_visible(self):
00027         states = ["0", "1", "2", "3"]
00028         alphabet = ["A", "C", "G", "T"]
00029         training_data = [
00030             ("AACCCGGGTTTTTTT", "001112223333333"),
00031             ("ACCGTTTTTTT", "01123333333"),
00032             ("ACGGGTTTTTT", "01222333333"),
00033             ("ACCGTTTTTTTT", "011233333333"),
00034             ]
00035         markov_model = MarkovModel.train_visible(states, alphabet, training_data)
00036         states = MarkovModel.find_states(markov_model, "AACGTT")
00037         self.assertEqual(len(states), 1)
00038         state_list, state_float = states[0]
00039         self.assertEqual(state_list, ['0', '0', '1', '2', '3', '3'])
00040         self.assertAlmostEqual(state_float, 0.0082128906)
00041         self.assertEqual(markov_model.states, ['0', '1', '2', '3'])
00042         self.assertEqual(markov_model.alphabet, ['A', 'C', 'G', 'T'])
00043         self.assertEqual(len(markov_model.p_initial), 4)
00044         self.assertAlmostEqual(markov_model.p_initial[0], 1.0)
00045         self.assertAlmostEqual(markov_model.p_initial[1], 0.0)
00046         self.assertAlmostEqual(markov_model.p_initial[2], 0.0)
00047         self.assertAlmostEqual(markov_model.p_initial[3], 0.0)
00048         self.assertEqual(len(markov_model.p_transition), 4)
00049         self.assertEqual(len(markov_model.p_transition[0]), 4)
00050         self.assertEqual(len(markov_model.p_transition[1]), 4)
00051         self.assertEqual(len(markov_model.p_transition[2]), 4)
00052         self.assertEqual(len(markov_model.p_transition[3]), 4)
00053         self.assertAlmostEqual(markov_model.p_transition[0][0], 0.2)
00054         self.assertAlmostEqual(markov_model.p_transition[0][1], 0.8)
00055         self.assertAlmostEqual(markov_model.p_transition[0][2], 0.0)
00056         self.assertAlmostEqual(markov_model.p_transition[0][3], 0.0)
00057         self.assertAlmostEqual(markov_model.p_transition[1][0], 0.0)
00058         self.assertAlmostEqual(markov_model.p_transition[1][1], 0.5)
00059         self.assertAlmostEqual(markov_model.p_transition[1][2], 0.5)
00060         self.assertAlmostEqual(markov_model.p_transition[1][3], 0.0)
00061         self.assertAlmostEqual(markov_model.p_transition[2][0], 0.0)
00062         self.assertAlmostEqual(markov_model.p_transition[2][1], 0.0)
00063         self.assertAlmostEqual(markov_model.p_transition[2][2], 0.5)
00064         self.assertAlmostEqual(markov_model.p_transition[2][3], 0.5)
00065         self.assertAlmostEqual(markov_model.p_transition[3][0], 0.0)
00066         self.assertAlmostEqual(markov_model.p_transition[3][1], 0.0)
00067         self.assertAlmostEqual(markov_model.p_transition[3][2], 0.0)
00068         self.assertAlmostEqual(markov_model.p_transition[3][3], 1.0)
00069         self.assertEqual(len(markov_model.p_emission), 4)
00070         self.assertEqual(len(markov_model.p_emission[0]), 4)
00071         self.assertEqual(len(markov_model.p_emission[1]), 4)
00072         self.assertEqual(len(markov_model.p_emission[2]), 4)
00073         self.assertEqual(len(markov_model.p_emission[3]), 4)
00074         self.assertAlmostEqual(markov_model.p_emission[0][0], 0.666667,
00075                                places=4)
00076         self.assertAlmostEqual(markov_model.p_emission[0][1], 0.111111,
00077                                places=4)
00078         self.assertAlmostEqual(markov_model.p_emission[0][2], 0.111111,
00079                                places=4)
00080         self.assertAlmostEqual(markov_model.p_emission[0][3], 0.111111,
00081                                places=4)
00082         self.assertAlmostEqual(markov_model.p_emission[1][0], 0.083333,
00083                                places=4)
00084         self.assertAlmostEqual(markov_model.p_emission[1][1], 0.750000,
00085                                places=4)
00086         self.assertAlmostEqual(markov_model.p_emission[1][2], 0.083333,
00087                                places=4)
00088         self.assertAlmostEqual(markov_model.p_emission[1][3], 0.083333,
00089                                places=4)
00090         self.assertAlmostEqual(markov_model.p_emission[2][0], 0.083333,
00091                                places=4)
00092         self.assertAlmostEqual(markov_model.p_emission[2][1], 0.083333,
00093                                places=4)
00094         self.assertAlmostEqual(markov_model.p_emission[2][2], 0.750000,
00095                                places=4)
00096         self.assertAlmostEqual(markov_model.p_emission[2][3], 0.083333,
00097                                places=4)
00098         self.assertAlmostEqual(markov_model.p_emission[3][0], 0.031250,
00099                                places=4)
00100         self.assertAlmostEqual(markov_model.p_emission[3][1], 0.031250,
00101                                places=4)
00102         self.assertAlmostEqual(markov_model.p_emission[3][2], 0.031250,
00103                                places=4)
00104         self.assertAlmostEqual(markov_model.p_emission[3][3], 0.906250,
00105                                places=4)


The documentation for this class was generated from the following file: