report_html 0.4.1 → 0.5.6

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.
@@ -137,8 +137,7 @@ class Report_html
137
137
  # DATA MANIPULATION METHODS
138
138
  #-------------------------------------------------------------------------------------
139
139
  def get_data(options)
140
- data = []
141
- data = extract_data(options)
140
+ data, smp_attr, var_attr = extract_data(options)
142
141
  if !data.empty?
143
142
  if @data_from_files # If data on container is loaded using html_report as lib, we don't care about data format
144
143
  # if data comes from files and is loaded as strings. We need to format correctly the data.
@@ -155,9 +154,14 @@ class Report_html
155
154
  end
156
155
  end
157
156
  add_header_row_names(data, options)
158
- data = data.transpose if options[:transpose]
157
+ if options[:transpose]
158
+ data = data.transpose
159
+ smp_attr_bkp = smp_attr
160
+ smp_attr = var_attr
161
+ var_attr = smp_attr_bkp
162
+ end
159
163
  end
160
- return data
164
+ return data, smp_attr, var_attr
161
165
  end
162
166
 
163
167
  def add_header_row_names(data, options)
@@ -176,6 +180,8 @@ class Report_html
176
180
 
177
181
  def extract_data(options)
178
182
  data = []
183
+ smp_attr = nil
184
+ var_attr = nil
179
185
  ids = options[:id]
180
186
  fields = options[:fields]
181
187
  ids = ids.split(',') if ids.class == String && ids.include?(',') # String syntax
@@ -193,16 +199,25 @@ class Report_html
193
199
  end
194
200
  else
195
201
  fields = fields.first if fields.class == Array
196
- data = extract_fields(ids, options[:fields])
202
+ smp_attr = process_attributes(extract_fields(ids, options[:smp_attr]), options[:var_attr], aggregated = true) if !options[:smp_attr].nil? && !options[:smp_attr].empty?
203
+ var_attr = process_attributes(extract_rows(ids, options[:var_attr]), options[:smp_attr], aggregated = false) if !options[:var_attr].nil? && !options[:var_attr].empty?
204
+ data = extract_fields(ids, options[:fields], del_fields = options[:smp_attr], del_rows = options[:var_attr])
197
205
  end
198
- return data
206
+ return data, smp_attr, var_attr
199
207
  end
200
208
 
201
- def extract_fields(id, fields)
209
+ def extract_fields(id, fields, del_fields = [], del_rows = [])
202
210
  data = []
203
- @hash_vars[id].each do |row|
211
+ @hash_vars[id].each_with_index do |row, i|
212
+ next if !del_rows.nil? && del_rows.include?(i)
204
213
  if fields.empty?
205
- data << row.dup # Dup generates a array copy that avoids to modify original objects on data manipulation creating graphs
214
+ row = row.dup # Dup generates a array copy that avoids to modify original objects on data manipulation creating graphs
215
+ if !del_fields.nil?
216
+ del_fields.sort.reverse_each do |j|
217
+ row.delete_at(j)
218
+ end
219
+ end
220
+ data << row
206
221
  else
207
222
  data << fields.map{|field| row[field]} #Map without bang do the same than dup
208
223
  end
@@ -210,6 +225,35 @@ class Report_html
210
225
  return data
211
226
  end
212
227
 
228
+ def extract_rows(id, rows)
229
+ table = @hash_vars[id]
230
+ data = rows.map{|field| table[field]}
231
+ return data
232
+ end
233
+
234
+ def process_attributes(attribs, delete_items, aggregated = false)
235
+ parsed_attr = []
236
+ if aggregated
237
+ if !delete_items.nil? && !delete_items.empty?
238
+ (1..delete_items.length).reverse_each do |ind|
239
+ attribs.delete_at(1)
240
+ end
241
+ end
242
+ attribs.first.length.times do |i|
243
+ parsed_attr << attribs.map{|at| at[i]}
244
+ end
245
+ else
246
+ attribs.each do |attrib|
247
+ if !delete_items.nil? && !delete_items.empty?
248
+ (1..delete_items.length).reverse_each do |ind|
249
+ attrib.delete_at(ind)
250
+ end
251
+ end
252
+ parsed_attr << attrib
253
+ end
254
+ end
255
+ return parsed_attr
256
+ end
213
257
  # TABLE METHODS
