f20f28b07df4e9738560a839a7636a7708d64969 kate Mon Oct 31 20:23:33 2011 -0700 Add filtering by assembly diff --git src/hg/js/encodeDataSummary.js src/hg/js/encodeDataSummary.js index af93a8d..b0086fe 100644 --- src/hg/js/encodeDataSummary.js +++ src/hg/js/encodeDataSummary.js @@ -1,37 +1,38 @@ /* encodeDataSummary.js - pull experiment table and metadata from server and display in summary tables Formatted: jsbeautify.py -j -k Syntax checked: jslint indent:4, plusplus: true, continue: true, unparam: true, sloppy: true, browser: true */ /*global $, encodeProject */ $(function () { - var selectedDataType = null, - dataTypeLabelHash = {}, - server, requests = [ - // Requests to server API + var selectedDataType = null, dataTypeLabelHash = {}; + var server, organism, assembly, header; + var spinner; + var requests = [ + // requests to server API encodeProject.serverRequests.experiment, encodeProject.serverRequests.dataType, - encodeProject.serverRequests.antibody]; + encodeProject.serverRequests.antibody, + encodeProject.serverRequests.expId + ]; function tableOut(table, types, exps, selectableData) { // Helper function to output tables to document - var total = 0, - row = 0, - assembly = encodeDataSummary_assembly; + var total = 0, row = 0; $.each(exps, function (key, value) { types.push(key); total += parseInt(value, 10); }); types.sort(); // lay out table $.each(types, function (i, value) { if (dataTypeLabelHash[value]) { description = dataTypeLabelHash[value].description; } else { description = ''; } // quote the end tags so HTML validator doesn't whine @@ -43,77 +44,73 @@ $(".dataItem").addClass("selectable"); $(".dataItem").click(function () { // TODO: base on preview ? var term = dataTypeLabelHash[$(this).attr("id")].term; var url = encodeProject.getSearchUrl(assembly); url += ('&hgt_mdbVar1=dataType&hgt_mdbVal1=' + term + '&hgt_mdbVar2=view&hgt_mdbVal2=Any'); // TODO: open search window //window.open(url, "searchWindow"); window.location = url; // TODO: if antibody table, add mdbVar2 and mdbVal2 // TODO: same for histones }); } - $(table).append("<tr><td class='totals'>Total: " + types.length + "<\/td><td class='totals'>" + total + "<\/td><\/tr>"); if (total === 0) { $(table).remove(); } } function handleServerData(responses) { // Main actions, called when loading data from server is complete - var experiments = responses[0], - dataTypes = responses[1], - antibodies = responses[2], - antibodyHash = {}, - dataTypeHash = {}, - refGenomeExps = {}, - cellAssayExps = {}, - tfbsExps = {}, - antibody, target, dataType, total, refGenomeTypes = [], - elementTypes = [], - tfbsTypes = [], - organism, assembly, header; - - // variables passed in hidden fields - organism = encodeDataSummary_organism; - assembly = encodeDataSummary_assembly; - header = encodeDataSummary_pageHeader; + var experiments = responses[0], dataTypes = responses[1], + antibodies = responses[2], expIds = responses[3]; + var antibodyHash = {}, dataTypeHash = {}, + cellAssayExps = {}, tfbsExps = {}, refGenomeExps = {}; + var refGenomeTypes = [], elementTypes = [], tfbsTypes = []; + var dataType, antibody, target; + hideLoadingImage(spinner); $('.summaryTable').show(); $('#searchTypePanel').show(); $("#pageHeader").text(header); document.title = 'ENCODE ' + header; $.each(antibodies, function (i, item) { antibodyHash[item.term] = item; }); $.each(dataTypes, function (i, item) { dataTypeHash[item.term] = item; dataTypeLabelHash[item.label] = item; }); + // use to filter out experiments not in this assembly + expIdHash = encodeProject.getExpIdHash(expIds); + $.each(experiments, function (i, exp) { // todo: filter out with arg to hgApi if (exp.organism !== organism) { return true; } + // experiment not in this assembly + if (expIdHash[exp.ix] === undefined) { + return true; + } antibody = encodeProject.antibodyFromExp(exp); if (antibody) { target = encodeProject.targetFromAntibody(antibody, antibodyHash); } // add experiments into the appropriate table object if (exp.cellType === 'None') { dataType = dataTypeHash[exp.dataType].label; if (!refGenomeExps[dataType]) { refGenomeExps[dataType] = 0; } refGenomeExps[dataType]++; } else if (exp.dataType === 'ChipSeq') { if (!target) { return true; } @@ -139,38 +136,49 @@ } }); // fill in tables and activate buttons tableOut("#refGenomeTable", refGenomeTypes, refGenomeExps, true); tableOut("#elementTable", elementTypes, cellAssayExps, true); $("#buttonDataMatrix").click(function () { window.location = "encodeDataMatrixHuman.html"; }); // TODO: enable selectable items in antibody table tableOut("#tfbsTable", tfbsTypes, tfbsExps, false); $("#buttonChipMatrix").click(function () { window.location = "encodeChipMatrixHuman.html"; }); } + // initialize + // get server from calling web page (intended for genome-preview) if ('encodeDataMatrix_server' in window) { server = encodeDataMatrix_server; } else { server = document.location.hostname; // or document.domain ? } - // initialize + + // variables from calling page + organism = encodeDataSummary_organism; + assembly = encodeDataSummary_assembly; + $("#assemblyLabel").text(assembly); + header = encodeDataSummary_pageHeader; + $("#pageHeader").text(header); + document.title = 'ENCODE ' + header; + encodeProject.setup({ - server: server + server: server, + assembly: assembly }); - // show only spinner until data is retrieved - spinner = showLoadingImage("spinner"); - // add radio buttons for search type to specified div on page encodeProject.addSearchPanel('#searchTypePanel'); + + // show only spinner until data is retrieved $('#searchTypePanel').hide(); $('.summaryTable').hide(); + spinner = showLoadingImage("spinner"); // load data from server encodeProject.loadAllFromServer(requests, handleServerData); });