Skip to content

Commit

Permalink
Merge pull request #274 from Steinbeck-Lab/feat-partial-inchikey-search
Browse files Browse the repository at this point in the history
feat: Partial inchikey search
  • Loading branch information
Kohulan authored Oct 14, 2024
2 parents cc62abf + 10711c4 commit 2e04d2b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/Actions/Coconut/SearchMolecule.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ public function query($query, $size, $type, $sort, $tagType, $page)
}

return [$results, $this->collection, $this->organisms];

} catch (QueryException $exception) {

return $this->handleException($exception);

}
}

Expand All @@ -89,6 +87,7 @@ private function determineQueryType($query)
$patterns = [
'inchi' => '/^((InChI=)?[^J][0-9BCOHNSOPrIFla+\-\(\)\\\\\/,pqbtmsih]{6,})$/i',
'inchikey' => '/^([0-9A-Z\-]{27})$/i', // Modified to ensure exact length
'parttialinchikey' => '/^([A-Z]{14})$/i',
'smiles' => '/^([^J][0-9BCOHNSOPrIFla@+\-\[\]\(\)\\\\\/%=#$]{6,})$/i',
];

Expand All @@ -102,6 +101,8 @@ private function determineQueryType($query)
return 'inchi';
} elseif ($type == 'inchikey' && substr($query, 14, 1) == '-' && strlen($query) == 27) {
return 'inchikey';
} elseif ($type == 'parttialinchikey' && strlen($query) == 14) {
return 'parttialinchikey';
} elseif ($type == 'smiles') {
return 'smiles';
}
Expand Down Expand Up @@ -179,6 +180,7 @@ private function buildStatement($queryType, $offset, $filterMap)
break;

case 'inchikey':
case 'parttialinchikey':
$statement = "SELECT id, COUNT(*) OVER ()
FROM molecules
WHERE standard_inchi_key LIKE '%{$this->query}%'
Expand Down Expand Up @@ -330,7 +332,7 @@ private function buildDefaultStatement($offset)
WHEN \"name\"::TEXT ILIKE '%{$this->query}%' THEN 4
WHEN \"synonyms\"::TEXT ILIKE '%{$this->query}%' THEN 5
WHEN \"identifier\"::TEXT ILIKE '%{$this->query}%' THEN 6
ELSE 7
ELSE 7
END
LIMIT {$this->size} OFFSET {$offset}";
} else {
Expand Down

0 comments on commit 2e04d2b

Please sign in to comment.