214
258
  #-------------------------------------------------------------------------------------
215
259
  def table(user_options = {}, &block)
@@ -220,13 +264,15 @@ class Report_html
220
264
  add_header_row_names: false,
221
265
  transpose: false,
222
266
  fields: [],
267
+ smp_attr: [],
268
+ var_attr: [],
223
269
  border: 1,
224
270
  cell_align: [],
225
271
  attrib: {}
226
272
  }
227
273
  options.merge!(user_options)
228
274
  table_attr = prepare_table_attribs(options[:attrib])
229
- array_data = get_data(options)
275
+ array_data, _, _ = get_data(options)
230
276
  block.call(array_data) if !block.nil?
231
277
  rowspan, colspan = get_col_n_row_span(array_data)
232
278
  table_id = 'table_' + @count_objects.to_s
@@ -329,7 +375,7 @@ class Report_html
329
375
  def add_sample_attributes(data_structure, options)
330
376
  parsed_sample_attributes = {}
331
377
  options[:sample_attributes].each do |key, col|
332
- data = get_data({id: options[:id], fields: [col], text: true})
378
+ data, _, _ = get_data({id: options[:id], fields: [col], text: true})
333
379
  data.shift if options[:header]
334
380
  parsed_sample_attributes[key] = data.flatten
335
381
  end
@@ -358,6 +404,9 @@ class Report_html
358
404
  options = {
359
405
  id: nil,
360
406
  fields: [],
407
+ smp_attr: [],
408
+ var_attr: [],
409
+ segregate: [],
361
410
  data_format: 'one_axis',
362
411
  responsive: true,
363
412
  height: '600px',
@@ -386,7 +435,7 @@ class Report_html
386
435
  # Data manipulation
387
436
  #------------------------------------------
388
437
  no_data_string = ERB.new("<div width=\"#{options[:width]}\" height=\"#{options[:height]}\" > <p>NO DATA<p></div>").result(binding)
389
- data_array = get_data(options)
438
+ data_array, smp_attr, var_attr = get_data(options)
390
439
  return no_data_string if data_array.empty?
391
440
  block.call(data_array) if !block.nil?
392
441
  object_id = "obj_#{@count_objects}_"
@@ -400,7 +449,11 @@ class Report_html
400
449
  end
401
450
  values = data_array
402
451
 
403
- yield(options, config, samples, vars, values, object_id)
452
+ x = {}
453
+ z = {}
454
+ add_canvas_attr(x, var_attr) if !var_attr.nil? && !var_attr.empty?
455
+ add_canvas_attr(z, smp_attr) if !smp_attr.nil? && !smp_attr.empty?
456
+ yield(options, config, samples, vars, values, object_id, x, z)
404
457
  # Build JSON objects and Javascript code
405
458
  #-----------------------------------------------
406
459
  @count_objects += 1
@@ -409,7 +462,9 @@ class Report_html
409
462
  'vars' => vars,
410
463
  'smps' => samples,
411
464
  'data' => values
412
- }
465
+ },
466
+ 'x' => x,
467
+ 'z' => z
413
468
  }
414
469
  events = false
415
470
  info = false
@@ -422,6 +477,7 @@ class Report_html
422
477
  end
423
478
  add_sample_attributes(data_structure, options) if !options[:sample_attributes].empty?
424
479
  extracode = "#{options[:extracode]}\n"
480
+ extracode << segregate_data("C#{object_id}", options[:segregate]) if !options[:segregate].empty?
425
481
  extracode << "C#{object_id}.groupSamples(#{options[:group_samples]})\n" if !options[:group_samples].nil?
426
482
  plot_data = "
427
483
  var data = #{data_structure.to_json};
@@ -438,11 +494,32 @@ class Report_html
438
494
  return ERB.new(html).result(binding)
439
495
  end
440
496
 
