Class: ViennaRna::Package::EnergyGrid2d
- Inherits:
-
Base
- Object
- Base
- ViennaRna::Package::EnergyGrid2d
show all
- Includes:
- Enumerable
- Defined in:
- lib/vienna_rna/package/energy_grid_2d.rb
Defined Under Namespace
Modules: EnergyGrid2dWrapper
Classes: Row2d
Instance Attribute Summary
Attributes inherited from Base
#data, #response, #runtime
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
bootstrap, #debugger, #initialize, #serialize
included
included
Class Method Details
.aligned_distributions(*energy_grids) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/vienna_rna/package/energy_grid_2d.rb', line 40
def self.aligned_distributions(*energy_grids)
point_set = set_of_points(*energy_grids)
energy_grids.map do |grid|
(grid.distribution + (point_set - grid.map(&:position)).map { |i, j| Row2d.new(i, j, 0, Float::INFINITY) }).sort
end
end
|
.inherited(subclass) ⇒ Object
6
7
8
|
# File 'lib/vienna_rna/package/energy_grid_2d.rb', line 6
def self.inherited(subclass)
subclass.class_eval { prepend EnergyGrid2dWrapper }
end
|
.set_of_points(*energy_grids) ⇒ Object
48
49
50
|
# File 'lib/vienna_rna/package/energy_grid_2d.rb', line 48
def self.set_of_points(*energy_grids)
energy_grids.inject([]) { |list, grid| list + grid.map(&:position) }.uniq.sort
end
|
Instance Method Details
#each(&block) ⇒ Object
52
53
54
|
# File 'lib/vienna_rna/package/energy_grid_2d.rb', line 52
def each(&block)
distribution.each(&block)
end
|
#inspect ⇒ Object
76
77
78
|
# File 'lib/vienna_rna/package/energy_grid_2d.rb', line 76
def inspect
"#<#{self.class.name} on #{data.inspect}>"
end
|
#quick_plot(num_colors: 8) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/vienna_rna/package/energy_grid_2d.rb', line 56
def quick_plot(num_colors: 8)
Graphing::R.matrix_heatmap(
distribution.map(&:i),
distribution.map(&:j),
distribution.map { |row| Math.log(row.p) },
title: "#{self.class.name} Matrix Heatmap",
x_label: "Distance from structure 2",
y_label: "Distance from structure 1",
num_colors: num_colors
)
end
|
#to_csv(energy_term: :p) ⇒ Object
68
69
70
|
# File 'lib/vienna_rna/package/energy_grid_2d.rb', line 68
def to_csv(energy_term: :p)
map { |row| row.to_csv(energy_term: energy_term) }.join(?\n) + ?\n
end
|
#to_csv!(filename, energy_term: :p) ⇒ Object
72
73
74
|
# File 'lib/vienna_rna/package/energy_grid_2d.rb', line 72
def to_csv!(filename, energy_term: :p)
File.open(filename, ?w) { |file| file.write(to_csv(energy_term: energy_term)) }
end
|