This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
/
addAnnotations.js
46 lines (40 loc) · 1.71 KB
/
addAnnotations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var ac = require('ve-api-check');
var areNonNegativeIntegers = require('validate.io-nonnegative-integer-array');
var isBoolean = require('validate.io-boolean');
// import ObjectID from 'bson-objectid';
export default function addAnnotations({input: {annotationType, annotationsToInsert, throwErrors}, state, output}) {
ac.throw(ac.annotationType, annotationType);
ac.throw(ac.arrayOf(ac.range), annotationsToInsert);
ac.throw(ac.bool.optional, throwErrors);
annotationsToInsert.forEach(function(annotationToInsert) {
if (!isBoolean(annotationToInsert.forward)) {
if (throwErrors) {
throw new Error('annotation direction not specified')
} else {
console.log('annotation direction not specified')
annotationToInsert.forward = true;
}
}
if (!areNonNegativeIntegers([annotationToInsert.start])) {
if (throwErrors) {
throw new Error('annotation position not specified')
} else {
console.log('annotation position not specified')
annotationToInsert.start = 0;
}
}
if (!areNonNegativeIntegers([annotationToInsert.end])) {
if (throwErrors) {
throw new Error('annotation position not specified')
} else {
console.log('annotation position not specified')
annotationToInsert.end = 0;
}
}
delete annotationToInsert.id;
// if (annotationToInsert.id === undefined) {
// annotationToInsert.id = ObjectID().str;
// }
state.push(['sequenceData', annotationType], annotationToInsert);
});
}