vienna_rna 0.8.6 → 0.9.0
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 +4 -4
- data/lib/vienna_rna/global/parser.rb +19 -0
- data/lib/vienna_rna/global/rna.rb +115 -0
- data/lib/vienna_rna/global/rna_extensions.rb +109 -0
- data/lib/vienna_rna/{modules/graphing.rb → graphing/r.rb} +49 -111
- data/lib/vienna_rna/package/base.rb +117 -0
- data/lib/vienna_rna/package/energy_grid_2d.rb +69 -0
- data/lib/vienna_rna/package/eval.rb +11 -0
- data/lib/vienna_rna/package/fftbor.rb +19 -0
- data/lib/vienna_rna/package/fftbor2d.rb +25 -0
- data/lib/vienna_rna/package/fold.rb +31 -0
- data/lib/vienna_rna/package/heat.rb +15 -0
- data/lib/vienna_rna/package/rna2dfold.rb +27 -0
- data/lib/vienna_rna/package/rnabor.rb +32 -0
- data/lib/vienna_rna/package/subopt.rb +19 -0
- data/lib/vienna_rna/package/xbor.rb +63 -0
- data/lib/vienna_rna.rb +27 -14
- metadata +22 -38
- data/lib/vienna_rna/modules/base.rb +0 -124
- data/lib/vienna_rna/modules/batch.rb +0 -26
- data/lib/vienna_rna/modules/energy_grid_2d.rb +0 -63
- data/lib/vienna_rna/modules/eval.rb +0 -9
- data/lib/vienna_rna/modules/fftbor.rb +0 -21
- data/lib/vienna_rna/modules/fftbor2d.rb +0 -23
- data/lib/vienna_rna/modules/ffthairpin.rb +0 -4
- data/lib/vienna_rna/modules/fftmultiloop.rb +0 -4
- data/lib/vienna_rna/modules/fold.rb +0 -29
- data/lib/vienna_rna/modules/heat.rb +0 -13
- data/lib/vienna_rna/modules/parser.rb +0 -17
- data/lib/vienna_rna/modules/rna.rb +0 -113
- data/lib/vienna_rna/modules/rna2dfold.rb +0 -25
- data/lib/vienna_rna/modules/rna_extensions.rb +0 -101
- data/lib/vienna_rna/modules/rnabor.rb +0 -33
- data/lib/vienna_rna/modules/subopt.rb +0 -17
- data/lib/vienna_rna/modules/utils.rb +0 -34
- data/lib/vienna_rna/modules/xbor.rb +0 -64
@@ -0,0 +1,31 @@
|
|
1
|
+
module ViennaRna
|
2
|
+
module Package
|
3
|
+
class Fold < Base
|
4
|
+
BASE_FLAGS = {
|
5
|
+
"-noPS" => :empty
|
6
|
+
}
|
7
|
+
|
8
|
+
attr_reader :mfe_rna, :structure, :mfe
|
9
|
+
|
10
|
+
def post_process
|
11
|
+
structure = ViennaRna::Global::Parser.rnafold_mfe_structure(@response)
|
12
|
+
|
13
|
+
unless data.seq.length == structure.length
|
14
|
+
raise "Sequence: '#{data.seq}'\nStructure: '#{structure}'"
|
15
|
+
else
|
16
|
+
@mfe_rna, @structure, @mfe = RNA.from_string(data.seq, structure), structure, ViennaRna::Global::Parser.rnafold_mfe(@response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Batch
|
21
|
+
def with_different_structures
|
22
|
+
run.inject(Hash.new { |hash, key| hash[key] = [] }) do |hash, folded_sequence|
|
23
|
+
hash.tap do
|
24
|
+
hash[folded_sequence.structure] << folded_sequence
|
25
|
+
end
|
26
|
+
end.values.map(&:first)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ViennaRna
|
2
|
+
module Package
|
3
|
+
class Heat < Base
|
4
|
+
attr_reader :specific_heats
|
5
|
+
|
6
|
+
def post_process
|
7
|
+
@specific_heats = @response.split(/\n/).map { |line| line.split(/\s+/).map(&:to_f) }.inject({}) do |hash, (temp, specific_heat)|
|
8
|
+
hash.tap do
|
9
|
+
hash[temp] = specific_heat
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ViennaRna
|
2
|
+
module Package
|
3
|
+
class Rna2dfold < EnergyGrid2d
|
4
|
+
BASE_FLAGS = {
|
5
|
+
d: 0,
|
6
|
+
p: :empty,
|
7
|
+
"-noBT" => :empty
|
8
|
+
}
|
9
|
+
|
10
|
+
self.executable_name = "RNA2Dfold"
|
11
|
+
|
12
|
+
def run_command(flags = {})
|
13
|
+
ViennaRna.debugger { "Running RNA2Dfold on #{data.inspect}" }
|
14
|
+
|
15
|
+
"cat %s | %s %s" % [
|
16
|
+
data.temp_fa_file!,
|
17
|
+
exec_name,
|
18
|
+
stringify_flags(BASE_FLAGS.merge(self.class.const_defined?(:FLAGS) ? self.class.const_get(:FLAGS) : {}).merge(flags))
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
def distribution
|
23
|
+
response.split(/\n/)[6..-1].map { |line| line.split(/\t/).at_indexes([0, 1, 2, 6]) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ViennaRna
|
2
|
+
module Package
|
3
|
+
class Rnabor < Xbor
|
4
|
+
FLAGS = {
|
5
|
+
nodangle: :empty
|
6
|
+
}
|
7
|
+
|
8
|
+
def partition
|
9
|
+
non_zero_shells.inject(&:+)
|
10
|
+
end
|
11
|
+
|
12
|
+
def total_count
|
13
|
+
counts.inject(&:+)
|
14
|
+
end
|
15
|
+
|
16
|
+
def counts
|
17
|
+
(non_zero_counts = self.class.parse(response).map { |row| BigDecimal.new(row[2]).to_i }) + [0] * (data.seq.length - non_zero_counts.length + 1)
|
18
|
+
end
|
19
|
+
|
20
|
+
def distribution(options = {})
|
21
|
+
options = { precision: 4 }.merge(options)
|
22
|
+
|
23
|
+
distribution_before_precision = (non_zero_distribution = non_zero_shells.map { |i| i / partition }) + [0.0] * (data.seq.length - non_zero_distribution.length + 1)
|
24
|
+
distribution_before_precision.map { |value| options[:precision].zero? ? value : (value * 10 ** options[:precision]).truncate / 10.0 ** options[:precision] }
|
25
|
+
end
|
26
|
+
|
27
|
+
def non_zero_shells
|
28
|
+
self.class.parse(response).map { |row| BigDecimal.new(row[1]) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ViennaRna
|
2
|
+
module Package
|
3
|
+
class Subopt < Base
|
4
|
+
attr_reader :structures
|
5
|
+
|
6
|
+
def post_process
|
7
|
+
@structures = @response.split(/\n/)[1..-1].map { |output| RNA.from_string(data.seq, output.split(/\s+/).first) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def bin(count = 1)
|
11
|
+
run(p: count).structures.inject(Hash.new { |hash, key| hash[key] = 0 }) do |hash, structure|
|
12
|
+
hash.tap do
|
13
|
+
hash[structure] += 1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module ViennaRna
|
2
|
+
module Package
|
3
|
+
class Xbor < Base
|
4
|
+
BASE_FLAGS = {
|
5
|
+
E: "/usr/local/bin/energy.par"
|
6
|
+
}
|
7
|
+
|
8
|
+
self.executable_name = -> { name.demodulize.gsub(/^([A-Z].*)bor$/) { |match| $1.upcase + "bor" } }
|
9
|
+
|
10
|
+
def run_command(flags = {})
|
11
|
+
file = Tempfile.new("rna")
|
12
|
+
file.write("%s\n" % data.seq)
|
13
|
+
file.write("%s\n" % data.str)
|
14
|
+
file.close
|
15
|
+
|
16
|
+
ViennaRna.debugger { "Running FFTbor on #{data.inspect}" }
|
17
|
+
|
18
|
+
"%s %s %s" % [
|
19
|
+
exec_name,
|
20
|
+
stringify_flags(BASE_FLAGS.merge(self.class.const_defined?(:FLAGS) ? self.class.const_get(:FLAGS) : {}).merge(flags)),
|
21
|
+
file.path
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.bootstrap_from_file(path, klass = self)
|
26
|
+
log = File.read(path)
|
27
|
+
sequence = log.split(/\n/).first.split(/\s+/)[1]
|
28
|
+
structure = log.split(/\n/).first.split(/\s+/)[2]
|
29
|
+
|
30
|
+
klass.bootstrap(RNA.from_string(sequence, structure), log)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.parse(response)
|
34
|
+
response.split(/\n/).select { |line| line =~ /^\d+\t-?\d+/ }.map { |line| line.split(/\t/) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def full_distribution
|
38
|
+
distribution = run.distribution
|
39
|
+
full_distribution = distribution + ([0.0] * ((differnece = data.seq.length - distribution.length + 1) < 0 ? 0 : differnece))
|
40
|
+
end
|
41
|
+
|
42
|
+
def k_p_points
|
43
|
+
full_distribution.each_with_index.to_a.map(&:reverse)[0..data.seq.length]
|
44
|
+
end
|
45
|
+
|
46
|
+
def expected_k
|
47
|
+
k_p_points.map { |array| array.inject(&:*) }.inject(&:+)
|
48
|
+
end
|
49
|
+
|
50
|
+
def quick_plot(options = {})
|
51
|
+
ViennaRna::Graphing::Gnuplot.quick_plot(
|
52
|
+
k_p_points,
|
53
|
+
options[:title] || "%s\\n%s\\n%s" % [self.class.name, data.seq, data.safe_structure],
|
54
|
+
options
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def inspect
|
59
|
+
"#<#{self.class.name} #{data.inspect}>"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/vienna_rna.rb
CHANGED
@@ -1,33 +1,46 @@
|
|
1
|
+
require "benchmark"
|
1
2
|
require "set"
|
2
3
|
require "bio"
|
3
4
|
require "shuffle"
|
4
5
|
require "matrix"
|
5
|
-
require "gnuplot"
|
6
6
|
require "rinruby"
|
7
7
|
require "rroc"
|
8
|
+
require "tempfile"
|
9
|
+
require "bigdecimal"
|
10
|
+
require "diverge"
|
8
11
|
require "active_support/inflector"
|
9
12
|
require "active_support/core_ext/class"
|
10
13
|
require "active_support/core_ext/module/aliasing"
|
11
14
|
|
15
|
+
require "vienna_rna/global/rna_extensions"
|
16
|
+
require "vienna_rna/global/rna"
|
17
|
+
require "vienna_rna/global/parser"
|
18
|
+
require "vienna_rna/graphing/r"
|
19
|
+
require "vienna_rna/package/base"
|
20
|
+
|
12
21
|
begin; R.quit; rescue IOError; end
|
13
22
|
|
14
23
|
module ViennaRna
|
15
24
|
@debug = true
|
16
25
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
module Package
|
27
|
+
Dir[File.join(File.dirname(__FILE__), "vienna_rna", "package", "*.rb")].reject { |file| file =~ /\/base.rb/ }.each do |file|
|
28
|
+
# Doesn't support autoloading modules that are of the form: TwoWords
|
29
|
+
autoload(File.basename(file, ".rb").camelize.to_sym, "vienna_rna/package/#{File.basename(file, '.rb')}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.const_missing(name)
|
33
|
+
if Base.exec_exists?(name)
|
34
|
+
module_eval do
|
35
|
+
const_set(name, Class.new(Base))
|
36
|
+
end
|
28
37
|
end
|
29
38
|
end
|
30
39
|
end
|
40
|
+
|
41
|
+
def self.deserialize(string)
|
42
|
+
YAML.load(File.exist?(string) ? File.read(string) : string)
|
43
|
+
end
|
31
44
|
|
32
45
|
def self.debugger
|
33
46
|
STDERR.puts yield if ViennaRna.debug
|
@@ -52,7 +65,7 @@ end
|
|
52
65
|
module RNA
|
53
66
|
def self.method_missing(name, *args, &block)
|
54
67
|
if "#{name}" =~ /^from_\w+$/
|
55
|
-
ViennaRna::Rna.send("init_#{name}", *args)
|
68
|
+
ViennaRna::Global::Rna.send("init_#{name}", *args)
|
56
69
|
else super end
|
57
70
|
end
|
58
|
-
end
|
71
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vienna_rna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Senter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bio
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.1.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: gnuplot
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2.5.0
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2.5.0
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rinruby
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,31 +80,28 @@ dependencies:
|
|
94
80
|
- - '>='
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: 0.1.1
|
97
|
-
description: A Ruby 2.0 API for interacting with
|
83
|
+
description: A Ruby 2.0 API for interacting with command line tools involving RNA
|
84
|
+
molecules through a standard interface.
|
98
85
|
email: evansenter@gmail.com
|
99
86
|
executables: []
|
100
87
|
extensions: []
|
101
88
|
extra_rdoc_files: []
|
102
89
|
files:
|
103
|
-
- lib/vienna_rna/
|
104
|
-
- lib/vienna_rna/
|
105
|
-
- lib/vienna_rna/
|
106
|
-
- lib/vienna_rna/
|
107
|
-
- lib/vienna_rna/
|
108
|
-
- lib/vienna_rna/
|
109
|
-
- lib/vienna_rna/
|
110
|
-
- lib/vienna_rna/
|
111
|
-
- lib/vienna_rna/
|
112
|
-
- lib/vienna_rna/
|
113
|
-
- lib/vienna_rna/
|
114
|
-
- lib/vienna_rna/
|
115
|
-
- lib/vienna_rna/
|
116
|
-
- lib/vienna_rna/
|
117
|
-
- lib/vienna_rna/
|
118
|
-
- lib/vienna_rna/modules/rnabor.rb
|
119
|
-
- lib/vienna_rna/modules/subopt.rb
|
120
|
-
- lib/vienna_rna/modules/utils.rb
|
121
|
-
- lib/vienna_rna/modules/xbor.rb
|
90
|
+
- lib/vienna_rna/global/parser.rb
|
91
|
+
- lib/vienna_rna/global/rna.rb
|
92
|
+
- lib/vienna_rna/global/rna_extensions.rb
|
93
|
+
- lib/vienna_rna/graphing/r.rb
|
94
|
+
- lib/vienna_rna/package/base.rb
|
95
|
+
- lib/vienna_rna/package/energy_grid_2d.rb
|
96
|
+
- lib/vienna_rna/package/eval.rb
|
97
|
+
- lib/vienna_rna/package/fftbor.rb
|
98
|
+
- lib/vienna_rna/package/fftbor2d.rb
|
99
|
+
- lib/vienna_rna/package/fold.rb
|
100
|
+
- lib/vienna_rna/package/heat.rb
|
101
|
+
- lib/vienna_rna/package/rna2dfold.rb
|
102
|
+
- lib/vienna_rna/package/rnabor.rb
|
103
|
+
- lib/vienna_rna/package/subopt.rb
|
104
|
+
- lib/vienna_rna/package/xbor.rb
|
122
105
|
- lib/vienna_rna.rb
|
123
106
|
- README.md
|
124
107
|
homepage: http://rubygems.org/gems/vienna_rna
|
@@ -140,8 +123,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
123
|
version: '0'
|
141
124
|
requirements: []
|
142
125
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.1.2
|
144
127
|
signing_key:
|
145
128
|
specification_version: 4
|
146
|
-
summary: Bindings to the Vienna RNA package
|
129
|
+
summary: Bindings to the Vienna RNA package, and other major command line utilities
|
130
|
+
for RNA.
|
147
131
|
test_files: []
|
@@ -1,124 +0,0 @@
|
|
1
|
-
require "benchmark"
|
2
|
-
|
3
|
-
module ViennaRna
|
4
|
-
class Base
|
5
|
-
class_attribute :executable_name
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def method_added(name)
|
9
|
-
if name == :run
|
10
|
-
unless @chaining
|
11
|
-
@chaining = true
|
12
|
-
alias_method_chain :run, :hooks
|
13
|
-
else
|
14
|
-
remove_instance_variable(:@chaining)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def exec_exists?(name)
|
20
|
-
!%x[which RNA#{name.to_s.downcase}].empty?
|
21
|
-
end
|
22
|
-
|
23
|
-
def run(*data)
|
24
|
-
flags = data.length > 1 && data.last.is_a?(Hash) ? data.pop : {}
|
25
|
-
new(data).run(flags)
|
26
|
-
end
|
27
|
-
|
28
|
-
def bootstrap(data: nil, output: "")
|
29
|
-
new(data).tap do |object|
|
30
|
-
object.instance_variable_set(:@response, File.exist?(output) ? File.read(output).chomp : output)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Time to redo batch stuff.
|
35
|
-
def batch(fastas = [])
|
36
|
-
ViennaRna::Batch.new(self, fastas).tap do |batch|
|
37
|
-
if const_defined?(:Batch)
|
38
|
-
@@me = self
|
39
|
-
|
40
|
-
batch.singleton_class.class_eval { include @@me.const_get(:Batch) }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
attr_reader :data, :response, :runtime
|
47
|
-
|
48
|
-
def exec_name
|
49
|
-
if executable_name
|
50
|
-
executable_name.respond_to?(:call) ? self.class.module_exec(&executable_name) : executable_name
|
51
|
-
else
|
52
|
-
"RNA#{self.class.name.split('::').last.underscore}"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def exec_sequence_format
|
57
|
-
if data.str
|
58
|
-
'"%s
|
59
|
-
%s"' % [data.seq, data.str]
|
60
|
-
else
|
61
|
-
data.seq
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def initialize(data)
|
66
|
-
data = [data] unless data.is_a?(Array)
|
67
|
-
|
68
|
-
@data = case data.map(&:class)
|
69
|
-
when [Rna] then data.first
|
70
|
-
when *(1..3).map { |i| [String] * i } then Rna.init_from_string(*data)
|
71
|
-
when [Hash] then Rna.init_from_hash(*data)
|
72
|
-
when [Array] then Rna.init_from_array(*data)
|
73
|
-
when [NilClass] then Rna.placeholder
|
74
|
-
else raise TypeError.new("Unsupported ViennaRna::Rna#initialize format: #{data}")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def run_with_hooks(flags = {})
|
79
|
-
unless @response
|
80
|
-
tap do
|
81
|
-
@runtime = Benchmark.measure do
|
82
|
-
pre_run_check unless respond_to?(:run_command)
|
83
|
-
@response = run_without_hooks(flags)
|
84
|
-
post_process if respond_to?(:post_process)
|
85
|
-
end
|
86
|
-
|
87
|
-
ViennaRna.debugger { "Total runtime: %.3f sec." % runtime.real }
|
88
|
-
end
|
89
|
-
else
|
90
|
-
self
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def pre_run_check
|
95
|
-
if %x[which #{exec_name}].empty?
|
96
|
-
raise RuntimeError.new("#{exec_name} is not defined on this machine")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def stringify_flags(flags)
|
101
|
-
base_flags = self.class.const_defined?(:BASE_FLAGS) ? self.class.const_get(:BASE_FLAGS) : {}
|
102
|
-
|
103
|
-
flags.merge(base_flags).inject("") do |string, (flag, value)|
|
104
|
-
(string + (value == :empty ? " -%s" % flag : " -%s %s" % [flag, value])).strip
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def run(flags = {})
|
109
|
-
command = if respond_to?(:run_command)
|
110
|
-
method(:run_command).arity.zero? ? run_command : run_command(flags)
|
111
|
-
else
|
112
|
-
"echo #{exec_sequence_format} | #{exec_name} #{stringify_flags(flags)}"
|
113
|
-
end
|
114
|
-
|
115
|
-
ViennaRna.debugger { command }
|
116
|
-
|
117
|
-
%x[#{command}]
|
118
|
-
end
|
119
|
-
|
120
|
-
def debugger(&block)
|
121
|
-
self.class.debugger(&block)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module ViennaRna
|
2
|
-
class Batch
|
3
|
-
include Enumerable
|
4
|
-
|
5
|
-
attr_reader :type, :collection
|
6
|
-
|
7
|
-
def initialize(type, data)
|
8
|
-
@type = type
|
9
|
-
@collection = data.map(&type.method(:new))
|
10
|
-
end
|
11
|
-
|
12
|
-
def each
|
13
|
-
collection.each { |element| yield element }
|
14
|
-
end
|
15
|
-
|
16
|
-
def run(flags = {})
|
17
|
-
tap do
|
18
|
-
if (@memo ||= {})[flags]
|
19
|
-
@memo[flags]
|
20
|
-
else
|
21
|
-
@memo[flags] = map { |element| element.run(flags) }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module ViennaRna
|
2
|
-
class EnergyGrid2d < Base
|
3
|
-
include Enumerable
|
4
|
-
|
5
|
-
def self.inherited(subclass)
|
6
|
-
subclass.class_eval { prepend EnergyGrid2dWrapper }
|
7
|
-
end
|
8
|
-
|
9
|
-
module EnergyGrid2dWrapper
|
10
|
-
def distribution
|
11
|
-
super.map { |row| Row2d.new(*row) }.select { |row| row.p > 0 }.sort
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class Row2d
|
16
|
-
attr_reader :i, :j, :p, :ensemble
|
17
|
-
|
18
|
-
def initialize(i, j, p, ensemble)
|
19
|
-
@i, @j, @p, @ensemble = i.to_i, j.to_i, BigDecimal.new(p.to_s), BigDecimal.new(ensemble.to_s)
|
20
|
-
end
|
21
|
-
|
22
|
-
def position
|
23
|
-
[i, j]
|
24
|
-
end
|
25
|
-
|
26
|
-
def <=>(other_row)
|
27
|
-
i == other_row.i ? j <=> other_row.j : i <=> other_row.i
|
28
|
-
end
|
29
|
-
|
30
|
-
def inspect
|
31
|
-
"#<Row2d (%d, %d), p: %+f, ensemble: %+f>" % [i, j, p, ensemble]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.aligned_distributions(*energy_grids)
|
36
|
-
point_set = set_of_points(*energy_grids)
|
37
|
-
|
38
|
-
energy_grids.map do |grid|
|
39
|
-
(grid.distribution + (point_set - grid.map(&:position)).map { |i, j| Row2d.new(i, j, 0, Float::INFINITY) }).sort
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.set_of_points(*energy_grids)
|
44
|
-
energy_grids.inject([]) { |list, grid| list + grid.map(&:position) }.uniq.sort
|
45
|
-
end
|
46
|
-
|
47
|
-
def each(&block)
|
48
|
-
distribution.each(&block)
|
49
|
-
end
|
50
|
-
|
51
|
-
def quick_plot(num_colors: 8)
|
52
|
-
Graphing::R.matrix_heatmap(
|
53
|
-
distribution.map(&:i),
|
54
|
-
distribution.map(&:j),
|
55
|
-
distribution.map { |row| Math.log(row.p) },
|
56
|
-
title: "#{self.class.name} Matrix Heatmap",
|
57
|
-
x_label: "Distance from structure 2",
|
58
|
-
y_label: "Distance from structure 1",
|
59
|
-
num_colors: num_colors
|
60
|
-
)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "tempfile"
|
2
|
-
require "bigdecimal"
|
3
|
-
require "diverge"
|
4
|
-
|
5
|
-
module ViennaRna
|
6
|
-
class Fftbor < Xbor
|
7
|
-
def partition
|
8
|
-
response.split(/\n/).find { |line| line =~ /^Scaling factor.*:\s+(\d+\.\d+)/ }
|
9
|
-
BigDecimal.new($1)
|
10
|
-
end
|
11
|
-
|
12
|
-
def total_count
|
13
|
-
response.split(/\n/).find { |line| line =~ /^Number of structures: (\d+)/ }
|
14
|
-
$1.to_i
|
15
|
-
end
|
16
|
-
|
17
|
-
def distribution
|
18
|
-
self.class.parse(response).map { |row| BigDecimal.new(row[1]) }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module ViennaRna
|
2
|
-
class Fftbor2d < EnergyGrid2d
|
3
|
-
BASE_FLAGS = {
|
4
|
-
S: :empty
|
5
|
-
}
|
6
|
-
|
7
|
-
self.executable_name = "FFTbor2D"
|
8
|
-
|
9
|
-
def run_command(flags = {})
|
10
|
-
ViennaRna.debugger { "Running FFTbor2D on #{data.inspect}" }
|
11
|
-
|
12
|
-
"%s %s %s" % [
|
13
|
-
exec_name,
|
14
|
-
stringify_flags(BASE_FLAGS.merge(self.class.const_defined?(:FLAGS) ? self.class.const_get(:FLAGS) : {}).merge(flags)),
|
15
|
-
data.temp_fa_file!
|
16
|
-
]
|
17
|
-
end
|
18
|
-
|
19
|
-
def distribution
|
20
|
-
response.split(/\n/).map { |line| line.split(/\t/) }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module ViennaRna
|
2
|
-
class Fold < Base
|
3
|
-
BASE_FLAGS = {
|
4
|
-
"-noPS" => :empty
|
5
|
-
}
|
6
|
-
|
7
|
-
attr_reader :mfe_rna, :structure, :mfe
|
8
|
-
|
9
|
-
def post_process
|
10
|
-
structure = Parser.rnafold_mfe_structure(@response)
|
11
|
-
|
12
|
-
unless data.seq.length == structure.length
|
13
|
-
raise "Sequence: '#{data.seq}'\nStructure: '#{structure}'"
|
14
|
-
else
|
15
|
-
@mfe_rna, @structure, @mfe = Rna.init_from_string(data.seq, structure), structure, Parser.rnafold_mfe(@response)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module Batch
|
20
|
-
def with_different_structures
|
21
|
-
run.inject(Hash.new { |hash, key| hash[key] = [] }) do |hash, folded_sequence|
|
22
|
-
hash.tap do
|
23
|
-
hash[folded_sequence.structure] << folded_sequence
|
24
|
-
end
|
25
|
-
end.values.map(&:first)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module ViennaRna
|
2
|
-
class Heat < Base
|
3
|
-
attr_reader :specific_heats
|
4
|
-
|
5
|
-
def post_process
|
6
|
-
@specific_heats = @response.split(/\n/).map { |line| line.split(/\s+/).map(&:to_f) }.inject({}) do |hash, (temp, specific_heat)|
|
7
|
-
hash.tap do
|
8
|
-
hash[temp] = specific_heat
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|