comparison js/csOverview.js @ 2:a64ece32a01a draft default tip

"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/cs_overview commit a46097db0b6056e1125237393eb6974cfd51eb41"
author azomics
date Tue, 28 Jul 2020 08:32:36 -0400
parents
children
comparison
equal deleted inserted replaced
1:bca68066a957 2:a64ece32a01a
1 // Copyright (c) 2016 Northrop Grumman.
2 // All rights reserved.
3
4 var url = "./csOverview.tsv",
5 boxplotUrl = "./csBoxplotData.json",
6 pctablecontent,
7 newSmpNames= {},
8 newPopNames = {},
9 configBoxplot = {},
10 configAreaplot = {};
11
12 var waitForFinalEvent = (function () {
13 var timers = {};
14 return function (callback, ms, uniqueId) {
15 if (!uniqueId) {
16 uniqueId = "Don't call this twice without a uniqueId";
17 }
18 if (timers[uniqueId]) {
19 clearTimeout (timers[uniqueId]);
20 }
21 timers[uniqueId] = setTimeout(callback, ms);
22 };
23 })();
24
25 var preprocess = function(text){
26 var crossSampleData = d3.tsv.parseRows(text).map(function(row) {
27 return row.map(function(value) {
28 if (isNaN(value)) {
29 return value;
30 }
31 return +value;
32 })
33 })
34 return crossSampleData;
35 };
36
37 var displayProp = function() {
38 d3.text(url, function(error, data) {
39 var fileID = [],
40 sampleNames = [],
41 popTableData = [],
42 propHeadings = [],
43 propTableData = [],
44 propTableHeadings = [],
45 propTargets = [],
46 popTableHeadings = [],
47 propEditorData = [],
48 popEditorData = [],
49 smpcol = 2,
50 propHTML = '<table id="proptable" class="dtable display compact nowrap" cellspacing="0" width="100%"/>',
51 popHTML = '<table id="popnamestable" class="popt dtable display nowrap compact" cellspacing="0" width="100%"/>';
52
53 if (error) {
54 alert("Problem retrieving data");
55 return;
56 }
57 propHeadings = data.split("\n")[0].split("\t");
58 propHeadings.unshift("Comment");
59 data = d3.tsv.parse(data);
60 function propHandle(method, url, d, successCallBack, errorCallBack) {
61 var output = {data : propTableData};
62 successCallBack(output);
63 }
64
65 function popHandle(method, url, d, successCallBack, errorCallBack) {
66 var output = {data : popTableData};
67 successCallBack(output);
68 }
69
70 propTableData = $.extend(true,[],data);
71 propTableData.forEach(function(d) {
72 d.Comment = d.SampleName;
73 newSmpNames[d.SampleName] = d.Comment;
74 fileID.push(d.FileID);
75 sampleNames.push(d.SampleName);
76 });
77
78 for (var i = 3, j = propHeadings.length; i < j; i++){
79 propTargets.push(i);
80 }
81 propHeadings.forEach(function(d) {
82 propTableHeadings.push({"data":d, "title":d});
83 propEditorData.push({"label":d,"name":d});
84 if (d != 'Comment' && d != 'SampleName' && d != "FileID") {
85 newPopNames[d] = d.toString();
86 popTableHeadings.push({"data":d, "title":d});
87 popEditorData.push({"label":d,"name":d});
88 }
89 });
90 popTableData.push(newPopNames);
91 pctablecontent = $.extend(true,[],propTableData);
92
93 $('#propDiv').empty();
94 $('#propDiv').html(propHTML);
95 var smpEditor = new $.fn.dataTable.Editor({
96 ajax: propHandle,
97 table: '#proptable',
98 fields: propEditorData,
99 idSrc: 'SampleName'
100 });
101
102 $('#proptable').on( 'click', 'tbody td:first-child', function (e) {
103 smpEditor.bubble( this );
104 });
105 var propTable = $('#proptable').DataTable({
106 columns: propTableHeadings,
107 data: propTableData,
108 order: [[ smpcol, "asc" ]],
109 pageLength: 10,
110 scrollX: true,
111 scrollCollapse: true,
112 dom: '<"top"Bi>t<"bottom"lp><"clear">',
113 columnDefs: [{
114 targets: propTargets,
115 className: "dt-body-right",
116 render: function(data, type, row){
117 return parseFloat(data).toFixed(2) + '%';
118 }
119 }, {
120 targets: [smpcol - 1, smpcol, smpcol + 1],
121 className: "dt-body-left",
122 }],
123 buttons: [
124 'copy', 'pdfHtml5','csvHtml5', 'colvis'
125 ],
126 colReorder: {
127 fixedColumnsLeft:1
128 },
129 select: true
130 });
131
132 // Add titles to File ID and Sample Name
133 $('#proptable tr').each(function(i,d){
134 if (i > 0) {
135 $(this).find('td').each(function(j,e){
136 if (j == 1 ) {
137 $(this).prop('title', fileID[i - 1] );
138 }
139 if (j == 2) {
140 $(this).prop('title', sampleNames[i - 1]);
141 }
142 });
143 }
144 });
145
146 // Add a table below to rename pops
147 // Might want to change that some other time?
148 $('#popnamesDiv').html(popHTML);
149 var popEditor = new $.fn.dataTable.Editor({
150 ajax: popHandle,
151 table: '#popnamestable',
152 fields: popEditorData,
153 idSrc: '1'
154 });
155
156 $('#popnamestable').on( 'click', 'tbody td', function (e) {
157 popEditor.bubble(this);
158 });
159 var popTable = $('#popnamestable').DataTable({
160 columns: popTableHeadings,
161 dom: 't',
162 select: true,
163 data: popTableData
164 });
165
166 smpEditor.on( 'preSubmit', function(e, object, action){
167 var data = object.data;
168 var key = Object.keys(data)[0];
169 var count = object.data[key]['Comment'];
170
171 propTableData.forEach(function(d){
172 if (d.SampleName === key) {
173 d.Comment = count;
174 newSmpNames[key] = count;
175 }
176 });
177 pctablecontent = $.extend(true, [], propTableData);
178 });
179 popEditor.on( 'preSubmit', function(e, object, action){
180 var data = object.data;
181 var key = Object.keys(data['1'])[0];
182 var count = object.data['1'][key];
183 popTableData[0][key] = count;
184 newPopNames[key] = count;
185 });
186 });
187 };
188
189 var displayStackedAreaPlot = function() {
190 $.ajax({
191 url: url,
192 dataType: "text",
193 success: function(text) {
194 configAreaplot = {
195 displaybutton : '#updateDisplayA',
196 popSelectj : '.popSelectA',
197 plotdivj : '#plotDivA',
198 toggledisplayj : '#togglePlot',
199 toggledisplay : 'toggleButtonImg',
200 csdata : preprocess(text),
201 plotdiv : 'plotDivA',
202 type : 'areaplot',
203 table : '#popTableA tbody',
204 popSelect : 'popSelectA',
205 allPopulations : [],
206 selectedPopulations : [],
207 popSelectAll : '#popSelectAllA',
208 popSelectCheck : '.popSelectA:checked'
209 };
210 displayToolbar(configAreaplot);
211 }
212 });
213 };
214
215 var displayBoxplot = function() {
216 $.ajax({
217 url: boxplotUrl,
218 dataType: "json",
219 success: function(data) {
220 configBoxplot = {
221 displaybutton : '#updateDisplayC',
222 toggledisplayj : '#changeDisplayC',
223 toggledisplay : 'changeDisplayC',
224 popSelectj : '.popSelectC',
225 plotdivj : '#plotDivC',
226 csdata : data,
227 plotdiv : 'plotDivC',
228 type : 'boxplot',
229 table : '#popTableC tbody',
230 popSelect : 'popSelectC',
231 allMarkers : [],
232 selectedMarkers: [],
233 allPopulations : [],
234 selectedPopulations : [],
235 popSelectAll : '#popSelectAllC',
236 popSelectCheck: '.popSelectC:checked',
237 mrkrSelectAll : '#mrkrSelectAllC',
238 mrkrSelectCheck: '.mrkrSelectC:checked',
239 mrkrSelect : 'mrkrSelectC',
240 mtable : '#mrkrTableC tbody',
241 mrkrSelectj: '.mrkrSelectC',
242 displayvalues: '#displayLabelsC',
243 displayMFI: '#displayMFIC',
244 view: 'p',
245 mrkrNames : Object.keys(data.mfi)
246 };
247 displayToolbar(configBoxplot);
248 }
249 });
250 };