497
+ def segregate_data(obj_id, segregate)
498
+ string =""
499
+ segregate.each do |data_type, names|
500
+ if data_type == :var
501
+ string << "#{obj_id}.segregateVariables(#{names.inspect});\n"
502
+ elsif data_type == :smp
503
+ string << "#{obj_id}.segregateSamples(#{names.inspect});\n"
504
+ end
505
+ end
506
+ return string
507
+ end
508
+
509
+ def add_canvas_attr(hash_attr, attr2add)
510
+ attr2add.each do |attrs|
511
+ attr_name = attrs.shift
512
+ canvas_attr = []
513
+ attrs.each{|at| canvas_attr << "#{attr_name} : #{at}" }
514
+ hash_attr[attr_name] = canvas_attr
515
+ end
516
+ end
517
+
441
518
  def line(user_options = {}, &block)
442
519
  default_options = {
443
520
  row_names: true
444
521
  }.merge!(user_options)
445
- html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id|
522
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
446
523
  config['graphType'] = 'Line'
447
524
  end
448
525
  return html_string
@@ -452,7 +529,7 @@ class Report_html
452
529
  default_options = {
453
530
  row_names: true,
454
531
  }.merge!(user_options)
455
- html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id|
532
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
456
533
  config['graphType'] = 'Stacked'
457
534
  end
458
535
  return html_string
@@ -462,17 +539,33 @@ class Report_html
462
539
  default_options = {
463
540
  row_names: true
464
541
  }.merge!(user_options)
465
- html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id|
542
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
466
543
  config['graphType'] = 'Bar'
467
544
  end
468
545
  return html_string
469
546
  end
470
547
 
548
+ def dotplot(user_options = {}, &block)
549
+ default_options = {
550
+ row_names: true,
551
+ connect: false
552
+ }.merge!(user_options)
553
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
554
+ config['graphType'] = 'Dotplot'
555
+ if default_options[:connect]
556
+ config['dotplotType'] = "stacked"
557
+ config['connectBy'] = "Connect"
558
+ z[:Connect] = Array.new(vars.length, 1)
559
+ end
560
+ end
561
+ return html_string
562
+ end
563
+
471
564
  def heatmap(user_options = {}, &block)
472
565
  default_options = {
473
566
  row_names: true
474
567
  }.merge!(user_options)
475
- html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id|
568
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
476
569
  config['graphType'] = 'Heatmap'
477
570
  end
478
571
  return html_string
@@ -483,7 +576,7 @@ class Report_html
483
576
  row_names: true,
484
577
  header: true
485
578
  }.merge!(user_options)
486
- html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id|
579
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
487
580
  config['graphType'] = 'Boxplot'
488
581
  options[:mod_data_structure] = 'boxplot'
489
582
  if options[:extracode].nil?
@@ -497,7 +590,7 @@ class Report_html
497
590
  default_options = {
498
591
  transpose: false
499
592
  }.merge!(user_options)
500
- html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id|
593
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
501
594
  config['graphType'] = 'Pie'
502
595
  if samples.length > 1
503
596
  config['showPieGrid'] = true
@@ -509,12 +602,24 @@ class Report_html
509
602
  return html_string
510
603
  end
511
604
 
605
+ def corplot(user_options = {}, &block)
606
+ default_options = {
607
+ transpose: false,
608
+ correlationAxis: 'samples'
609
+ }.merge!(user_options)
610
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
611
+ config['graphType'] = 'Correlation'
612
+ config['correlationAxis'] = default_options[:correlationAxis]
613
+ end
614
+ return html_string
615
+ end
616
+
512
617
  def sccater2D(user_options = {}, &block)
513
618
  default_options = {
514
619
  row_names: false,
515
620
  transpose: false
516
621
  }.merge!(user_options)
517
- html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id|
622
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
518
623
  config['graphType'] = 'Scatter2D'
519
624
  config['xAxis'] = [samples.first] if config['xAxis'].nil?
520
625
  config['yAxis'] = samples[1..samples.length-1] if config['yAxis'].nil?
@@ -537,7 +642,7 @@ class Report_html
537
642
  row_names: true,
538
643
  transpose: false
539
644
  }.merge!(user_options)
540
- html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id|
645
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
541
646
  config['graphType'] = 'ScatterBubble2D'
542
647
  if options[:xAxis].nil?
543
648
  config['xAxis'] = [samples[0]]
@@ -579,7 +684,7 @@ class Report_html
579
684
  ringsType: [],
580
685
  ringsWeight: []
581
686
  }.merge!(user_options)
582
- html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id|
687
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
583
688
  options[:mod_data_structure] = 'circular'
584
689
  config['graphType'] = 'Circular'
585
690
  config['segregateVariablesBy'] = ['Ring']
@@ -601,7 +706,7 @@ class Report_html
601
706
  end
602
707
  if !default_options[:links].nil?
603
708
  if !@hash_vars[default_options[:links]].nil? && !@hash_vars[default_options[:links]].empty?
604
- link_data = get_data({id: default_options[:links], fields: [], add_header_row_names: false, text: true, transpose: false})
709
+ link_data, _, _ = get_data({id: default_options[:links], fields: [], add_header_row_names: false, text: true, transpose: false})
605
710
  config['connections'] = assign_rgb(link_data)
606
711
  end
607
712
  end
@@ -631,6 +736,39 @@ class Report_html
631
736
  end
632
737
  end
633
738
 
739
+ def circular_genome(user_options = {}, &block)
740
+ default_options = {}.merge!(user_options)
741
+ coordinates = user_options[:genomic_coordinates]
742
+ html_string = canvasXpress_main(default_options, block) do |options, config, samples, vars, values, object_id, x, z|
743
+ config['graphType'] = 'Circular'
744
+ config["arcSegmentsSeparation"] = 3
745
+ config["colorScheme"] = "Tableau"
746
+ config["colors"] = ["#332288","#6699CC","#88CCEE","#44AA99","#117733","#999933","#DDCC77","#661100","#CC6677","#AA4466","#882255","#AA4499"]
747
+ config["showIdeogram"] = true
748
+ chr = []
749
+ pos = []
750
+ tags2remove = []
751
+ vars.each_with_index do |var, i|
752
+ coord = coordinates[var]
753
+ if !coord.nil?
754
+ tag = coord.first.gsub(/[^\dXY]/,'')
755
+ if tag == 'X' || tag == 'Y' || (tag.to_i > 0 && tag.to_i <= 22)
756
+ chr << coord.first.gsub(/[^\dXY]/,'')
757
+ pos << coord.last - 1
758
+ else
759
+ tags2remove << i
760
+ end
761
+ else
762
+ tags2remove << i
763
+ end
764
+ end
765
+ tags2remove.reverse_each{|i| ent = vars.delete_at(i); warn("Feature #{ent} has not valid coordinates")} # Remove entities with invalid coordinates
766
+ z['chr'] = chr
767
+ z['pos'] = pos
768
+ end
769
+ return html_string
770
+ end
771
+
634
772
  # EMBED FILES
635
773
  ###################################################################################
636
774
 
@@ -1,3 +1,3 @@
1
1
  module ReportHtml
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: report_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - seoanezonjic
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-01 00:00:00.000000000 Z
11
+ date: 2022-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,9 +62,7 @@ files:
62
62
  - bin/report_html
63
63
  - bin/setup
64
64
  - js/canvasXpress.css
65
- - js/canvasXpress.css_old
66
65
  - js/canvasXpress.min.js
67
- - js/canvasXpress.min.js_old
68
66
  - js/canvasXpress_license
69
67
  - lib/report_html.rb
70
68
  - lib/report_html/report_html.rb
@@ -74,7 +72,7 @@ homepage: ''
74
72
  licenses:
75
73
  - MIT
76
74
  metadata: {}
77
- post_install_message:
75
+ post_install_message:
78
76
  rdoc_options: []
79
77
  require_paths:
80
78
  - lib
@@ -89,9 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
87
  - !ruby/object:Gem::Version
90
88
  version: '0'
91
89
  requirements: []
92
- rubyforge_project:
93
- rubygems_version: 2.6.14
94
- signing_key:
90
+ rubygems_version: 3.2.15
91
+ signing_key:
95
92
  specification_version: 4
96
93
  summary: Gem to build html interactive reports.
97
94
  test_files: []