Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bioschemas #222

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Controllers\API\Schemas\Bioschema;
namespace App\Http\Controllers\API\Schemas\Bioschemas;

use App\Http\Controllers\Controller;
use App\Models\Molecule;
Expand Down
105 changes: 97 additions & 8 deletions app/Models/Molecule.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,23 @@ public function related()
/**
* Get schema json
*/
public function getSchema($type = 'bioschema')
public function getSchema($type = 'bioschemas')
{
if ($type == 'bioschema') {
if ($type == 'bioschemas') {
$moleculeSchema = Schema::MolecularEntity();
$moleculeSchema['@id'] = $this->inchi_key;
$moleculeSchema['dct:conformsTo'] = $this->prepareConformsTo();

$moleculeSchema->identifier($this->identifier)
->name($this->name)
->url(env('APP_URL').'/compound/'.$this->identifier)
->inChI($this->inchi)
->inChIKey($this->inchi_key)
->inChI($this->standard_inchi)
->inChIKey($this->standard_inchi_key)
->iupacName($this->iupac_name)
->molecularFormula($this->molecular_formula)
->molecularWeight($this->molecular_weight)
->smiles($this->cannonical_smiles);
->molecularFormula($this->properties->molecular_formula)
->molecularWeight($this->properties->molecular_weight)
->monoisotopicMolecularWeight($this->properties->exact_molecular_weight)
->smiles($this->canonical_smiles);

if ($this->synonyms || $this->cas) {
$alternateNames = $this->synonyms ?? [];
Expand All @@ -175,7 +176,95 @@ public function getSchema($type = 'bioschema')
$moleculeSchema->alternateName($alternateNames);
}

return $moleculeSchema;
if ($this->organisms) {
$organisms = $this->organisms ?? [];
$names = [];
foreach($organisms as $organism) {
$name = $organism->name;
array_push($names, $name);
}
$moleculeSchema->taxonomicRange($names);
}

$additionalPropertysSchemas = [];
$moleculeAdditionalPropertys = array(
"annotation_level" => "Annotation level"
);

foreach($moleculeAdditionalPropertys as $key => $value) {
$propertySchema = Schema::PropertyValue();
$propertySchema->name($value)
->value($this->$key);
array_push($additionalPropertysSchemas, $propertySchema);
}

$propertyAdditionalPropertys = array(
"total_atom_count" => "Total atom count",
"aromatic_rings_count" => "Aromatic rings count",
"qed_drug_likeliness" => "QED drug likeliness",
"formal_charge" => "Formal charge",
"contains_sugar" => "Contains sugar",
"np_likeness" => "NP likeness",
"chemical_class" => "Chemical class",
"chemical_sub_class" => "Chemical sub class",
"chemical_super_class" => "Chemical super class",
);

foreach($propertyAdditionalPropertys as $key => $value) {
$propertySchema = Schema::PropertyValue();
$propertySchema->name($value)
->value($this->properties->$key);
array_push($additionalPropertysSchemas, $propertySchema);
}

if ($this->geo_locations) {
$geo_locations = $this->geo_locations ?? [];
$names = [];
foreach($geo_locations as $geo_location) {
$name = $geo_location->name;
array_push($names, $name);
}
$propertySchema = Schema::PropertyValue();
$propertySchema->name("Geographic location")
->value($names);
array_push($additionalPropertysSchemas, $propertySchema);
}

$moleculeSchema->additionalProperty($additionalPropertysSchemas);

$datasetSchema = Schema::Dataset();
$catalogs = [];
if ($this->collections) {
$collections = $this->collections ?? [];
foreach($collections as $collection) {
$dataCatalogSchema = Schema::DataCatalog();
$dataCatalogSchema->name("Geographic location")
// ->license($collection->licenses->url)
->additionalType("collection")
->description($collection->description)
->identifier($collection->identifier)
->url($collection->url)
->name($collection->title);
}
array_push($catalogs, $dataCatalogSchema);
}

$datasetSchema->includedInDataCatalog($catalogs)
->about($moleculeSchema);

$citationsSchemas = [];
if ($this->citations) {
$citations = $this->citations ?? [];
foreach($citations as $citation) {
$citationSchema = Schema::CreativeWork();
$citationSchema->identifier($citation->doi)
->headline($citation->title)
->author($citation->authors);
array_push($citationsSchemas, $citationSchema);
}
}
$datasetSchema->citation($citationsSchemas);
return $datasetSchema;
}
}

Expand Down
6 changes: 3 additions & 3 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use App\Http\Controllers\API\Auth\RegisterController;
use App\Http\Controllers\API\Auth\VerificationController;
use App\Http\Controllers\API\CompoundController;
use App\Http\Controllers\API\Schemas\Bioschema\MolecularEntityController;
use App\Http\Controllers\API\Schemas\Bioschemas\MolecularEntityController;
use App\Http\Controllers\API\SearchController;
use Illuminate\Support\Facades\Route;
use Laravel\Fortify\Features;
Expand Down Expand Up @@ -54,7 +54,7 @@
});

Route::prefix('schemas')->group(function () {
Route::prefix('bioschema')->group(function () {
Route::prefix('bioschemas')->group(function () {
Route::get('/{id}', [MolecularEntityController::class, 'moleculeSchema']);
});
});
Expand All @@ -72,7 +72,7 @@
// // Schemas
// Route::get('/compounds', [CompoundController::class, 'list']);
// Route::prefix('schemas')->group(function () {
// Route::prefix('bioschema')->group(function () {
// Route::prefix('bioschemas')->group(function () {
// Route::get('/{id}', [MolecularEntityController::class, 'moleculeSchema']);
// });
// });
Expand Down
8 changes: 4 additions & 4 deletions storage/api-docs/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,19 @@
}
}
},
"/api/v1/schemas/bioschema/{id}": {
"/api/v1/schemas/bioschemas/{id}": {
"get": {
"tags": [
"schemas"
],
"summary": "Get bioschema schema details by COCONUT id.",
"description": "Get bioschema schema details by COCONUT id.",
"summary": "Get bioschemas schema details by COCONUT id.",
"description": "Get bioschemas schema details by COCONUT id.",
"operationId": "moleculeSchema",
"parameters": [
{
"name": "id",
"in": "path",
"description": "COCONUT id - bioschema",
"description": "COCONUT id - bioschemas",
"required": true,
"schema": {
"type": "string"
Expand Down