rails-clustergrammer 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c48ee734df599a0de09e7e2ccd0b12b27428155d20a09812fa3022cbe8c27011
4
- data.tar.gz: f8256f5db3addf26ac0e16b339dae1487c3ac24e11c227c8fa28d61a8b9ed914
3
+ metadata.gz: 5691a8f9d4e222ee953cfaf289e58589e83272677033bb60a69e169c09697b7a
4
+ data.tar.gz: 031230a8a39f3435cc0266be56a720daae37bab435e596dbaea04fcf930df2a5
5
5
  SHA512:
6
- metadata.gz: a8edc92df391f4855f6f6de11c1ed8118e092347712d2316b8ea44f592e4b0c5a6c7bed1ea91ef9ebda7324d18db645b2231ba27438d749fffb340afb5c22aea
7
- data.tar.gz: 7a1f1c569b55d4935f5ee6a2622efec5a7e21c310e4008ab1db635cff00852bea3b44c9be1e222587c443fddc0477f8d14312e091335008332397fb48251ac2b
6
+ metadata.gz: 790b6295f055f60ea3bb62f6be0029ff3e008e937431da2014525ab33f7e48c955db33608517e762459cf9c87ce59c85719cdecbbc944c0e39a3b87d4ec45f25
7
+ data.tar.gz: a49c44ce93d10c02eef417b515b9c01777d649eff30eace99a85da6d8775d02c9214609ab2c6edcc0f5b481461c92fa1503ef964e91c4ec0ed82fd177e302315
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ .DS_Store
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-clustergrammer (0.1.0)
4
+ rails-clustergrammer (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -20,8 +20,19 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+
24
+ Add require javascript and gem
25
+ ```ruby
26
+ gem 'underscore-rails', '~> 1.8', '>= 1.8.3'
27
+ gem 'd3_rails', '~> 4.1', '>= 4.1.1'
28
+ ```
29
+
23
30
  Add the clustergrammer to your manifest file:
31
+ ```ruby
32
+ //= require d3
33
+ //= require underscore
24
34
  //= require clustergrammer
35
+ ```
25
36
 
26
37
  ## Development
27
38
 
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Clustergrammer
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1,755 @@
1
+ var genes_were_found = {};
2
+ enr_obj = {};
3
+
4
+ function check_setup_enrichr(inst_cgm){
5
+
6
+ var has_enrichrgram = _.has(inst_cgm.params.network_data, 'enrichrgram');
7
+
8
+ var make_enrichrgram = false;
9
+ if (has_enrichrgram){
10
+ make_enrichrgram = inst_cgm.params.network_data.enrichrgram;
11
+ }
12
+
13
+ // Toggle Enrichrgram function
14
+ if (has_enrichrgram === false){
15
+
16
+ // check with Hzome whether rows are genes
17
+ ////////////////////////////////////////////
18
+ genes_were_found[inst_cgm.params.root] = false;
19
+
20
+ var all_rows = inst_cgm.params.network_data.row_nodes_names;
21
+ var max_num_genes = 20;
22
+
23
+ if (all_rows.length > 20){
24
+ all_rows = all_rows.slice(0,20);
25
+ }
26
+
27
+ var wait_unit = 500;
28
+ var wait_time = 0;
29
+
30
+ _.each(all_rows, function(inst_name){
31
+ setTimeout(check_gene_request, wait_time, inst_cgm, inst_name, run_ini_enrichr);
32
+ wait_time = wait_time + wait_unit;
33
+ });
34
+
35
+ } else if (make_enrichrgram) {
36
+
37
+ // make enrichrgram without checking with Hzome
38
+ /////////////////////////////////////////////////
39
+ run_ini_enrichr(inst_cgm);
40
+
41
+ genes_were_found[inst_cgm.params.root] = true;
42
+
43
+ }
44
+
45
+ }
46
+
47
+ function run_ini_enrichr(inst_cgm){
48
+
49
+ var inst_root = inst_cgm.params.root;
50
+
51
+ var has_enrichrgram = _.has(inst_cgm.params.network_data, 'enrichrgram');
52
+
53
+ var make_enrichrgram = false;
54
+ if (has_enrichrgram){
55
+ make_enrichrgram = inst_cgm.params.network_data.enrichrgram;
56
+ }
57
+
58
+ if (genes_were_found[inst_root] || make_enrichrgram){
59
+
60
+ if (d3.select(inst_root + ' .enrichr_logo').empty()){
61
+
62
+ // set up Enrichr category import
63
+ enr_obj[inst_root] = Enrichrgram(inst_cgm);
64
+ enr_obj[inst_root].enrichr_icon();
65
+
66
+ // set up Enrichr export in dendro modal
67
+ //////////////////////////////////////////
68
+
69
+ // only display for rows
70
+ var enrichr_section = d3.selectAll(inst_root + ' .dendro_info')
71
+ .select('.modal-body')
72
+ .append('div')
73
+ .classed('enrichr_export_section', true)
74
+ .style('margin-top', '10px');
75
+ // .style('display','none');
76
+
77
+ enrichr_section
78
+ .append('text')
79
+ .text('Send genes to ');
80
+
81
+ enrichr_section
82
+ .append('a')
83
+ .html('Enrichr')
84
+ .on('click', function(){
85
+
86
+ var group_string = d3.select(inst_root + ' .dendro_text input').attr('value');
87
+
88
+ // replace all instances of commas with new line
89
+ var gene_list = group_string.replace(/, /g, '\n');
90
+
91
+ ///////////////
92
+ // clean list
93
+ ///////////////
94
+ var enrichr_info = {list: gene_list, description: 'Clustergrammer gene-cluster list' , popup: true};
95
+
96
+ // defined globally - will improve
97
+ send_to_Enrichr(enrichr_info);
98
+
99
+ });
100
+
101
+ }
102
+
103
+ }
104
+
105
+ }
106
+
107
+ function check_gene_request(inst_cgm, gene_symbol, run_ini_enrichr){
108
+
109
+ if (gene_symbol.indexOf(' ') > 0){
110
+ gene_symbol = gene_symbol.split(' ')[0];
111
+ } else if (gene_symbol.indexOf('_') > 0){
112
+ gene_symbol = gene_symbol.split('_')[0];
113
+ }
114
+
115
+
116
+ var base_url = 'https://amp.pharm.mssm.edu/Harmonizome/api/1.0/gene/';
117
+ var url = base_url + gene_symbol;
118
+
119
+ if (genes_were_found[inst_cgm.params.root] === false){
120
+
121
+ // make sure value is non-numeric
122
+ if (isNaN(gene_symbol)){
123
+
124
+ $.get(url, function(data) {
125
+
126
+ data = JSON.parse(data);
127
+
128
+ if (data.name != undefined){
129
+ genes_were_found[inst_cgm.params.root] = true;
130
+ }
131
+
132
+ run_ini_enrichr(inst_cgm, gene_symbol);
133
+
134
+ });
135
+
136
+ }
137
+ }
138
+
139
+ }
140
+
141
+ function Enrichrgram(inst_cgm){
142
+
143
+ var inst_root = inst_cgm.params.root;
144
+
145
+ function enrichr_icon(){
146
+
147
+ var low_opacity = 0.7;
148
+ var high_opacity = 1.0;
149
+ var icon_size = 42;
150
+ var d3_tip_custom = inst_cgm.d3_tip_custom();
151
+
152
+ // var enrichr_description = 'Perform enrichment analysis on your gene-list <br>'+
153
+ // 'using Enrichr to find biological information that is unique to your list.'
154
+ var enrichr_description = 'Perform enrichment analysis, using Enrichr, to find biological <br>'+
155
+ 'information specific to your set (or subset) of genes. <br><br>' +
156
+ 'Select a subset of genes for analysis by cropping the matrix using: the brush-cropping tool in the sidebar, or the crop buttons on the dendrogram.'
157
+ // d3-tooltip
158
+ var enr_tip = d3_tip_custom()
159
+ .attr('class', function(){
160
+ var root_tip_selector = inst_cgm.params.viz.root_tips.replace('.','');
161
+ var class_string = root_tip_selector + '_enr_tip d3-tip';
162
+ return class_string;
163
+ })
164
+ .direction('se')
165
+ .style('display', 'none')
166
+ .offset([-10,-5])
167
+ .html(function(d){
168
+ return enrichr_description;
169
+ });
170
+
171
+ var enr_logo = d3.select(inst_root+' .viz_svg').append("svg:image")
172
+ .attr('x', 50)
173
+ .attr('y', 2)
174
+ .attr('width', icon_size)
175
+ .attr('height', icon_size)
176
+ .attr("xlink:href", "https://amp.pharm.mssm.edu/Enrichr/images/enrichr-icon.png")
177
+ .style('opacity', low_opacity)
178
+ .classed('enrichr_logo', true)
179
+ .attr('id', function(){
180
+ var inst_id = 'enrichr_menu_button_' + inst_cgm.params.root.replace('#','');
181
+ return inst_id;
182
+ })
183
+ .on('click', function(){
184
+ toggle_enrichr_menu();
185
+ })
186
+ .on('mouseover', function(){
187
+
188
+ var is_showing = d3.select(inst_cgm.params.root+' .enrichr_menu')
189
+ .classed('showing');
190
+
191
+ if (is_showing === false){
192
+ // show tooltip
193
+ d3.selectAll( inst_cgm.params.viz.root_tips + '_enr_tip')
194
+ .style('opacity', 1)
195
+ .style('display', 'block');
196
+
197
+ enr_tip.show();
198
+ }
199
+
200
+ })
201
+ .on('mouseout', function(){
202
+
203
+ // hide tooltip
204
+ d3.selectAll( inst_cgm.params.viz.root_tips + '_enr_tip')
205
+ .style('opacity', 0)
206
+ .style('display', 'block');
207
+
208
+ enr_tip.hide();
209
+ })
210
+ .call(enr_tip);
211
+
212
+ var enr_menu = d3.select(inst_cgm.params.root+' .viz_svg')
213
+ .append('g')
214
+ .classed('showing', false)
215
+ .classed('enrichr_menu', true)
216
+ .attr('transform', 'translate(85,40)')
217
+ .style('display', 'none');
218
+
219
+ enr_menu
220
+ .append('rect')
221
+ .classed('enr_menu_background', true)
222
+ .attr('width', 475)
223
+ .attr('height', 500)
224
+ .attr('opacity', 0.95)
225
+ .attr('fill', 'white')
226
+ .attr('stroke', '#A3A3A3')
227
+ .attr('stroke-width', '3px');
228
+
229
+ enr_menu
230
+ .append('text')
231
+ .attr('transform', 'translate(20,30)')
232
+ .attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif')
233
+ .attr('font-size','18px')
234
+ .attr('font-weight', 800)
235
+ .attr('cursor', 'default')
236
+ .text('Choose Enrichr Library');
237
+
238
+ // clear results button
239
+ enr_menu
240
+ .append('text')
241
+ .classed('enr_menu_clear', true)
242
+ .attr('transform', 'translate(345, 30)')
243
+ .attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif')
244
+ .style('font-size','18px')
245
+ .style('font-weight', 800)
246
+ .style('cursor', 'default')
247
+ .text('Clear Results')
248
+ .style('fill', 'red')
249
+ .style('opacity', 0.75)
250
+ .style('display', 'none')
251
+ .on('click', function(){
252
+
253
+
254
+ // reset enrichr menu
255
+ toggle_enrichr_menu();
256
+
257
+ // clear enrichr results and run resizing
258
+ clear_enrichr_results(true);
259
+
260
+ })
261
+
262
+ var lib_section = enr_menu
263
+ .append('g')
264
+ .attr('transform', 'translate(20,60)')
265
+ .style('width', 460)
266
+ .style('height', 370)
267
+ .classed('enr_lib_section','true');
268
+
269
+ var possible_libraries = [
270
+ 'ChEA_2016',
271
+ 'KEA_2015',
272
+ 'ENCODE_TF_ChIP-seq_2015',
273
+ 'ENCODE_Histone_Modifications_2015',
274
+ 'Disease_Perturbations_from_GEO_up',
275
+ 'Disease_Perturbations_from_GEO_down',
276
+ 'GO_Molecular_Function_2015',
277
+ 'GO_Biological_Process_2015',
278
+ 'GO_Cellular_Component_2015',
279
+ 'Reactome_2016',
280
+ 'KEGG_2016',
281
+ 'MGI_Mammalian_Phenotype_Level_4',
282
+ 'LINCS_L1000_Chem_Pert_up',
283
+ 'LINCS_L1000_Chem_Pert_down',
284
+ ];
285
+
286
+ var vertical_space = 30;
287
+
288
+ enr_menu
289
+ .append('rect')
290
+ .classed('enr_menu_line', true)
291
+ .attr('height', '2px')
292
+ .attr('width', '435px')
293
+ .style('stroke-width', '3px')
294
+ .style('opacity', 0.3)
295
+ .style('fill','black')
296
+ .attr('transform', 'translate(20, 465)');
297
+
298
+ var enr_export_container = enr_menu
299
+ .append('g')
300
+ .classed('enr_export_container', true)
301
+ .attr('transform', 'translate(20, 487)');
302
+
303
+ enr_export_container
304
+ .append('text')
305
+ .style('font-size','16px')
306
+ .attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif')
307
+ .style('cursor', 'default')
308
+ .text('Export gene list to ');
309
+
310
+ enr_export_container
311
+ .append('text')
312
+ .style('font-size','16px')
313
+ .attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif')
314
+ .style('cursor', 'default')
315
+ .text('Enrichr')
316
+ .style('fill','#337ab7')
317
+ .attr('transform', 'translate(135, 0)')
318
+ .on('click', function(){
319
+
320
+ // get gene list and send to Enrichr
321
+ var gene_list = inst_cgm.params.network_data.row_nodes_names.join('\n');
322
+
323
+ var enrichr_info = {list: gene_list, description: 'Clustergrammer gene list' , popup: true};
324
+
325
+ // defined globally - will improve
326
+ enrich(enrichr_info);
327
+
328
+ })
329
+
330
+ var lib_groups = lib_section
331
+ .selectAll('g')
332
+ .data(possible_libraries)
333
+ .enter()
334
+ .append('g')
335
+ .attr('transform', function(d,i){
336
+ var vert = i*vertical_space
337
+ var transform_string = 'translate(0,'+ vert+')';
338
+ return transform_string;
339
+ })
340
+
341
+ lib_groups
342
+ .append('circle')
343
+ .attr('cx', 10)
344
+ .attr('cy', -6)
345
+ .attr('r', 7)
346
+ .style('stroke', '#A3A3A3')
347
+ .style('stroke-width', '2px')
348
+ .style('fill','white')
349
+
350
+ lib_groups
351
+ .append('text')
352
+ .attr('transform', 'translate(25,0)')
353
+ .style('font-size','16px')
354
+ .attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif')
355
+ .style('cursor', 'default')
356
+ .text(function(d){
357
+ return d.replace(/_/g, ' ');
358
+ });
359
+
360
+ lib_groups
361
+ .on('click', function(d){
362
+
363
+ d3.select(inst_cgm.params.root+' .enr_lib_section')
364
+ .selectAll('g')
365
+ .select('circle')
366
+ .style('fill','white');
367
+
368
+ // indicate that library was selected
369
+ d3.select(this)
370
+ .select('circle')
371
+ .style('fill','red')
372
+
373
+ // turn on clear sign
374
+ d3.select(inst_cgm.params.root+' .enr_menu_clear')
375
+ .transition()
376
+ .delay(1000)
377
+ .style('display', 'block');
378
+
379
+ // request enrichment results from Enrichr
380
+ enr_obj.enrichr_rows(d, update_viz_callback, 10);
381
+
382
+ make_enr_wait_circle();
383
+ animate_wait();
384
+
385
+ setTimeout(toggle_enrichr_menu, 500);
386
+ })
387
+
388
+ }
389
+
390
+ function clear_enrichr_results(run_resize_viz){
391
+
392
+ d3.select(inst_cgm.params.root+ ' .enr_menu_clear')
393
+ .style('display', 'none');
394
+
395
+ // unselect library
396
+ d3.select(inst_cgm.params.root+' .enr_lib_section')
397
+ .selectAll('g')
398
+ .select('circle')
399
+ .style('fill','white');
400
+
401
+ // clear categories
402
+ inst_cgm.reset_cats(run_resize_viz);
403
+
404
+ // remove title and bars
405
+ d3.select(inst_cgm.params.root+' .enr_title').remove();
406
+ d3.selectAll(inst_cgm.params.root+' .enrichr_bars').remove();
407
+
408
+ }
409
+
410
+ function toggle_enrichr_menu(){
411
+
412
+ var enr_menu = d3.select(inst_cgm.params.root+' .enrichr_menu');
413
+
414
+ if (enr_menu.classed('showing') === false){
415
+
416
+ // show menu
417
+ ///////////////////////
418
+ enr_menu
419
+ .classed('showing', true)
420
+ .style('display', 'block');
421
+
422
+ d3.select(inst_cgm.params.root+' .enrichr_menu')
423
+ .style('opacity',0)
424
+ .transition()
425
+ .style('opacity',1)
426
+
427
+ d3.selectAll('.row_cat_super').style('display','none');
428
+
429
+ // hide tooltip
430
+ d3.selectAll( inst_cgm.params.viz.root_tips + '_enr_tip')
431
+ .style('opacity', 0)
432
+ .style('display', 'none');
433
+
434
+ } else {
435
+
436
+ // hide menu
437
+ ///////////////////////
438
+ setTimeout(function(){enr_menu.style('display', 'none');}, 1000)
439
+
440
+ d3.select(inst_cgm.params.root+' .enrichr_menu')
441
+ .classed('showing', false)
442
+ .style('opacity',1)
443
+ .transition()
444
+ .style('opacity',0)
445
+
446
+ d3.selectAll('.row_cat_super').style('display','block');
447
+ }
448
+
449
+ }
450
+
451
+ function get_enr_with_list(ini_gene_list, library, callback_function){
452
+
453
+ // clean gene list
454
+ var gene_list = []
455
+ _.each(ini_gene_list, function(gene_symbol){
456
+ if (gene_symbol.indexOf(' ') > 0){
457
+ gene_symbol = gene_symbol.split(' ')[0];
458
+ } else if (gene_symbol.indexOf('_') > 0){
459
+ gene_symbol = gene_symbol.split('_')[0];
460
+ }
461
+ gene_list.push(gene_symbol)
462
+ })
463
+
464
+ enr_obj.library = library;
465
+ enr_obj.gene_list = gene_list;
466
+
467
+ enr_obj.post_list(gene_list, function(){
468
+
469
+ if (typeof callback_function != 'undefined'){
470
+ enr_obj.get_enr(library, callback_function);
471
+ } else {
472
+ enr_obj.get_enr(library);
473
+ }
474
+
475
+ });
476
+ }
477
+
478
+ function post_list(gene_list, callback_function){
479
+
480
+ var gene_list_string = gene_list.join('\n');
481
+
482
+ var form = new FormData();
483
+ var response;
484
+
485
+ form.append("list", gene_list_string);
486
+
487
+ form.append("description", "clustergrammer");
488
+
489
+ var settings = {
490
+ "async": true,
491
+ "crossDomain": true,
492
+ "url": "https://amp.pharm.mssm.edu/Enrichr/addList",
493
+ "method": "POST",
494
+ "processData": false,
495
+ "contentType": false,
496
+ "mimeType": "multipart/form-data",
497
+ "data": form
498
+ }
499
+
500
+ if (typeof callback_function === 'undefined'){
501
+ callback_function = confirm_save;
502
+ }
503
+
504
+ $.ajax(settings)
505
+ .done(function(response){
506
+ response = JSON.parse(response);
507
+ enr_obj.user_list_id = response.userListId;
508
+
509
+ // make get request
510
+ setTimeout(callback_function, 500, response);
511
+ // callback_function(response);
512
+ });
513
+ }
514
+
515
+ function confirm_save(response){
516
+ console.log('saved user_list_id '+String(enr_obj.user_list_id));
517
+ }
518
+
519
+ function get_enr(library, callback_function){
520
+
521
+ if (enr_obj.user_list_id !== null){
522
+ var form = new FormData();
523
+
524
+ var base_url = 'https://amp.pharm.mssm.edu/Enrichr/enrich?';
525
+ var library_string = 'backgroundType=' + String(library);
526
+ var list_id_string = 'userListId=' + String(enr_obj.user_list_id);
527
+
528
+ var full_url = base_url + library_string + '&' + list_id_string;
529
+
530
+ // get request
531
+ var settings = {
532
+ "async": true,
533
+ "crossDomain": true,
534
+ "url": full_url,
535
+ "method": "GET",
536
+ "processData": false,
537
+ "contentType": false,
538
+ "mimeType": "multipart/form-data",
539
+ "data": form
540
+ }
541
+
542
+ $.ajax(settings)
543
+ .done(function (response, textStatus, jqXHR) {
544
+
545
+ response = JSON.parse(response);
546
+ enr_obj.enr_data = response;
547
+
548
+ // parse enr_data to cat_data format
549
+ /////////////////////////////////////
550
+ // enr_obj.cat_data = enr_obj.enr_data
551
+ enr_obj.enr_data_to_cats();
552
+
553
+ if (typeof callback_function != 'undefined'){
554
+ callback_function(enr_obj);
555
+ }
556
+ d3.select(inst_cgm.params.root+' .enr_wait_circle').remove();
557
+
558
+ })
559
+ .fail(function( jqXHR, textStatus, errorThrown ){
560
+
561
+ enr_obj.get_tries = enr_obj.get_tries + 1;
562
+
563
+ if (enr_obj.get_tries < 2){
564
+ // enr_obj.get_enr(library, callback_function);
565
+ setTimeout( enr_obj.get_enr, 500, library_string, callback_function )
566
+ } else {
567
+ console.log('did not get response from Enrichr - need to remove wait circle')
568
+ d3.select(inst_cgm.params.root+' .enr_wait_circle').remove();
569
+ }
570
+
571
+ });
572
+
573
+ } else {
574
+ console.log('no user_list_id defined')
575
+ }
576
+ }
577
+
578
+ function enrichr_rows(library, callback_function, num_terms){
579
+
580
+ // set up a variable number of terms
581
+
582
+ enr_obj.library = library;
583
+ var gene_list = inst_cgm.params.network_data.row_nodes_names;
584
+ enr_obj.get_enr_with_list(gene_list, library, callback_function)
585
+
586
+ }
587
+
588
+ function enr_data_to_cats(){
589
+
590
+ var library_name = _.keys(this.enr_data)[0];
591
+
592
+ var enr_terms = this.enr_data[library_name];
593
+
594
+ // keep the top 10 enriched terms
595
+ enr_terms = enr_terms.slice(0,10);
596
+
597
+ cat_data = []
598
+
599
+ _.each(enr_terms, function(inst_term){
600
+
601
+ inst_data = {};
602
+ inst_data['cat_title'] = inst_term[1];
603
+ inst_data['cats'] = [];
604
+ inst_data['pval'] = inst_term[2];
605
+
606
+ // keep the combined score
607
+ inst_data['combined_score'] = inst_term[4]
608
+
609
+ cat_details = {};
610
+ cat_details.cat_name = 'true';
611
+ cat_details.members = inst_term[5]
612
+
613
+ // there are only two categories for Enrichr: true/false
614
+ inst_data['cats'].push(cat_details)
615
+
616
+ cat_data.push(inst_data);
617
+ });
618
+
619
+ this.cat_data = cat_data;
620
+
621
+ }
622
+
623
+ function animate_wait() {
624
+
625
+ var repeat_time = 700;
626
+ var max_opacity = 0.8;
627
+ var min_opacity = 0.2
628
+
629
+ d3.select(inst_cgm.params.root+' .enr_wait_circle')
630
+ .transition()
631
+ .ease('linear')
632
+ .style('opacity', min_opacity)
633
+ .transition()
634
+ .ease('linear')
635
+ .duration(repeat_time)
636
+ .style('opacity', max_opacity)
637
+ .transition()
638
+ .ease('linear')
639
+ .duration(repeat_time)
640
+ .style('opacity', min_opacity)
641
+ .each("end", animate_wait);
642
+ }
643
+
644
+ function update_viz_callback(enr_obj){
645
+
646
+ inst_cgm.update_cats(enr_obj.cat_data);
647
+
648
+ // Enrichrgram title
649
+ ////////////////////
650
+ d3.select(inst_cgm.params.root+' .enr_title').remove();
651
+
652
+ var enr_title = d3.select(inst_cgm.params.root+' .viz_svg')
653
+ .append('g')
654
+ .classed('enr_title', true)
655
+ .attr('transform', function(){
656
+
657
+ var trans = d3.select(inst_cgm.params.root+' .row_cat_label_container')
658
+ .attr('transform').split('(')[1].split(')')[0];
659
+ x_offset = Number(trans.split(',')[0]) - 10;
660
+
661
+ return 'translate('+ String(x_offset)+', 0)';
662
+
663
+ });
664
+
665
+ enr_title
666
+ .append('rect')
667
+ .attr('width', inst_cgm.params.viz.cat_room.row)
668
+ .attr('height', 25)
669
+ .attr('fill', 'white');
670
+
671
+ var library_string = enr_obj.library.substring(0,40);
672
+ enr_title
673
+ .append('text')
674
+ .attr('transform', 'translate(0, 17)')
675
+ .text(library_string.replace(/_/g, ' '))
676
+ .style('font-size', '15px')
677
+ .attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif');
678
+
679
+ var extra_y_room = 1.25;
680
+ var unit_length = extra_y_room * inst_cgm.params.viz.cat_room.symbol_width;
681
+ var bar_width = unit_length * 0.9;
682
+
683
+ // Enrichr bars
684
+ ///////////////////////////////
685
+ d3.selectAll(inst_cgm.params.root+' .enrichr_bars').remove();
686
+
687
+ var bar_height = inst_cgm.params.viz.clust.margin.top - 35;
688
+ var max_score = enr_obj.cat_data[0].combined_score;
689
+ var bar_scale = d3.scale.linear()
690
+ .domain([0, max_score])
691
+ .range([0, bar_height]);
692
+
693
+ d3.select(inst_cgm.params.root+' .row_cat_label_bar_container')
694
+ .selectAll()
695
+ .data(inst_cgm.params.viz.all_cats.row)
696
+ .enter()
697
+ .append('rect')
698
+ .classed('enrichr_bars', true)
699
+ .attr('height', bar_width +'px')
700
+ .attr('fill', 'red')
701
+ .attr('width', function(d){
702
+ var enr_index = d.split('-')[1];
703
+ var inst_comb_score = enr_obj.cat_data[enr_index].combined_score;
704
+ var bar_lenth = bar_scale(inst_comb_score);
705
+ var bar_length_string = bar_lenth + 'px'
706
+ return bar_length_string;
707
+ })
708
+ .attr('opacity', 0.4)
709
+ .attr('transform', function(d){
710
+ var inst_y = unit_length * (parseInt( d.split('-')[1], 10 ) -0.75 );
711
+ return 'translate(0,'+inst_y+')';
712
+ });
713
+
714
+ }
715
+
716
+ function make_enr_wait_circle(){
717
+ var pos_x = 72;
718
+ var pos_y = 25;
719
+
720
+ var click_circle = d3.select(inst_cgm.params.root+' .viz_svg')
721
+ .append('circle')
722
+ .classed('enr_wait_circle', true)
723
+ .attr('cx',pos_x)
724
+ .attr('cy',pos_y)
725
+ .attr('r',23)
726
+ .style('stroke','#666666')
727
+ .style('stroke-width','3px')
728
+ .style('fill','white')
729
+ .style('fill-opacity',0)
730
+ .style('opacity', 0);
731
+ }
732
+
733
+ // example of how to check gene list
734
+ // http://amp.pharm.mssm.edu/Enrichr/view?userListId=1284420
735
+
736
+ var enr_obj = {};
737
+ enr_obj.user_list_id = null;
738
+ enr_obj.enr_data = null;
739
+ enr_obj.cat_data = null;
740
+ enr_obj.get_tries = 0;
741
+ enr_obj.library = null;
742
+ enr_obj.gene_list = null;
743
+
744
+ enr_obj.enrichr_icon = enrichr_icon;
745
+ enr_obj.post_list = post_list;
746
+ enr_obj.get_enr = get_enr;
747
+ enr_obj.get_enr_with_list = get_enr_with_list;
748
+ enr_obj.enrichr_rows = enrichr_rows;
749
+ enr_obj.enr_data_to_cats = enr_data_to_cats;
750
+ enr_obj.update_viz_callback = update_viz_callback;
751
+ enr_obj.clear_enrichr_results = clear_enrichr_results;
752
+
753
+ return enr_obj;
754
+
755
+ }