Skip to content

Commit

Permalink
Merge pull request #1099 from NFDI4Chem/bioschemas
Browse files Browse the repository at this point in the history
fix: extend Bioschemas to cover samples with no projects
  • Loading branch information
CS76 committed Apr 4, 2024
2 parents ad0f34a + e3c5d5d commit 8fb25e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,17 @@ public function prepareMoleculesSchemas($sample)
*/
public function getSample($study)
{
$prefix = '';
if (property_exists($study, 'project')) {
$prefix = $study->project->name.'.';
}
$sample = $study->sample;
$molecules = $this->prepareMoleculesSchemas($sample);

$sampleSchema = Schema::ChemicalSubstance();
$sampleSchema['@id'] = $study->doi;
$sampleSchema['dct:conformsTo'] = BioschemasHelper::conformsTo(['https://bioschemas.org/types/ChemicalSubstance/0.3-RELEASE-2019_09_02']);
$sampleSchema->name($study->project->name.'.'.$sample->name);
$sampleSchema->name($prefix.$sample->name);
$sampleSchema->description($sample->description);
$sampleSchema->url(env('APP_URL').'/'.explode(':', $study->identifier ? $study->identifier : ':')[1]);
$sampleSchema->hasBioChemEntityPart($this->prepareMoleculesSchemas($sample));
Expand Down Expand Up @@ -451,7 +455,11 @@ public function datasetLite($dataset)
{
$nmriumInfo = $this->prepareNMRiumInfo($dataset);
if ($nmriumInfo) {
$prefix = $dataset->study->project->name.':'.$dataset->study->name.'.';
$study = $dataset->study;
$prefix = $dataset->study->name.'.';
if (property_exists($study, 'project')) {
$prefix = $study->project->name.':'.$prefix;
}
$datasetSchema = Schema::Dataset();
$datasetSchema['@id'] = $dataset->doi;
$datasetSchema['dct:conformsTo'] = BioschemasHelper::conformsTo(['https://schema.org/Dataset', 'https://isa-specs.readthedocs.io/en/latest/isamodel.html#assay']);
Expand Down Expand Up @@ -504,7 +512,10 @@ public function dataset($dataset)
*/
public function studyLite($study)
{
$prefix = $study->project->name.':';
$prefix = '';
if (property_exists($study, 'project')) {
$prefix = $study->project->name.':';
}
$studySchema = Bioschemas::Study();
$studySchema['@id'] = $study->doi;
$studySchema['dct:conformsTo'] = BioschemasHelper::conformsTo(['https://bioschemas.org/types/Study/0.3-DRAFT', 'https://isa-specs.readthedocs.io/en/latest/isamodel.html#study']);
Expand Down Expand Up @@ -534,7 +545,9 @@ public function studyLite($study)
public function study($study)
{
$studySchema = $this->studyLite($study);
$studySchema->isPartOf($this->projectLite($study->project));
if (property_exists($study, 'project')) {
$studySchema->isPartOf($this->projectLite($study->project));
}
$studySchema->hasPart($this->prepareDatasets($study));

return $studySchema;
Expand Down
11 changes: 8 additions & 3 deletions app/Http/Controllers/API/Schemas/Bioschemas/BioschemasHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public static function prepareCitations($model)
$citationsSchemas = [];
foreach ($model->citations as &$citation) {
$citationSchema = Schema::CreativeWork();
$citationSchema->abstract($citation->abstract);
$citationSchema->author($citation->authors);
$citationSchema->headline($citation->title);
$citationSchema->identifier($citation->doi);
Expand All @@ -149,11 +148,17 @@ public static function prepareDataDownload($dataset)
{
$url = env('APP_URL');
$user = $dataset->owner->username;
$slug = $dataset->project->slug;
if (property_exists($dataset, 'project')) {
$slug = $dataset->project->slug;
$name = $dataset->project->name;
} else {
$slug = $dataset->study->slug;
$name = $dataset->study->name;
}
$contentURL = $url.'/'.$user.'/datasets/'.$slug;

$DataDownloadSchema = Schema::DataDownload();
$DataDownloadSchema->name($dataset->project->name);
$DataDownloadSchema->name($name);
$DataDownloadSchema->encodingFormat('zip');
$DataDownloadSchema->contentURL($contentURL);

Expand Down

0 comments on commit 8fb25e7

Please sign in to comment.