f20f28b07df4e9738560a839a7636a7708d64969
kate
  Mon Oct 31 20:23:33 2011 -0700
Add filtering by assembly
diff --git src/hg/js/encodeChipMatrix.js src/hg/js/encodeChipMatrix.js
index e9207f1..2f9a811 100644
--- src/hg/js/encodeChipMatrix.js
+++ src/hg/js/encodeChipMatrix.js
@@ -1,27 +1,29 @@
 // encodeChipMatrix.js - pull experiment table and metadata from server 
 //      and display ChIP antibodies vs. cell types in a matrix
 // Formatted: jsbeautify.py -j
 // Syntax checked: jslint indent:4, plusplus: true, continue: true, unparam: true, sloppy: true, browser: true */
 /*global $, encodeProject */
 
 $(function () {
     var dataType, server, requests = [
         // requests to server API
         encodeProject.serverRequests.experiment,
         encodeProject.serverRequests.cellType,
-        encodeProject.serverRequests.antibody];
+        encodeProject.serverRequests.antibody,
+        encodeProject.serverRequests.expId
+        ];
 
     var cellTypeHash = {}, antibodyHash = {}, targetHash = {};
     var cellType, antibody, target;
     var organism, assembly, server, header;
     var karyotype;
     var spinner;
 
     function tableOut(matrix, cellTiers, antibodyGroups) {
         // Create table with rows for each cell type and columns for each antibody target
         var table, tableHeader, row, td;
 
         // fill in column headers from antibody targets returned by server
         tableHeader = $('#columnHeaders');
         $.each(antibodyGroups, function (i, group) {
             tableHeader.append('<th class="groupType"><div class="verticalText">' + 
@@ -126,67 +128,66 @@
                 $(".floatHeader #headerLabelRow").remove();
                 $(".floatHeader #searchTypePanel").remove();
                 $(".floatHeader #cellHeaderLabel").html('');
 
                 // Note: user-defined callback requires 
                 // default actions from floatHeader plugin
                 // implementation (stop+fadeIn)
                 header.stop(true, true);
                 header.fadeIn(100);
             }
         });
     }
 
     function handleServerData(responses) {
         // main actions, called when loading data from server is complete
-        var experiments = responses[0], cellTypes = responses[1], antibodies = responses[2];
-        var antibodyGroups, cellTiers;
+        var experiments = responses[0], cellTypes = responses[1], 
+                antibodies = responses[2], expIds = responses[3];
+        var antibodyGroups, cellTiers, expIdHash;
         var matrix = {};
 
         hideLoadingImage(spinner);
         $('#matrixTable').show();
 
-  // variables passed in hidden fields
-        organism = encodeChipMatrix_organism;
-        assembly = encodeChipMatrix_assembly;
-        header = encodeChipMatrix_pageHeader;
-
-        $("#pageHeader").text(header);
-        document.title = 'ENCODE ' + header;
-
         // set up structures for antibodies and their groups
         $.each(antibodies, function (i, item) {
             antibodyHash[item.term] = item;
         });
         antibodyGroups = encodeProject.getAntibodyGroups(antibodies);
 
         // set up structures for cell types and their tiers
         $.each(cellTypes, function (i, item) {
             cellTypeHash[item.term] = item;
         });
         cellTiers = encodeProject.getCellTiers(cellTypes);
 
+        // use to filter out experiments not in this assembly
+        expIdHash = encodeProject.getExpIdHash(expIds);
+
         // gather experiments into matrix
         $.each(experiments, function (i, exp) {
             // todo: filter out with arg to hgApi
             if (exp.organism !== organism) {
                 return true;
             }
             // exclude ref genome annotations
             if (exp.cellType === 'None') {
                 return true;
             }
+            if (expIdHash[exp.ix] === undefined) {
+                return true;
+            }
             // todo: filter out with arg to hgApi ?
             if (exp.dataType !== 'ChipSeq') {
                 return true;
             }
             // count experiments per target so we can prune those having none
             // (the matrix[cellType] indicates this for cell types 
             // so don't need hash for those
             antibody = encodeProject.antibodyFromExp(exp);
             target = encodeProject.targetFromAntibody(antibody, antibodyHash);
             if (!targetHash[target]) {
                 targetHash[target] = {
                     count: 0,
                     antibodies: {}
                 };
             }
@@ -197,36 +198,46 @@
 
             cellType = exp.cellType;
             if (!matrix[cellType]) {
                 matrix[cellType] = {};
             }
             if (!matrix[cellType][target]) {
                 matrix[cellType][target] = 0;
             }
             matrix[cellType][target]++;
         });
 
         // fill in table
         tableOut(matrix, cellTiers, antibodyGroups);
     }
 
+    // initialize
+
     // get server from calling web page (intended for genome-preview)
     if ('encodeDataMatrix_server' in window) {
         server = encodeDataMatrix_server;
     } else {
         server = document.location.hostname;
     }
 
-    // initialize
+    // variables passed from calling page
+    organism = encodeChipMatrix_organism;
+    assembly = encodeChipMatrix_assembly;
+    $("#assemblyLabel").text(assembly);
+    header = encodeChipMatrix_pageHeader;
+    $("#pageHeader").text(header);
+    document.title = 'ENCODE ' + header;
+
     encodeProject.setup({
-        server: server
+        server: server,
+        assembly: assembly
     });
 
     // show only spinner until data is retrieved
     $('#matrixTable').hide();
     spinner = showLoadingImage("spinner");
 
     // add radio buttons for search type to specified div on page
     encodeProject.addSearchPanel('#searchTypePanel');
 
     encodeProject.loadAllFromServer(requests, handleServerData);
 });