Skip to content

Commit

Permalink
Merge pull request #331 from Steinbeck-Lab/feat-charts
Browse files Browse the repository at this point in the history
Feat charts
  • Loading branch information
CS76 authored Jan 16, 2025
2 parents 78e604c + 7399e73 commit 14d31c6
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 191 deletions.
27 changes: 17 additions & 10 deletions app/Console/Commands/GenerateHeatMapData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle()
$molecule_identifiers = array_map(function ($item) {
return preg_replace('/^CNP/i', '', $item);
}, $molecule_identifiers);
$heat_map_data['ids'][$collection->id . '|' . $collection->title] = $molecule_identifiers;
$heat_map_data['ids'][$collection->id.'|'.$collection->title] = $molecule_identifiers;
}

// Calculate percentage overlaps -> ol_d = overlap data
Expand All @@ -42,24 +42,31 @@ public function handle()
$intersection = array_intersect($set1, $set2);
$intersection_count = count($intersection);

// Calculate percentage overlap
if ($set1_count > 0 && $set2_count > 0) {
// Using Jaccard similarity: intersection size / union size
$union_count = $set1_count + $set2_count - $intersection_count;
$overlap_percentage = ($intersection_count / $union_count) * 100;
} else {
$overlap_percentage = 0;
}
// Calculate directional overlap percentages
// What percentage of collection1's molecules are in collection2
$c1_in_c2_percentage = ($set1_count > 0)
? ($intersection_count / $set1_count) * 100
: 0;

// What percentage of collection2's molecules are in collection1
$c2_in_c1_percentage = ($set2_count > 0)
? ($intersection_count / $set2_count) * 100
: 0;

// For the main heatmap data, use the larger percentage
// This shows the stronger relationship between the collections
$overlap_percentage = max($c1_in_c2_percentage, $c2_in_c1_percentage);

$heat_map_data['ol_d'][$collection1_key][$collection2_key] = round($overlap_percentage, 2);

// Add additional overlap statistics -> ol_s = overlap_stats
$heat_map_data['ol_s'][$collection1_key][$collection2_key] = [
// ol = overlap count
'ol' => $intersection_count,
'c1_count' => $set1_count,
'c2_count' => $set2_count,
'p' => round($overlap_percentage, 2),
'c1_in_c2_p' => round($c1_in_c2_percentage, 2), // Percentage of collection1 contained in collection2
'c2_in_c1_p' => round($c2_in_c1_percentage, 2), // Percentage of collection2 contained in collection1
];
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/Livewire/CollectionOverlap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function mount()
}

// Store in the public property
$this->collections = $decodedData['ol_d'];
$this->collections = $decodedData;

}

public function render()
Expand Down
2 changes: 1 addition & 1 deletion public/reports/heat_map_metadata.json

Large diffs are not rendered by default.

Loading

0 comments on commit 14d31c6

Please sign in to comment.