Example #1
0
def _read_matrix(filename):
	with open(filename) as f:
		header = f.readline().split()

		buf = list(map(lambda l: list(map(float, l[1:].split())), f.readlines()))

	if len(buf) != len(header):
		raise ValueError('Distance matrix must be square')
	
	
	buf = list(zip(*buf))

	for i, l in enumerate(buf):
		if len(l) != len(header):
			raise ValueError('Distance matrix must be square')

		buf[i] =  list(l[:i + 1:])


	if not buf:
		return None

	res = TreeConstruction.DistanceMatrix(names=header,
			matrix=buf)
	
	return res