Skip to content

Instantly share code, notes, and snippets.

@j-coll
Last active February 24, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-coll/1906f8186f902c8fb84c90fdf8fe0cd2 to your computer and use it in GitHub Desktop.
Save j-coll/1906f8186f902c8fb84c90fdf8fe0cd2 to your computer and use it in GitHub Desktop.
Add _gn_so field in Variants collection. Related with opencb/opencga#500
// Use migration script https://gist.github.com/pfurio/f7cd90af08e0073699f0beeeef1958ba
migrateCollection("variants", {"annotation.ct":{$exists:1}, "annotation._gn_so":{$exists:false}}, {"annotation.ct":1}, function (bulk, doc) {
var id = doc._id;
var fields = ["gn", "ensg", "enst", "uni_a", "uni_n"];
var gn_so_obj = {}; /* Use as set */
for (var i in doc.annotation[0].ct) {
var ct = doc.annotation[0].ct[i];
for (var so_idx in ct.so) {
fields.forEach(function(field) {
if (ct.hasOwnProperty(field))
gn_so_obj[ct[field] + "_" + ct.so[so_idx]] = true;
})
}
}
var gn_so = [];
for(var k in gn_so_obj) gn_so.push(k);
if (gn_so.length > 0) {
bulk.find({_id: id}).update({$set: {"annotation.0._gn_so":gn_so}});
}
});
// Create sparse index
db.variants.ensureIndex({"annotation._gn_so":1}, {sparse:true, background: true})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment