Skip to content

Commit

Permalink
fix: dataset spectra parsing updates / issues fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Nov 14, 2023
1 parent ab06c28 commit 4c71480
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 129 deletions.
133 changes: 71 additions & 62 deletions app/Console/Commands/ExtractSpectra.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
}
}
Expand Down
34 changes: 21 additions & 13 deletions app/Http/Controllers/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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);
Expand All @@ -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();
Expand Down
93 changes: 39 additions & 54 deletions resources/js/Pages/Public/Project/Dataset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
class="pb-10 mb-10 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6"
>
<h1 class="mt-2 text-2xl font-bold break-words text-gray-900">
<span class="text-blue-500">
{{ study.data.name }}
<span>
{{ study.data.name }} >
<span class="text-blue-500"
>{{ dataset.data.name }}
<span v-if="dataset.data.type"
>- ({{
dataset.data.type.replace(/,\s*$/, "")
}})</span
></span
>
</span>
<div class="text-sm">
<span class="text-gray-400 pt-2">
<DOIBadge
:doi="study.data.doi"
color="bg-yellow-300"
:doi="dataset.data.doi"
color="bg-green-100"
></DOIBadge>
</span>
</div>
Expand Down Expand Up @@ -92,14 +100,6 @@
</Menu>
</span>
</div>

<div class="text-sm float-right mr-4">
<div
class="inline hover:text-blue-600 hover:cursor-pointer text-gray-200"
>
#{{ study.data.identifier }}
</div>
</div>
</h1>
<!-- <div class="mt-4">
<div class="relative">
Expand All @@ -123,6 +123,33 @@
v-html="md(study.data.description)"
></p>
</div> -->
<div class="mt-4">
<div class="relative">
<div
class="absolute inset-0 flex items-center"
aria-hidden="true"
>
<div class="w-full border-t border-gray-100"></div>
</div>
<div class="relative flex items-center justify-between">
<span
class="pr-3 text-md bg-white font-medium text-gray-400"
>
Spectra
</span>
</div>
</div>
<h1
class="mt-2 text-2xl font-bold break-words text-gray-900"
></h1>
<div class="my-7">
<SpectraViewer
:dataset="dataset.data"
:project="project.data"
:study="study.data"
></SpectraViewer>
</div>
</div>
<div v-if="study.data.tags.length > 0" class="mt-4">
<div class="relative">
<div
Expand Down Expand Up @@ -285,48 +312,6 @@
</div>
</div>
</div>
<div class="mt-4">
<div class="relative">
<div
class="absolute inset-0 flex items-center"
aria-hidden="true"
>
<div class="w-full border-t border-gray-100"></div>
</div>
<div class="relative flex items-center justify-between">
<span
class="pr-3 text-md bg-white font-medium text-gray-400"
>
Spectra
</span>
</div>
</div>
<h1
class="mt-2 text-2xl font-bold break-words text-gray-900"
>
{{ dataset.data.name }}
<span v-if="dataset.data.type"
>- ({{
dataset.data.type.replace(/,\s*$/, "")
}})</span
><br />
<div class="text-sm">
<span class="text-gray-400 pt-2">
<DOIBadge
:doi="dataset.data.doi"
color="bg-green-100"
></DOIBadge>
</span>
</div>
</h1>
<div class="my-7">
<SpectraViewer
:dataset="dataset.data"
:project="project.data"
:study="study.data"
></SpectraViewer>
</div>
</div>
</div>
</template>
</project-layout>
Expand Down

0 comments on commit 4c71480

Please sign in to comment.