Ejemplo n.º 1
0
Archivo: tree.py Proyecto: JCM333/JPP
def run_tests():
	# initialization
	import charmatrix
	cm = charmatrix.charmatrix("data/data2.txt")
	trees = list(all_trees(cm.taxon_set(), cm.get_outgroup()))
	
	# test equality checking and construction
	assert node(leaf(1), leaf(2)) == node(leaf(2), leaf(1)), "trees should be the same"

	# test tree.size
	assert trees[0].size() == 5, "there are 5 taxa in the tree"

	# test all_trees
	assert len(trees) == 15, "there are 15 trees for 4 taxa (excluding outgroup)"
	assert len(set(trees)) == 15, "trees should be unique"

	# test one_tree
	assert one_tree(cm).taxon_set() == cm.taxon_set(), "taxa in one_tree should be those in charmatrix"

	# test best and one_best
	correct_tree = parse("(0,(1,(2,(3,4))))")

	best_trees, length = best(trees, cm)

	assert len(best_trees) == 1, "there is only one optimal tree"
	assert best_trees[0] == correct_tree, "best tree is not correct"
	assert length == 8, "length of best tree is 8"

	one = one_best(trees, cm)
	assert one == correct_tree, "one_best should also return this tree"
Ejemplo n.º 2
0
Archivo: main.py Proyecto: JCM333/JPP
def main(args):
	if args.test:
		import run_tests
		run_tests.run()
	else:
		cm = charmatrix.charmatrix(args.datafile)
		cm.print_summary()

		if args.algorithm == 'exhaustive':
			import exhaustive
			trees = exhaustive.exhaustive_search(cm)
			for tree in trees:
				print tree.to_string(cm)
		elif args.algorithm in ('bnb', 'branch-and-bound'):
			import branchnbound
			trees = branchnbound.branchnbound_search(cm)
			for tree in trees:
				print tree.to_string(cm)
		else:
			import parallel_search
			comm = parallel_search.communicator(cm, args.time, args.interval)
			if args.algorithm == 'nni':
				import nni
				nni.nni_search(cm, comm)
			elif args.algorithm == 'spr':
				import spr
				spr.spr_search(cm, comm)
			elif args.algorithm == 'tbr':
				import tbr
				tbr.tbr_search(cm, comm)
			elif args.algorithm == 'mixed':
				import mixed
				mixed.mixed_search(cm, comm)
Ejemplo n.º 3
0
def run_tests():
	# random_not_in
	my_set = set([1, 2, 3, 4])
	assert random_not_in(5, my_set) == 0, "it can only be 0"
	# random_in
	assert random_in(5, my_set) in my_set, "number must be in set"

	# list_tree itself
	import charmatrix

	# prepare trees
	cm = charmatrix.charmatrix('data/shortoryzos.txt')
	t = tree.one_tree(cm)

	# test conversion with tree
	lt = list_tree(tree=t)
	tt = lt.to_tree()
	assert tt == t, "list_tree <=> tree conversion should be reversible"

	# test length
	assert t.length(cm) == lt.length(cm), "tree length should give same result for tree and list_tree"

	# test init_from_taxa
	taxa = cm.taxon_set()
	outgroup = cm.get_outgroup()
	lt2 = list_tree(taxa=taxa, outgroup=outgroup)
	assert lt2.to_tree().taxon_set() == taxa
Ejemplo n.º 4
0
def run_tests():
	import charmatrix
	cm = charmatrix.charmatrix("data/data2.txt")
	t = exhaustive_search(cm)
	assert t == tree.parse("(0,(1,(2,(3,4))))"), "exhaustive search must return this tree"