-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First push of the animal model systems script to insert sections into…
… the analysis for the intercenter meeting
- Loading branch information
Showing
1 changed file
with
133 additions
and
0 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
etc/fixtures/migrations/migrate-insert-animal-model-systems.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
const usage = ` | ||
mongosh --eval 'var cpamAnalysis="";var modelSystem=""' /tmp/fixtures/migrations/migrate-insert-animal-model-systems.js | ||
Script Options: | ||
help : Bool : Optional | ||
- If True print this help message | ||
cpamAnalysis : String : Required | ||
modelSystem : String : Required | ||
- Mus musculus (Mouse) Model System | ||
- Danio rerio (Zebrafish) Model System | ||
- Rattus norvegicus (Rat) Model System | ||
- Xenopus laevis (Frog) Model System | ||
- C. elegans (Roundworm) Model System | ||
Run mongosh help for mongosh connection and authentication usage. | ||
Example: | ||
mongosh --host localhost --port 27017 --eval 'var help=True;' /tmp/fixtures/migrations/migrate-insert-animal-model-systems.js | ||
docker exec -it <rosalution_db_container> mongosh --eval 'var cpamAnalysis="CPAM0002";var modelSystem="Mus musculus (Mouse) Model System"' /tmp/fixtures/migrations/migrate-insert-animal-model-systems.js | ||
` | ||
|
||
if (help === true) { | ||
print(usage); | ||
quit(1); | ||
} | ||
|
||
if (typeof databaseName === 'undefined') { | ||
databaseName = 'rosalution_db'; | ||
} else if (typeof databaseName !== 'string') { | ||
print('databaseName must be a string'); | ||
print(usage); | ||
quit(1); | ||
} | ||
|
||
if(typeof cpamAnalysis === 'undefined' || typeof cpamAnalysis !== 'string' || cpamAnalysis == '') { | ||
print('cpamAnalysis needs to be defined and must be a string'); | ||
print(usage); | ||
quit(1); | ||
} | ||
|
||
if(typeof modelSystem === 'undefined' || typeof modelSystem !== 'string' || modelSystem == '') { | ||
print('modelSystem needs to be defined and must be a string'); | ||
print(usage); | ||
quit(1); | ||
} | ||
|
||
print(`Adding ${modelSystem} to ${cpamAnalysis}...`) | ||
|
||
db = db.getSiblingDB(databaseName) | ||
|
||
const animalModelSystemSection = { | ||
"header": modelSystem, | ||
"content": [ | ||
{ | ||
"type": "section-text", | ||
"field": "Mutation", | ||
"value": [] | ||
}, | ||
{ | ||
"type": "section-text", | ||
"field": "Pathogenicity Test", | ||
"value": [] | ||
}, | ||
{ | ||
"type": "section-text", | ||
"field": "Design", | ||
"value": [] | ||
}, | ||
{ | ||
"type": "section-text", | ||
"field": "Founder Screening/Expansion", | ||
"value": [] | ||
}, | ||
{ | ||
"type": "section-text", | ||
"field": "Screening", | ||
"value": [] | ||
}, | ||
{ | ||
"type": "section-text", | ||
"field": "History", | ||
"value": [] | ||
}, | ||
{ | ||
"type": "section-text", | ||
"field": "Diagnoses", | ||
"value": [] | ||
}, | ||
{ | ||
"type": "section-text", | ||
"field": "Remarks", | ||
"value": [] | ||
}, | ||
{ | ||
"type": "supporting-evidence", | ||
"field": "Vetrinary Pathology Imaging", | ||
"value": {} | ||
}, | ||
{ | ||
"type": "supporting-evidence", | ||
"field": "Vetrinary Pathology Report", | ||
"value": {} | ||
} | ||
] | ||
} | ||
|
||
try { | ||
var analysis = db.analyses.findOne({name: cpamAnalysis}) | ||
print(`Found ${cpamAnalysis} in mongodb...`) | ||
var index = 0; | ||
|
||
for(section in analysis.sections) { | ||
if(analysis.sections[section].header == 'Pedigree') { | ||
index = section | ||
break; | ||
} | ||
} | ||
|
||
print(`Inserting '${modelSystem}' section into the analysis...`) | ||
analysis.sections.splice(index, 0, animalModelSystemSection) | ||
|
||
print(`Writing to mongodb...`) | ||
db.analyses.updateOne({'_id': analysis._id}, {'$set': analysis}) | ||
|
||
print(`Success! Done.`) | ||
} catch(e) { | ||
console.log(e.stack); | ||
console.log(usage); | ||
quit(1); | ||
} | ||
|