From b91181d88b5d6b5cad7029279de544eea4166e8e Mon Sep 17 00:00:00 2001 From: kohleman <kohleman> Date: Fri, 18 Sep 2015 10:16:15 +0000 Subject: [PATCH] - made the naming of (reads/clusters) depending on the bclversion used for flowcell statistics - bugfix, if bclversion is undefined - added openbis-dsu.js SVN: 34668 --- .../as/webapps/cellStatistics/html/index.html | 70 +++- .../as/webapps/laneStatistics/html/index.html | 16 +- .../illumina-qgf/1/as/webapps/openbis-dsu.js | 358 ++++++++++++++++++ 3 files changed, 421 insertions(+), 23 deletions(-) create mode 100644 deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/openbis-dsu.js diff --git a/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/cellStatistics/html/index.html b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/cellStatistics/html/index.html index 500eda484ab..127a1899a18 100644 --- a/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/cellStatistics/html/index.html +++ b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/cellStatistics/html/index.html @@ -11,6 +11,7 @@ <script type="text/javascript" src="/openbis/resources/js/FileSaver.js"></script> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="style.css" /> + </head> <body> <div id="container" class="container"> @@ -49,6 +50,13 @@ return Number(myFloat).toFixed(2); } + if (typeof String.prototype.startsWith != 'function') { + // see below for better implementation! + String.prototype.startsWith = function (str){ + return this.indexOf(str) === 0; + }; + } + /* -------------------------------------------------------------------*/ @@ -66,15 +74,31 @@ function loadData () { sampleCodes.push(webAppContext.getEntityIdentifier() + ":" + i); } + var clusters = "" + // just take the first lane to read out the BCL version + dsu.retrieveSampleWithPropertiesCode(sampleCodes[0], function(laneResponse) { + // console.log(laneResponse) + bclVersion = laneResponse.result[0].properties.BCL_VERSION + if (bclVersion !== undefined) { + if (bclVersion.startsWith("bcl2fastq v2")) { + clusters = "Clusters"; + } + else { + clusters = "Reads"; + } + } + else { clusters = "Reads"}; + }); + var deferrer = new openbisActionDeferrer(function(){ sumArray.sort(compare); sumArrayNOINDEX.sort(compare); - plotLaneTable (sumArrayNOINDEX, true); + plotLaneTable (sumArrayNOINDEX, true, clusters); placeholder() - plotLaneTable (sumArray, false); + plotLaneTable (sumArray, false, clusters); downloadButton ("tableStats"); $("#save_as" + "tableStats").click(function() { submit_download_form("html", "tableStats"); }); - }, sampleCodes); + }, sampleCodes, clusters); sampleCodes.forEach(function(sampleCode){ dsu.retrieveDataSetsForSample(sampleCode, function(response){ @@ -109,25 +133,39 @@ function loadData () { }); }; -function plotLaneTable (sumArray, withNOINDEX) { +function plotLaneTable (sumArray, withNOINDEX, clusters) { - d3.select("body").append("text") - .text("Summary Table") - .attr("class", "h3"); + //d3.select("body").append("text") + // .text("Summary Table") + // .attr("class", "h3"); d3.select("body").append("text") - .text(function (){if (withNOINDEX) {return " with NOINDEX";} return " without NOINDEX";}) - .attr("class", "h6"); + .text(function (){if (withNOINDEX) {return " All " + clusters;} return " Without Undetermined " + clusters;}) + .attr("class", "h3"); + + d3.select("body") + .append("p") + ; var laneTableStats = d3.select("body") .append("table") .attr("id", "tableStats") .attr("class", "tableStats") ; - header = {"Lane":1, "# of Samples":1, "Average Passed Filtering (PF)":1, "Sum Raw Reads":1, "Sum PF Reads":1, "Sum Raw Bases":1, - "Sum PF Bases":1, "Average Raw Clusters in % per Index":1, "Average PF Phred Score":1, "Average > 30 Phred Score":1 } - // create the table header + header = {} + header["Lane"] = 1 + header["# of Samples"] = 1 + header["AVG Passed Filtering (PF)"] = 1 + header["Sum Raw " + clusters] = 1 + header["Sum PF " + clusters] = 1 + header["Sum Raw Bases"] = 1 + header["Sum PF Bases"] = 1 + header["AVG Raw Clusters in % per Index"] = 1 + header["AVG PF Phred Score"] = 1 + header["AVG > 30 Phred Score"] = 1 + + // create the table header var thead = laneTableStats.selectAll("th") .data(d3.keys(header)) .enter().append("th") @@ -135,8 +173,8 @@ function plotLaneTable (sumArray, withNOINDEX) { ; // create rows - console.log("Sumarray") - console.log(sumArray) + // console.log("Sumarray") + // console.log(sumArray) //sumArray.splice(1,3) @@ -174,8 +212,8 @@ function placeholder() { var space = d3.select("body") .append("svg") .attr("id", "placeholder") - .attr("width", 1500) - .attr("height", 50) + .attr("width", 0) + .attr("height", 100) ; } diff --git a/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/laneStatistics/html/index.html b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/laneStatistics/html/index.html index 77b58f02ef9..bc7cc543b84 100644 --- a/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/laneStatistics/html/index.html +++ b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/laneStatistics/html/index.html @@ -276,13 +276,15 @@ function loadData () { dsu.retrieveSampleWithProperties(webAppContext.getEntityPermId(), function(laneResponse){ bclVersion = laneResponse.result[0].properties.BCL_VERSION - if (bclVersion.startsWith("bcl2fastq v2")) { - clusters = "Clusters"; - } - else { - clusters = "Reads"; - } - + if (bclVersion !== undefined) { + if (bclVersion.startsWith("bcl2fastq v2")) { + clusters = "Clusters"; + } + else { + clusters = "Reads"; + } + } + else {clusters = "Reads"}; if (! isNaN(statisticsArray[0].percFilteringPass)) { plotLaneTable(sumsWithNOINDEX, false) // TODO: removed for now, as there is a bug diff --git a/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/openbis-dsu.js b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/openbis-dsu.js new file mode 100644 index 00000000000..a1cc807e5a8 --- /dev/null +++ b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/1/as/webapps/openbis-dsu.js @@ -0,0 +1,358 @@ +/** + * openbis-dsu.js + * OpenBIS-DSU API + * + * A DSU-specific API for accessing openBIS. Depends on openbis.js. + * @author Chandrasekhar Ramakrishnan + */ + +/** + * The openbis_dsu object provides a dsu-specific interface to openbis. + * + * It creates objects for projects, experiments, samples, and datasets. These objects + * are designed to be passed on to GUI libraries (like d3). The openbis version of each + * object is stored in the bis variable. + * @constructor + */ +function openbis_dsu(url, dssUrl) { + this.server = new openbis(url, dssUrl); +} + +/** + * Request the sequencing samples for a project + */ +openbis_dsu.prototype.retrieveSequencingSamples = function(action) +{ + var sampleCriteria = + { + matchClauses : + [ {"@type":"AttributeMatchClause", + attribute : "TYPE", + fieldType : "ATTRIBUTE", + desiredValue : "ILLUMINA_SEQUENCING" + } ], + operator : "MATCH_ALL_CLAUSES" + }; + + this.server.searchForSamples(sampleCriteria, action); +} + + +/** + * Request a Sample using the code + */ +openbis_dsu.prototype.retrieveSample = function(sampleIdentifier, action) +{ + var sampleCriteria = + { + matchClauses : + [ {"@type":"AttributeMatchClause", + attribute : "CODE", + fieldType : "ATTRIBUTE", + desiredValue : sampleIdentifier + } ], + operator : "MATCH_ALL_CLAUSES" + }; + + this.server.searchForSamples(sampleCriteria, action); +} + + +/** + * Request a Sample with Properties using the code + */ +openbis_dsu.prototype.retrieveSampleWithPropertiesCode = function(sampleIdentifier, action) +{ + var sampleCriteria = + { + matchClauses : + [ {"@type":"AttributeMatchClause", + attribute : "CODE", + fieldType : "ATTRIBUTE", + desiredValue : sampleIdentifier + } ], + operator : "MATCH_ALL_CLAUSES" + }; + + var fetchOptions = ["PROPERTIES"]; + + var thisDsu = this; + this.server.searchForSamplesWithFetchOptions(sampleCriteria, fetchOptions, function(response){ + response.result = thisDsu.getInitializedSamples(response.result); + action(response); + }); +} + + +/** + * Request a Sample with Properties using the permID + */ +openbis_dsu.prototype.retrieveSampleWithProperties = function(samplePermId, action) +{ + var sampleCriteria = + { + matchClauses : + [ {"@type":"AttributeMatchClause", + attribute : "PERM_ID", + fieldType : "ATTRIBUTE", + desiredValue : samplePermId + } ], + operator : "MATCH_ALL_CLAUSES" + }; + + var fetchOptions = ["PROPERTIES"]; + + var thisDsu = this; + this.server.searchForSamplesWithFetchOptions(sampleCriteria, fetchOptions, function(response){ + response.result = thisDsu.getInitializedSamples(response.result); + action(response); + }); +} + + + +/** + * Request Parent Samples including properties + */ + +openbis_dsu.prototype.retrieveSampleParents = function(samplePermId, action) +{ + var sampleCriteria = + { + targetEntityKind : "SAMPLE_CHILD", + criteria : { + matchClauses : + [ {"@type":"AttributeMatchClause", + "attribute":"PERM_ID", + "fieldType":"ATTRIBUTE", + "desiredValue": samplePermId + }] + } + }; + + var parentCriteria = + { + subCriterias : [ sampleCriteria ], + matchClauses : + [ + ], + operator : "MATCH_ALL_CLAUSES" + }; + + var fetchOptions = ["PROPERTIES"]; + + var thisDsu = this; + this.server.searchForSamplesWithFetchOptions(parentCriteria, fetchOptions, function(response){ + response.result = thisDsu.getInitializedSamples(response.result); + action(response); + }); +} + + +/** + * Request Child Samples including properties + */ + +openbis_dsu.prototype.retrieveSampleChildren = function(samplePermIds, action) +{ + var permIdClauses = []; + + samplePermIds.forEach(function(samplePermId){ + var clause = {"@type":"AttributeMatchClause", + "attribute":"PERM_ID", + "fieldType":"ATTRIBUTE", + "desiredValue": samplePermId + } + permIdClauses.push(clause) + }); + + var sampleCriteria = + { + targetEntityKind : "SAMPLE_PARENT", + criteria : { + matchClauses : permIdClauses, + operator : "MATCH_ANY_CLAUSES" + } + }; + + var childCriteria = + { + subCriterias : [ sampleCriteria ], + matchClauses : + [ + ], + operator : "MATCH_ALL_CLAUSES" + }; + + var fetchOptions = ["PROPERTIES", "PARENTS"]; + + var thisDsu = this; + this.server.searchForSamplesWithFetchOptions(childCriteria, fetchOptions, function(response){ + response.result = thisDsu.getInitializedSamples(response.result); + action(response); + }); +} + +/** + * Get the data sets for a sample specified by sample permId + */ +openbis_dsu.prototype.retrieveDataSetsForSampleWithPermIds = function(samplePermIds, action) +{ + var clauses = []; + + samplePermIds.forEach(function(samplePermId){ + var clause = {"@type":"AttributeMatchClause", + "attribute":"PERM_ID", + "fieldType":"ATTRIBUTE", + "desiredValue": samplePermId + } + clauses.push(clause) + }); + + var sampleCriteria = + { + targetEntityKind : "SAMPLE", + criteria : { + matchClauses : clauses, + operator: "MATCH_ANY_CLAUSES" + } + }; + + var dataSetCriteria = + { + subCriterias : [ sampleCriteria ], + matchClauses : + [ {"@type":"AttributeMatchClause", + attribute : "TYPE", + fieldType : "ATTRIBUTE", + desiredValue : "FASTQ_GZ" + } ], + operator : "MATCH_ALL_CLAUSES" + }; + + this.server.searchForDataSets(dataSetCriteria, action) +} + + + +/** + * Get the data sets for a sample specified by sample identifier + */ +openbis_dsu.prototype.retrieveDataSetsForSample = function(sampleIdentifier, action) +{ + var sampleIdentifierTokens = sampleIdentifier.split("/"); + var sampleCriteria = + { + targetEntityKind : "SAMPLE", + criteria : { + matchClauses : + [ {"@type":"AttributeMatchClause", + "attribute":"CODE", + "fieldType":"ATTRIBUTE", + "desiredValue": sampleIdentifierTokens[2] + }] + } + }; + + var dataSetCriteria = + { + subCriterias : [ sampleCriteria ], + matchClauses : + [ {"@type":"AttributeMatchClause", + attribute : "TYPE", + fieldType : "ATTRIBUTE", + desiredValue : "FASTQ_GZ" + } ], + operator : "MATCH_ALL_CLAUSES" + }; + + this.server.searchForDataSets(dataSetCriteria, action) +} + +/** + * Get all data sets connected to a sequencing sample + */ +openbis_dsu.prototype.retrieveDataSetsForSequencingSample = function(sequencing, action) +{ + this.server.listDataSetsForSample(sequencing.bis, false, action); +} + +openbis_dsu.prototype.getInitializedSamples = function(result) { + // + // Fill Map that uses as key the sample @id and value the sample object + // + var samplesById = {}; + + function storeSamplesById(originalSample) + { + var stack = [originalSample]; + + var referredSample = null; + while (referredSample = stack.pop()) { + if (isNaN(referredSample)) { + samplesById[referredSample["@id"]] = referredSample; + if (referredSample.parents) { + for(var i = 0, len = referredSample.parents.length; i < len; ++i) { + stack.push(referredSample.parents[i]); + } + } + if (referredSample.children) { + for(var i = 0, len = referredSample.children.length; i < len; ++i) { + stack.push(referredSample.children[i]); + } + } + } + } + } + + for(var i = 0; i < result.length; i++) { + var sampleOrId = result[i]; + storeSamplesById(sampleOrId); + } + + // + // Fix Result List + // + function fixSamples(result) + { + for(var i = 0; i < result.length; i++) + { + var sampleOrId = result[i]; + if (isNaN(sampleOrId)) + { + sampleOrId = samplesById[sampleOrId["@id"]]; + } else + { + sampleOrId = samplesById[sampleOrId]; + } + result[i] = sampleOrId; + + + //Fill Parents + if(sampleOrId.parents) { + for(var j = 0; j < sampleOrId.parents.length; j++) { + var parentOrId = sampleOrId.parents[j]; + if(!isNaN(parentOrId)) { //If is an Id get the reference + sampleOrId.parents[j] = samplesById[parentOrId]; + } + } + fixSamples(sampleOrId.parents); + } + + //Fill Children + if(sampleOrId.children) { + for(var j = 0; j < sampleOrId.children.length; j++) { + var childOrId = sampleOrId.children[j]; + if(!isNaN(childOrId)) { //If is an Id get the reference + sampleOrId.children[j] = samplesById[childOrId]; + } + } + fixSamples(sampleOrId.children); + } + } + } + + fixSamples(result); + + return result; + } -- GitLab