vienna_rna 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/modules/base.rb +15 -3
- data/lib/modules/fftbor.rb +4 -17
- data/lib/modules/rnabor.rb +8 -17
- data/lib/modules/xbor.rb +21 -0
- data/lib/vienna_rna.rb +4 -5
- metadata +3 -3
- data/lib/modules/fft_in_r.rb +0 -26
data/lib/modules/base.rb
CHANGED
@@ -52,12 +52,20 @@ module ViennaRna
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
def debugger
|
57
|
+
STDERR.puts yield if ViennaRna.debug
|
58
|
+
end
|
55
59
|
end
|
56
60
|
|
57
61
|
attr_reader :data, :response, :runtime
|
58
62
|
|
59
63
|
def exec_name
|
60
|
-
executable_name
|
64
|
+
if executable_name
|
65
|
+
executable_name.respond_to?(:call) ? self.class.module_exec(&executable_name) : executable_name
|
66
|
+
else
|
67
|
+
"rna#{self.class.name.split('::').last.underscore}"
|
68
|
+
end
|
61
69
|
end
|
62
70
|
|
63
71
|
def exec_sequence_format
|
@@ -80,7 +88,7 @@ module ViennaRna
|
|
80
88
|
post_process if respond_to?(:post_process)
|
81
89
|
end
|
82
90
|
|
83
|
-
|
91
|
+
debugger { "Total runtime: %.3f sec." % runtime.real }
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
@@ -101,9 +109,13 @@ module ViennaRna
|
|
101
109
|
"echo #{exec_sequence_format} | #{exec_name} #{stringify_flags(flags)}"
|
102
110
|
end
|
103
111
|
|
104
|
-
|
112
|
+
debugger { command }
|
105
113
|
|
106
114
|
%x[#{command}]
|
107
115
|
end
|
116
|
+
|
117
|
+
def debugger(&block)
|
118
|
+
self.class.debugger(&block)
|
119
|
+
end
|
108
120
|
end
|
109
121
|
end
|
data/lib/modules/fftbor.rb
CHANGED
@@ -1,20 +1,11 @@
|
|
1
1
|
require "tempfile"
|
2
|
+
require "bigdecimal"
|
2
3
|
|
3
4
|
module ViennaRna
|
4
|
-
class Fftbor <
|
5
|
-
def run_command(flags)
|
6
|
-
file = Tempfile.new("rna")
|
7
|
-
file.write("%s\n" % data.seq)
|
8
|
-
file.write("%s\n" % data.safe_structure)
|
9
|
-
file.close
|
10
|
-
|
11
|
-
"./FFTbor %s" % file.path
|
12
|
-
end
|
13
|
-
|
5
|
+
class Fftbor < Xbor
|
14
6
|
def partition
|
15
|
-
# Scaling factor (Z{1, n}): 586.684
|
16
7
|
response.split(/\n/).find { |line| line =~ /^Scaling factor.*:\s+(\d+\.\d+)/ }
|
17
|
-
$1
|
8
|
+
BigDecimal.new($1)
|
18
9
|
end
|
19
10
|
|
20
11
|
def total_count
|
@@ -23,11 +14,7 @@ module ViennaRna
|
|
23
14
|
end
|
24
15
|
|
25
16
|
def distribution
|
26
|
-
self.class.parse(response).map { |row| row[1]
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.parse(response)
|
30
|
-
response.split(/\n/).select { |line| line =~ /^\d+\t\d+(\.\d+)?/ }.map { |line| line.split(/\t/) }
|
17
|
+
self.class.parse(response).map { |row| BigDecimal.new(row[1]) }
|
31
18
|
end
|
32
19
|
end
|
33
20
|
end
|
data/lib/modules/rnabor.rb
CHANGED
@@ -1,16 +1,8 @@
|
|
1
1
|
require "tempfile"
|
2
|
+
require "bigdecimal"
|
2
3
|
|
3
4
|
module ViennaRna
|
4
|
-
class Rnabor <
|
5
|
-
def run_command(flags)
|
6
|
-
file = Tempfile.new("rna")
|
7
|
-
file.write("%s\n" % data.seq)
|
8
|
-
file.write("%s\n" % data.safe_structure)
|
9
|
-
file.close
|
10
|
-
|
11
|
-
"./RNAbor -nodangle %s" % file.path
|
12
|
-
end
|
13
|
-
|
5
|
+
class Rnabor < Xbor
|
14
6
|
def partition
|
15
7
|
non_zero_shells.sum
|
16
8
|
end
|
@@ -23,16 +15,15 @@ module ViennaRna
|
|
23
15
|
(non_zero_counts = self.class.parse(response).map { |row| row[2].to_i }) + [0] * (data.seq.length - non_zero_counts.length + 1)
|
24
16
|
end
|
25
17
|
|
26
|
-
def distribution
|
27
|
-
|
18
|
+
def distribution(options = {})
|
19
|
+
options = { precision: 4 }.merge(options)
|
20
|
+
|
21
|
+
distribution_before_precision = (non_zero_distribution = non_zero_shells.map { |i| i / partition }) + [0.0] * (data.seq.length - non_zero_distribution.length + 1)
|
22
|
+
distribution_before_precision.map { |value| options[:precision].zero? ? value : (value * 10 ** options[:precision]).truncate / 10.0 ** options[:precision] }
|
28
23
|
end
|
29
24
|
|
30
25
|
def non_zero_shells
|
31
|
-
self.class.parse(response).map { |row| row[1]
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.parse(response)
|
35
|
-
response.split(/\n/)[2..-1].map { |line| line.split(/\t/) }
|
26
|
+
self.class.parse(response).map { |row| BigDecimal.new(row[1]) }
|
36
27
|
end
|
37
28
|
end
|
38
29
|
end
|
data/lib/modules/xbor.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
require "bigdecimal"
|
3
|
+
|
4
|
+
module ViennaRna
|
5
|
+
class Xbor < Base
|
6
|
+
self.executable_name = -> { name.demodulize.gsub(/^([A-Z].*)bor$/) { |match| $1.upcase + "bor" } }
|
7
|
+
|
8
|
+
def run_command(flags)
|
9
|
+
file = Tempfile.new("rna")
|
10
|
+
file.write("%s\n" % data.seq)
|
11
|
+
file.write("%s\n" % data.safe_structure)
|
12
|
+
file.close
|
13
|
+
|
14
|
+
"./%s -nodangle %s" % [exec_name, file.path]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse(response)
|
18
|
+
response.split(/\n/).select { |line| line =~ /^\d+\t\d+/ }.map { |line| line.split(/\t/) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/vienna_rna.rb
CHANGED
@@ -3,11 +3,6 @@ require "active_support/inflector"
|
|
3
3
|
require "active_support/core_ext/class"
|
4
4
|
require "active_support/core_ext/module/aliasing"
|
5
5
|
|
6
|
-
# Clean up this include order.
|
7
|
-
Dir[File.join(File.dirname(__FILE__), "/modules/*")].each do |file|
|
8
|
-
require file
|
9
|
-
end
|
10
|
-
|
11
6
|
module Enumerable
|
12
7
|
def sum
|
13
8
|
inject(&:+)
|
@@ -17,6 +12,10 @@ end
|
|
17
12
|
module ViennaRna
|
18
13
|
@debug = true
|
19
14
|
|
15
|
+
Dir[File.join(File.dirname(__FILE__), "/modules/*")].each do |file|
|
16
|
+
autoload File.basename(file, ".rb").camelize.to_sym, file
|
17
|
+
end
|
18
|
+
|
20
19
|
def self.const_missing(name)
|
21
20
|
if Base.exec_exists?(name)
|
22
21
|
module_eval do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vienna_rna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bio
|
@@ -51,13 +51,13 @@ extra_rdoc_files: []
|
|
51
51
|
files:
|
52
52
|
- ./lib/modules/base.rb
|
53
53
|
- ./lib/modules/batch.rb
|
54
|
-
- ./lib/modules/fft_in_r.rb
|
55
54
|
- ./lib/modules/fftbor.rb
|
56
55
|
- ./lib/modules/fold.rb
|
57
56
|
- ./lib/modules/heat.rb
|
58
57
|
- ./lib/modules/rnabor.rb
|
59
58
|
- ./lib/modules/subopt.rb
|
60
59
|
- ./lib/modules/utils.rb
|
60
|
+
- ./lib/modules/xbor.rb
|
61
61
|
- ./lib/vienna_rna.rb
|
62
62
|
homepage: http://rubygems.org/gems/vienna_rna
|
63
63
|
licenses: []
|
data/lib/modules/fft_in_r.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module ViennaRna
|
2
|
-
class FftInR < Base
|
3
|
-
attr_reader :processed_response, :points, :total_count, :precision
|
4
|
-
|
5
|
-
def initialize(points, total_count, precision)
|
6
|
-
@points = points
|
7
|
-
@total_count = total_count
|
8
|
-
@precision = precision
|
9
|
-
end
|
10
|
-
|
11
|
-
def run_command
|
12
|
-
vector = "c(%s)" % points.map { |point| 10 ** precision * point / total_count }.join(", ")
|
13
|
-
"Rscript -e 'vector <- #{vector}; fft(vector) / length(vector);'" % vector
|
14
|
-
end
|
15
|
-
|
16
|
-
def post_process
|
17
|
-
@processed_response = response.split(/\n/).map do |line|
|
18
|
-
line.strip.match(/\[\d+\]\s+(.*)$/)[1].split(/\s+/)
|
19
|
-
end.flatten.map do |i|
|
20
|
-
i.match(/(-?\d+\.\d+e[\+-]\d+)/)[1].to_f
|
21
|
-
end.map do |i|
|
22
|
-
precision.zero? ? i : i.truncate / 10.0 ** precision
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|