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

Add genomeSequences field to schema per spec #318

Merged
merged 2 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions data-serving/data-service/schemas/cases.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,37 @@
}
}
},
"genomeSequences": {
"bsonType": "array",
"uniqueItems": true,
"items": {
"bsonType": "object",
"additionalProperties": false,
"properties": {
"_id": {
"bsonType": "objectId"
},
"sampleCollectionDate": {
"bsonType": "date"
},
"repositoryUrl": {
"bsonType": "string"
},
"sequenceId": {
"bsonType": "string"
},
"sequenceName": {
"bsonType": "string"
},
"sequenceLength": {
"bsonType": "int"
},
"notes": {
"bsonType": "string"
}
}
}
},
"location": {
"bsonType": "object",
"additionalProperties": false,
Expand Down
6 changes: 6 additions & 0 deletions data-serving/data-service/src/model/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { CaseReferenceDocument, caseReferenceSchema } from './case-reference';
import { DemographicsDocument, demographicsSchema } from './demographics';
import { DictionaryDocument, dictionarySchema } from './dictionary';
import { EventDocument, eventSchema } from './event';
import {
GenomeSequenceDocument,
genomeSequenceSchema,
} from './genome-sequence';
import { LocationDocument, locationSchema } from './location';
import { PathogenDocument, pathogenSchema } from './pathogen';
import {
Expand All @@ -27,6 +31,7 @@ const caseSchema = new mongoose.Schema(
message: 'Must include an event with name "confirmed"',
},
},
genomeSequences: [genomeSequenceSchema],
importedCase: {},
location: locationSchema,
revisionMetadata: {
Expand Down Expand Up @@ -68,6 +73,7 @@ type CaseDocument = mongoose.Document & {
caseReference: CaseReferenceDocument;
demographics: DemographicsDocument;
events: [EventDocument];
genomeSequences: [GenomeSequenceDocument];
importedCase: {};
location: LocationDocument;
revisionMetadata: RevisionMetadataDocument;
Expand Down
21 changes: 21 additions & 0 deletions data-serving/data-service/src/model/genome-sequence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { dateFieldInfo } from './date';
import mongoose from 'mongoose';
import { positiveIntFieldInfo } from './positive-int';

export const genomeSequenceSchema = new mongoose.Schema({
sampleCollectionDate: dateFieldInfo,
repositoryUrl: String,
sequenceId: String,
sequenceName: String,
sequenceLength: positiveIntFieldInfo,
notes: String,
});

export type GenomeSequenceDocument = mongoose.Document & {
sampleCollectionDate: Date;
repositoryUrl: string;
sequenceId: string;
sequenceName: string;
sequenceLength: number;
notes: string;
};
10 changes: 10 additions & 0 deletions data-serving/data-service/test/model/data/case.full.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
"nationality": "Swedish",
"ethnicity": "Other"
},
"genomeSequences": [
{
"sampleCollectionDate": "2019-12-30",
"repositoryUrl": "https://www.ncbi.nlm.nih.gov/nuccore/NC_045512",
"sequenceId": "NC_045512.2",
"sequenceName": "Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1, complete genome",
"sequenceLength": 33000,
"notes": "The reference sequence is identical to MN908947."
}
],
"location": {
"country": "France",
"administrativeAreaLevel1": "Île-de-France",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"sampleCollectionDate": "2019-12-30",
"repositoryUrl": "https://www.ncbi.nlm.nih.gov/nuccore/NC_045512",
"sequenceId": "NC_045512.2",
"sequenceName": "Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1, complete genome",
"sequenceLength": 33000,
"notes": "The reference sequence is identical to MN908947."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
42 changes: 42 additions & 0 deletions data-serving/data-service/test/model/genome-sequence.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
GenomeSequenceDocument,
genomeSequenceSchema,
} from '../../src/model/genome-sequence';

import { Error } from 'mongoose';
import fullModel from './data/genome-sequence.full.json';
import minimalModel from './data/genome-sequence.minimal.json';
import mongoose from 'mongoose';

const GenomeSequence = mongoose.model<GenomeSequenceDocument>(
'GenomeSequence',
genomeSequenceSchema,
);

describe('validate', () => {
it('genome sequence with non-conforming date is invalid', async () => {
return new GenomeSequence({
...minimalModel,
...{ sampleCollectionDate: Date.parse('2019-10-31') },
}).validate((e) => {
expect(e.name).toBe(Error.ValidationError.name);
});
});

it('genome sequence with non-integer length is invalid', async () => {
return new GenomeSequence({
...minimalModel,
...{ sequenceLength: 2.2 },
}).validate((e) => {
expect(e.name).toBe(Error.ValidationError.name);
});
});

it('minimal genome sequence model is valid', async () => {
return new GenomeSequence(minimalModel).validate();
});

it('fully specified genome sequence model is valid', async () => {
return new GenomeSequence(fullModel).validate();
});
});
12 changes: 12 additions & 0 deletions data-serving/samples/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
],
"ethnicity": "Other"
},
"genomeSequences": [
{
"sampleCollectionDate": {
"$date": "2019-12-30T00:00:00Z"
},
"repositoryUrl": "https://www.ncbi.nlm.nih.gov/nuccore/NC_045512",
"sequenceId": "NC_045512.2",
"sequenceName": "Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1, complete genome",
"sequenceLength": 33000,
"notes": "The reference sequence is identical to MN908947."
}
],
"location": {
"country": "France",
"administrativeAreaLevel1": "Île-de-France",
Expand Down