Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Opencga 1.1.0 migration
// Use migration script https://gist.github.com/pfurio/f7cd90af08e0073699f0beeeef1958ba
/*
Migrate NUMERIC variables to DOUBLE https://github.com/opencb/opencga/issues/545
*/
// This function receives an array of variables (not variableSet),
// and will modify NUMERIC variables to DOUBLE recursively
function modifyNumeric(variables) {
var modified = false;
if (typeof variables === "undefined" || variables === null || variables.length == 0) {
return modified;
}
for (var i in variables) {
var variable = variables[i];
if (variable.type === "NUMERIC") {
variable.type = "DOUBLE";
modified = true;
} else if (typeof variable.variableSet !== "undefined") {
if (modifyNumeric(variable.variableSet)) {
modified = true;
}
}
}
return modified;
}
migrateCollection("study", {"variableSets" : { $exists: true, $ne: [] } }, {}, function(bulk, doc) {
var modified = false;
var variableSets = doc.variableSets;
for (i in variableSets) {
modified = modifyNumeric(variableSets[i].variables);
}
if (modified) {
print("Migrating variable sets from study " + doc.alias);
bulk.find({"_id": doc._id}).updateOne({"$set": {"variableSets": variableSets}});
}
});
/*
Create indexes for new family collection https://github.com/opencb/opencga/issues/582
*/
db.family.createIndex({"name": 1, "_studyId": 1}, {"unique": true});
db.family.createIndex({"mother.id": 1}, {});
db.family.createIndex({"father.id": 1}, {});
db.family.createIndex({"children.id": 1}, {});
db.family.createIndex({"acl.member": 1, "_studyId": 1}, {});
db.family.createIndex({"status.name": 1, "_studyId": 1}, {});
db.family.createIndex({"annotationSets.name": 1}, {});
db.family.createIndex({"annotationSets.variableSetId": 1}, {});
db.family.createIndex({"annotationSets.annotations.name": 1, "annotationSets.annotations.value": 1}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.