From fa0571a58a62ef30167f39256e87dc241268fc47 Mon Sep 17 00:00:00 2001 From: Sorin Date: Thu, 22 Feb 2024 21:24:42 +0200 Subject: [PATCH] version 2.0.0 --- CHANGELOG.md | 3 + README.md | 11 ++- examples/simple.php | 12 ++- src/SuperPREDTargetPrediction.php | 130 +++++++++++++++++++++++++----- 4 files changed, 127 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59a4765..2218a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to `superpred-targetprediction` will be documented in this file +## 2.0.0 - 2024-02-22 +- modified to get known strong binders and indications of predicted targets too +- breaking changes ## 1.0.1 - 2024-01-25 - make request timeout changeable (as longer SMILES codes take way longer to retrieve) diff --git a/README.md b/README.md index ebdc267..505256e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/nekhbet/superpred-targetprediction.svg?style=flat-square)](https://packagist.org/packages/nekhbet/superpred-targetprediction) [![Total Downloads](https://img.shields.io/packagist/dt/nekhbet/superpred-targetprediction.svg?style=flat-square)](https://packagist.org/packages/nekhbet/superpred-targetprediction) -Lets you take (and filter) the predicted targets based on a SMILES code from Super-PRED website (https://prediction.charite.de/subpages/target_prediction.php). +Lets you take (and filter) the predicted targets, indicators and known binders based on a SMILES code from Super-PRED website (https://prediction.charite.de/subpages/target_prediction.php). ## Installation @@ -16,10 +16,13 @@ composer require nekhbet/superpred-targetprediction ## Usage ```php -$api = new SuperPREDTargetPrediction(); -$data = $api +$client = new SuperPREDTargetPrediction(requestTimeout: 60); +$client ->setSMILESCode('Cc1cc(O)c2C(=O)c3c(O)cc(O)c4c3c3c2c1c1c2c3c3c4c(O)cc(O)c3C(=O)c2c(O)cc1C') - ->getTargets(min_probability: 80, min_model_accuracy: 96); + ->run(); +$binders = $client->getBinders(); +$targets = $client->getTargets(min_probability: 80, min_model_accuracy: 95); +$indications = $client->getIndications(min_probability: 80, min_model_accuracy: 95); ``` ```txt diff --git a/examples/simple.php b/examples/simple.php index 173b3c9..b92b10b 100644 --- a/examples/simple.php +++ b/examples/simple.php @@ -6,15 +6,19 @@ include(__DIR__.'/../vendor/autoload.php'); -$api = new SuperPREDTargetPrediction(); +$client = new SuperPREDTargetPrediction(requestTimeout: 60); try { - $data = $api + $client ->setSMILESCode('Cc1cc(O)c2C(=O)c3c(O)cc(O)c4c3c3c2c1c1c2c3c3c4c(O)cc(O)c3C(=O)c2c(O)cc1C') - ->getTargets(min_probability: 80, min_model_accuracy: 96); +// ->setSMILESCode('c1ncccc1[C@@H]2CCCN2C') + ->run(); + $binders = $client->getBinders(); + $targets = $client->getTargets(min_probability: 80, min_model_accuracy: 95); + $indications = $client->getIndications(min_probability: 80, min_model_accuracy: 95); } catch (GuzzleException $e) { die("Connection Exception: ".$e->getMessage()); } catch (SuperPREDTargetPredictionException $e) { die("LIB Exception: ".$e->getMessage()); } -print_r($data); \ No newline at end of file +print_r([$binders, $targets, $indications]); \ No newline at end of file diff --git a/src/SuperPREDTargetPrediction.php b/src/SuperPREDTargetPrediction.php index 055f1eb..f97a272 100644 --- a/src/SuperPREDTargetPrediction.php +++ b/src/SuperPREDTargetPrediction.php @@ -26,6 +26,8 @@ class SuperPREDTargetPrediction private string $SMILES_code = ''; private int $requestTimeout; + private array $raw_data = []; + private array $nicefied_data = []; public function __construct(int $requestTimeout = 20) { @@ -51,23 +53,16 @@ public function setSMILESCode(string $SMILES): SuperPREDTargetPrediction * @throws GuzzleException * @throws SuperPREDTargetPredictionException */ - public function getTargets(float $min_probability = 0, float $min_model_accuracy = 0): array + public function run(): void { - $rawData = $this->getRawTargets(); - if ($min_probability > 0 || $min_model_accuracy > 0) { - $rawData = array_filter($rawData, function ($item) use ($min_probability, $min_model_accuracy) { - return ($item['probability'] >= $min_probability) && ($item['model_accuracy'] >= $min_model_accuracy); - }); - } - - return $rawData; + $this->scrapeData(); } /** * @throws GuzzleException * @throws SuperPREDTargetPredictionException */ - public function getRawTargets(): array + private function scrapeData(): void { if ( ! $this->SMILES_code) { throw new SuperPREDTargetPredictionException("SMILES Code not set!"); @@ -122,9 +117,8 @@ public function getRawTargets(): array } // Extract all info - $raw_data = $this->extractRawData($contentStage2); - - return $this->decorateRawData($raw_data); + $this->raw_data = $this->extractRawData($contentStage2); + $this->nicefied_data = $this->decorateRawData($this->raw_data); } @@ -163,20 +157,51 @@ private function extractSIM(string $contentStage1): string private function extractRawData(string $contentStage2): array { - $ret = []; + $ret = [ + 'binders' => [], + 'targets' => [], + 'indications' => [], + ]; $doc = new DOMDocument(); libxml_use_internal_errors(true); $doc->loadHTML($contentStage2); - $xpath = new DOMXPath($doc); - $rows = $xpath->query('//div[@class="container"]//table[@id="targets"]/tbody/tr'); + + // Get binders + $rows = $xpath->query('//div[@class="container"]//table[@id="known"]/tbody/tr'); + if ($rows->length > 0) { + foreach ($rows as $row) { + $cells = $row->getElementsByTagName('td'); + $rowData = []; + foreach ($cells as $key => $cell) { + $rowData[] = $cell->nodeValue; + } + $ret['binders'][] = $rowData; + } + } + + // Get indications + $rows = $xpath->query('//div[@class="container"]//table[@id="indications"]/tbody/tr'); + if ($rows->length > 0) { + foreach ($rows as $row) { + $cells = $row->getElementsByTagName('td'); + $rowData = []; + foreach ($cells as $key => $cell) { + $rowData[] = $cell->nodeValue; + } + $ret['indications'][] = $rowData; + } + } + + // Get targets + $rows = $xpath->query('//div[@class="container"]//table[@id="targets"]/tbody/tr'); foreach ($rows as $row) { $cells = $row->getElementsByTagName('td'); $rowData = []; foreach ($cells as $key => $cell) { $rowData[] = $cell->nodeValue; } - $ret[] = $rowData; + $ret['targets'][] = $rowData; } return $ret; @@ -184,10 +209,40 @@ private function extractRawData(string $contentStage2): array private function decorateRawData(array $raw_data): array { - $cleaned = []; - if ($raw_data) { - foreach ($raw_data as $raw_row) { - $cleaned[] = [ + $cleaned = [ + 'binders' => [], + 'indications' => [], + 'targets' => [], + ]; + if ($raw_data['binders']) { + foreach ($raw_data['binders'] as $raw_row) { + $cleaned['binders'][] = [ + 'target_name' => trim($raw_row[0]), + 'id_chembl' => trim($raw_row[1]), + 'id_uniprot' => trim($raw_row[2]), + 'id_pdb' => (trim($raw_row[3]) === 'Not Available') ? '' : trim($raw_row[3]), + 'id_tdd' => (trim($raw_row[4]) === 'Not Available') ? '' : trim($raw_row[4]), + 'min_activity' => trim($raw_row[5]), + 'assay_type' => trim($raw_row[6]), + ]; + } + } + + if ($raw_data['indications']) { + foreach ($raw_data['indications'] as $raw_row) { + $cleaned['indications'][] = [ + 'target_name' => trim($raw_row[0]), + 'id_chembl' => trim($raw_row[1]), + 'indication' => trim($raw_row[2]), + 'probability' => floatval(trim(trim($raw_row[3]), '%')), + 'model_accuracy' => floatval(trim(trim($raw_row[4]), '%')), + ]; + } + } + + if ($raw_data['targets']) { + foreach ($raw_data['targets'] as $raw_row) { + $cleaned['targets'][] = [ 'target_name' => trim($raw_row[0]), 'id_chembl' => trim($raw_row[1]), 'id_uniprot' => trim($raw_row[2]), @@ -202,5 +257,38 @@ private function decorateRawData(array $raw_data): array return $cleaned; } + public function getBinders(): array + { + return $this->nicefied_data['binders']; + } + + public function getIndications(float $min_probability = 0, float $min_model_accuracy = 0): array + { + $data = $this->nicefied_data['indications']; + if ($data) { + if ($min_probability > 0 || $min_model_accuracy > 0) { + $data = array_filter($data, function ($item) use ($min_probability, $min_model_accuracy) { + return ($item['probability'] >= $min_probability) && ($item['model_accuracy'] >= $min_model_accuracy); + }); + } + } + + return $data; + } + + public function getTargets(float $min_probability = 0, float $min_model_accuracy = 0): array + { + $data = $this->nicefied_data['targets']; + if ($data) { + if ($min_probability > 0 || $min_model_accuracy > 0) { + $data = array_filter($data, function ($item) use ($min_probability, $min_model_accuracy) { + return ($item['probability'] >= $min_probability) && ($item['model_accuracy'] >= $min_model_accuracy); + }); + } + } + + return $data; + } + }