Skip to content

Commit 37f54dd

Browse files
committed
knowledge PDB reference SAS
1 parent b3c4645 commit 37f54dd

3 files changed

Lines changed: 253 additions & 138 deletions

File tree

src/routes/knowledge/index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const handler = require('../../utils/generic-handler');
55
const getDatabase = require('../../database');
66
// Standard HTTP response status codes
77
const { NOT_FOUND } = require('../../utils/status-codes');
8+
// Fet a keyword to ask for the reference value, using the original PDB structure
9+
const { KNOWLEDGE_REFERENCE_KEYWORD } = require('../../utils/constants');
810

911
const router = Router({ mergeParams: true });
1012

@@ -43,7 +45,7 @@ router.route('/:pdbid').get(
4345
const cursor = await database.projects.find(projectsQuery, projectsProjection);
4446
// Consume the cursor
4547
const projects = await cursor.toArray();
46-
return projects.map(project => project.accession);
48+
return [ KNOWLEDGE_REFERENCE_KEYWORD, ...projects.map(project => project.accession) ];
4749
}
4850
}),
4951
);
@@ -52,14 +54,32 @@ router.route('/:pdbid').get(
5254
router.route('/:pdbid/:project').get(
5355
handler({
5456
async retriever(request) {
57+
// Set the requested PDB id
58+
const pdbId = request.params.pdbid;
5559
// Stablish database connection and retrieve our custom handler
5660
const database = await getDatabase(request);
61+
// If the requested project is the reference keyword then set the analyses available for this specific reference data
62+
// This was specifically tailored to get a reference SASA value
63+
if (request.params.project === KNOWLEDGE_REFERENCE_KEYWORD) {
64+
// Get the reference data
65+
const referenceData = await database.getReferenceData('pdbs', pdbId);
66+
if (referenceData.error) return referenceData;
67+
// Set the available analyses depending on the available fields
68+
const availableAnalyses = [];
69+
if (referenceData.chain_sas) availableAnalyses.push('sasa');
70+
// If no analysis is available then return an error
71+
if (availableAnalyses.length === 0) return {
72+
headerError: NOT_FOUND,
73+
error: 'No supported analyses available'
74+
};
75+
// Finally return the list with every available analysis
76+
return availableAnalyses;
77+
}
5778
// Get the requested project data
5879
const project = await database.getProject();
5980
// If there was any problem then return the errors
6081
if (project.error) return project;
6182
// Just to make it coherent, make sure the project has the PDB id in the request
62-
const pdbId = request.params.pdbid;
6383
if (!project.data.metadata.PDBIDS.includes(pdbId)) return {
6484
headerError: NOT_FOUND,
6585
error: `Project ${project.accession} has no PDB ${pdbId}`

0 commit comments

Comments
 (0)