Skip to content

Commit

Permalink
Merge pull request #152 from privrja/devel
Browse files Browse the repository at this point in the history
Version 1.0.2
  • Loading branch information
privrja committed Jun 16, 2021
2 parents f4d27b9 + 9699760 commit 6224e08
Show file tree
Hide file tree
Showing 12 changed files with 572 additions and 331 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ To drop DB and create new use:

```php bin/console doctrine:mig:mig```

```php bin/console doctrine:fixtures:load```
```php bin/console doctrine:fixtures:load --group=prod``` or dev group

### Run tests
Before every test you need to delete, create, migrate and purge DB like in previuos step, now test can't be run more times in a row.
Expand All @@ -33,5 +33,5 @@ To run test use ```composer test``` or ```php ./vendor/symfony/phpunit-bridge/bi

```symfony server:start```

Documentation of API is [localhost:8000/api/doc](https://localhost:8000/api/doc)
Documentation of API is [localhost:8000/rest/doc](https://localhost:8000/rest/doc)
Rest API is on [localhost:8000/rest](https://localhost:8000/rest)
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
"netresearch/jsonmapper": "^4.0",
"sensio/framework-extra-bundle": "^6.0",
"symfony/apache-pack": "^1.0",
"symfony/asset": "5.2.*",
"symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*",
"symfony/expression-language": "5.2.*",
"symfony/asset": "5.3.*",
"symfony/console": "5.3.*",
"symfony/dotenv": "5.3.*",
"symfony/expression-language": "5.3.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.2.*",
"symfony/framework-bundle": "5.3.*",
"symfony/monolog-bundle": "^3.5",
"symfony/orm-pack": "^2.0",
"symfony/security-bundle": "5.2.*",
"symfony/security-bundle": "5.3.*",
"symfony/twig-pack": "^1.0",
"symfony/yaml": "5.2.*"
"symfony/yaml": "5.3.*"
},
"require-dev": {
"symfony/maker-bundle": "^1.14",
Expand Down
799 changes: 511 additions & 288 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/packages/nelmio_api_doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ nelmio_api_doc:
in: header
areas: # to filter documented areas
path_patterns:
- ^/rest
- ^/rest(?!/doc.*$)
4 changes: 2 additions & 2 deletions config/routes/nelmio_api_doc.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Expose your documentation as JSON swagger compliant
app.swagger:
path: /api/doc.json
path: /rest/doc.json
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger }

## Requires the Asset component and the Twig bundle
## $ composer require twig asset
app.swagger_ui:
path: /api/doc
path: /rest/doc
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger_ui }
15 changes: 14 additions & 1 deletion src/Base/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
class ReferenceHelper {

const SMILES = "SMILES: ";
const CHEBI = 'CHEBI: ';

public static function reference($database, $reference, $smiles) {
if ($reference == 0) {
if (!isset($reference) || $reference === '') {
return self::defaultValue($smiles);
}
switch ($database) {
Expand All @@ -24,7 +25,19 @@ public static function reference($database, $reference, $smiles) {
case ServerEnum::PDB:
return ServerEnum::$cycloBranchValues[ServerEnum::PDB] . $reference;
case ServerEnum::NORINE:
case ServerEnum::COCONUT:
case ServerEnum::NP_ATLAS:
return $reference;
case ServerEnum::CHEBI:
if (str_contains($reference, 'CHEBI:')) {
if (str_contains($reference, self::CHEBI)) {
return strtoupper($reference);
} else {
return self::CHEBI . substr($reference, 6);
}
} else {
return self::CHEBI . $reference;
}
case ServerEnum::SIDEROPHORE_BASE:
return ServerEnum::$cycloBranchValues[ServerEnum::SIDEROPHORE_BASE] . $reference;
case ServerEnum::DOI:
Expand Down
2 changes: 2 additions & 0 deletions src/Base/SequenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ function findBlocks(Container $container, BlockRepository $blockRepository): arr
if (!isset($block)) {
return [];
}
$b2s->setBlockOriginalId($len);
$b2s->setSort($len);
$b2s->setBlock($block);
$b2s->setIsBranch($this->branch);
$branchNextAcronym = $this->branchNext(true);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/SmilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function similarityContainer(Container $container, Request $request, Logg
}
$setup = $setupRepository->findOneBy(['id' => 1]);
if ($setup->getSimilarity() === 'name') {
return new JsonResponse($sequenceFamilyRepository->similarity(1, $trans->sequenceName));
return new JsonResponse($sequenceFamilyRepository->similarity($container->getId(), $trans->sequenceName));
} else {
if ($trans->blockLengthUnique === 0) {
return ResponseHelper::jsonResponse(new Message(ErrorConstants::ERROR_EMPTY_PARAMS, Response::HTTP_BAD_REQUEST));
Expand Down
20 changes: 3 additions & 17 deletions src/Enum/ServerEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,8 @@ class ServerEnum {
const DOI = 6;
const SIDEROPHORE_BASE = 7;
const LIPID_MAPS = 8;

/** @var array mapping int code to string */
public static $values = [
self::PUBCHEM => "PubChem",
self::CHEMSPIDER => "ChemSpider",
self::NORINE => "Norine",
self::PDB => "PDB",
self::CHEBI => "ChEBI",
];

public static $backValues = [
'CID: ' => self::PUBCHEM,
'CSID: ' => self::CHEMSPIDER,
':' => self::NORINE,
'PDB: ' => self::PDB,
];
const COCONUT = 9;
const NP_ATLAS = 10;

/** @var array mapping int code to CycloBranch format string */
public static $cycloBranchValues = [
Expand All @@ -42,7 +28,7 @@ class ServerEnum {
];

public static function isOneOf(int $source): bool {
return $source >= self::PUBCHEM && $source <= self::LIPID_MAPS;
return $source >= self::PUBCHEM && $source <= self::NP_ATLAS;
}

}
8 changes: 6 additions & 2 deletions src/Model/ContainerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ private function updateBlockProperties(Container $container, BlockTransformed $t
$acronym = $block->getAcronym();
$this->entityManager->beginTransaction();
$block = $this->setupBlock($container, $block, $trans);
$this->entityManager->persist($block);
$this->entityManager->flush();
try {
$this->entityManager->persist($block);
$this->entityManager->flush();
} catch (UniqueConstraintViolationException $exception) {
return new Message('Block with this acronym is already in container');
}
if ($acronym !== $trans->getAcronym()) {
$blockUsages = $this->blockRepository->blockUsage($block->getContainer()->getId(), $block->getId(), []);
foreach ($blockUsages as $usage) {
Expand Down
19 changes: 13 additions & 6 deletions src/Repository/BlockRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,32 @@ function findMergeByFormula(int $containerId) {
$conn = $this->getEntityManager()->getConnection();
$sql = '
select
group_concat(distinct src.block_name order by src.block_name separator \'/\') as block_name,
group_concat(distinct src.acronym order by src.block_name separator \'/\') as acronym,
group_concat(src.block_name order by src.block_name separator \'/\') as block_name, --
group_concat(src.acronym order by src.block_name separator \'/\') as acronym, --
src.residue,
coalesce(src.block_mass, \'\') as block_mass,
group_concat(distinct coalesce(src.losses, \'\') order by src.block_name separator \'/\') as losses,
group_concat(distinct
group_concat(distinct coalesce(src.losses, \'\') order by src.block_name separator \'/\') as losses, --
group_concat( --
case when src.source is not null then
concat(case
when src.source = 0 then \'CID: \'
when src.source = 1 then \'CSID: \'
when src.source = 2 then \'\'
when src.source = 3 then \'PDB: \'
when src.source = 4 then \'\'
when src.source = 6 then \'DOI: \'
when src.source = 7 then \'SB: \'
when src.source = 8 then \'\'
when src.source = 9 then \'\'
when src.source = 10 then \'\'
else \'SMILES: \'
end, case when src.source > 3 then src.usmiles else src.identifier end)
end, case when src.source > 10 or src.source = 5 then src.usmiles else src.identifier end)
else \'\' end
order by src.block_name separator \'/\') as ref
from msb_block src
where src.container_id = :containerId
group by src.residue, src.block_mass';
group by src.residue, src.block_mass;
';
$stmt = $conn->prepare($sql);
$stmt->execute(['containerId' => $containerId]);
return $stmt->fetchAll();
Expand Down
14 changes: 10 additions & 4 deletions src/Repository/SequenceFamilyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ public function __construct(ManagerRegistry $registry) {
public function similarity(int $containerId, string $sequenceName) {
$conn = $this->getEntityManager()->getConnection();
$sql = '
select fam.id as value, fam.sequence_family_name as label
from msb_sequence_family fam
where :sequenceName like concat(\'%\', fam.sequence_family_name, \'%\')
and container_id = :containerId
select fam.id as value, fam.sequence_family_name as label
from (
select seq.id, row_number() over (order by abs(length(:sequenceName) - length(seq.sequence_name)) asc) as RN
from msb_sequence seq
where lower(substring_index(:sequenceName, \' \', 1)) like concat(\'%\', lower(substring_index(seq.sequence_name, \' \', 1)), \'%\')
and seq.container_id = :containerId
) seq
left join msb_s2f s2f on s2f.sequence_id = seq.id
left join msb_sequence_family fam on fam.id = s2f.family_id
where seq.RN = 1;
';
$stmt = $conn->prepare($sql);
$stmt->execute(['sequenceName' => $sequenceName, 'containerId' => $containerId]);
Expand Down

0 comments on commit 6224e08

Please sign in to comment.