From 5cfda8223a8ff56f27f6228fb1e35e94271bbdeb Mon Sep 17 00:00:00 2001 From: cramakri <cramakri> Date: Wed, 9 Jan 2013 14:23:46 +0000 Subject: [PATCH] CCS-26 SP-446 : Show phenotype information from Chicago DB in the strain browser SVN: 28039 --- .../basynthec/browser/basynthec-browser.js | 105 +++++++++++++++--- 1 file changed, 87 insertions(+), 18 deletions(-) diff --git a/eu_basynthec/source/core-plugins/basynthec/1/as/webapps/basynthec/browser/basynthec-browser.js b/eu_basynthec/source/core-plugins/basynthec/1/as/webapps/basynthec/browser/basynthec-browser.js index f5817fc003c..a8273cef9a6 100644 --- a/eu_basynthec/source/core-plugins/basynthec/1/as/webapps/basynthec/browser/basynthec-browser.js +++ b/eu_basynthec/source/core-plugins/basynthec/1/as/webapps/basynthec/browser/basynthec-browser.js @@ -451,6 +451,9 @@ function AppModel() { // A map holding data sets by type this.dataSetsByType = { }; + + // A set of all known growth media + this.growthMediaSet = {}; } AppModel.prototype.initialize = function(callback) { @@ -461,6 +464,15 @@ AppModel.prototype.initialize = function(callback) { this.initializeOd600WithPhenotypesAndPredictionsModel(callback); } +AppModel.prototype.addGrowthMedium = function(medium, strain) { + var mediumList = this.growthMediaSet[medium]; + if (null == mediumList) { + mediumList = []; + this.growthMediaSet[medium] = mediumList; + } + mediumList.push(strain); +} + /** Compute the dataSetsByType variable */ AppModel.prototype.initializeDataSetsByType = function() { // Group data sets by type @@ -536,6 +548,13 @@ AppModel.prototype.initializeOd600WithPhenotypesAndPredictionsModel = function(c for(strainName in model.dataSetsByStrain){ var strainData = strainDataMap[strainName]; var strainDatasets = model.dataSetsByStrain[strainName]; + strainData.phenotypeMap = {}; + if (strainData.hasPhenotypes) { + strainData.phenotypes.forEach(function(each) { + strainData.phenotypeMap[each.media] = each.relativeGrowth; + model.addGrowthMedium(each.media, strainName); + }); + } var hasPhenotypesOrPredictions = strainData && (strainData.hasPhenotypes || strainData.hasPredictions); var hasOd600Datasets = strainDatasets && strainDatasets.dataSets.some(function(dataset){ @@ -580,6 +599,19 @@ AppModel.prototype.initializeOd600WithPhenotypesAndPredictionsModel = function(c "mainGroupName" : "Strains without data in openBIS", "groups" : createStrainGroups(strainsUnknownToOpenbisWithPhenotypesOrPredictions) }); + + var commonGrowthMedia = [] + var allGrowthMedia = [] + for (medium in model.growthMediaSet) { + allGrowthMedia.push(medium); + if (model.growthMediaSet[medium].length > 20) { + commonGrowthMedia.push(medium); + } + } + allGrowthMedia.sort(); + commonGrowthMedia.sort(); + model.allGrowthMedia = allGrowthMedia; + model.commonGrowthMedia = commonGrowthMedia; callback(); }); @@ -996,6 +1028,8 @@ Od600InspectorView.prototype.updateView = function(duration) d.showSmall = !d.showSmall; od600InspectorView.updateView(); }); + + appendGrowthSection(inspectorEnter); appendObjectSection({ getSectionContainer: function(){ @@ -1014,24 +1048,6 @@ Od600InspectorView.prototype.updateView = function(duration) return prediction_props_to_pairs(d); } }); - - appendObjectSection({ - getSectionContainer: function(){ - return inspectorEnter; - }, - getSectionName: function(){ - return "Phenotypes"; - }, - getSectionClass: function(){ - return "phenotypeSection"; - }, - getSectionObjects: function(d){ - return d.data.phenotypes ? d.data.phenotypes : []; - }, - getSectionObjectProperties: function(d){ - return phenotype_props_to_pairs(d); - } - }); function graphWidth(d) { return d.showSmall ? GRAPH_SMALL_WIDTH : GRAPH_LARGE_WIDTH } function graphHeight(d) { return d.showSmall ? GRAPH_SMALL_HEIGHT : GRAPH_LARGE_HEIGHT } @@ -1156,6 +1172,59 @@ Od600InspectorView.prototype.updateView = function(duration) .remove(); } +function appendGrowthSection(inspectorEnter) { + var growthMediaSection = inspectorEnter.append("div"); + var growsSection = growthMediaSection.selectAll("div.growth") + .data(function(d) { var growsOn = []; + model.allGrowthMedia.forEach(function(m) { + var value = d.data.phenotypeMap[m] + if (value && value > 0) growsOn.push(m); + }); + return growsOn.length > 0 ? [growsOn] : []; + }); + growsSection.enter().append("div") + .attr("class", "growth") + .text("Grows on: "); + growsSection.selectAll("span") + .data(function(d) { return d }) + .enter().append("span") + .text(function (d) { return d + " "}); + + var doesNotGrowSection = growthMediaSection.selectAll("div.nogrow") + .data(function(d) { var doesNotGrowOn = []; + model.allGrowthMedia.forEach(function(m) { + var value = d.data.phenotypeMap[m] + if (value && value < 0.01) doesNotGrowOn.push(m); + }); + return doesNotGrowOn.length > 0 ? [doesNotGrowOn] : []; + }); + doesNotGrowSection.enter().append("div") + .attr("class", "nogrow") + .text("No growth on: "); + doesNotGrowSection.selectAll("span") + .data(function(d) { return d }) + .enter().append("span") + .text(function (d) { return d + " "}); + + + var unknownGrowthSection = growthMediaSection.selectAll("div.unknown") + .data(function(d) { var unknownGrowOn = []; + model.commonGrowthMedia.forEach(function(m) { + var value = d.data.phenotypeMap[m] + if (!value) unknownGrowOn.push(m); + }); + return unknownGrowOn.length > 0 ? [unknownGrowOn] : []; + }); + unknownGrowthSection.enter().append("div") + .attr("class", "unknown") + .text("Unknown growth on: "); + + unknownGrowthSection.selectAll("span") + .data(function(d) { return d}) + .enter().append("span") + .text(function (d) { return d + " "}); +} + function appendObjectSection(config){ var section = config.getSectionContainer().append("div") -- GitLab