Skip to content

Commit

Permalink
feat: Add Triangulation class for modular SNP comp
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 12, 2024
1 parent a113381 commit 2062835
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Triangulation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

require_once 'SNPs.php';

class Triangulation {

public static function compareMultipleKits($kitsData) {
$snpsLists = array_map(function($kit) { return $kit->getSnps(); }, $kitsData);
$commonSnps = call_user_func_array('array_intersect_key', $snpsLists);
foreach ($commonSnps as $key => $snp) {
if (!self::isSnpCommonAcrossAllKits($snp, $kitsData)) {
unset($commonSnps[$key]);
}
}
return array_values($commonSnps);
}

private static function isSnpCommonAcrossAllKits($snp, $kitsData) {
foreach ($kitsData as $kit) {
$snps = $kit->getSnps();
if (!array_key_exists($snp['pos'], $snps) || $snps[$snp['pos']]['genotype'] !== $snp['genotype']) {
return false;
}
}
return true;
}
}
?>

0 comments on commit 2062835

Please sign in to comment.