Skip to content

Calculates the inbreeding coefficient of a node

License

Notifications You must be signed in to change notification settings

tkassala/inbreed

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Calculates the inbreeding coefficient of a node

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%