From ff830aee0ed2fe71d941b6de3ce75f5f9b1394d4 Mon Sep 17 00:00:00 2001 From: Sagar Date: Mon, 16 Dec 2024 19:06:35 +0100 Subject: [PATCH 1/5] feat: new command to generate heatmap data --- app/Console/Commands/GenerateHeatMapData.php | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 app/Console/Commands/GenerateHeatMapData.php diff --git a/app/Console/Commands/GenerateHeatMapData.php b/app/Console/Commands/GenerateHeatMapData.php new file mode 100644 index 0000000..4ddaecf --- /dev/null +++ b/app/Console/Commands/GenerateHeatMapData.php @@ -0,0 +1,74 @@ +molecules()->pluck('identifier')->toArray(); + $heat_map_data['identifier_data'][$collection->id.'|'.$collection->title] = $molecule_identifiers; + } + + // Calculate percentage overlaps + $heat_map_data['overlap_data'] = []; + $collection_keys = array_keys($heat_map_data['identifier_data']); + + foreach ($collection_keys as $collection1_key) { + $heat_map_data['overlap_data'][$collection1_key] = []; + $set1 = array_unique($heat_map_data['identifier_data'][$collection1_key]); + $set1_count = count($set1); + + foreach ($collection_keys as $collection2_key) { + $set2 = array_unique($heat_map_data['identifier_data'][$collection2_key]); + $set2_count = count($set2); + + // Calculate intersection + $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; + } + + $heat_map_data['overlap_data'][$collection1_key][$collection2_key] = round($overlap_percentage, 2); + + // Add additional overlap statistics + $heat_map_data['overlap_stats'][$collection1_key][$collection2_key] = [ + 'intersection_count' => $intersection_count, + 'collection1_count' => $set1_count, + 'collection2_count' => $set2_count, + 'percentage' => round($overlap_percentage, 2), + ]; + } + } + + $json = json_encode($heat_map_data, JSON_PRETTY_PRINT); + + // Save the JSON to a file + $filePath = public_path('reports/heat_map_metadata.json'); + if (! file_exists(dirname($filePath))) { + mkdir(dirname($filePath), 0777, true); + } + file_put_contents($filePath, $json); + + $this->info('JSON metadata saved to public/reports/heat_map_metadata.json'); + } +} From 61a3efcdb67759a1cb532aeaa243098d7165b969 Mon Sep 17 00:00:00 2001 From: Sagar Date: Mon, 16 Dec 2024 19:07:25 +0100 Subject: [PATCH 2/5] feat: new component to display heat map on the stats page --- app/Livewire/CollectionOverlap.php | 54 ++++++ .../livewire/collection-overlap.blade.php | 179 ++++++++++++++++++ resources/views/livewire/stats.blade.php | 3 + 3 files changed, 236 insertions(+) create mode 100644 app/Livewire/CollectionOverlap.php create mode 100644 resources/views/livewire/collection-overlap.blade.php diff --git a/app/Livewire/CollectionOverlap.php b/app/Livewire/CollectionOverlap.php new file mode 100644 index 0000000..d216a31 --- /dev/null +++ b/app/Livewire/CollectionOverlap.php @@ -0,0 +1,54 @@ +collections = $decodedData['overlap_data']; + // Example data structure - replace with your actual data fetching logic + // $this->collections = [ + // 'Collection A' => [ + // 'Collection A' => 100, + // 'Collection B' => 75, + // 'Collection C' => 45, + // ], + // 'Collection B' => [ + // 'Collection A' => 75, + // 'Collection B' => 100, + // 'Collection C' => 60, + // ], + // 'Collection C' => [ + // 'Collection A' => 45, + // 'Collection B' => 60, + // 'Collection C' => 100, + // ], + // ]; + } + + public function render() + { + return view('livewire.collection-overlap', [ + 'collectionsData' => json_encode($this->collections), + ]); + } +} diff --git a/resources/views/livewire/collection-overlap.blade.php b/resources/views/livewire/collection-overlap.blade.php new file mode 100644 index 0000000..c64b683 --- /dev/null +++ b/resources/views/livewire/collection-overlap.blade.php @@ -0,0 +1,179 @@ +
+
+
+
+ + \ No newline at end of file diff --git a/resources/views/livewire/stats.blade.php b/resources/views/livewire/stats.blade.php index 9c11dd7..385fb92 100644 --- a/resources/views/livewire/stats.blade.php +++ b/resources/views/livewire/stats.blade.php @@ -113,6 +113,9 @@ class="pointer-events-none absolute inset-0 rounded-xl ring-1 ring-inset ring-gr 'chartData' => $chartData, ]) @endforeach + +
+ @livewire('collection-overlap')
\ No newline at end of file From 3d74cf74f2a3594b9dd94a957d6592f115468c7b Mon Sep 17 00:00:00 2001 From: Sagar Date: Mon, 16 Dec 2024 19:30:46 +0100 Subject: [PATCH 3/5] fix: added tool tip, corrected the names, and moved legend to the right. --- .../livewire/collection-overlap.blade.php | 73 ++++++++++--------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/resources/views/livewire/collection-overlap.blade.php b/resources/views/livewire/collection-overlap.blade.php index c64b683..2f63d32 100644 --- a/resources/views/livewire/collection-overlap.blade.php +++ b/resources/views/livewire/collection-overlap.blade.php @@ -6,6 +6,7 @@