def test_pathoscope_em_4(self): U = {2: 1} NU = {0: [[0, 1], [50, 50], [0.5, 0.5]], 1: [[0, 1], [50, 50], [0.5, 0.5]], 3: [[2, 3], [50, 50], [0.5, 0.5]], 4: [[2, 0], [50, 50], [0.5, 0.5]]} ### Genome hash genomes = {0:"genome3", 1:"genome4", 2:"genome1", 3:"genome2"} (initPi, pi, theta, NU) = PathoID.pathoscope_em(U, NU, genomes, self.maxIter, self.emEpsilon, self.verbose) print initPi, pi, theta, NU expectedInitPi = [0.3, 0.4, 0.2, 0.1] for j in range(len(expectedInitPi)): self.assertAlmostEquals(initPi[j], expectedInitPi[j], 4, "Failed EM Example 4 Initial PI Assertion j=%d" %j) expectedPi = [0.57, 0.20, 0.23, 0.0] for j in range(len(expectedPi)): self.assertAlmostEquals(pi[j], expectedPi[j], 2, "Failed EM Example 4 PI Assertion") expectedTheta = [0.72, 0.0, 0.28, 0.0] for j in range(len(expectedTheta)): self.assertAlmostEquals(theta[j], expectedTheta[j], 2, "Failed EM Example 4 Theta Assertion") expectedNU = {0: [[0, 1], [50, 50], [1.0, 0.0]], 1: [[0, 1], [50, 50], [1.0, 0.0]], 3: [[2, 3], [50, 50], [1.0, 0.0]], 4: [[2, 0], [50, 50], [0.14, 0.86]]} for read in expectedNU: self.assertEquals(NU[read][0], expectedNU[read][0], "Failed EM Example 4 Non-Unique Read %d genome mapping Assertion" %read) self.assertEquals(NU[read][1], expectedNU[read][1], "Failed EM Example 4 Non-Unique Read %d score Assertion" %read) for j in range(len(expectedNU[read][2])): self.assertAlmostEquals(NU[read][2][j], expectedNU[read][2][j], 2, "Failed EM Example 4 Non-Unique Read %d proportion Assertion" %read)
def test_pathoscope_em_3(self): U = {0: 0, 1: 0, 2: 0, 3: 1, 4: 1} NU = {5: [[0, 1, 2], [33, 33, 33], [0.3333, 0.3333, 0.3333]], 6: [[0, 1, 2], [33, 33, 33], [0.3333, 0.3333, 0.3333]], 7: [[0, 1, 2], [33, 33, 33], [0.3333, 0.3333, 0.3333]]} ### Genome hash genomes = {0:"genome1", 1:"genome2", 2:"genome3"} (initPi, pi, theta, NU) = PathoID.pathoscope_em(U, NU, genomes, self.maxIter, self.emEpsilon, self.verbose) print initPi, pi, theta, NU expectedInitPi = [0.5, 0.375, 0.125] for j in range(len(expectedInitPi)): self.assertAlmostEquals(initPi[j], expectedInitPi[j], 4, "Failed EM Example 3 Initial PI Assertion j=%d" %j) expectedPi = [0.75, 0.25, 0.0] for j in range(len(expectedPi)): self.assertAlmostEquals(pi[j], expectedPi[j], 2, "Failed EM Example 3 PI Assertion") expectedTheta = [1.0, 0.0, 0.0] for j in range(len(expectedTheta)): self.assertAlmostEquals(theta[j], expectedTheta[j], 2, "Failed EM Example 3 Theta Assertion") expectedNU = {5: [[0, 1, 2], [33, 33, 33], [1.0, 0.0, 0.0]], 6: [[0, 1, 2], [33, 33, 33], [1.0, 0.0, 0.0]], 7: [[0, 1, 2], [33, 33, 33], [1.0, 0.0, 0.0]]} for read in expectedNU: self.assertEquals(NU[read][0], expectedNU[read][0], "Failed EM Example 3 Non-Unique Read %d genome mapping Assertion" %read) self.assertEquals(NU[read][1], expectedNU[read][1], "Failed EM Example 3 Non-Unique Read %d score Assertion" %read) for j in range(len(expectedNU[read][2])): self.assertAlmostEquals(NU[read][2][j], expectedNU[read][2][j], 2, "Failed EM Example 3 Non-Unique Read %d proportion Assertion" %read)
def test_pathoscope_em_2(self): U = {} NU = { 0: [[0, 1], [50, 50], [0.5, 0.5]], 1: [[0, 1], [50, 50], [0.5, 0.5]], 2: [[0, 2], [50, 50], [0.5, 0.5]], 3: [[0, 2], [50, 50], [0.5, 0.5]], 4: [[0, 1, 2], [33, 33, 33], [0.3333, 0.3333, 0.3333]], 5: [[0, 1, 2], [33, 33, 33], [0.3333, 0.3333, 0.3333]], 6: [[0, 1, 2], [33, 33, 33], [0.3333, 0.3333, 0.3333]] } ### Genome hash genomes = {0: "genome1", 1: "genome2", 2: "genome3"} (initPi, pi, theta, NU) = PathoID.pathoscope_em(U, NU, genomes, self.maxIter, self.emEpsilon, self.verbose) print initPi, pi, theta, NU expectedInitPi = [0.4286, 0.2857, 0.2857] for j in range(len(expectedInitPi)): self.assertAlmostEquals( initPi[j], expectedInitPi[j], 4, "Failed EM Example 2 Initial PI Assertion j=%d" % j) expectedPi = [1.0, 0.0, 0.0] for j in range(len(expectedPi)): self.assertAlmostEquals(pi[j], expectedPi[j], 4, "Failed EM Example 2 PI Assertion") expectedTheta = [1.0, 0.0, 0.0] for j in range(len(expectedTheta)): self.assertAlmostEquals(theta[j], expectedTheta[j], 4, "Failed EM Example 2 Theta Assertion") expectedNU = { 0: [[0, 1], [50, 50], [1.0, 0.0]], 1: [[0, 1], [50, 50], [1.0, 0.0]], 2: [[0, 2], [50, 50], [1.0, 0.0]], 3: [[0, 2], [50, 50], [1.0, 0.0]], 4: [[0, 1, 2], [33, 33, 33], [1.0, 0.0, 0.0]], 5: [[0, 1, 2], [33, 33, 33], [1.0, 0.0, 0.0]], 6: [[0, 1, 2], [33, 33, 33], [1.0, 0.0, 0.0]] } for read in expectedNU: self.assertEquals( NU[read][0], expectedNU[read][0], "Failed EM Example 2 Non-Unique Read %d genome mapping Assertion" % read) self.assertEquals( NU[read][1], expectedNU[read][1], "Failed EM Example 2 Non-Unique Read %d score Assertion" % read) for j in range(len(expectedNU[read][2])): self.assertAlmostEquals( NU[read][2][j], expectedNU[read][2][j], 4, "Failed EM Example 2 Non-Unique Read %d proportion Assertion" % read)
def test_pathoscope_em_4(self): U = {2: 1} NU = { 0: [[0, 1], [50, 50], [0.5, 0.5]], 1: [[0, 1], [50, 50], [0.5, 0.5]], 3: [[2, 3], [50, 50], [0.5, 0.5]], 4: [[2, 0], [50, 50], [0.5, 0.5]] } ### Genome hash genomes = {0: "genome3", 1: "genome4", 2: "genome1", 3: "genome2"} (initPi, pi, theta, NU) = PathoID.pathoscope_em(U, NU, genomes, self.maxIter, self.emEpsilon, self.verbose) print initPi, pi, theta, NU expectedInitPi = [0.3, 0.4, 0.2, 0.1] for j in range(len(expectedInitPi)): self.assertAlmostEquals( initPi[j], expectedInitPi[j], 4, "Failed EM Example 4 Initial PI Assertion j=%d" % j) expectedPi = [0.57, 0.20, 0.23, 0.0] for j in range(len(expectedPi)): self.assertAlmostEquals(pi[j], expectedPi[j], 2, "Failed EM Example 4 PI Assertion") expectedTheta = [0.72, 0.0, 0.28, 0.0] for j in range(len(expectedTheta)): self.assertAlmostEquals(theta[j], expectedTheta[j], 2, "Failed EM Example 4 Theta Assertion") expectedNU = { 0: [[0, 1], [50, 50], [1.0, 0.0]], 1: [[0, 1], [50, 50], [1.0, 0.0]], 3: [[2, 3], [50, 50], [1.0, 0.0]], 4: [[2, 0], [50, 50], [0.14, 0.86]] } for read in expectedNU: self.assertEquals( NU[read][0], expectedNU[read][0], "Failed EM Example 4 Non-Unique Read %d genome mapping Assertion" % read) self.assertEquals( NU[read][1], expectedNU[read][1], "Failed EM Example 4 Non-Unique Read %d score Assertion" % read) for j in range(len(expectedNU[read][2])): self.assertAlmostEquals( NU[read][2][j], expectedNU[read][2][j], 2, "Failed EM Example 4 Non-Unique Read %d proportion Assertion" % read)