Calculate inbreed coefficient. Forked from inbreed
See @sunmingtao's blog post: http://sunmingtao.blogspot.com/2016/11/inbreeding-coefficient.html
npm install inbreeding-coefficient
Require package. The module exports a class called Node.
const Node = require("inbreeding-coefficient");
To calculate the inbreeding coefficient you can either create a tree of nodes manually
const a = new Node("a");
const b = new Node("b");
const x = new Node("x", a, b);
console.log(x.inbreedingCoefficient()); // 0
or you can use the static method Node.fromTree()
to create the a tree of nodes from a binary tree.
const n = Node.fromTree({
name: "e",
father: {
name: "c",
father: { name: "a" },
mother: { name: "b" },
},
mother: {
name: "d",
father: { name: "a" },
mother: { name: "b" },
},
});
console.log(n.inbreedingCoefficient()); // 0.25
Properties of the exported Node class
{String} Node.name
the name of this Node{Node} Node.father
the father of this Node{Node} Node.mother
the mother of this Node
const n = new Node(name, father, mother);
const n = Node.fromTree({
name: "e",
father: { name: "c" },
mother: { name: "d" },
});
parentPaths()
Returns an array of Path objects
fatherPaths(), motherPaths()
Both of these call parentPaths() with Node.father and Node.mother respectively.
paths()
Concats fatherPaths() and motherPaths()
stepsToCommonAncestor(c1, c2)
If a common ancestor is found in the mothers and fathers tree, returns the number of steps between them
inbreedingCoefficient()
Returns the inbreeding coefficient of this Node
- Make
Node.fromTree()
an override of the constructor.- Figure out how to document such an override.
- Document the Path class or get rid of it.