vienna_rna 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/modules/base.rb +33 -8
- data/lib/modules/fftbor.rb +48 -0
- data/lib/modules/fold.rb +2 -2
- data/lib/modules/rnabor.rb +19 -26
- data/lib/modules/utils.rb +0 -2
- data/lib/vienna_rna.rb +2 -2
- metadata +12 -19
data/lib/modules/base.rb
CHANGED
@@ -1,5 +1,26 @@
|
|
1
|
+
require "benchmark"
|
2
|
+
|
1
3
|
module ViennaRna
|
2
4
|
class Base
|
5
|
+
class Rna
|
6
|
+
attr_reader :sequence, :structure
|
7
|
+
|
8
|
+
def initialize(sequence, structure = nil)
|
9
|
+
@sequence = sequence
|
10
|
+
@structure = structure
|
11
|
+
end
|
12
|
+
|
13
|
+
alias :seq :sequence
|
14
|
+
|
15
|
+
def safe_structure
|
16
|
+
structure || empty_structure
|
17
|
+
end
|
18
|
+
|
19
|
+
def empty_structure
|
20
|
+
"." * seq.length
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
3
24
|
class_attribute :executable_name
|
4
25
|
|
5
26
|
class << self
|
@@ -33,29 +54,33 @@ module ViennaRna
|
|
33
54
|
end
|
34
55
|
end
|
35
56
|
|
36
|
-
attr_reader :
|
57
|
+
attr_reader :data, :response, :runtime
|
37
58
|
|
38
59
|
def exec_name
|
39
60
|
executable_name || "rna#{self.class.name.split('::').last.underscore}"
|
40
61
|
end
|
41
62
|
|
42
63
|
def exec_sequence_format
|
43
|
-
|
64
|
+
data.seq
|
44
65
|
end
|
45
66
|
|
46
67
|
def initialize(data)
|
47
|
-
|
48
|
-
@fasta = case data
|
68
|
+
@data = case data
|
49
69
|
when Bio::FastaFormat then data
|
50
|
-
when String then
|
70
|
+
when String then Rna.new(data)
|
71
|
+
when Hash then Rna.new(data[:sequence] || data[:seq], data[:structure] || data[:str])
|
51
72
|
end
|
52
73
|
end
|
53
74
|
|
54
75
|
def run_with_hooks(flags = {})
|
55
76
|
tap do
|
56
|
-
|
57
|
-
|
58
|
-
|
77
|
+
@runtime = Benchmark.measure do
|
78
|
+
pre_run_check unless respond_to?(:run_command)
|
79
|
+
@response = run_without_hooks(flags)
|
80
|
+
post_process if respond_to?(:post_process)
|
81
|
+
end
|
82
|
+
|
83
|
+
puts "Total runtime: %.3f sec." % runtime.real if ViennaRna.debug
|
59
84
|
end
|
60
85
|
end
|
61
86
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ViennaRna
|
2
|
+
class Fftbor < Base
|
3
|
+
attr_reader :flags
|
4
|
+
|
5
|
+
def run_command(flags)
|
6
|
+
@flags = flags
|
7
|
+
|
8
|
+
"./FFTbor -s %s -r %s -c %s -p %s" % [
|
9
|
+
data.seq,
|
10
|
+
data.safe_structure,
|
11
|
+
flags[:scaling_factor] ||= 1,
|
12
|
+
flags[:precision] ||= 6
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_partition
|
17
|
+
response.split(/\n/).find { |line| line =~ /^Z\[1\]\[\d+\]:/ }.match(/^Z\[1\]\[\d+\]:\s*(.*)/)[1].to_f
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_total_count
|
21
|
+
response.split(/\n/).find { |line| line =~ /^Z\[\d+\]\[1\]:/ }.match(/^Z\[\d+\]\[1\]:\s*(.*)/)[1].to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_points
|
25
|
+
self.class.parse(response, "ROOTS AND SOLUTIONS") { |line| line.strip.split(/\s\s+/).map { |value| eval("Complex(#{value})") } }
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_distribution
|
29
|
+
if flags[:scaling_factor] != 1
|
30
|
+
puts "Warning: The scaling factor was set to #{flags[:scaling_factor]}. The Boltzmann distribution is not setup to handle scaling in this fashion."
|
31
|
+
end
|
32
|
+
|
33
|
+
self.class.parse(response, "DISTRIBUTION") { |line| line.strip.split(/:\s*/).last.to_f }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.parse(response, delimiter)
|
37
|
+
response.split(/\n/).reject do |line|
|
38
|
+
line.empty?
|
39
|
+
end.drop_while do |line|
|
40
|
+
line !~ /^START #{delimiter}/i
|
41
|
+
end.reverse.drop_while do |line|
|
42
|
+
line !~ /^END #{delimiter}/i
|
43
|
+
end.reverse[1..-2].map do |line|
|
44
|
+
yield line
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/modules/fold.rb
CHANGED
@@ -5,8 +5,8 @@ module ViennaRna
|
|
5
5
|
def post_process
|
6
6
|
structure = @response.split(/\n/).last.gsub(/ \(\s*(-?\d*\.\d*)\)$/, "")
|
7
7
|
|
8
|
-
unless
|
9
|
-
raise "Sequence: '#{
|
8
|
+
unless data.seq.length == structure.length
|
9
|
+
raise "Sequence: '#{data.seq}'\nStructure: '#{structure}'"
|
10
10
|
else
|
11
11
|
@structure, @mfe = structure, $1.to_f
|
12
12
|
end
|
data/lib/modules/rnabor.rb
CHANGED
@@ -1,45 +1,38 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
|
1
3
|
module ViennaRna
|
2
4
|
class Rnabor < Base
|
3
5
|
def run_command(flags)
|
4
|
-
|
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 %s" % file.path
|
5
12
|
end
|
6
13
|
|
7
|
-
def
|
8
|
-
|
14
|
+
def parse_partition
|
15
|
+
parse_non_zero_shells.sum
|
9
16
|
end
|
10
17
|
|
11
|
-
def
|
12
|
-
|
18
|
+
def parse_total_count
|
19
|
+
parse_counts.sum
|
13
20
|
end
|
14
21
|
|
15
22
|
def parse_counts
|
16
|
-
self.class.parse(response
|
23
|
+
(non_zero_counts = self.class.parse(response).map { |row| row[2].to_i }) + [0] * (data.seq.length - non_zero_counts.length + 1)
|
17
24
|
end
|
18
25
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
options[:unscale] ? results.map { |i| i * parse_total_count } : results
|
26
|
+
def parse_distribution
|
27
|
+
(non_zero_distribution = parse_non_zero_shells.map { |i| i / parse_partition }) + [0.0] * (data.seq.length - non_zero_distribution.length + 1)
|
23
28
|
end
|
24
29
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
run unless response
|
29
|
-
|
30
|
-
ViennaRna::FftInR.new(parse_points.map(&:last), parse_total_count, options[:precision]).run
|
30
|
+
def parse_non_zero_shells
|
31
|
+
self.class.parse(response).map { |row| row[1].to_f }
|
31
32
|
end
|
32
33
|
|
33
|
-
def self.parse(response
|
34
|
-
response.split(/\n/).
|
35
|
-
line.empty?
|
36
|
-
end.drop_while do |line|
|
37
|
-
line !~ /^START #{delimiter}/i
|
38
|
-
end.reverse.drop_while do |line|
|
39
|
-
line !~ /^END #{delimiter}/i
|
40
|
-
end.reverse[1..-2].map do |line|
|
41
|
-
yield line
|
42
|
-
end
|
34
|
+
def self.parse(response)
|
35
|
+
response.split(/\n/)[2..-1].map { |line| line.split(/\t/) }
|
43
36
|
end
|
44
37
|
end
|
45
38
|
end
|
data/lib/modules/utils.rb
CHANGED
data/lib/vienna_rna.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -49,24 +49,16 @@ executables: []
|
|
49
49
|
extensions: []
|
50
50
|
extra_rdoc_files: []
|
51
51
|
files:
|
52
|
-
-
|
53
|
-
|
54
|
-
-
|
55
|
-
|
56
|
-
-
|
57
|
-
|
58
|
-
-
|
59
|
-
|
60
|
-
-
|
61
|
-
|
62
|
-
- !binary |-
|
63
|
-
Li9saWIvbW9kdWxlcy9ybmFib3IucmI=
|
64
|
-
- !binary |-
|
65
|
-
Li9saWIvbW9kdWxlcy9zdWJvcHQucmI=
|
66
|
-
- !binary |-
|
67
|
-
Li9saWIvbW9kdWxlcy91dGlscy5yYg==
|
68
|
-
- !binary |-
|
69
|
-
Li9saWIvdmllbm5hX3JuYS5yYg==
|
52
|
+
- ./lib/modules/base.rb
|
53
|
+
- ./lib/modules/batch.rb
|
54
|
+
- ./lib/modules/fft_in_r.rb
|
55
|
+
- ./lib/modules/fftbor.rb
|
56
|
+
- ./lib/modules/fold.rb
|
57
|
+
- ./lib/modules/heat.rb
|
58
|
+
- ./lib/modules/rnabor.rb
|
59
|
+
- ./lib/modules/subopt.rb
|
60
|
+
- ./lib/modules/utils.rb
|
61
|
+
- ./lib/vienna_rna.rb
|
70
62
|
homepage: http://rubygems.org/gems/vienna_rna
|
71
63
|
licenses: []
|
72
64
|
post_install_message:
|
@@ -92,3 +84,4 @@ signing_key:
|
|
92
84
|
specification_version: 3
|
93
85
|
summary: Bindings to the Vienna RNA package.
|
94
86
|
test_files: []
|
87
|
+
has_rdoc:
|