Barand Posted December 11, 2015 Share Posted December 11, 2015 In the code I posted, A - J would be in the sires array and O - U would be in the dams array, which would produce no common ancestors Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527829 Share on other sites More sharing options...
Triple_Deuce Posted December 11, 2015 Author Share Posted December 11, 2015 (edited) In the code I posted, A - J would be in the sires array and O - U would be in the dams array, which would produce no common ancestors Yes, this is correct but I was talking about getting U's ICO... Based on given info I get .5 (50%) as inbreeding on FU (ID#: 59) instead of .375 (37.5%). Edited December 11, 2015 by Triple_Deuce Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527832 Share on other sites More sharing options...
Barand Posted December 11, 2015 Share Posted December 11, 2015 I get these results, which look right to me DOG: J | A | 0.0312 | 2 | 2 | | A | 0.0312 | 2 | 2 | | B | 0.0312 | 2 | 2 | | B | 0.0312 | 2 | 2 | COI : 0.1250 DOG: U | Q | 0.1250 | 1 | 1 | | O | 0.0312 | 2 | 2 | | O | 0.0312 | 2 | 2 | | P | 0.0312 | 2 | 2 | | P | 0.0312 | 2 | 2 | | R | 0.1250 | 1 | 1 | COI : 0.3750 DOG: Z COI : 0.0000 Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527833 Share on other sites More sharing options...
Triple_Deuce Posted December 11, 2015 Author Share Posted December 11, 2015 Are you getting that on my thing? http://play.ratsofnimh.com/pedigree/inbreeding2.php or somewhere else? Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527835 Share on other sites More sharing options...
Barand Posted December 11, 2015 Share Posted December 11, 2015 Those results were from my own code. Yours almost agrees with mine in that we both get | 44 | A | 2,2| 2,2| but I interpret that as A | 0.03125 | 2 | 2 | A | 0.03125 | 2 | 2 | whereas you apparently have doubled it to A | 0.03125 | 2 | 2 | A | 0.03125 | 2 | 2 | A | 0.03125 | 2 | 2 | A | 0.03125 | 2 | 2 | Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527836 Share on other sites More sharing options...
Triple_Deuce Posted December 11, 2015 Author Share Posted December 11, 2015 (edited) Ok, as I was typing this, I think i see my error! DogU is supposed to be .375 (37.5%) DogO & DogP are only behind DogU TWICE. I have my equation in a nested foreach() which is why I'm getting the 4 extra (2 of each) when I shouldnt. foreach($sires[$id] as $keyS => $valueS){ foreach($dams[$id] as $keyD => $valueD){ $ico = pow(.5,($valueS + $valueD + 1)) + $ico; } } What would be the best approach to break out of that and and potentially pair either $sires or $dams with empty $valueD/S? Edited December 11, 2015 by Triple_Deuce Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527837 Share on other sites More sharing options...
Triple_Deuce Posted December 11, 2015 Author Share Posted December 11, 2015 Ok, I've put in the following: $c = array_map(function () { return array_sum(func_get_args()); }, $sires[$id], $dams[$id]); foreach($c AS $key =>$value){ $ico = pow(.5,($value + 1)) + $ico; } print_r($c); which calculates U correctly now... however J is now wrong, it's showing as 0.125 instead of .5 (full sibling x full sibling = .5 (50%)). What am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527841 Share on other sites More sharing options...
Barand Posted December 11, 2015 Share Posted December 11, 2015 I'm struggling too. My method got U correct but not J. Using your nested foreach() method gets J correct but not U. Time for a new algorithm? Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527844 Share on other sites More sharing options...
Barand Posted December 13, 2015 Share Posted December 13, 2015 This my best attempt yet. Instead of counting I store the traversed path then eliminate duplicates. <?php // // ARRAY OF DOGS // id => [sire, dam, name] // $dogs = array ( 1 => array ( 0 => '2', 1 => '3', 2 => 'Nimh\'s Delorean', ), 2 => array ( 0 => '4', 1 => '9', 2 => 'Dog B', ), 3 => array ( 0 => '7', 1 => '8', 2 => 'Dog C', ), 4 => array ( 0 => '7', 1 => '9', 2 => 'Dog E', ), 5 => array ( 0 => '10', 1 => '11', 2 => 'Dog F', ), 7 => array ( 0 => '14', 1 => '15', 2 => 'Dog H', ), 8 => array ( 0 => '16', 1 => '17', 2 => 'Dog I', ), 9 => array ( 0 => '16', 1 => '17', 2 => 'Dog J', ), 10 => array ( 0 => '18', 1 => '19', 2 => 'Dog K', ), 11 => array ( 0 => '20', 1 => '21', 2 => 'Dog L', ), 14 => array ( 0 => '20', 1 => '17', 2 => 'Dog O', ), 15 => array ( 0 => '0', 1 => '0', 2 => 'Dog P', ), 16 => array ( 0 => '14', 1 => '17', 2 => 'Dog Q', ), 17 => array ( 0 => '0', 1 => '0', 2 => 'Dog R', ), 18 => array ( 0 => '0', 1 => '0', 2 => 'Dog S', ), 19 => array ( 0 => '0', 1 => '0', 2 => 'Dog T', ), 20 => array ( 0 => '0', 1 => '0', 2 => 'Dog U', ), 21 => array ( 0 => '0', 1 => '0', 2 => 'Dog V', ), 22 => array ( 0 => '0', 1 => '0', 2 => 'Dog W', ), 23 => array ( 0 => '0', 1 => '0', 2 => 'Dog X', ), 24 => array ( 0 => '25', 1 => '26', 2 => 'Cedric', ), 25 => array ( 0 => '27', 1 => '0', 2 => 'Phantom', ), 26 => array ( 0 => '27', 1 => '0', 2 => 'Walton Mare', ), 27 => array ( 0 => '0', 1 => '0', 2 => 'Walton', ), 28 => array ( 0 => '0', 1 => '0', 2 => 'A', ), 29 => array ( 0 => '0', 1 => '0', 2 => 'B', ), 30 => array ( 0 => '29', 1 => '28', 2 => 'C', ), 31 => array ( 0 => '29', 1 => '28', 2 => 'D', ), 32 => array ( 0 => '0', 1 => '30', 2 => 'E', ), 33 => array ( 0 => '0', 1 => '31', 2 => 'F', ), 34 => array ( 0 => '33', 1 => '32', 2 => 'I', ), 35 => array ( 0 => '0', 1 => '0', 2 => 'J', ), 36 => array ( 0 => '0', 1 => '0', 2 => 'K', ), 37 => array ( 0 => '0', 1 => '0', 2 => 'L', ), 38 => array ( 0 => '0', 1 => '0', 2 => 'M', ), 39 => array ( 0 => '0', 1 => '0', 2 => 'N', ), 40 => array ( 0 => '0', 1 => '0', 2 => 'Dog1', ), 41 => array ( 0 => '0', 1 => '0', 2 => 'Dog2', ), 42 => array ( 0 => '40', 1 => '41', 2 => 'Dog3', ), 43 => array ( 0 => '42', 1 => '41', 2 => 'Dog4', ), 44 => array ( 0 => '0', 1 => '0', 2 => 'O', ), 45 => array ( 0 => '0', 1 => '0', 2 => 'P', ), 46 => array ( 0 => '44', 1 => '45', 2 => 'Q', ), 47 => array ( 0 => '44', 1 => '45', 2 => 'R', ), 48 => array ( 0 => '46', 1 => '47', 2 => 'S', ), 49 => array ( 0 => '46', 1 => '47', 2 => 'T', ), 50 => array ( 0 => '48', 1 => '49', 2 => 'U', ), 51 => array ( 0 => '0', 1 => '0', 2 => 'A', ), 52 => array ( 0 => '0', 1 => '0', 2 => 'B', ), 53 => array ( 0 => '51', 1 => '52', 2 => 'C', ), 54 => array ( 0 => '51', 1 => '52', 2 => 'D', ), 55 => array ( 0 => '51', 1 => '52', 2 => 'E', ), 56 => array ( 0 => '51', 1 => '52', 2 => 'G', ), 57 => array ( 0 => '53', 1 => '54', 2 => 'H', ), 58 => array ( 0 => '55', 1 => '56', 2 => 'I', ), 59 => array ( 0 => '57', 1 => '58', 2 => 'J', ), 60 => array ( 0 => '59', 1 => '50', 2 => 'Z', ) ); // // CALCULATE INBREEDING COEFFICIENTS // $doglist = [4,9,34,50,59,60]; echo "<pre>\n"; foreach ($doglist as $dogid) { printf("%-20s (#%03d) COI : %0.4f<br>", $dogs[$dogid][2], $dogid, COI($dogid, $dogs)); } echo "</pre>\n"; // // FUNCTIONS // function getAncestors($id, &$dogs, &$ancests, $path) { if ($id==0) return; $ancests[$id][] = $path; if (isset($dogs[$id]) ) { getAncestors($dogs[$id][0], $dogs, $ancests, $path.$dogs[$id][0].','); getAncestors($dogs[$id][1], $dogs, $ancests, $path.$dogs[$id][1].','); } } function COI($id, &$dogs) { if ($id==0) return 0; $sires = $dams = []; getAncestors($dogs[$id][0], $dogs, $sires, ''); getAncestors($dogs[$id][1], $dogs, $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, $dogs)); $result += $intermed; // printf("| %5s | %8.4f | %12s | %12s |\n", $dogs[$did][2], $intermed, $paths, $pathd); } } } } return $result; } Results Dog E (#004) COI : 0.1875 Dog J (#009) COI : 0.3750 I (#034) COI : 0.0625 U (#050) COI : 0.3750 J (#059) COI : 0.2500 Z (#060) COI : 0.0000 Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527888 Share on other sites More sharing options...
Triple_Deuce Posted December 14, 2015 Author Share Posted December 14, 2015 Is there anyway to get the $sires & $dams arrays to properly display like this when necessary? It looks like it's not tracking all occurrences. DOG ID: 52 | ID | NAME | SIRE | DAM | | | | DIST | DIST | |-----|--------------------|------|------| | 44 | A | 2,2,2,2| 2,2,2,2| .5^(4+1) = 0.03125 .5^(4+1) = 0.03125 .5^(4+1) = 0.03125 .5^(4+1) = 0.03125 | 45 | B | 2,2,2,2| 2,2,2,2| .5^(4+1) = 0.03125 .5^(4+1) = 0.03125 .5^(4+1) = 0.03125 .5^(4+1) = 0.03125 total ICO: 0.25 Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1527938 Share on other sites More sharing options...
Yranac Posted November 9, 2016 Share Posted November 9, 2016 why i get my post deleted? Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1539148 Share on other sites More sharing options...
Jacques1 Posted November 9, 2016 Share Posted November 9, 2016 Because you're not supposed to hijack threads of other users or dig out discussions from 2015. Create your own thread. It's not that hard. You can still link to this thread if you feel it's relevant. Got it now? Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1539149 Share on other sites More sharing options...
Yranac Posted November 9, 2016 Share Posted November 9, 2016 yes, much more easy when you explain it Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1539153 Share on other sites More sharing options...
Beluga Posted May 7, 2020 Share Posted May 7, 2020 On 12/8/2015 at 8:24 PM, Barand said: Hi Anybody see this topic? I need little help for my database. I have a planner and i wouldlike showing the COI, if possible. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1577669 Share on other sites More sharing options...
Barand Posted May 7, 2020 Share Posted May 7, 2020 @Beluga Don't attribute things to me that I didn't say. Don't hijack other people's threads Don't resurrect old topics. Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1577674 Share on other sites More sharing options...
Beluga Posted May 7, 2020 Share Posted May 7, 2020 (edited) sorry, can you deleted Edited May 7, 2020 by Beluga Quote Link to comment https://forums.phpfreaks.com/topic/292600-calculating-inbreeding-on-a-10-generation-pedigree/page/2/#findComment-1577678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.