Skip to content

Commit

Permalink
Merge pull request #898 from NFDI4Chem/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
NishaSharma14 authored Nov 15, 2023
2 parents acf920b + 345da39 commit d61e788
Show file tree
Hide file tree
Showing 28 changed files with 449 additions and 269 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
17 changes: 11 additions & 6 deletions app/Http/Controllers/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,22 @@ public function downloadFromProject(Request $request, $username, $project, $key
array_push($s3keys, substr($fsObj->path, 1));
}
} else {
$command = $s3Client->getCommand('ListObjects');
$command['Bucket'] = $bucket;

$command = [
'Bucket' => $bucket,
];
if ($path[0] == '/') {
$command['Prefix'] = ltrim($path, $path[0]).'/';
} else {
$command['Prefix'] = $path.'/';
}
$result = $s3Client->execute($command);
if ($result['Contents']) {
foreach ($result['Contents'] as $file) {
array_push($s3keys, $file['Key']);
$results = $s3Client->getPaginator('ListObjects', $command);
foreach ($results as $result) {
$contents = $result->get('Contents');
if ($contents) {
foreach ($contents as $file) {
array_push($s3keys, $file['Key']);
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/DraftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,13 @@ public function isJcampDX($folder)
$isDX = true;
}

if ($isJDX || $isDX) {
$fileTypes = ['jcamp'];
$isJCAMP = false;
if (array_intersect($fileTypes, $extensions) == $fileTypes) {
$isJCAMP = true;
}

if ($isJDX || $isDX || $isJCAMP) {
return true;
}

Expand Down
36 changes: 22 additions & 14 deletions app/Http/Controllers/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ public function nmriumInfo(Request $request, Study $study)
$studyFSObject = $study->fsObject;
$datasetFSObject = $dataset->fsObject;
$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
16 changes: 10 additions & 6 deletions app/Jobs/ArchiveProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,21 @@ public function handle(): void
array_push($s3keys, substr($fsObject->path, 1));
}
} else {
$command = $s3Client->getCommand('ListObjects');
$command['Bucket'] = $bucket;
$command = [
'Bucket' => $bucket,
];
if ($path[0] == '/') {
$command['Prefix'] = ltrim($path, $path[0]).'/';
} else {
$command['Prefix'] = $path.'/';
}
$result = $s3Client->execute($command);
if ($result['Contents']) {
foreach ($result['Contents'] as $file) {
array_push($s3keys, $file['Key']);
$results = $s3Client->getPaginator('ListObjects', $command);
foreach ($results as $result) {
$contents = $result->get('Contents');
if ($contents) {
foreach ($contents as $file) {
array_push($s3keys, $file['Key']);
}
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions app/Jobs/ArchiveStudy.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,22 @@ public function handle(): void
array_push($s3keys, substr($fsObject->path, 1));
}
} else {
$command = $s3Client->getCommand('ListObjects');
$command['Bucket'] = $bucket;

$command = [
'Bucket' => $bucket,
];
if ($path[0] == '/') {
$command['Prefix'] = ltrim($path, $path[0]).'/';
} else {
$command['Prefix'] = $path.'/';
}
$result = $s3Client->execute($command);
if ($result['Contents']) {
foreach ($result['Contents'] as $file) {
array_push($s3keys, $file['Key']);
$results = $s3Client->getPaginator('ListObjects', $command);
foreach ($results as $result) {
$contents = $result->get('Contents');
if ($contents) {
foreach ($contents as $file) {
array_push($s3keys, $file['Key']);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use Illuminate\Support\Facades\App;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand All @@ -26,7 +27,7 @@ public function register()
*/
public function boot()
{
if ($this->app->environment('production')) {
if (App::environment() == 'production') {
\URL::forceScheme('https');
}
}
Expand Down
50 changes: 50 additions & 0 deletions database/scripts/sync_index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
SELECT setval('announcements_id_seq', max(id)) FROM announcements;
SELECT setval('assays_id_seq', max(id)) FROM assays;
SELECT setval('audits_id_seq', max(id)) FROM audits;
SELECT setval('author_project_id_seq', max(id)) FROM author_project;
SELECT setval('authors_id_seq', max(id)) FROM authors;
SELECT setval('citation_project_id_seq', max(id)) FROM citation_project;
SELECT setval('citations_id_seq', max(id)) FROM citations;
SELECT setval('dataset_invitations_id_seq', max(id)) FROM dataset_invitations;
SELECT setval('dataset_molecule_id_seq', max(id)) FROM dataset_molecule;
SELECT setval('dataset_user_id_seq', max(id)) FROM dataset_user;
SELECT setval('datasets_id_seq', max(id)) FROM datasets;
SELECT setval('drafts_id_seq', max(id)) FROM drafts;
SELECT setval('failed_jobs_id_seq', max(id)) FROM failed_jobs;
SELECT setval('file_system_objects_id_seq', max(id)) FROM file_system_objects;
SELECT setval('licenses_id_seq', max(id)) FROM licenses;
SELECT setval('linked_social_accounts_id_seq', max(id)) FROM linked_social_accounts;
SELECT setval('markable_reactions_id_seq', max(id)) FROM markable_reactions;
SELECT setval('markable_likes_id_seq', max(id)) FROM markable_likes;
SELECT setval('markable_favorites_id_seq', max(id)) FROM markable_favorites;
SELECT setval('markable_bookmarks_id_seq', max(id)) FROM markable_bookmarks;
SELECT setval('migrations_id_seq', max(id)) FROM migrations;
-- model_has_permissions -- combi
-- model_has_roles SELECT setval('molecule_sample_id_seq', max(id)) FROM molecule_sample; -- combi
SELECT setval('molecule_sample_id_seq', max(id)) FROM molecule_sample;
SELECT setval('molecules_id_seq', max(id)) FROM molecules;
SELECT setval('nmrium_id_seq', max(id)) FROM nmrium;
-- SELECT setval('notifications_id_seq', max(id)) FROM notifications; UUID
-- SELECT setval('password_resets_id_seq', max(id)) FROM password_resets; no pkey
SELECT setval('permissions_id_seq', max(id)) FROM permissions;
SELECT setval('personal_access_tokens_id_seq', max(id)) FROM personal_access_tokens;
SELECT setval('project_invitations_id_seq', max(id)) FROM project_invitations;
SELECT setval('project_user_id_seq', max(id)) FROM project_user;
SELECT setval('projects_id_seq', max(id)) FROM projects;
-- role_has_permissions SELECT setval('role_has_permissions_id_seq', max(id)) FROM role_has_permissions; -- combi
SELECT setval('roles_id_seq', max(id)) FROM roles;
SELECT setval('samples_id_seq', max(id)) FROM samples;
-- SELECT setval('sessions_id_seq', max(id)) FROM sessions; UUID
SELECT setval('studies_id_seq', max(id)) FROM studies;
SELECT setval('study_invitations_id_seq', max(id)) FROM study_invitations;
SELECT setval('study_user_id_seq', max(id)) FROM study_user;
-- SELECT setval('taggables_id_seq', max(id)) FROM taggables; no pkey
SELECT setval('tags_id_seq', max(id)) FROM tags;
SELECT setval('team_invitations_id_seq', max(id)) FROM team_invitations;
SELECT setval('team_user_id_seq', max(id)) FROM team_user;
SELECT setval('teams_id_seq', max(id)) FROM teams;
SELECT setval('templates_id_seq', max(id)) FROM templates;
SELECT setval('tickers_id_seq', max(id)) FROM tickers;
SELECT setval('users_id_seq', max(id)) FROM users;
SELECT setval('validations_id_seq', max(id)) FROM validations;
SELECT setval('versions_version_id_seq', max(version_id)) FROM versions;
Loading

0 comments on commit d61e788

Please sign in to comment.