Skip to content

Commit

Permalink
Merge pull request #231 from EyeSeeTea/feature/api-structural-hub
Browse files Browse the repository at this point in the history
Replace covid19-data json for Django API endpoint
  • Loading branch information
adrianq authored May 22, 2024
2 parents 5b9678d + b70baf6 commit 1d68eeb
Show file tree
Hide file tree
Showing 104 changed files with 10,254 additions and 433,831 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,73 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: '16.14.0'
- name: Check versions
run: |
main_version=$(grep -E '^# 3DBIONOTES-WS v[0-9.]+' README.md | sed -E 's/^# 3DBIONOTES-WS v([0-9.]+)$/\1/')
viewer_protvista_version=$(cat app/views/webserver/viewer.html.haml | grep -Eo 'protvista-pdb-[0-9.]+-est-[0-9]+(-beta.[0-9]+){0,1}' | awk '{print $1}')
viewer_pdbe_molstar_version=$(cat app/views/webserver/viewer.html.haml | grep -Eo 'pdbe-molstar-plugin-[0-9.]+-est-[0-9]+(-beta.[0-9]+){0,1}' | awk '{print $1}')
cd app/assets/javascripts/covid19
bio_covid19_version=$(cat package.json | jq -r '.version')
cd ../3dbio_viewer
bio_viewer_version=$(cat package.json | jq -r '.version')
protvista_version=$(cat package.json | jq -r '.dependencies["@3dbionotes/protvista-pdb"]')
pdbe_molstar_version=$(cat package.json | jq -r '.dependencies["@3dbionotes/pdbe-molstar"]')
index_protvista_version=$(cat public/index.html | grep -Eo 'protvista-pdb-[0-9.]+-est-[0-9]+(-beta.[0-9]+){0,1}' | awk '{print $1}')
index_pdbe_molstar_version=$(cat public/index.html | grep -Eo 'pdbe-molstar-plugin-[0-9.]+-est-[0-9]+(-beta.[0-9]+){0,1}' | awk '{print $1}')
if [ "$bio_viewer_version" != "$bio_covid19_version" ] ||
[ "$main_version" != "$bio_covid19_version" ]; then
echo "3dbio_viewer version doesn't match with covid19 version"
echo "3dbio_viewer: $bio_viewer_version"
echo "covid19: $bio_covid19_version"
echo "README.md version: $main_version"
exit 1
fi
if [ "$viewer_protvista_version" != "$index_protvista_version" ] ||
[ "$viewer_pdbe_molstar_version" != "$index_pdbe_molstar_version" ] ||
[ "$(echo "$index_protvista_version" | sed 's/protvista-pdb-//')" != "$protvista_version" ] ||
[ "$(echo "$index_pdbe_molstar_version" | sed 's/pdbe-molstar-plugin-//')" != "$pdbe_molstar_version" ]; then
echo "Versions don't match:"
echo "Viewer and index protvista: $viewer_protvista_version, $index_protvista_version"
echo "Viewer and index pdbe-molstar: $viewer_pdbe_molstar_version, $index_pdbe_molstar_version"
echo "3dbio_viewer dependency and index protvista: $protvista_version, $(echo "$index_protvista_version" | sed 's/protvista-pdb-//')"
echo "3dbio_viewer dependency and index pdbe-molstar: $pdbe_molstar_version, $(echo "$index_pdbe_molstar_version" | sed 's/pdbe-molstar-plugin-//'), "
exit 1
fi
echo "3dbio_viewer versions match"
echo "README.md version: $main_version"
echo "3DBIONOTES version: $bio_viewer_version"
echo "protvista-pdb version: $protvista_version"
echo "pdbe-molstar version: $pdbe_molstar_version"
- name: Install and build (3dbio_viewer)
run: |
cd app/assets/javascripts/3dbio_viewer
yarn install
yarn build
- name: Check build dependency versions (3dbioviewer)
run: |
cd app/assets/javascripts/3dbio_viewer
index_protvista_version=$(cat public/index.html | grep -Eo 'protvista-pdb-[0-9.]+-est-[0-9]+(-beta.[0-9]+){0,1}' | awk '{print $1}')
index_pdbe_molstar_version=$(cat public/index.html | grep -Eo 'pdbe-molstar-plugin-[0-9.]+-est-[0-9]+(-beta.[0-9]+){0,1}' | awk '{print $1}')
build_pdbe_molstar_file="build/pdbe-molstar/$index_pdbe_molstar_version.js"
if [ -f "$build_pdbe_molstar_file" ]; then
echo "Build file $build_pdbe_molstar_file exists."
else
echo "Build file $build_pdbe_molstar_file does not exist."
exit 1
fi
build_protvista_file="build/protvista-pdb/$index_protvista_version.js"
if [ -f "$build_protvista_file" ]; then
echo "Build file $build_protvista_file exists."
else
echo "Build file $build_protvista_file does not exist."
exit 1
fi
- name: Run tests (3dbio_viewer)
run: |
cd app/assets/javascripts/3dbio_viewer
yarn test:nowatch
- name: Install and build (covid19)
run: |
Expand Down
7 changes: 5 additions & 2 deletions app/assets/javascripts/3dbio_viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@3dbionotes/pdbe-molstar": "3.1.0-est-2",
"@3dbionotes/protvista-pdb": "2.0.1-est-2",
"@3dbionotes/protvista-pdb": "2.0.1-est-2-beta.1",
"@material-ui/core": "^4.11.2",
"@material-ui/data-grid": "4.0.0-alpha.35",
"@material-ui/icons": "^4.11.2",
Expand All @@ -14,6 +14,7 @@
"classnames": "^2.2.6",
"d2-ui-components": "^2.4.0",
"data-loader": "^3.0.0",
"file-saver": "^2.0.5",
"fluture": "^13.0.1",
"jszip": "^3.10.1",
"purify-ts": "^1.1.0",
Expand Down Expand Up @@ -42,8 +43,10 @@
"@types/axios": "^0.14.0",
"@types/classnames": "^2.2.11",
"@types/express": "^4.17.11",
"@types/file-saver": "^2.0.7",
"@types/hookrouter": "^2.2.5",
"@types/jest": "^26.0.15",
"@types/mime-types": "^2.1.4",
"@types/node": "^12.0.0",
"@types/react": "17.0.2",
"@types/react-dom": "17.0.2",
Expand Down Expand Up @@ -114,4 +117,4 @@
"\\.(jpg|jpeg|png|svg)$": "<rootDir>/config/fileMock.js"
}
}
}
}
2 changes: 1 addition & 1 deletion app/assets/javascripts/3dbio_viewer/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
type="text/css"
/>

