def test_computeMinimalDistance(self): distanceDictionary = { "0 1": 1, "0 2": 2, "0 3": 3, "1 2": 2, "1 3": 3, "1 4": 3 } upgma = UpgmaWpgma(distanceDictionary, 4) expectedValue = ["0 1", 1] self.assertEqual(expectedValue, upgma.compute_minimal_distance())
def upgmaWpgma(upgmaWpgma, sequences, outputFile, fileFormat): """Executes the a phylogenetic clustering with a upgm or wpgm weighting. sequences: All defined input sequences as a list. outputFile: The name of the output file fileFormat: The file format of the output file""" #create print "The following sequences are given:" for i in sequences: print i print "Computing clustering..." data = mah().createDataForUpgmaWpgma(sequences) if upgmaWpgma: upgma = UpgmaWpgma(data[0], len(data[1])) upgma.compute_clustering() if not fileFormat: outputFile += ".graphML" io().writeGraphMLFile(upgma.mapping, outputFile) print "Clustering written as graphML file: ", os.path.abspath(outputFile) else: outputFile += ".newickTree" cluster = upgma.get_newick_tree(with_edge_weights=True) io().writeNewickTree(cluster, outputFile) print "Computed upgma cluster: ", cluster print "The clustering was also written to: ", os.path.abspath(outputFile) else: wpgma = UpgmaWpgma(data[0], len(data[1]), False, data[2]) wpgma.compute_clustering() if not fileFormat: outputFile += ".graphML" io().writeGraphMLFile(wpgma.mapping, outputFile) print "Clustering written as graphML file: ", os.path.abspath(outputFile) else: outputFile += ".newickTree" cluster = wpgma.get_newick_tree(with_edge_weights=True) io().writeNewickTree(cluster, outputFile) print "Computed wpgma cluster: ", cluster print "The clustering was also written to: ", os.path.abspath(outputFile)
def test_getNewickTree(self): mapping = {'1 3': 5, '4 6': 7, '5 7': 8, '0 2': 6} distanceDictionary = {} upgma = UpgmaWpgma(distanceDictionary, 5) upgma.mapping = mapping upgma.get_newick_tree()
def test_computeClustering(self): distanceDictionary = {"0 1": 1, "0 2": 2, "0 3": 3, "1 2": 2, "1 3": 3, "2 3": 3} upgma = UpgmaWpgma(distanceDictionary, 4) expectedValue = {"0 1": 4, "2 4": 5, "3 5": 6} upgma.compute_clustering() print upgma.get_newick_tree() self.assertEqual(expectedValue, upgma.mapping) print upgma.get_newick_tree(with_edge_weights=True) distanceDictionary = {"0 1": 6, "0 2": 10, "0 3": 10, "0 4": 10, "1 2": 10, "1 3": 10, "1 4": 10, "2 3": 2, "2 4": 6, "3 4": 6} upgma2 = UpgmaWpgma(distanceDictionary, 5) expectedValue = {"2 3": 5, "0 1": 7, "4 5": 6, "6 7": 8} upgma2.compute_clustering() print upgma2.get_newick_tree(with_edge_weights=False) self.assertEqual(expectedValue, upgma2.mapping) print upgma2.get_newick_tree(with_edge_weights=True)
def test_computeMinimalDistance(self): distanceDictionary = {"0 1": 1, "0 2": 2, "0 3": 3, "1 2": 2, "1 3": 3, "1 4": 3} upgma = UpgmaWpgma(distanceDictionary, 4) expectedValue = ["0 1", 1] self.assertEqual(expectedValue, upgma.compute_minimal_distance())
def test_computeClustering(self): distanceDictionary = { "0 1": 1, "0 2": 2, "0 3": 3, "1 2": 2, "1 3": 3, "2 3": 3 } upgma = UpgmaWpgma(distanceDictionary, 4) expectedValue = {"0 1": 4, "2 4": 5, "3 5": 6} upgma.compute_clustering() print upgma.get_newick_tree() self.assertEqual(expectedValue, upgma.mapping) print upgma.get_newick_tree(with_edge_weights=True) distanceDictionary = { "0 1": 6, "0 2": 10, "0 3": 10, "0 4": 10, "1 2": 10, "1 3": 10, "1 4": 10, "2 3": 2, "2 4": 6, "3 4": 6 } upgma2 = UpgmaWpgma(distanceDictionary, 5) expectedValue = {"2 3": 5, "0 1": 7, "4 5": 6, "6 7": 8} upgma2.compute_clustering() print upgma2.get_newick_tree(with_edge_weights=False) self.assertEqual(expectedValue, upgma2.mapping) print upgma2.get_newick_tree(with_edge_weights=True)
def buildTree(self): """This function computes the phylogenetic tree with UPGMA and stores it in the Newick-Tree format.""" upgma = UpgmaWpgma(self.distanceDictionary, len(self.sequences)) upgma.compute_clustering() self.newickTree = upgma.get_newick_tree()