diff --git a/src/js/ibcJS.js b/src/js/ibcJS.js index a97f19d8f7b04620596874d3d778e63bdfdcb0f1..689a9cc34c26d94cffefb8da164ee2a664381992 100644 --- a/src/js/ibcJS.js +++ b/src/js/ibcJS.js @@ -41,7 +41,9 @@ globalThis.ibc = (() => { let prefix_len = (nca, ncb) => { let i = 0; for (i = 0; i < Math.min(nca.length, ncb.length); i++) { - if (nca[i] !== ncb[i]) { break; } + if (nca[i] !== ncb[i]) { + break; + } } return i; }; @@ -54,7 +56,9 @@ globalThis.ibc = (() => { let match = false; b.nodecodes.forEach(ncb => { let l = prefix_len(nca, ncb); - if (l === 0 && match) { return; } + if (l === 0 && match) { + return; + } if (l > 0) { match = true; @@ -79,8 +83,12 @@ globalThis.ibc = (() => { } let ret = null; - if (n.mother !== null) { ret = find_nc(nc, n.mother); } - if (n.father !== null && ret === null) { ret = find_nc(nc, n.father); } + if (n.mother !== null) { + ret = find_nc(nc, n.mother); + } + if (n.father !== null && ret === null) { + ret = find_nc(nc, n.father); + } return ret; }; @@ -98,13 +106,17 @@ globalThis.ibc = (() => { ret.nodecodes.forEach(nc => { let i = pfx_s.indexOf(nc.join(';')); - if (i === -1) { return; } + if (i === -1) { + return; + } pfx.pop(i); pfx_s.pop(i); }); - if (anc.findIndex(s => (s[0] == ret)) === -1) { anc.push([ret, p]); } + if (anc.findIndex(s => (s[0] == ret)) === -1) { + anc.push([ret, p]); + } } return anc; @@ -133,7 +145,11 @@ globalThis.ibc = (() => { let kinship = (mother, father) => { let _coeff = 0; - if (!mother || !father) { _coeff = 0; } else if (mother === father) { _coeff = 0.5 * (1 + coeff(mother)); } else { + if (!mother || !father) { + _coeff = 0; + } else if (mother === father) { + _coeff = 0.5 * (1 + coeff(mother)); + } else { let cf = 0; let cmn = common(mother, father); @@ -147,12 +163,16 @@ globalThis.ibc = (() => { cmn.forEach(el2 => { let co = el2[0]; - if (co == c) { return; } + if (co == c) { + return; + } let m_pp = []; let f_pp = []; co.nodecodes.forEach(nc => { - if (nc.slice(0, p.length).join(';') != p_s) { return; } + if (nc.slice(0, p.length).join(';') != p_s) { + return; + } m_pp = m_pp.concat(mps(mother, nc)); f_pp = f_pp.concat(mps(father, nc)); @@ -162,7 +182,9 @@ globalThis.ibc = (() => { f_pp.forEach(fp => { let mf_s = [mp.join(';'), fp.join(';')].join(','); let i = paths_s.indexOf(mf_s); - if (i === -1) { return; } + if (i === -1) { + return; + } paths_s.pop(i); paths.pop(i); }); @@ -183,7 +205,9 @@ globalThis.ibc = (() => { // Determine the coefficient of inbreeding of a node `n` let coeff = n => { - if (n._coeff === null) { n._coeff = kinship(n.mother, n.father); } + if (n._coeff === null) { + n._coeff = kinship(n.mother, n.father); + } return n._coeff; }; @@ -218,7 +242,9 @@ globalThis.ibc = (() => { let seen = []; let curid = 0; Object.values(nodes).forEach(n => { - if (n.mother !== null || n.father !== null) { return; } + if (n.mother !== null || n.father !== null) { + return; + } n.nodecodes.push([curid]); curid += 1; seen.push(n.id); @@ -239,8 +265,9 @@ globalThis.ibc = (() => { seen.push(n.id); // Compute the NodeCodes from its parents [n.mother, n.father].forEach((a, i) => { - if (a === null || (n.mother === n.father && i === 1)) // Ignore missing parents/repeated - { return; } + if (a === null || (n.mother === n.father && i === 1)) { // Ignore missing parents/repeated + return; + } a.nodecodes.forEach(nc => { // Copy the NodeCode, push the child number, then add it @@ -381,10 +408,14 @@ globalThis.ibc = (() => { * @returns {number} */ let coeff_slave = (slave, ignore_coeffs = false) => { - if (!ignore_coeffs && "inbreedingCoeff" in slave && slave.inbreedingCoeff !== -1) { return slave.inbreedingCoeff; } + if (!ignore_coeffs && "inbreedingCoeff" in slave && slave.inbreedingCoeff !== -1) { + return slave.inbreedingCoeff; + } let gp = find_gp(slave.ID); - if (!ignore_coeffs && gp !== null && "inbreedingCoeff" in gp && gp.inbreedingCoeff !== -1) { return gp.inbreedingCoeff; } + if (!ignore_coeffs && gp !== null && "inbreedingCoeff" in gp && gp.inbreedingCoeff !== -1) { + return gp.inbreedingCoeff; + } return coeff_slaves([slave], ignore_coeffs)[slave.ID]; }; @@ -419,9 +450,15 @@ globalThis.ibc = (() => { // occurrences of the COI for the affected slaves /** @type {IBCRelative[]} */ let all_slave_like = V.slaves.concat(V.genePool).concat(V.cribs).concat(V.tanks).concat(Object.values(V.missingTable)); - if (V.boomerangSlave !== 0) { all_slave_like.push(V.boomerangSlave); } - if (V.traitor !== 0) { all_slave_like.push(V.traitor); } - if (V.activeSlave !== 0) { all_slave_like.push(V.activeSlave); } + if (V.boomerangSlave !== 0) { + all_slave_like.push(V.boomerangSlave); + } + if (V.traitor !== 0) { + all_slave_like.push(V.traitor); + } + if (V.activeSlave !== 0) { + all_slave_like.push(V.activeSlave); + } all_slave_like.push(V.PC); // Add a fake entry for the PC's old master all_slave_like.push(oldMaster); @@ -440,8 +477,12 @@ globalThis.ibc = (() => { // Add fetuses all_fetuses.filter(f => (f.father === id || f.mother === id)).forEach(f => { // We may have to manually add the parents later - if (specificCharacterID(f.father)) { cur_fetus_parents.add(f.father); } - if (specificCharacterID(f.mother)) { cur_fetus_parents.add(f.mother); } + if (specificCharacterID(f.father)) { + cur_fetus_parents.add(f.father); + } + if (specificCharacterID(f.mother)) { + cur_fetus_parents.add(f.mother); + } cur_fetuses.add(f); }); @@ -490,7 +531,9 @@ globalThis.ibc = (() => { // Use a string of the form "parent;parent" to store the cache value; since kinship is // commutative, the minimum parent ID will be first let kinship_str = Math.min(f.mother, f.father) + ';' + Math.max(f.mother, f.father); - if (!kinship_cache.has(kinship_str)) { kinship_cache.set(kinship_str, kinship(nodes[f.mother], nodes[f.father])); } + if (!kinship_cache.has(kinship_str)) { + kinship_cache.set(kinship_str, kinship(nodes[f.mother], nodes[f.father])); + } f.inbreedingCoeff = kinship_cache.get(kinship_str); });