<script src="/protvista-pdb/protvista-pdb-2.0.1-est-2.js"></script>
<script src="/protvista-pdb/protvista-pdb-2.0.1-est-2-beta.1.js"></script>
<script src="/pdbe-molstar/pdbe-molstar-plugin-3.1.0-est-2.js"></script>

<title>3dbio Viewer</title>
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/3dbio_viewer/src/compositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import { BionotesOrganismRepository } from "./data/repositories/BionotesOrganism
import { ExportAllAnnotationsUseCase } from "./domain/usecases/ExportAllAnnotationsUseCase";
import { AnnotationsExportApiRepository } from "./data/repositories/AnnotationsExportApiRepository";
import { ExportAnnotationsUseCase } from "./domain/usecases/ExportAnnotationsUseCase";
import { GetPartialNMRTargetUseCase } from "./domain/usecases/GetPartialNMRTargetUseCase";
import { SaveNMRTargetUseCase } from "./domain/usecases/SaveNMRTargetUseCase";
import { NMRApiRepository } from "./data/repositories/NMRApiRepository";
import { GetSourcesUseCase } from "./domain/usecases/GetSourcesUseCase";
import { SourcesApiRepository } from "./data/repositories/SourcesApiRepository";

export function getCompositionRoot() {
const pdbRepository = new ApiPdbRepository();
Expand All @@ -33,8 +38,11 @@ export function getCompositionRoot() {
const ontologyRepository = new BionotesOntologyRepository();
const organismRepository = new BionotesOrganismRepository();
const annotationsExportRepository = new AnnotationsExportApiRepository();
const nmrRepository = new NMRApiRepository();
const sourcesRepository = new SourcesApiRepository();

return {
getSources: new GetSourcesUseCase(sourcesRepository),
getPdb: new GetPdbUseCase(pdbRepository, ontologyRepository, organismRepository),
getPdbInfo: new GetPdbInfoUseCase(pdbInfoRepository),
searchDbModels: new SearchDbModelsUseCase(dbModelRepository),
Expand All @@ -50,6 +58,8 @@ export function getCompositionRoot() {
exportAnnotations: new ExportAnnotationsUseCase(annotationsExportRepository),
buildNetwork: new BuildNetworkUseCase(networkRepository),
getNetwork: new GetNetworkUseCase(networkRepository),
getPartialNMR: new GetPartialNMRTargetUseCase(nmrRepository),
saveNMR: new SaveNMRTargetUseCase(nmrRepository),
};
}

Expand Down
79 changes: 79 additions & 0 deletions app/assets/javascripts/3dbio_viewer/src/data/NMRScreening.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import _ from "lodash";
import { Codec, GetType, nullType, number, oneOf, string } from "purify-ts";
import { NMRFragmentTarget } from "../domain/entities/Protein";
import { commonLigand, pdbLigandC } from "./PdbLigands";

const featureTypeCodec = Codec.interface({
dataSource: string,
name: string, // binding | not binding
description: string,
externalLink: string,
});

export const nmrFragmentCodec = Codec.interface({
name: string,
description: string,
externalLink: string,
pdbentry: nullType,
uniprotentry: string,
ligandentity: oneOf([Codec.interface(commonLigand), pdbLigandC]),
details: Codec.interface({
type: string, // binding | notbinding
entity: string, // NMR target
}),
start: number,
end: number,
featureType: featureTypeCodec,
});

export type NMRScreeningFragment = GetType<typeof nmrFragmentCodec>;

export function getNMR(nmrScreenings: NMRScreeningFragment[]): NMRFragmentTarget[] {
const fragments = nmrScreenings.map(nmr => ({
...nmr,
binding: !nmr.details.type.toLowerCase().includes("not"),
}));

const targets = _(fragments)
.groupBy(i => i.details.entity)
.toPairs()
.value();

return targets.flatMap(([name, targetFragments]) => {
const fragments = targetFragments.map(
({ name, description, externalLink, binding, ligandentity, start, end }) => ({
name,
description,
externalLink,
binding,
ligand: {
...ligandentity,
inChI: ligandentity.IUPACInChIkey,
smiles: ligandentity.canonicalSMILES,
pubchemId: ligandentity.pubChemCompoundId,
formula: ligandentity.formula,
imageDataResource: undefined,
},
start,
end,
})
);

const start = _.first(fragments.map(({ start }) => start));
const end = _.first(fragments.map(({ end }) => end));
const uniprotId = _.first(targetFragments.map(({ uniprotentry }) => uniprotentry));
if (!start || !end || !uniprotId) return [];

return [
{
name,
uniprotId,
fragments,
bindingCount: fragments.filter(({ binding }) => binding).length,
notBindingCount: fragments.filter(({ binding }) => !binding).length,
start,
end,
},
];
});
}
11 changes: 11 additions & 0 deletions app/assets/javascripts/3dbio_viewer/src/data/NMRTarget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import _ from "lodash";
import { Codec, GetType, number, string } from "purify-ts";

export const nmrTargetCodec = Codec.interface({
entity: string,
start: number,
end: number,
uniprot_acc: string,
});

export type NMRTarget = GetType<typeof nmrTargetCodec>;
10 changes: 3 additions & 7 deletions app/assets/javascripts/3dbio_viewer/src/data/Ontologies.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { array, Codec, GetType, nullType, number, oneOf, string } from "purify-ts";

function maybeNull<Data>(type: Codec<Data>) {
return oneOf([type, nullType]);
}
import { array, Codec, GetType, nullable, number, string } from "purify-ts";

function getOntologiesResponse<T>(codec: Codec<T>) {
return Codec.interface({
count: number,
next: maybeNull(string),
previous: maybeNull(string),
next: nullable(string),
previous: nullable(string),
results: codec,
});
}
Expand Down
10 changes: 3 additions & 7 deletions app/assets/javascripts/3dbio_viewer/src/data/Organisms.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import _ from "lodash";
import { array, Codec, GetType, nullType, number, oneOf, string } from "purify-ts";
import { array, Codec, GetType, nullable, number, string } from "purify-ts";
import { Organism } from "../domain/entities/LigandImageData";

function maybeNull<Data>(type: Codec<Data>) {
return oneOf([type, nullType]);
}

function getOrganismsResponse<T>(codec: Codec<T>) {
return Codec.interface({
count: number,
next: maybeNull(string),
previous: maybeNull(string),
next: nullable(string),
previous: nullable(string),
results: codec,
});
}
Expand Down
13 changes: 10 additions & 3 deletions app/assets/javascripts/3dbio_viewer/src/data/PdbLigands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,22 @@ const imageDataC = Codec.interface({
assays: array(assayC),
});

export const pdbLigandC = Codec.interface({
export const commonLigand = {
IUPACInChIkey: string,
dbId: string,
pubChemCompoundId: string,
name: string,
formula: string,
formula_weight: number,
imageLink: string,
externalLink: string,
pubChemCompoundId: string,
IUPACInChI: string,
isomericSMILES: string,
canonicalSMILES: string,
};

export const pdbLigandC = Codec.interface({
...commonLigand,
dbId: string,
imageData: optional(array(imageDataC)), //it shouldn't be an array...
});

Expand Down Expand Up @@ -256,6 +260,9 @@ export function getPdbLigand(pdbLigandOptions: PdbLigandsOptions): PdbLigand {
name: ligand.name,
inChI: ligand.IUPACInChIkey,
imageDataResource: idr,
smiles: ligand.canonicalSMILES,
formula: ligand.formula,
pubchemId: ligand.pubChemCompoundId,
};
}

Expand Down
21 changes: 21 additions & 0 deletions app/assets/javascripts/3dbio_viewer/src/data/codec-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Codec, array, nullable, number, optional, string } from "purify-ts";

export function paginationCodec<Data>(type: Codec<Data>): Codec<Pagination<Data>> {
return Codec.interface({
count: number,
next: optional(nullable(string)),
previous: optional(nullable(string)),
results: array(type),
});
}

export function getResults<Data>(pagination?: Pagination<Data>) {
return pagination?.results ?? [];
}

export type Pagination<K> = {
count: number;
next: string | null | undefined;
previous: string | null | undefined;
results: K[];
};
Loading

0 comments on commit 1d68eeb

Please sign in to comment.