コード例 #1
0
        tree = join_neighbors(tree, i, j, di, dj)

    d = m[0][1]
    return join_neighbors(tree, 0, 1, d / 2, d / 2)[0]


def _random_joining(ids):
    """Generates a tree by repeatedly joining elements randomly."""
    r = Random()
    tree = [Leaf(id_) for id_ in ids]
    for _ in xrange(len(ids) - 1):
        i, j = sorted(r.sample(xrange(len(tree)), 2))
        tree = join_neighbors(tree, i, j, r.random(), r.random())

    return tree[0]


if __name__ == '__main__':
    from tree import test_tree
    expected_tree, m, ids = test_tree()
    tree = neighbor_joining(m, ids)

    print tree, expected_tree

    # Random test
    from tree import distance_matrix
    expected_tree = _random_joining(map(str, xrange(10)))
    m, ids = distance_matrix(expected_tree)
    tree = neighbor_joining(m, ids)
    print tree, expected_tree
コード例 #2
0
    i, j = sorted(matrix_argmin(q))
    m, di, dj = update_distance_matrix(m, s, i, j)
    tree = join_neighbors(tree, i, j, di, dj)

  d = m[0][1]
  return join_neighbors(tree, 0, 1, d/2, d/2)[0]

def _random_joining(ids):
  """Generates a tree by repeatedly joining elements randomly."""
  r = Random()
  tree = [Leaf(id_) for id_ in ids]
  for _ in xrange(len(ids) - 1):
    i, j = sorted(r.sample(xrange(len(tree)), 2))
    tree = join_neighbors(tree, i, j, r.random(), r.random())

  return tree[0]

if __name__ == '__main__':
  from tree import test_tree
  expected_tree, m, ids = test_tree()
  tree = neighbor_joining(m, ids)

  print tree, expected_tree

  # Random test
  from tree import distance_matrix
  expected_tree = _random_joining(map(str, xrange(10)))
  m, ids = distance_matrix(expected_tree)
  tree = neighbor_joining(m, ids)
  print tree, expected_tree
コード例 #3
0
ファイル: __init__.py プロジェクト: l-singh-biomsu/histonedb
from tree import test_tree
from treecollection import test_tree_collection
from taxonomyreference import test_taxonomy_reference
from taxa import test_taxa

__doc__ = ""
__doc__ += test_tree()
__doc__ += test_tree_collection()
__doc__ += test_taxonomy_reference()
__doc__ += test_taxa()