1.0.4 • Published 4 years ago

inbreeding-coefficient v1.0.4

Weekly downloads
-
License
GPL-3
Repository
github
Last release
4 years ago

Inbreeding Coefficient

Calculate inbreed coefficient. Forked from inbreed

See @sunmingtao's blog post: http://sunmingtao.blogspot.com/2016/11/inbreeding-coefficient.html

Installation

npm install inbreeding-coefficient

Usage

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

Node class

Properties of the exported Node class

Members

  • {String} Node.name the name of this Node
  • {Node} Node.father the father of this Node
  • {Node} Node.mother the mother of this Node

Methods

Constructor

const n = new Node(name, father, mother);

fromTree()

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

TODO

  • 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.
1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago