diff --git a/app/Console/Commands/ImportClassyFire.php b/app/Console/Commands/ImportClassyFire.php index 0a9b76f5..03e822e4 100644 --- a/app/Console/Commands/ImportClassyFire.php +++ b/app/Console/Commands/ImportClassyFire.php @@ -2,10 +2,10 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; -use Log; use App\Models\Properties; use DB; +use Illuminate\Console\Command; +use Log; class ImportClassyFire extends Command { @@ -36,7 +36,7 @@ public function handle() return 1; } - Log::info("Reading file: " . $file); + Log::info('Reading file: '.$file); $batchSize = 10000; $header = null; @@ -85,7 +85,7 @@ private function insertBatch(array $data) foreach ($data as $row) { Properties::updateorCreate( [ - 'molecule_id' => $row['id'] + 'molecule_id' => $row['id'], ], [ 'chemical_class' => str_replace('"', '', $row['chemical_class']), diff --git a/app/Console/Commands/ImportProperties.php b/app/Console/Commands/ImportProperties.php index 1f9593d7..4787c0ba 100644 --- a/app/Console/Commands/ImportProperties.php +++ b/app/Console/Commands/ImportProperties.php @@ -2,10 +2,10 @@ namespace App\Console\Commands; -use Illuminate\Console\Command; -use Log; use App\Models\Properties; use DB; +use Illuminate\Console\Command; +use Log; class ImportProperties extends Command { @@ -36,7 +36,7 @@ public function handle() return 1; } - Log::info("Reading file: " . $file); + Log::info('Reading file: '.$file); $batchSize = 10000; $header = null; @@ -85,7 +85,7 @@ private function insertBatch(array $data) foreach ($data as $row) { Properties::updateorCreate( [ - 'molecule_id' => $row['id'] + 'molecule_id' => $row['id'], ], [ 'total_atom_count' => str_replace('"', '', $row['atom_count']), @@ -110,7 +110,7 @@ private function insertBatch(array $data) 'contains_ring_sugars' => str_replace('"', '', $row['circular_sugars']), 'contains_sugar' => filter_var(str_replace('"', '', $row['linear_sugars']), FILTER_VALIDATE_BOOLEAN) || filter_var(str_replace('"', '', $row['circular_sugars']), FILTER_VALIDATE_BOOLEAN), 'murko_framework' => str_replace('"', '', $row['murko_framework']), - 'nplikeness' => str_replace('"', '', $row['nplikeness']), + 'np_likeness' => str_replace('"', '', $row['nplikeness']), 'molecular_formula' => str_replace('"', '', $row['molecular_formula']), ] ); diff --git a/app/Filament/Dashboard/Resources/CollectionResource/Widgets/CollectionStats.php b/app/Filament/Dashboard/Resources/CollectionResource/Widgets/CollectionStats.php index 836f914a..31a0656b 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/Widgets/CollectionStats.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/Widgets/CollectionStats.php @@ -48,8 +48,9 @@ protected function getStats(): array $molecules = $this->record->molecules; $count = 0; foreach ($molecules as $molecule) { - $count += $molecule->geoLocations()->count(); + $count += $molecule->geo_locations()->count(); } + return $count; })), ]; diff --git a/app/Filament/Dashboard/Resources/MoleculeResource/RelationManagers/GeoLocationRelationManager.php b/app/Filament/Dashboard/Resources/MoleculeResource/RelationManagers/GeoLocationRelationManager.php index d7c071c4..e6fe5e6d 100644 --- a/app/Filament/Dashboard/Resources/MoleculeResource/RelationManagers/GeoLocationRelationManager.php +++ b/app/Filament/Dashboard/Resources/MoleculeResource/RelationManagers/GeoLocationRelationManager.php @@ -11,7 +11,7 @@ class GeoLocationRelationManager extends RelationManager { - protected static string $relationship = 'geoLocations'; + protected static string $relationship = 'geo_locations'; public function form(Form $form): Form { diff --git a/app/Livewire/DataSources.php b/app/Livewire/DataSources.php index 5ecb1785..aaa07634 100644 --- a/app/Livewire/DataSources.php +++ b/app/Livewire/DataSources.php @@ -3,8 +3,8 @@ namespace App\Livewire; use App\Models\Collection; -use Livewire\Component; use Cache; +use Livewire\Component; class DataSources extends Component { @@ -12,7 +12,7 @@ class DataSources extends Component public function mount() { - $this->collections = Cache::rememberForever('collections', function (){ + $this->collections = Cache::rememberForever('collections', function () { return Collection::limit(10)->pluck('title'); }); } diff --git a/app/Livewire/MoleculeDepict2d.php b/app/Livewire/MoleculeDepict2d.php index 581ddf6c..5d639a59 100644 --- a/app/Livewire/MoleculeDepict2d.php +++ b/app/Livewire/MoleculeDepict2d.php @@ -18,7 +18,7 @@ class MoleculeDepict2d extends Component #[Computed] public function source() { - return env('CM_API').'depict/2D?smiles='.urlencode($this->smiles).'&height='.$this->height.'&width='.$this->width.'&CIP='.$this->CIP.'&toolkit=rdkit'; + return env('CM_API').'depict/2D?smiles='.urlencode($this->smiles).'&height='.$this->height.'&width='.$this->width.'&toolkit=cdk'; } public function render() diff --git a/app/Livewire/MoleculeDetails.php b/app/Livewire/MoleculeDetails.php index 661098c5..a201eff4 100644 --- a/app/Livewire/MoleculeDetails.php +++ b/app/Livewire/MoleculeDetails.php @@ -3,6 +3,7 @@ namespace App\Livewire; use App\Models\Molecule; +use Cache; use Livewire\Attributes\Layout; use Livewire\Component; @@ -12,7 +13,9 @@ class MoleculeDetails extends Component public function mount($id) { - $this->molecule = Molecule::with('properties', 'citations', 'collections', 'audits', 'variants')->where('identifier', $id)->first(); + $this->molecule = Cache::remember('molecules.'.$id, 1440, function () use ($id) { + return Molecule::with('properties', 'citations', 'collections', 'audits', 'variants', 'organisms', 'geo_locations', 'related')->where('identifier', $id)->first(); + }); } #[Layout('layouts.guest')] diff --git a/app/Livewire/RecentMolecules.php b/app/Livewire/RecentMolecules.php index f0fda83b..c53cb810 100644 --- a/app/Livewire/RecentMolecules.php +++ b/app/Livewire/RecentMolecules.php @@ -4,9 +4,9 @@ use App\Http\Resources\MoleculeResource; use App\Models\Molecule; +use Cache; use Livewire\Component; use Livewire\WithPagination; -use Cache; class RecentMolecules extends Component { @@ -17,10 +17,9 @@ class RecentMolecules extends Component public function render() { return view('livewire.recent-molecules', [ - 'molecules' => - Cache::rememberForever('molecules.recent', function (){ + 'molecules' => Cache::rememberForever('molecules.recent', function () { return MoleculeResource::collection(Molecule::where('has_variants', true)->where('name', '!=', null)->orderByDesc('updated_at')->paginate($this->size)); - }) + }), ]); } } diff --git a/app/Models/Molecule.php b/app/Models/Molecule.php index 5be95a9c..2618b92e 100644 --- a/app/Models/Molecule.php +++ b/app/Models/Molecule.php @@ -120,7 +120,7 @@ public function organisms(): BelongsToMany /** * Get all of the geo-locations for the molecule. */ - public function geoLocations(): BelongsToMany + public function geo_locations(): BelongsToMany { return $this->belongsToMany(GeoLocation::class)->withPivot('locations')->withTimestamps(); } diff --git a/resources/views/livewire/molecule-details.blade.php b/resources/views/livewire/molecule-details.blade.php index bae56c97..b4fbcbab 100644 --- a/resources/views/livewire/molecule-details.blade.php +++ b/resources/views/livewire/molecule-details.blade.php @@ -99,6 +99,33 @@ class="flex items-baseline flex-wrap justify-between gap-y-2 gap-x-4 border-t bo