js血型遗传规律根据多个或单个子女血型查父母可能血型及不可能血型
JavaScipt
2026-06-02 19:13:59
一、血型遗传基本原理
ABO血型由三个等位基因 A、B、O 控制,其中 A 和 B 对 O 为显性,A 与 B 共显性。每个人的基因型为以下之一:
A 型:AA 或 AO
B 型:BB 或 BO
AB 型:AB
O 型:OO
子女从父母各获得一个等位基因,由此子女的基因型一定是由父母各贡献的一个等位基因组合而成。
子女血型推理父母血型的核心:如果某对父母的血型不可能生出给定血型的子女,那么该父母组合应被排除;反之,只要存在一组可能的父母基因型(即使其中一方为纯合或杂合)能够产生该子女血型,该父母组合即为可能。
二、血型遗传口诀
孩 O 父母不 AB,且须二人都有 O;
孩 A 禁双 B 与双 O,至少一方带 A 来;
孩 B 禁双 A 与双 O,至少一方带 B 去;
孩 AB 最挑剔,父母不能有 O,且须 A 和 B 各一方。
三、根据血型遗传原理给出JavaScript代码
// 辅助函数:根据基因型得到血型
function genotypeToBloodType(genotype) {
if (genotype === 'AA' || genotype === 'AO') return 'A';
if (genotype === 'BB' || genotype === 'BO') return 'B';
if (genotype === 'AB') return 'AB';
if (genotype === 'OO') return 'O';
throw new Error('Invalid genotype');
}
// 辅助函数:给定父母基因型,返回所有可能的子女血型(去重)
function getPossibleChildrenBloodTypes(fatherGeno, motherGeno) {
const fAlleles = fatherGeno.split('');
const mAlleles = motherGeno.split('');
const childGenotypes = new Set();
for (let fa of fAlleles) {
for (let ma of mAlleles) {
// 组合等位基因,注意排序以使基因型规范(如 AO 与 OA 相同)
let childGeno = [fa, ma].sort().join('');
childGenotypes.add(childGeno);
}
}
const bloodSet = new Set();
for (let geno of childGenotypes) {
bloodSet.add(genotypeToBloodType(geno));
}
return bloodSet;
}
/**
* 根据多个子女的血型,推算父母可能和不可能的血型组合
* @param {string[]} childrenBloodTypes - 子女血型数组,例如 ['A', 'B', 'O', 'AB']
* @returns {Object} 包含可能和不可能的父母血型组合(有序对)
*/
function possibleParentBloodTypes(childrenBloodTypes) {
// 所有血型
const bloodTypes = ['A', 'B', 'AB', 'O'];
// 每个血型对应的可能基因型(等位基因对)
const genotypeMap = {
'A': ['AA', 'AO'],
'B': ['BB', 'BO'],
'AB': ['AB'],
'O': ['OO']
};
// 去重子女血型(只需判断每个血型是否可能出现)
const uniqueChildren = [...new Set(childrenBloodTypes)];
const possiblePairs = [];
const impossiblePairs = [];
// 枚举所有有序父母血型对 (father, mother)
for (let fType of bloodTypes) {
for (let mType of bloodTypes) {
let possible = false;
// 枚举父亲的所有可能基因型
const fGenotypes = genotypeMap[fType];
const mGenotypes = genotypeMap[mType];
for (let fGeno of fGenotypes) {
for (let mGeno of mGenotypes) {
const childBloodSet = getPossibleChildrenBloodTypes(fGeno, mGeno);
// 检查是否包含所有子女血型
if (uniqueChildren.every(blood => childBloodSet.has(blood))) {
possible = true;
break;
}
}
if (possible) break;
}
const pair = [fType, mType];
if (possible) {
possiblePairs.push(pair);
} else {
impossiblePairs.push(pair);
}
}
}
return { possible: possiblePairs, impossible: impossiblePairs };
}
// 示例用法
const children = ['A', 'O']; // 两个孩子分别为 A 型和 O 型
const result = possibleParentBloodTypes(children);
console.log('可能父母组合:', result.possible);
console.log('不可能父母组合:', result.impossible);四、注意项
反向推断不能唯一确定父母血型,只能提供可能集合并排除绝对不可能的配对。如需确认亲子关系,仍以 DNA 鉴定为准。
基因型概率:表中“可能组合”仅表示存在性,不表示组合出现的概率。例如 A×B 可以生出 O 型,但需要双方都是杂合子(AO+BO),若其中一方是纯合则无法实现。在实际反向推理中,如果已知父母一方血型但不确定纯杂,则仍保留该可能性。
罕见突变:极少数情况(如顺式 AB、获得性抗原等)可能打破上述规律,但不影响常规医学与生活应用。
六月初字帖坊小程序
你想要的字帖模板及工具,这里都有!
919篇文章
94人已阅读
六月初