diff --git a/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_tests.js b/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_tests.js index 10322aa34..5e834c7f8 100644 --- a/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_tests.js +++ b/shrine-webclient/src/main/html/js-i2b2/cells/plugins/MedCo/MedCo_tests.js @@ -1,447 +1,456 @@ i2b2.MedCo.test = {}; i2b2.MedCo.test.ctrlr = { // A query is a list of panels. Each panel is a list of parameters. Each parameter is represented as // {"sensitive": boolean, "values": {type: "concept/gene/protein", name: ""}} // The "values" field will be substituted by the true values of this parameter (which may need to be fetched from // the database). The "name" can be used to retrieve the values of the parameter from the parameter_to_values map // (in which we store the values fetched from the database). // Query used for testing queryTest: { description: [ - [{"sensitive": true, "values": {type: "concept", name: "cutaneous_melanoma"}}] + [{"sensitive": true, "toBeEncrypted": true, "values": {type: "concept", name: "cutaneous_melanoma"}}] ], definition: null, // here we store the query to be sent (after fetching the needed variants) }, // Query A: // -panel 1: // cutaneous_melanoma // -panel 2: // braf_gene // -panel 3: // protein_600 queryA: { description: [ - [{"sensitive": true, "values": {type: "concept", name: "cutaneous_melanoma"}}], - [{"sensitive": true, "values": {type: "gene", name: "BRAF"}}], - [{"sensitive": true, "values": {type: "protein", name: "V600K"}}, // 0 - {"sensitive": true, "values": {type: "protein", name: "V600E"}}] // 2 (or viceversa) + [{"sensitive": true, "toBeEncrypted": true, "values": {type: "concept", name: "cutaneous_melanoma"}}], + [{"sensitive": true, "toBeEncrypted": false, "values": {type: "gene", name: "BRAF"}}], + [{"sensitive": true, "toBeEncrypted": false, "values": {type: "protein", name: "V600K"}}, // 0 + {"sensitive": true, "toBeEncrypted": false, "values": {type: "protein", name: "V600E"}}] // 2 (or viceversa) ], definition: null, // here we store the query to be sent (after fetching the needed variants) }, // Query B: // -panel 1: // cutaneous_melanoma // -panel 2: // braf_gene // -panel 3: // pten_gene, cdkn2a_gene, map2k1_gene, map2k2_gene queryB: { description: [ - [{"sensitive": true, "values": {type: "concept", name: "cutaneous_melanoma"}}], - [{"sensitive": true, "values": {type: "gene", name: "BRAF"}}], // 91 variants - [{"sensitive": true, "values": {type: "gene", name: "PTEN"}}, // 319 - {"sensitive": true, "values": {type: "gene", name: "CDKN2A"}}, // 117 - {"sensitive": true, "values": {type: "gene", name: "MAP2K1"}}, // 35 - {"sensitive": true, "values": {type: "gene", name:"MAP2K2"}}] // 33 + [{"sensitive": true, "toBeEncrypted": true, "values": {type: "concept", name: "cutaneous_melanoma"}}], + [{"sensitive": true, "toBeEncrypted": false,"values": {type: "gene", name: "BRAF"}}], // 91 variants + [{"sensitive": true, "toBeEncrypted": false, "values": {type: "gene", name: "PTEN"}}, // 319 + {"sensitive": true, "toBeEncrypted": false, "values": {type: "gene", name: "CDKN2A"}}, // 117 + {"sensitive": true, "toBeEncrypted": false, "values": {type: "gene", name: "MAP2K1"}}, // 35 + {"sensitive": true, "toBeEncrypted": false, "values": {type: "gene", name:"MAP2K2"}}] // 33 ], definition: null, // here we store the query to be sent (after fetching the needed variants) }, // map to store the values of each query parameter (also the fetched variants from the database) parameter_to_values: { "cutaneous_melanoma": ["2"], // no need to fetch this // hardcoded variant ids // (25 variants): gene // "BRAF": ["-7054948997223410688", "-7054948998062267136", "-7054968999892742144", "-7054948999337337856", "-7054948997064022784", "-7054953138544961536", "-7054948997064020736", "-7054923607457132544", "-7054904773018905600", "-7054898625779855360", "-7054948987408734208", "-7054923379857424384", "-7054917142457610240", "-7054861692282335232", "-7054948050082458624", "-7054922546600210432", "-7054949048695910400", "-7054923381098933248", "-7054861517262417920", "-7054918645662608384", "-7054905185268658176", "-7054904954414166016", "-7054898626853597184", "-7054904932905773056", "-7054861823278837760"], // // (58 variants): protein position // "-/600": ["-8933802084025738584", "-6486664075878068224", "-5631356589790194688", "-3744382902155078656", "-4243330163464466432", "-8390864270639754240", "-2861998644146466816", "-8933794510723345408", "-2275778788769918976", "-3744380364936704000", "-4847903122799977472", "-3744370070973837312", "-6486663046126103552", "-2862005101596240896", "-8933793458456358912", "-3731886507003209728", "-4243326752186690560", "-3684888714590289920", "-6600247701843995648", "-5707938912580661248", "-6600348525161082880", "-4243327620843826176", "-5707936738253467648", "-3744381594337537024", "-8390871813676067840", "-6486638321073122304", "-8718336899686591488", "-8161767032237320192", "-8718388095730315264", "-6600348471507544064", "-4847902555864297472", "-8718385496201359360", "-3744381715771026432", "-8390900435338128384", "-4243331029974117376", "-8718385510160003072", "-5707941003155992576", "-5707940965541473280", "-3744377054557105152", "-8390878215358377984", "-8161775324644764672", "-8161760075430494208", "-8933792699320889344", "-8933788672755493888", "-8718360110998468096", "-5707941120160295936", "-6600276494231006208", "-8933788638429310976", "-6486653465127809024", "-3744380416476311552", "-3729075172548795136", "-6600294904608320512", "-8933788867136319488", "-5707939282988035072", "-3744381760767524864", "-2275781595497491456", "-8933793225454383104", "-4243329794097277952"], // // (14 variants): gene // "PTEN": ["-6244734599302213632", "-6244835122005142528", "-6244734615609652992", "-6244731379150482432", "-6244761261385445376", "-6244761331212216320", "-6244803225329855488", "-6244761257090477056", "-6244761165822422016", "-6244761148709661696", "-6244761290443582464", "-6244734719527742464", "-6244803244478955520", "-6244731450050998272"], // // (22 variants): gene // "CDKN2A": ["-6605707269956960256", "-6605707340823916544", "-6605707363372498944", "-6605707399913269248", "-6605707450345581568", "-6605707366560164864", "-6605707493295259648", "-6605707451419324416", "-6605707339750174720", "-6605707347467692032", "-6605707487054123520", "-6605707304132149248", "-6605703514008055808", "-6605707366560165888", "-6605707438500867072", "-6605707503026037760", "-6605703519225765120", "-6605707607111888896", "-6605707340672917504", "-6605703519376764928", "-6605707351594886144", "-6605707619996790784"], // // (9 variants): gene // "MAP2K1": ["-4828214681296432128", "-4828266596713621504", "-4828266483970731008", "-4828258079793473536", "-4828266501150601216", "-4828266502224342016", "-4828257969198066688", "-4828266574613577728", "-4828218249340513280"], // // (7 variants): gene // "MAP2K2": ["-3742593253707344896", "-3742593391179853824", "-3742595392634613760", "-3742581279372079104", "-3742593229011282944", "-3742591331743035392", "-3742581136564416512"], }, // time the action started startTime: null, // whether the query has been encrypted encrypted: false, // whether it is already doing something (encrypting or sending the queries) doing: "", // pointer to the interval object so to stop it timeinterval: null, // response of the query response: null, fetchVariantIds: function(){ // fetch the variant ids needed for the query and store them in the map parameter_to_values if (this.doing != ""){ alert("Already " + this.doing); return } this.doing = "fetching the variant ids..."; var startTime = new Date().getTime(); var query = this.getSelectedQuery().description; var fetchByGenePHPreq = "js-i2b2/cells/plugins/MedCo/php/fetchVariants.php?" + "query_type=gene_and_zygosity&" + "gene_value=$geneValue" + "&zygosity[]=Heterozygous&zygosity[]=Homozygous&zygosity[]=Unknown"; var fetchByProteinPHPreq = "js-i2b2/cells/plugins/MedCo/php/fetchVariants.php?" + "query_type=protein_position_and_zygosity&" + "protein_change_value=$proteinChangeValue" + "&zygosity[]=Heterozygous&zygosity[]=Homozygous&zygosity[]=Unknown"; var numFetchedVariants = 0; var numResponses = 0; var success = function (paramName) { return function(responseText) { if (responseText.indexOf("error") >= 0) { alert(responseText); return; } var response = JSON.parse(responseText); // store the fetched variant ids in the map i2b2.MedCo.test.ctrlr.parameter_to_values[paramName] = response.variants; numFetchedVariants += response.variants.length; numResponses++; } }; var error = function (err) { alert("Error when trying to retrieve the variants from the database: " + err) }; var numQueries = 0; for (var panel=0; panel< query.length; panel++) { for (var parameter = 0; parameter < query[panel].length; parameter++) { var param = query[panel][parameter].values; if (param.type=="gene"){ var phpQuery = fetchByGenePHPreq.replace("$geneValue", param.name); } else if (param.type=="protein"){ var phpQuery = fetchByProteinPHPreq.replace("$proteinChangeValue", param.name); } else{ // no need to fetch variant ids fro this parameter continue; } numQueries++; phpGETRequest(success(param.name), error, phpQuery); } } document.getElementById("MedCoTest-NumVariantIds").innerHTML = "-"; document.getElementById("MedCoTest-NumPHPQueriesCurr").innerHTML = 0; document.getElementById("MedCoTest-NumPHPQueriesTot").innerHTML = numQueries; // start timer var dothis = function(){ document.getElementById("MedCoTest-NumVariantIds").innerHTML = numFetchedVariants; document.getElementById("MedCoTest-NumPHPQueriesCurr").innerHTML = numResponses; }; var done = function(){ if (numResponses>=numQueries){ document.getElementById("MedCoTest-NumVariantIds").innerHTML = numFetchedVariants; return true } return false }; this.startTimer(startTime, "MedCoTest-VariantIdsTime", done, dothis); }, encrypt: function(){ // encrypt the sensitive parameters of the query if (this.doing != ""){ alert("Already " + this.doing); return } var query = this.getSelectedQuery(); if (query.definition==null) { if (!this.defineQuery(query)) { alert("You have to fetch the variants."); return } } query = query.definition; this.doing = "encrypting..."; var startTime = new Date().getTime(); // clear encryption cache and start encryption i2b2.MedCo.ctrlr.background.encryptionCache = {}; var tot = 0; for (var panel = 0; panel < query.length; panel++){ for (var parameter = 0; parameter < query[panel].length; parameter++){ - if (query[panel][parameter].sensitive) { - i2b2.MedCo.ctrlr.background.toBeEncrypted(query[panel][parameter].values) - tot += query[panel][parameter].values.length + var entry = query[panel][parameter]; + if (entry.sensitive) { + if (entry.toBeEncrypted) { + i2b2.MedCo.ctrlr.background.toBeEncrypted(entry.values); + } + else{ + // HACK (avoid encrypting already tagged variants) + for (var i=0; i\n\n"; // callback processor to run the query from definition this.MedCocallback = new i2b2_scopedCallback(); this.MedCocallback.scope = this; this.MedCocallback.callback = function (results) { var endTime = new Date().getTime(); queryTimes.push(endTime-startTime); numResponses++; // extract the server times try{ if (results.error) { alert(results.errorMsg); return; } else { i2b2.MedCo.test.ctrlr.response = results; } } catch(e){ alert("Error when extracting the results of the query: " + e.message) } if (numResponses < numQueries){ // other queries to be sent sendQuery(); } }; i2b2.CRC.ajax.runQueryInstance_fromQueryDefinition("PLUGIN:MedCo", this.MedCoparams, this.MedCocallback); } sendQuery(); document.getElementById("MedCoTest-QueryTimeMean").innerHTML = "-"; document.getElementById("MedCoTest-QueryTimeStd").innerHTML = "-"; // show tot response count document.getElementById("MedCoTest-QueryTot").innerHTML = numQueries; // start timer var dothis = function(){ document.getElementById("MedCoTest-QueryCurr").innerHTML = numResponses; }; var done = function(){ if (numResponses >= numQueries){ // done sending queries. clear panels i2b2.MedCo.QT.ctrlr.clear(); // compute mean time var mean = 0; for (i=0; i 1){ for (i=0; i stop the timer) // dothis: if given this function is while updating the timer this.clearTimer(); this.startTime = startTime; this.timeinterval = setInterval(function(){i2b2.MedCo.test.ctrlr.updateTimer(label, stop, dothis)}, 100); }, updateTimer: function(label, stop, dothis){ if (dothis instanceof Function) { dothis(); } var now = new Date().getTime(); document.getElementById(label).innerHTML = prettyTime(now-this.startTime); if (stop()){ this.stopTimer() } }, clearTimer: function(){ this.startTime = null; clearInterval(this.timeinterval); this.timeinterval = null; }, stopTimer: function(){ this.clearTimer(); this.doing = ""; }, defineQuery: function(query){ // given a query, build it from description. Returns false if we are missing some parameters (variant ids). // clone the description query.definition = JSON.parse(JSON.stringify(query.description)); for (var panel=0; panel< query.definition.length; panel++){ for (var parameter=0; parameter> 'Start_Position' = '5239176' $query = "SELECT variant_id FROM genomic_annotations WHERE variant_annotations ->> '". $_GET["annotation_name"] . "' = '" . $_GET["annotation_value"] ."'"; break; default: echo "Error: query type not recognized"; return; } -//echo $query; -//return; +echo $query; +return; include 'sqlConnection.php'; $result = pg_query($conn, $query); if (!$result) { echo "An error occurred while querying the database.\n"; exit; } // In json format return both the panel number and the list of variants echo "{ \"variants\" : "; $variantList = ""; while ($row = pg_fetch_row($result)) { $variantList .= "\"$row[0]\","; } // drop the last comma echo "[" . substr($variantList, 0, -1) . "]}";