Skip to content

Commit

Permalink
Merge pull request #222 from Steinbeck-Lab/bioschemas
Browse files Browse the repository at this point in the history
Bioschemas
  • Loading branch information
CS76 authored Aug 30, 2024
2 parents 383314d + 116d952 commit 483e452
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 16 deletions.
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

0 comments on commit 483e452

Please sign in to comment.