Skip to content

Commit

Permalink
feat: Add ClusterOverlapCalculator for efficient S
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 12, 2024
1 parent 2f1e204 commit 61b745c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Snps/Analysis/ClusterOverlapCalculator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Dna\Snps\Analysis;

class ClusterOverlapCalculator
{
public function computeClusterOverlap(array $snps, array $chipClusters, float $clusterOverlapThreshold = 0.95): array
{
$overlapResults = [];
foreach ($chipClusters as $clusterId => $clusterData) {
$snpsInCluster = array_filter($snps, function ($snp) use ($clusterData) {
return in_array($snp['chrom'], $clusterData['chromosomes']) && $snp['pos'] >= $clusterData['start'] && $snp['pos'] <= $clusterData['end'];
});

$snpsInCommon = count($snpsInCluster);
$totalSnpsInCluster = count($clusterData['snps']);
$overlapWithCluster = $snpsInCommon / $totalSnpsInCluster;
$overlapWithSelf = $snpsInCommon / count($snps);

if ($overlapWithCluster > $clusterOverlapThreshold && $overlapWithSelf > $clusterOverlapThreshold) {
$overlapResults[$clusterId] = [
'overlapWithCluster' => $overlapWithCluster,
'overlapWithSelf' => $overlapWithSelf,
'snpsInCommon' => $snpsInCommon,
'totalSnpsInCluster' => $totalSnpsInCluster,
];
}
}

return $overlapResults;
}
}

0 comments on commit 61b745c

Please sign in to comment.