8e7458b6824acecaeae94cf3969e152c0cf9ee3d
kate
  Sun May 13 21:16:14 2012 -0700
Generalize experiment matrix to handle mouse
diff --git src/hg/js/encodeProject.js src/hg/js/encodeProject.js
index 85ce8ff..e6141cc 100644
--- src/hg/js/encodeProject.js
+++ src/hg/js/encodeProject.js
@@ -155,52 +155,81 @@
                     dataGroups.push(item);
                 }
             });
             dataGroups.sort(encodeProject.cmpCV);
             dataGroups.push(otherGroup);
             $.each(dataGroups, function (i, group) {
                 if (!dataGroups[i]) {
                     // for some reason there's  __ element here (not my property)
                     return true;
                 }
                 dataGroups[i].dataTypes.sort(encodeProject.cmpNoCase);
             });
             return dataGroups;
         },
 
+        pruneDataGroupsToExps: function (groups, dataTypeExps) {
+            // Create new list of data groups and types having experiments (prune old list)
+            var dataGroups = [], dataGroup, dataType;
+            $.each(groups, function (i, group) {
+                dataGroup = { 
+                    label: group.label, 
+                    dataTypes: [] 
+                };
+                $.each(group.dataTypes, function (i, label) {
+                    dataType = encodeProject.getDataTypeByLabel(label);
+                    if (dataTypeExps[dataType.term]){
+                        dataGroup.dataTypes.push(dataType.label);
+                    }
+                });
+                if (dataGroup.dataTypes.length) {
+                    dataGroups.push(dataGroup);
+                }
+            });
+            return dataGroups;
+        },
+
         getCellType: function (cellType) {
             // Return cellType object from term
             // Needs loader function (using getCellTiers below for now)
             if (cellTypeTermHash !== undefined) {
                 return cellTypeTermHash[cellType];
             }
             return undefined;
         },
 
-        getCellTiers: function (cellTypes) {
+        getCellTiers: function (cellTypes, org) {
             // Unpack JSON list of cellTypes
             // Return sorted array of cellTier objects each having a .term,
             // with tier number, .celltypes, and an array of cell types, alphasorted
             // Also loads hash for lookup by term (for now)
             var cellTiers = [],
                 tier;
             $.each(cellTypes, function (i, cellType) {
+                if (cellType.organism !== org) {
+                    return true;
+                }
                 tier = cellType.tier;
+                if (org === 'human') {
                 // ignore untiered cell types (all human should have a tier)
                 if (!tier) {
                     return true;
                 }
+                } else {
+                    // no tiers in mouse, so assign to dummy tier 0
+                    tier = 0;
+                }
                 cellTypeTermHash[cellType.term] = cellType;
                 if (!cellTiers[tier]) {
                     cellTiers[tier] = {
                         term: tier,
                         cellTypes: []
                     };
                 }
                 cellTiers[tier].cellTypes.push(cellType.term);
             });
             cellTiers.sort(encodeProject.cmpCV);
             $.each(cellTiers, function (i, tier) {
                 if (!cellTiers[i]) {
                     // for some reason there's  __ element here (not my property)
                     return true;
                 }
@@ -281,18 +310,39 @@
 
             // unpack temp stash into sorted array of groups containing
             // sorted array of antibody targets
             $.each(antibodyGroupHash, function (key, item) {
                 antibodyGroups.push(item);
             });
             antibodyGroups.sort(encodeProject.cmpCV);
             $.each(antibodyGroups, function (i, group) {
                 if (!antibodyGroups[i]) {
                     // for some reason there's  __ element here (not my property)
                     return true;
                 }
                 antibodyGroups[i].targets.sort(encodeProject.cmpNoCase);
             });
             return antibodyGroups;
+        },
+
+        pruneAntibodyGroupsToExps: function (groups, antibodyTargetExps) {
+            // Create new list of antibody groups and types to those having experiments
+            var antibodyGroups = [], antibodyGroup;
+            $.each(groups, function (i, group) {
+                antibodyGroup = { 
+                    label: group.label, 
+                    targets: [] 
+                };
+                $.each(group.targets, function (i, target) {
+                    if (antibodyTargetExps[target]){
+                        antibodyGroup.targets.push(target);
+                    }
+                });
+                if (antibodyGroup.targets.length) {
+                    antibodyGroups.push(antibodyGroup);
+                }
+            });
+            return antibodyGroups;
         }
     };
+
 }());