Skip to content

Commit e0b78f4

Browse files
committed
add mongo script to merge dataset
1 parent e8300ff commit e0b78f4

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

mongoScript/mongoscript.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// [feiqiao@tahsin191 ~]$ mongo < ~/script/mongoscript.js
2+
3+
print("define local variables\n");
4+
5+
var host="129.49.249.191";
6+
var port="27015";
7+
var dbname="u24_luad";
8+
var case_id="TCGA-55-7994-01Z-00-DX1";
9+
var subject_id = "TCGA-55-7994";
10+
var merge_execution_id="merge_seq_1";
11+
var user="tester"
12+
13+
14+
//show dbs;
15+
//use u24_luad
16+
//show collections
17+
//db = connect("localhost:27020/myDatabase");
18+
19+
db = connect(host+":"+ port+"/"+ dbname);
20+
21+
//db.getCollectionNames();
22+
23+
db.createCollection("newcollection");
24+
25+
db.newcollection.remove({});
26+
27+
print("get segmentations within irregular annotation ... \n");
28+
//get segmentations within irregular annotation
29+
db.objects.find({"provenance.image.case_id":case_id,
30+
"provenance.image.subject_id":subject_id,
31+
"provenance.analysis.execution_id":"humantest",
32+
"geometry.type":null
33+
}).forEach( function(annotation)
34+
{db.objects.aggregate([ { $match: {"provenance.image.case_id":case_id,
35+
"provenance.image.subject_id":subject_id,
36+
"provenance.analysis.execution_id":annotation.algorithm,
37+
"geometry": {
38+
$geoWithin: {
39+
$geometry: {
40+
type : "Polygon" ,
41+
coordinates: annotation.geometry.coordinates
42+
}
43+
}
44+
}
45+
} }, { $out: "tmpCollection" } ]);
46+
db.tmpCollection.copyTo("newcollection");
47+
} );
48+
49+
db.newcollection.find().count();
50+
51+
print("get segmentations within rectangle annotation ... \n");
52+
//get segmentations within rectangle annotation
53+
db.objects.find({"provenance.image.case_id":case_id,
54+
"provenance.image.subject_id":subject_id,
55+
"provenance.analysis.execution_id":"humantest",
56+
"geometry.type": {$exists : true, $ne : ""}
57+
}).forEach( function(annotation)
58+
{db.objects.aggregate([ { $match: {"provenance.image.case_id":case_id,
59+
"provenance.image.subject_id":subject_id,
60+
"provenance.analysis.execution_id":annotation.algorithm,
61+
x : { '$gte':annotation.geometry.coordinates[0][0][0], '$lte':annotation.geometry.coordinates[0][2][0]},
62+
y : { '$gte':annotation.geometry.coordinates[0][0][1], '$lte':annotation.geometry.coordinates[0][2][1]}
63+
} }, { $out: "tmpCollection" } ]);
64+
db.tmpCollection.copyTo("newcollection");
65+
} );
66+
67+
print("composite dataset record count:");
68+
db.newcollection.find().count();
69+
70+
print("update execution_id for this new collection:");
71+
// update execution_id for this new collection
72+
db.newcollection.update({},
73+
{$set : {"provenance.analysis.execution_id":merge_execution_id}},
74+
{upsert:false, multi:true});
75+
76+
77+
print("delete all old composite dataset of segmentations:");
78+
// delete all merged segmentations
79+
db.objects.deleteMany({"provenance.image.case_id":case_id,
80+
"provenance.image.subject_id":subject_id,
81+
"provenance.analysis.execution_id":merge_execution_id
82+
} );
83+
84+
print("insert new dataset from newcollection as array:");
85+
//insert from newcollection as array
86+
db.objects.insert( db.newcollection.find({ },{"_id":0}).toArray() );
87+
88+
89+
//print("insert new metadate document of merging dataset to the metadata collection:");
90+
// insert new metadate document of merging dataset to the metadata collection
91+
var merge_execution_id_records= db.metadata.find({"image.case_id":case_id,"image.subject_id":subject_id,"provenance.analysis_execution_id":merge_execution_id}).count();
92+
93+
if(merge_execution_id_records == 0){
94+
print("insert new metadate document of merging dataset to the metadata collection:");
95+
db.metadata.insertOne(
96+
{
97+
"title" : "merge_seq_1",
98+
"user":user,
99+
"provenance" : {
100+
"analysis_execution_id" : merge_execution_id,
101+
"type" : "human"
102+
},
103+
"image" : {
104+
"case_id" : case_id,
105+
"subject_id" : subject_id
106+
}
107+
});
108+
}
109+
110+
111+
exit;
112+
113+
114+

0 commit comments

Comments
 (0)