Skip to content

Commit e3f47ed

Browse files
committed
supported external pointers
1 parent 54fd7bc commit e3f47ed

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

src/routes/pointers/index.js

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { REFERENCES } = require('../../utils/constants');
88
// Standard codes for HTTP responses
99
const { BAD_REQUEST, INTERNAL_SERVER_ERROR, NOT_FOUND } = require('../../utils/status-codes');
1010
// Import auxiliar functions
11-
const { getValueGetter, getBaseURL, getHost } = require('../../utils/auxiliar-functions');
11+
const { getValueGetter, getBaseURL, getHost, round2tenths } = require('../../utils/auxiliar-functions');
1212
const { rangeNotation } = require('../../utils/parse-query-range');
1313
// Set the supported references
1414
// We exclude chains since it does not make sense, although it should work anyway
@@ -216,7 +216,7 @@ const pointersEndpoint = handler({
216216
const systemResidueCount = topology.residue_reference_indices.length;
217217
// Count the total number of reference residues in the system
218218
const referenceResidueCount = referenceResidueIndicies.length;
219-
const presence = referenceResidueCount / systemResidueCount;
219+
const presence = round2tenths(referenceResidueCount / systemResidueCount);
220220
currentPointer.presence = presence;
221221
}
222222
}
@@ -237,11 +237,63 @@ const pointersEndpoint = handler({
237237
currentPointer.covered_residues = rangeNotation(coveredResidues);
238238
// Get the percent of reference residues covered in the system
239239
const referenceResidueCount = referencesResidueCounts[referenceId];
240-
currentPointer.coverage = coveredResidues.length / referenceResidueCount;
240+
const coverage = round2tenths(coveredResidues.length / referenceResidueCount);
241+
currentPointer.coverage = coverage;
241242
}
242243
}
243244
});
244245
});
246+
// Now get data from the pointers collections
247+
// This collection contains minimal metadata to external non-MDDB simulations (e.g. ATLAS)
248+
// Set the pointers cursor
249+
const externalPointersFinder = hasTarget
250+
? { [`${referenceName}.${reference.idField}`]: targetReferenceId }
251+
: { [referenceName]: { $exists: true, $not: { $size: 0 } } };
252+
const externalPointersCursor = await database.pointers.find(externalPointersFinder);
253+
// Consume the pointers cursor
254+
const externalPointersData = await externalPointersCursor.toArray();
255+
// Add the external pointers to the overall pointers
256+
externalPointersData.forEach(externalPointerData => {
257+
const externalPointer = {
258+
id: externalPointerData.accession,
259+
api: externalPointerData.api,
260+
web: externalPointerData.web,
261+
};
262+
// Add projection fields if they are present in the external pointer data
263+
projection.forEach(field => {
264+
if (field in externalPointerData)
265+
externalPointer[field] = externalPointerData[field];
266+
})
267+
// Get refeence data
268+
const referenceData = externalPointerData[referenceName];
269+
// "present_residues":"0-414", "presence":1,
270+
// "covered_residues": "5-419", "coverage":0.9431818181818182,
271+
// Add the external pointer to every pertinent reference
272+
referenceData.forEach(ref => {
273+
// If only une reference is requested then ignore others
274+
const referenceId = ref[reference.idField];
275+
if (hasTarget && targetReferenceId !== referenceId) return;
276+
// Duplicate the pointer so we do not mutate the original
277+
const referenceExternalPointer = { ...externalPointer };
278+
// Add presence and or coverage when supported and available
279+
if (supportedPresence) {
280+
if (ref.present_residues)
281+
referenceExternalPointer.present_residues = ref.present_residues;
282+
if (ref.presence)
283+
referenceExternalPointer.presence = ref.presence;
284+
}
285+
// Check if the requested reference supports "coverage" measuring
286+
if (supportedCoverage) {
287+
if (ref.covered_residues)
288+
referenceExternalPointer.covered_residues = ref.covered_residues;
289+
if (ref.coverage)
290+
referenceExternalPointer.coverage = ref.coverage;
291+
}
292+
// Add the pointer to the overall pointers dict
293+
if (referenceId in pointers) pointers[referenceId].push(externalPointer);
294+
else pointers[referenceId] = [ externalPointer ];
295+
});
296+
});
245297
// If there is no output format then return the response as is
246298
if (format === 'json') return hasTarget ? pointers[targetReferenceId] : pointers;
247299
// At this point (for now) it means the requested format is CSV

src/utils/constants/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const LOCAL_COLLECTION_NAMES = {
4040
analyses: 'analyses',
4141
files: 'fs.files',
4242
old_chains: 'chains',
43+
pointers: 'pointers',
4344
};
4445
// Add local reference collections
4546
Object.entries(REFERENCES).forEach(([referenceName, reference]) => {

0 commit comments

Comments
 (0)