Skip to content

Commit

Permalink
version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nekhbet committed Feb 22, 2024
1 parent ad3842a commit fa0571a
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions examples/simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
print_r([$binders, $targets, $indications]);
130 changes: 109 additions & 21 deletions src/SuperPREDTargetPrediction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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!");
Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -163,31 +157,92 @@ 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;
}

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]),
Expand All @@ -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;
}


}

0 comments on commit fa0571a

Please sign in to comment.