Skip to content

Rapid Neighbor-Joining phylogenetic tree creation method implementation for Node.js

Notifications You must be signed in to change notification settings

biosustain/neighbor-joining

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neighbor-joining is an NPM package for creating phylogenetic trees. It bases on Rapid Neighbour-Joining algorithm.

Installation

To install Neighbor-joining package with NPM use: npm install neighbor-joining

Usage

var RNJ = new RapidNeighborJoining(D, taxa, copyDistanceMatrix, taxonIdAccessor);

Description of arguments used in initialization:

  • D - distance matrix (two dimensional array of size NxN)
  • taxa - array of size N with taxa data (such as strings or objects). Element (taxon) at first index corresponds to first row/column of the distance matrix and so on.
  • copyDistanceMatrix - flag specifying whether D can be modified or must be copied. Copying might minimally increase the initialization time. Default: false.
  • taxonIdAccessor - function for retrieving the name/identifier of a taxon. It is only called during Newick tree creation. Default: function(t){ return t.name }.

Example

var D = [
    [0,  5,  9,  9, 8],
    [5,  0, 10, 10, 9],
    [9, 10,  0,  8, 7],
    [9, 10,  8,  0, 3],
    [8,  9,  7,  3, 0]
];
var taxa = [
    {
        name: "A",
        genotype: "g1"
    },
    {
        name: "B",
        genotype: "g2"
    },
    {
        name: "C",
        genotype: "g3"
    },
    {
        name: "D",
        genotype: "g4"
    },
    {
        name: "E",
        genotype: "g5"
    }
];
var RNJ = new RapidNeighborJoining(D, taxa);
RNJ.run();
var treeObject = RNJ.getAsObject();
var treeNewick = RNJ.getAsNewick();

Then, treeObject will contain the following object:

{
    "taxon": null,
    "length": null,
    "children": [{
        "taxon": {
            "name": "C",
            "genotype": "g3"
        },
        "length": 2,
        "children": []
    }, {
        "taxon": null,
        "length": 2,
        "children": [{
            "taxon": null,
            "length": 3,
            "children": [{
                "taxon": {
                    "name": "A",
                    "genotype": "g1"
                },
                "length": 2,
                "children": []
            }, {
                "taxon": {
                    "name": "B",
                    "genotype": "g2"
                },
                "length": 3,
                "children": []
            }]
        }, {
            "taxon": null,
            "length": 2,
            "children": [{
                "taxon": {
                    "name": "D",
                    "genotype": "g4"
                },
                "length": 2,
                "children": []
            }, {
                "taxon": {
                    "name": "E",
                    "genotype": "g5"
                },
                "length": 1,
                "children": []
            }]
        }]
    }]
}

treeNewick will keep the following string:

"(C:2,((A:2,B:3):3,(D:2,E:1):2):2);"