From e854cbbd1c4c1681c79f128d8bd4f43b1f2524a1 Mon Sep 17 00:00:00 2001 From: Venkata Chandra Sekhar Nainala Date: Mon, 13 Nov 2023 00:52:42 +0100 Subject: [PATCH] fix: updated dataset spectra loading logic and other minor updates --- app/Console/Commands/ArchiveData.php | 4 +- app/Console/Commands/ExtractSpectra.php | 85 +++++++++++---------- app/Http/Controllers/DatasetController.php | 2 +- resources/js/Pages/Public/Project/Study.vue | 1 - resources/js/Shared/SpectraViewer.vue | 37 +++++++-- 5 files changed, 78 insertions(+), 51 deletions(-) diff --git a/app/Console/Commands/ArchiveData.php b/app/Console/Commands/ArchiveData.php index 7f6bf796..1c0e5986 100644 --- a/app/Console/Commands/ArchiveData.php +++ b/app/Console/Commands/ArchiveData.php @@ -36,8 +36,8 @@ public function handle() ])->get(); foreach ($projects as $project) { - echo($project->identifier); - echo("\r\n"); + echo $project->identifier; + echo "\r\n"; ArchiveProject::dispatch($project); ArchiveStudy::dispatch($project); } diff --git a/app/Console/Commands/ExtractSpectra.php b/app/Console/Commands/ExtractSpectra.php index d471e39c..ae6e55ec 100644 --- a/app/Console/Commands/ExtractSpectra.php +++ b/app/Console/Commands/ExtractSpectra.php @@ -35,6 +35,7 @@ public function handle() ])->get(); foreach ($projects as $project) { + echo "\r\n"; echo $project->identifier; echo "\r\n"; $studies = $project->studies; @@ -90,61 +91,63 @@ public function handle() } $study = $study->fresh(); foreach ($study->datasets as $dataset) { - echo $dataset->identifier; - echo "\r\n"; + // echo $dataset->identifier; + // echo "\r\n"; // if(!$dataset->has_nmrium){ $nmriumInfo = json_decode($study->nmrium['nmrium_info'], true); $_nmriumJSON = $nmriumInfo; $fsObject = $dataset->fsObject; - $level = -($fsObject->level); - // echo $fsObject->path; - // echo("\r\n"); - // echo $study->name; - // echo("\r\n"); - $path = $study->name.'/'.$dataset->name; + + $studyFSObject = $study->fsObject; + $datasetFSObject = $dataset->fsObject; + $path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name; + // echo($path); + // echo "\r\n"; + $pathsMatch = false; foreach ($nmriumInfo['data']['spectra'] as $spectra) { unset($_nmriumJSON['data']['spectra']); $files = $spectra['sourceSelector']['files']; - // echo($path); - // echo("\r\n"); - $pathsMatch = true; if ($files) { foreach ($files as $file) { - // echo $file; - // echo "\r\n"; - if (! str_contains($file, $path)) { - $pathsMatch = false; + if (str_contains($file, $path)) { + $pathsMatch = true; } } } - // echo($pathsMatch); - // echo("\r\n"); if ($pathsMatch) { - $_nmriumJSON['data']['spectra'] = [$spectra]; - // dd($_nmriumJSON); - $_nmrium = $dataset->nmrium; - if ($_nmrium) { - $_nmrium->nmrium_info = json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE); - $dataset->has_nmrium = true; - $_nmrium->save(); - } else { - $_nmrium = NMRium::create([ - 'nmrium_info' => json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE), - ]); - $dataset->nmrium()->save($_nmrium); - $dataset->has_nmrium = true; - } - $experimentDetailsExists = array_key_exists('experiment', $spectra['info']); - if ($experimentDetailsExists) { - $experiment = $spectra['info']['experiment']; - $nucleus = $spectra['info']['nucleus']; - if (is_array($nucleus)) { - $nucleus = implode('-', $nucleus); - } - $dataset->type = $experiment.','.$nucleus; + break; + } + } + if (! $pathsMatch) { + echo $project->identifier; + echo "\r\n"; + + echo '===========> no match'; + echo "\r\n"; + } else { + $_nmriumJSON['data']['spectra'] = [$spectra]; + $_nmrium = $dataset->nmrium; + if ($_nmrium) { + $_nmrium->nmrium_info = json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE); + $dataset->has_nmrium = true; + $_nmrium->save(); + } else { + $_nmrium = NMRium::create([ + 'nmrium_info' => json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE), + ]); + $dataset->nmrium()->save($_nmrium); + $dataset->has_nmrium = true; + } + $experimentDetailsExists = array_key_exists('experiment', $spectra['info']); + if ($experimentDetailsExists) { + $experiment = $spectra['info']['experiment']; + $nucleus = $spectra['info']['nucleus']; + if (is_array($nucleus)) { + $nucleus = implode('-', $nucleus); } - $dataset->save(); + $dataset->type = $experiment.','.$nucleus; } + $dataset->save(); } // } } @@ -154,7 +157,7 @@ public function handle() public function processSpectra($url) { - $response = Http::timeout(300)->post('https://nodejsdev.nmrxiv.org/spectra-parser', [ + $response = Http::timeout(300)->post('https://nodejs.nmrxiv.org/spectra-parser', [ 'urls' => [$url], 'snapshot' => false, ]); diff --git a/app/Http/Controllers/DatasetController.php b/app/Http/Controllers/DatasetController.php index 1254d5c7..f1bcbf5b 100644 --- a/app/Http/Controllers/DatasetController.php +++ b/app/Http/Controllers/DatasetController.php @@ -31,7 +31,7 @@ public function fetchNMRium(Request $request, Dataset $dataset) if ($dataset) { $nmrium = $dataset->nmrium; if ($nmrium) { - return $nmrium; + return json_decode($nmrium->nmrium_info); } else { return null; } diff --git a/resources/js/Pages/Public/Project/Study.vue b/resources/js/Pages/Public/Project/Study.vue index f27f914a..d5fb6adc 100644 --- a/resources/js/Pages/Public/Project/Study.vue +++ b/resources/js/Pages/Public/Project/Study.vue @@ -336,7 +336,6 @@
diff --git a/resources/js/Shared/SpectraViewer.vue b/resources/js/Shared/SpectraViewer.vue index 75feef26..4990be4a 100644 --- a/resources/js/Shared/SpectraViewer.vue +++ b/resources/js/Shared/SpectraViewer.vue @@ -331,10 +331,10 @@ export default { this.currentMolecules = []; this.updateLoadingStatus(true); if (iframe) { - if (this.study.has_nmrium) { + if (this.dataset && this.dataset.has_nmrium) { this.infoLog("Loading Spectra from NMRium JSON.."); axios - .get("/studies/" + this.study.id + "/nmriumInfo") + .get("/datasets/" + this.dataset.id + "/nmriumInfo") .then((response) => { let nmrium_info = response.data; if (nmrium_info) { @@ -353,10 +353,35 @@ export default { } }); } else { - if (this.study.download_url) { - let urls = []; - urls.push(this.study.download_url); - this.loadFromURL(urls); + if (this.study.has_nmrium) { + this.infoLog("Loading Spectra from NMRium JSON.."); + axios + .get( + "/studies/" + this.study.id + "/nmriumInfo" + ) + .then((response) => { + let nmrium_info = response.data; + if (nmrium_info) { + let data = { + data: nmrium_info, + type: "nmrium", + }; + iframe.postMessage( + { type: `nmr-wrapper:load`, data }, + "*" + ); + } else { + let urls = []; + urls.push(this.study.download_url); + this.loadFromURL(urls); + } + }); + } else { + if (this.study.download_url) { + let urls = []; + urls.push(this.study.download_url); + this.loadFromURL(urls); + } } } }