Skip to main content

Creating a neighbour joining tree.

Project description

This repository stores a basic implementation for creating a neighbour joining tree from a given distance or similarity matrix.

Generating a distance matrix (A good way to do this is to use sklearn.DistanceMetrics with real data):

from sklearn.neighbors import DistanceMetric

dist = DistanceMetric.get_metric('euclidean')
X = [[0, 1, 2],
     [3, 4, 5],
     [2, 3, 1],
     [0, 2, 1]]
dist_mat = dist.pairwise(X)

Now that we have our distance matrix, we can now use it to construct a neighbour joining tree, giving some labels for the different samples:

import numpy
import TreeMethods.TreeBuild as TB

tree = TB.njTree(dist_mat, numpy.array(['A', 'B', 'C', 'D']))

We can then use ete3 to construct this into a tree object:

from ete3 import Tree

tree = Tree(tree)

  |   /-D
  |   \-A

Project details

Release history Release notifications

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for TreeMethods, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size TreeMethods-1.0.3-py3-none-any.whl (4.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size TreeMethods-1.0.3.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page