Hi everyone.
i am trying to calculate inbreeding in a canary pedigree page http://www.pedigricced.com i tried with the code from this old post:
https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/
but i am not really sure it is working properly, Could i get some help? some recent version?
i post my code, i only changed the fill of the array, i fill it with
$badape2 = $pajaro->arraycompleto($con);
all the rest is same code...
<?php
function coeficiente_consanguinidad($dogid, $padre = 0, $madre = 0){
include_once('class/conexion.php');
include_once('class/pajaro.php');
$con = new conexion();
$con->conectar();
$con->selecciona_db();
$pajaro = new pajaro();
$badape2 = $pajaro->arraycompleto($con);
if($padre != 0 && $madre != 0){
$badape2[$dogid] = array($padre, $madre, "pajaro virtual");
}
//print_r($badape2);
//
// ARRAY OF DOGS
// id => [sire, dam, name]
//
/*$badape2 = array (
5722 => array ( 0 => 2292, 1 => 3266, 2 => 'Nimh\'s Delorean', ),
2292 => array ( 0 => 2743, 1 => 2289, 2 => 'Dog B', ),
2743 => array ( 0 => 0, 1 => 0, 2 => 'Dog C', ),
2289 => array ( 0 => 0, 1 => 0, 2 => 'Dog E', ),
3266 => array ( 0 => 2743, 1 => 3263, 2 => 'Dog F', ),
3263 => array ( 0 => 0, 1 => 0, 2 => 'Dog H', )
);*/
//var_dump($badape2);
//
// CALCULATE INBREEDING COEFFICIENTS
//
//echo "<pre>\n";
return COI($dogid, $badape2);
//echo "</pre>\n";
}
//
// FUNCTIONS
//
function getAncestors($id, &$badape2, &$ancests, $path)
{
if ($id==0) return;
$ancests[$id][] = $path;
if (isset($badape2[$id]) ) {
getAncestors($badape2[$id][0], $badape2, $ancests, $path.$badape2[$id][0].',');
getAncestors($badape2[$id][1], $badape2, $ancests, $path.$badape2[$id][1].',');
}
}
function COI($id, &$badape2)
{
if ($id==0) return 0;
$sires = $dams = array();
getAncestors($badape2[$id][0], $badape2, $sires, '');
getAncestors($badape2[$id][1], $badape2, $dams, '');
$result=0;
foreach ($sires as $did=>$dists) {
if (isset($dams[$did])) {
$distd = $dams[$did];
foreach ($dists as $paths) {
foreach ($distd as $pathd) {
$ds = count(explode(',', $paths));
$dd = count(explode(',', $pathd));
if ($paths==$pathd && $ds>2) continue;
$sumd = $ds + $dd-1;
$intermed = pow(0.5, $sumd) * (1 + COI($did, $badape2));
$result += $intermed;
//printf("| %5s | %8.4f | %12s | %12s |\n", $badape2[$did][2], $intermed, $paths, $pathd);
}
}
}
}
return $result;
}
function generaciones_equivalentes($codpajaro, $nivel){
$retorno = 0;
$divisor = $nivel * 2; //cada vez que llamamos a la función el "peso" del pajaro es menor en el numero de generaciones equivalentes
include_once('class/conexion.php');
include_once('class/pajaro.php');
$con = new conexion();
$con->conectar();
$con->selecciona_db();
$pajaro = new pajaro();
$pajaro->porcodigo($con, $codpajaro);
if($pajaro->idpadre != 0){
$retorno = $retorno + (1 / $divisor) + generaciones_equivalentes($pajaro->idpadre, $divisor);
}
if($pajaro->idmadre != 0){
$retorno = $retorno + (1 / $divisor) + generaciones_equivalentes($pajaro->idmadre, $divisor);
}
return $retorno;
}
?>
thanks for help