Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace covid19-data json for Django API endpoint #231

Merged
merged 152 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
9615250
Minor refactor
p3rcypj May 17, 2023
83e3be7
Add NMR block
p3rcypj May 17, 2023
0c160b8
Add tooltip
p3rcypj May 17, 2023
69cf722
Tooltip table
p3rcypj May 18, 2023
4eb13b2
Merge branch 'development' into feature/nmr
p3rcypj May 23, 2023
c53a4fb
NMR codec
p3rcypj May 23, 2023
76bacbd
Domain types and view
p3rcypj Jun 12, 2023
f8dd2ce
NMR: work in progress
p3rcypj Jul 9, 2023
e7f6944
Merge branch 'development' into feature/nmr
p3rcypj Oct 20, 2023
826b1d2
NMR types changes, tracks, block defs
p3rcypj Oct 25, 2023
1a2798b
Block to only dialog
p3rcypj Oct 25, 2023
2d72e5c
Dialog open action from protvista
p3rcypj Oct 25, 2023
5dc124e
Show NMR badge on covid19 table
p3rcypj Oct 25, 2023
b5957a6
Repo
p3rcypj Oct 26, 2023
96107c1
Types
p3rcypj Oct 26, 2023
78ea1a1
Badge, dialog, entity cell
p3rcypj Oct 26, 2023
f3bc5e2
NMR Pagination
p3rcypj Nov 23, 2023
4ec842e
Loading rows, and loading on export
p3rcypj Nov 23, 2023
4744bfc
Add sequential on Future
p3rcypj Nov 23, 2023
fdecc95
Add getAll
p3rcypj Nov 23, 2023
e989d6a
Save NMR, loader, cancel
p3rcypj Nov 23, 2023
4fd358c
Page + 1
p3rcypj Nov 26, 2023
127651a
Loaders NMR and IDR
p3rcypj Nov 26, 2023
ea2ee2c
isDev
p3rcypj Nov 26, 2023
f6a68e3
Filter NMR
p3rcypj Nov 26, 2023
b93db87
Clone NMR on viewer
p3rcypj Nov 28, 2023
b2cc874
Refactor
p3rcypj Nov 28, 2023
a7890f1
NSPTarget to NMRTarget
p3rcypj Nov 28, 2023
236e99a
NMRScreening
p3rcypj Nov 28, 2023
35f7d7d
i18n
p3rcypj Nov 28, 2023
873e33a
Nullable
p3rcypj Nov 28, 2023
7e5a556
Domain entities refactor
p3rcypj Nov 28, 2023
a935d4f
Encapsulate uniprotId, start, end
p3rcypj Nov 28, 2023
abe64d4
NMRPagination viewer
p3rcypj Nov 28, 2023
7cbdb34
Encapsulate uniprotId, start, end in viewer
p3rcypj Nov 28, 2023
2f6e933
Small refactor
p3rcypj Nov 29, 2023
26c7b80
i18n-scanner error
p3rcypj Dec 4, 2023
fdbf1d4
i18n
p3rcypj Dec 4, 2023
3e99c4e
NMRFragmentTarget
p3rcypj Dec 5, 2023
be162a1
NMR Target
p3rcypj Dec 5, 2023
2a8731c
Merge pull request #97 from EyeSeeTea/development
adrianq Jan 8, 2024
362914c
Merge pull request #100 from EyeSeeTea/development
adrianq Jan 8, 2024
c124c83
Merge branch 'development' into feature/nmr
p3rcypj Feb 7, 2024
6f964e9
Merge pull request #103 from EyeSeeTea/development
adrianq Feb 12, 2024
3932e07
Merge branch 'feature/data-updates' into develop
Feb 13, 2024
9309405
Merge remote-tracking branch 'origin/master' into develop
Feb 13, 2024
55541bd
Weekly data update
Feb 13, 2024
9a8a8ec
Weekly data update
Feb 13, 2024
86f2438
Merge branch 'development' into feature/nmr
p3rcypj Feb 14, 2024
52fa4dc
Fix errors with merge
p3rcypj Feb 14, 2024
c0e39fd
Merge branch 'feature/weekly-data-updates' of https://github.com/3dbi…
p3rcypj Feb 14, 2024
1445cac
Update NMR to be target string
p3rcypj Feb 15, 2024
ab87627
protvista version beta
p3rcypj Feb 21, 2024
b1ace21
i18n
p3rcypj Feb 21, 2024
8827ffb
Protvista versions
p3rcypj Feb 21, 2024
e635c91
yarn lock
p3rcypj Feb 21, 2024
3432257
Update github actions with versions check
p3rcypj Feb 22, 2024
83627d1
Merge branch 'development' into feature/nmr
p3rcypj Feb 22, 2024
19333fc
Fix workflow
p3rcypj Feb 22, 2024
02d08de
Typo
p3rcypj Feb 22, 2024
19c6161
Change NMR filter name
p3rcypj Mar 5, 2024
7acb8d1
Uniprot chains mapping with new endpoint
p3rcypj Mar 5, 2024
8b43875
Fix warning
p3rcypj Mar 5, 2024
f52dc12
Fix 8UYS
p3rcypj Mar 6, 2024
3c5098d
Update github actions with versions check
p3rcypj Feb 22, 2024
d5c6714
Fix workflow
p3rcypj Feb 22, 2024
f07a15c
Typo
p3rcypj Feb 22, 2024
83c7931
Add PDB entry, and everything in order to first run with api
p3rcypj Mar 12, 2024
5ed004e
Count, page, pageSize
p3rcypj Mar 12, 2024
08cfbbe
Remove no longer necessary data from covid19-data
p3rcypj Mar 13, 2024
da89f87
Add snackbar
p3rcypj Mar 13, 2024
0176932
Future: bitap
p3rcypj Mar 13, 2024
f512842
SnackbarProvider
p3rcypj Mar 13, 2024
28efe46
Timeout, use snackbar, add linear progress
p3rcypj Mar 13, 2024
a24d1f4
Add disabled state to Badge
p3rcypj Mar 15, 2024
eeb1942
Update i18n
p3rcypj Mar 15, 2024
62bff5f
Cancellable requests, extract pagination into Footer, refactor pagina…
p3rcypj Mar 15, 2024
4d7ebaa
Add skeleton
p3rcypj Mar 15, 2024
59dd46c
_.uniqBy on ligands, entities, organisms
p3rcypj Mar 15, 2024
bc18035
Update i18n
p3rcypj Mar 18, 2024
cd41809
Add filtering
p3rcypj Mar 18, 2024
dc6de3c
Change IDR display on backend
p3rcypj Mar 18, 2024
341ec13
Remove unused dynamic info, add sorting
p3rcypj Mar 18, 2024
4961e69
Search, mid autosuggestions
p3rcypj Mar 27, 2024
1127fa5
Fix warning
p3rcypj Mar 27, 2024
271c011
Remove exact match
p3rcypj Mar 27, 2024
5c9c4c8
Autosuggestions
p3rcypj Mar 27, 2024
af80729
Update yarn
p3rcypj Mar 27, 2024
f07210c
Replace dev api route
p3rcypj Mar 27, 2024
1750c1a
Change emdb to N:M
p3rcypj Apr 2, 2024
8d94ea7
Cache to StorageProvider
p3rcypj Apr 2, 2024
a1a9eda
Refactor PR
p3rcypj Apr 3, 2024
bccac4c
Small movement to useHook structures table, useStates, two simple cal…
p3rcypj Apr 7, 2024
63593c6
Move dialogs functionality to another useHook
p3rcypj Apr 7, 2024
35193bc
Noticer instead snackbar, loaders hook on component (render logic)
p3rcypj Apr 7, 2024
bccb41b
Data, setData
p3rcypj Apr 7, 2024
2e781ef
Refine options on search bar
p3rcypj Apr 7, 2024
3b1e615
Examples margin
p3rcypj Apr 7, 2024
af45d79
Previous value if blur and no search value
p3rcypj Apr 8, 2024
5482f63
Get data
p3rcypj Apr 8, 2024
92e3898
Change page, pageSize
p3rcypj Apr 8, 2024
de6b107
Disable prev, next on page limits
p3rcypj Apr 8, 2024
cda9557
Cancel request to useHook, columns, components
p3rcypj Apr 8, 2024
9342466
Fix bug: search value on blur changes to random search example
p3rcypj Apr 8, 2024
69313e6
Search value always as lowercase, componentsProps
p3rcypj Apr 8, 2024
1359dd7
SortModel
p3rcypj Apr 8, 2024
140ec31
isElementOfUnion
p3rcypj Apr 8, 2024
a17d0c9
Routes
p3rcypj Apr 8, 2024
c72961e
i18n
p3rcypj Apr 8, 2024
d8965e5
Revert undesired change
p3rcypj Apr 9, 2024
359d403
Entity, UseCase, Repository
p3rcypj Apr 15, 2024
14c27ac
API Request
p3rcypj Apr 15, 2024
a6e3fb0
CheckboxFilter descriptions by API
p3rcypj Apr 15, 2024
4814ef0
Sources on Badges from API
p3rcypj Apr 15, 2024
9a497ed
Add nmr source
p3rcypj Apr 15, 2024
5722a73
Change track, subtrack and color for NMR
p3rcypj Apr 15, 2024
5af0d80
Get NMR Source for viewer by API
p3rcypj Apr 15, 2024
e17faa6
NMR Dialog source content
p3rcypj Apr 15, 2024
5cb617a
NMR tooltip
p3rcypj Apr 15, 2024
f400b87
Repositories rename and move
p3rcypj Apr 16, 2024
f978c8e
i18n
p3rcypj Apr 16, 2024
666bcff
Mention VAR
p3rcypj Apr 22, 2024
0f3305b
Change var name
p3rcypj Apr 22, 2024
60d6391
Remove /api from repository
p3rcypj Apr 22, 2024
0432e9b
Remove details
p3rcypj Apr 22, 2024
734bc6c
Remove details from JSON repository
p3rcypj Apr 23, 2024
b92ff7d
Make pagination props immutable
p3rcypj Apr 23, 2024
3ebe156
Remove comments
p3rcypj Apr 23, 2024
9663c9e
If/Else branch
p3rcypj Apr 23, 2024
6b0b6a5
Remove JSON repository
p3rcypj Apr 23, 2024
e8ebeae
Page size as a useRef in order to not trigger request two times onPag…
p3rcypj Apr 23, 2024
0dbeb8c
Remove rinchen as it is down
p3rcypj Apr 23, 2024
9c2d3d2
EOF, and array reduce prevent intialValue
p3rcypj Apr 24, 2024
01d25e9
Remove bitap
p3rcypj Apr 24, 2024
155460c
Pagination
p3rcypj Apr 24, 2024
a286ce8
Array keyof
p3rcypj Apr 24, 2024
7cfb44e
Separate component export button
p3rcypj Apr 24, 2024
794d6e3
Dont provocate side effects before run
p3rcypj Apr 24, 2024
2567802
Not need of useMemo
p3rcypj Apr 24, 2024
9adea12
Descriptive name
p3rcypj Apr 24, 2024
3b48dc2
No need for type
p3rcypj Apr 24, 2024
c7c0152
Array reduce
p3rcypj Apr 24, 2024
4ce213c
Maybe instead of optional
p3rcypj Apr 24, 2024
8df2142
Move to useHook
p3rcypj Apr 24, 2024
d0963cf
Make Items a component, make smiles formula and pubchemId as mandatory
p3rcypj Apr 24, 2024
ae4860a
No need to cast
p3rcypj Apr 24, 2024
84b45d7
makeStyles
p3rcypj Apr 24, 2024
46e040a
Merge branch 'feature/api-structural-hub' into feature/nmr
p3rcypj May 6, 2024
5501743
Merge with api-structural-hub
p3rcypj May 6, 2024
c45cfb0
NMR as an Array
p3rcypj May 6, 2024
de2e4fa
Merge pull request #214 from EyeSeeTea/feature/nmr
adrianq May 21, 2024
b70baf6
Merge pull request #230 from EyeSeeTea/feature/uniprot-chains
adrianq May 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading