From 4c714807d92939b241c7d6b302fd2b34e92fd3bc Mon Sep 17 00:00:00 2001 From: Venkata Chandra Sekhar Nainala Date: Tue, 14 Nov 2023 13:34:48 +0100 Subject: [PATCH] fix: dataset spectra parsing updates / issues fixes --- app/Console/Commands/ExtractSpectra.php | 133 ++++++++++-------- app/Http/Controllers/StudyController.php | 34 +++-- resources/js/Pages/Public/Project/Dataset.vue | 93 +++++------- 3 files changed, 131 insertions(+), 129 deletions(-) diff --git a/app/Console/Commands/ExtractSpectra.php b/app/Console/Commands/ExtractSpectra.php index ae6e55ec..359af77c 100644 --- a/app/Console/Commands/ExtractSpectra.php +++ b/app/Console/Commands/ExtractSpectra.php @@ -79,78 +79,87 @@ public function handle() } } }); - } else { + } + $study = $study->fresh(); + if ($study->has_nmrium) { $nmriumInfo = json_decode($study->nmrium['nmrium_info'], true); if (count($nmriumInfo['data']['spectra']) == 0) { echo '--MISSING SPECTRA INFO (NMRIUM JSON)--'; echo "\r\n"; - } - } - } catch (Exception $e) { - echo 'Caught exception: ', $e->getMessage(), "\n"; - } - $study = $study->fresh(); - foreach ($study->datasets as $dataset) { - // echo $dataset->identifier; - // echo "\r\n"; - // if(!$dataset->has_nmrium){ - $nmriumInfo = json_decode($study->nmrium['nmrium_info'], true); - $_nmriumJSON = $nmriumInfo; - $fsObject = $dataset->fsObject; + } else { + foreach ($study->datasets as $dataset) { + echo $dataset->identifier; + echo "\r\n"; + // if(!$dataset->has_nmrium){ + $nmriumInfo = json_decode($study->nmrium['nmrium_info'], true); + $_nmriumJSON = $nmriumInfo; + $fsObject = $dataset->fsObject; - $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']; - if ($files) { - foreach ($files as $file) { - if (str_contains($file, $path)) { - $pathsMatch = true; - } - } - } - if ($pathsMatch) { - break; - } - } - if (! $pathsMatch) { - echo $project->identifier; - echo "\r\n"; + $studyFSObject = $study->fsObject; + $datasetFSObject = $dataset->fsObject; + $path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name; + // echo($path); + // echo "\r\n"; + $fsObject = $dataset->fsObject; + $studyFSObject = $study->fsObject; + $datasetFSObject = $dataset->fsObject; + $path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name; - 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); + $pathsMatch = false; + $spectrum = []; + $type = []; + foreach ($nmriumInfo['data']['spectra'] as $spectra) { + unset($_nmriumJSON['data']['spectra']); + $files = $spectra['sourceSelector']['files']; + if ($files) { + foreach ($files as $file) { + if (str_contains($file, $path)) { + $pathsMatch = true; + } + } + } + if ($pathsMatch) { + array_push($spectrum, $spectra); + $experimentDetailsExists = array_key_exists('experiment', $spectra['info']); + if ($experimentDetailsExists) { + $experiment = $spectra['info']['experiment']; + $nucleus = $spectra['info']['nucleus']; + if (is_array($nucleus)) { + $nucleus = implode('-', $nucleus); + } + array_push($type, $experiment.' - '.$nucleus); + } + $pathsMatch = false; + } + } + if (count($spectrum) > 0) { + $_nmriumJSON['data']['spectra'] = $spectrum; + $_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; + } + } + $uType = array_unique($type); + if (count($uType) == 1) { + $dataset->type = $uType[0]; + } + $dataset->save(); + // } } - $dataset->type = $experiment.','.$nucleus; } - $dataset->save(); } - // } + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; } + } } } diff --git a/app/Http/Controllers/StudyController.php b/app/Http/Controllers/StudyController.php index d915383d..21c06f4c 100644 --- a/app/Http/Controllers/StudyController.php +++ b/app/Http/Controllers/StudyController.php @@ -215,6 +215,8 @@ public function nmriumInfo(Request $request, Study $study) $path = '/'.$studyFSObject->name.'/'.$datasetFSObject->name; $pathsMatch = false; + $spectrum = []; + $type = []; foreach ($nmriumInfo['data']['spectra'] as $spectra) { unset($_nmriumJSON['data']['spectra']); $files = $spectra['sourceSelector']['files']; @@ -226,11 +228,21 @@ public function nmriumInfo(Request $request, Study $study) } } if ($pathsMatch) { - break; + array_push($spectrum, $spectra); + $experimentDetailsExists = array_key_exists('experiment', $spectra['info']); + if ($experimentDetailsExists) { + $experiment = $spectra['info']['experiment']; + $nucleus = $spectra['info']['nucleus']; + if (is_array($nucleus)) { + $nucleus = implode('-', $nucleus); + } + array_push($type, $experiment.' - '.$nucleus); + } + $pathsMatch = false; } } - if ($pathsMatch) { - $_nmriumJSON['data']['spectra'] = [$spectra]; + if (count($spectrum) > 0) { + $_nmriumJSON['data']['spectra'] = $spectrum; $_nmrium = $dataset->nmrium; if ($_nmrium) { $_nmrium->nmrium_info = json_encode($_nmriumJSON, JSON_UNESCAPED_UNICODE); @@ -243,17 +255,13 @@ public function nmriumInfo(Request $request, Study $study) $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; - } - $dataset->save(); } + $uType = array_unique($type); + if (count($uType) == 1) { + $dataset->type = $uType[0]; + } + $dataset->save(); + } return $study->fresh(); diff --git a/resources/js/Pages/Public/Project/Dataset.vue b/resources/js/Pages/Public/Project/Dataset.vue index 63375fa6..14ad36a0 100644 --- a/resources/js/Pages/Public/Project/Dataset.vue +++ b/resources/js/Pages/Public/Project/Dataset.vue @@ -6,14 +6,22 @@ class="pb-10 mb-10 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6" >

- - {{ study.data.name }} + + {{ study.data.name }} > + {{ dataset.data.name }} + - ({{ + dataset.data.type.replace(/,\s*$/, "") + }})
@@ -92,14 +100,6 @@
- -
-
- #{{ study.data.identifier }} -
-

+
+
+ +
+ + Spectra + +
+
+

+
+ +
+
-
-
- -
- - Spectra - -
-
-

- {{ dataset.data.name }} - - ({{ - dataset.data.type.replace(/,\s*$/, "") - }})
-
- - - -
-

-
- -
-