Skip to content

Commit

Permalink
fix: updated dataset spectra loading logic and other minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Nov 12, 2023
1 parent ca36ea6 commit e854cbb
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 51 deletions.
4 changes: 2 additions & 2 deletions app/Console/Commands/ArchiveData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
85 changes: 44 additions & 41 deletions app/Console/Commands/ExtractSpectra.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function handle()
])->get();

foreach ($projects as $project) {
echo "\r\n";
echo $project->identifier;
echo "\r\n";
$studies = $project->studies;
Expand Down Expand Up @@ -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();
}
// }
}
Expand All @@ -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,
]);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/DatasetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion resources/js/Pages/Public/Project/Study.vue
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@
<div class="mt-3">
<SpectraViewer
ref="spectraViewerREF"
:dataset="selectedDataset"
:project="project.data"
:study="study.data"
></SpectraViewer>
Expand Down
37 changes: 31 additions & 6 deletions resources/js/Shared/SpectraViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
}
Expand Down

0 comments on commit e854cbb

Please sign in to comment.