vienna_rna 0.10.0 → 0.11.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.rb +5 -1
- data/lib/vienna_rna/global/chain_extensions.rb +1 -1
- data/lib/vienna_rna/global/rna.rb +29 -15
- data/lib/vienna_rna/global/run_extensions.rb +1 -1
- data/lib/vienna_rna/graphing/r.rb +40 -21
- data/lib/vienna_rna/package/ffthairpin.rb +7 -0
- data/lib/vienna_rna/package/fftmultiloop.rb +7 -0
- data/lib/vienna_rna/package/mfpt.rb +9 -5
- data/lib/vienna_rna/package/tabu_path.rb +46 -0
- data/lib/vienna_rna/package/xbor.rb +1 -1
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bc9776db2ef5845bd44177de91c170f00941ce8
|
4
|
+
data.tar.gz: 99c917ee065b84b812f0e32358475f08c5e22880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bcb4350ac15e7bd7c583adf2bcc81178856a4aa246124359f5fdf74dd6a3603dc182ec66a30f7be351da89363212cf99574f9b512e955c178532da1d2b16c6b
|
7
|
+
data.tar.gz: 8f6b4f63ca2d9f8c41bdc212f35b7be261cfb058631462040fb73cc10fe78d752f122dad28b603c87e256d83509d05a9fc7d0c0787f17502cdf1cb7feb87925f
|
data/lib/vienna_rna.rb
CHANGED
@@ -4,7 +4,7 @@ require "shuffle"
|
|
4
4
|
require "rinruby"
|
5
5
|
require "tempfile"
|
6
6
|
require "bigdecimal"
|
7
|
-
require "
|
7
|
+
require "rroc"
|
8
8
|
require "active_support/inflector"
|
9
9
|
require "active_support/core_ext/class"
|
10
10
|
|
@@ -63,6 +63,10 @@ unless defined? RNA
|
|
63
63
|
end
|
64
64
|
|
65
65
|
module RNA
|
66
|
+
def self.random(size, *args)
|
67
|
+
RNA.from_array(args.unshift(ViennaRna::Global::Rna.generate_sequence(size).seq))
|
68
|
+
end
|
69
|
+
|
66
70
|
def self.method_missing(name, *args, &block)
|
67
71
|
if "#{name}" =~ /^from_\w+$/
|
68
72
|
ViennaRna::Global::Rna.send("init_#{name}", *args)
|
@@ -17,7 +17,7 @@ module ViennaRna
|
|
17
17
|
raise ArgumentError.new("#{class_chaining_to.name} doesn't support chaining because it doesn't define transform_for_chaining")
|
18
18
|
end
|
19
19
|
|
20
|
-
unless [chains_from].flatten.any?
|
20
|
+
unless [chains_from].flatten.any?(&method(:kind_of?))
|
21
21
|
raise ArgumentError.new("#{class_chaining_to.name} doesn't support chaining from #{self.class.name} because it isn't in the chains_from list")
|
22
22
|
end
|
23
23
|
|
@@ -3,6 +3,7 @@ module ViennaRna
|
|
3
3
|
class Rna
|
4
4
|
include RnaExtensions
|
5
5
|
|
6
|
+
attr_accessor :comment
|
6
7
|
attr_reader :sequence, :structure, :second_structure, :raw_data
|
7
8
|
|
8
9
|
class << self
|
@@ -19,6 +20,7 @@ module ViennaRna
|
|
19
20
|
sequence: hash[:sequence] || hash[:seq],
|
20
21
|
structure: hash[:structure] || hash[:str_1] || hash[:str],
|
21
22
|
second_structure: hash[:second_structure] || hash[:str_2],
|
23
|
+
comment: hash[:comment] || hash[:name],
|
22
24
|
raw_data: hash
|
23
25
|
)
|
24
26
|
end
|
@@ -28,8 +30,18 @@ module ViennaRna
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def init_from_fasta(string)
|
31
|
-
|
32
|
-
|
33
|
+
if File.exist?(string)
|
34
|
+
comment = File.basename(string, string.include?(?.) ? ".%s" % string.split(?.)[-1] : "")
|
35
|
+
string = File.read(string).chomp
|
36
|
+
end
|
37
|
+
|
38
|
+
init_from_string(*string.split(/\n/).reject { |line| line.start_with?(">") }[0, 3]).tap do |rna|
|
39
|
+
if (line = string.split(/\n/).first).start_with?(">") && !(file_comment = line.gsub(/^>\s*/, "")).empty?
|
40
|
+
rna.comment = file_comment
|
41
|
+
elsif comment
|
42
|
+
rna.comment = comment
|
43
|
+
end
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
47
|
def init_from_self(rna)
|
@@ -38,6 +50,7 @@ module ViennaRna
|
|
38
50
|
sequence: rna.sequence,
|
39
51
|
strucutre: rna.structure,
|
40
52
|
second_strucutre: rna.second_structure,
|
53
|
+
comment: rna.comment,
|
41
54
|
raw_data: rna.raw_data
|
42
55
|
)
|
43
56
|
end
|
@@ -45,8 +58,8 @@ module ViennaRna
|
|
45
58
|
alias_method :placeholder, :new
|
46
59
|
end
|
47
60
|
|
48
|
-
def initialize(sequence: "", structure: "", second_structure: "", raw_data: {})
|
49
|
-
@sequence, @raw_data = sequence.kind_of?(Rna) ? sequence.seq : sequence, raw_data
|
61
|
+
def initialize(sequence: "", structure: "", second_structure: "", comment: "", raw_data: {})
|
62
|
+
@sequence, @comment, @raw_data = sequence.kind_of?(Rna) ? sequence.seq : sequence, comment, raw_data
|
50
63
|
|
51
64
|
[:structure, :second_structure].each do |structure_symbol|
|
52
65
|
instance_variable_set(
|
@@ -78,6 +91,7 @@ module ViennaRna
|
|
78
91
|
alias :str :structure
|
79
92
|
alias :str_1 :structure
|
80
93
|
alias :str_2 :second_structure
|
94
|
+
alias :name :comment
|
81
95
|
|
82
96
|
def empty_structure
|
83
97
|
"." * seq.length
|
@@ -85,13 +99,13 @@ module ViennaRna
|
|
85
99
|
|
86
100
|
alias :empty_str :empty_structure
|
87
101
|
|
88
|
-
def write_fa!(filename
|
102
|
+
def write_fa!(filename)
|
89
103
|
filename.tap do |filename|
|
90
104
|
File.open(filename, ?w) do |file|
|
91
|
-
file.write("> %s\n" %
|
92
|
-
file.write("%s\n" % seq)
|
93
|
-
file.write("%s\n" % str_1)
|
94
|
-
file.write("%s\n" % str_2)
|
105
|
+
file.write("> %s\n" % name) if name
|
106
|
+
file.write("%s\n" % seq) if seq
|
107
|
+
file.write("%s\n" % str_1) if str_1
|
108
|
+
file.write("%s\n" % str_2) if str_2
|
95
109
|
end
|
96
110
|
end
|
97
111
|
end
|
@@ -105,12 +119,12 @@ module ViennaRna
|
|
105
119
|
end
|
106
120
|
|
107
121
|
def inspect
|
108
|
-
"
|
109
|
-
"#{
|
110
|
-
("#{
|
111
|
-
("#{
|
112
|
-
(
|
113
|
-
].compact.join(" ")
|
122
|
+
"#<RNA: %s>" % [
|
123
|
+
("#{seq[0, 20] + (seq.length > 20 ? '... [%d]' % seq.length : '')}" if seq && !seq.empty?),
|
124
|
+
("#{str_1[0, 20] + (str_1.length > 20 ? ' [%d]' % seq.length : '')}" if str_1 && !str_1.empty?),
|
125
|
+
("#{str_2[0, 20] + (str_2.length > 20 ? ' [%d]' % seq.length : '')}" if str_2 && !str_1.empty?),
|
126
|
+
(!name.empty? ? name : "#{self.class.name}")
|
127
|
+
].compact.join(", ")
|
114
128
|
end
|
115
129
|
end
|
116
130
|
end
|
@@ -81,6 +81,46 @@ module ViennaRna
|
|
81
81
|
line_graph(data, title: title, type: ?p, x_label: x_label, y_label: y_label, filename: filename)
|
82
82
|
end
|
83
83
|
|
84
|
+
def roc(data, title: nil, baseline: true, filename: false)
|
85
|
+
# data: [[-0.894, 1.0], [-0.950, 1.0], [0.516, -1.0], ..., [0.815, -1.0], [0.740, -1.0]]
|
86
|
+
auc = ROC.auc(data)
|
87
|
+
title_with_auc = title ? "%s (AUC: %.4f)" % [title, auc] : "AUC: %.4f" % auc
|
88
|
+
overlay(
|
89
|
+
[{ data: ROC.curve_points(data) }, { data: [[0, 0], [1, 1]] }],
|
90
|
+
title: title_with_auc,
|
91
|
+
x_label: "False positive rate",
|
92
|
+
y_label: "True positive rate",
|
93
|
+
legend: false,
|
94
|
+
filename: filename
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def roc_overlay(data, title: nil, auc_in_legend: true, filename: false)
|
99
|
+
# [{ data: [[-0.894, 1.0], [-0.950, 1.0], [0.516, -1.0], ..., [0.815, -1.0], [0.740, -1.0]], legend: "ROC 1" }, ...]
|
100
|
+
formatted_data = data.map do |hash|
|
101
|
+
curve_points = ROC.curve_points(hash[:data])
|
102
|
+
|
103
|
+
if auc_in_legend
|
104
|
+
auc = ROC.auc(hash[:data])
|
105
|
+
legend = hash[:legend] ? "%s (AUC: %.4f)" % [hash[:legend], auc] : "AUC: %.4f" % auc
|
106
|
+
|
107
|
+
hash.merge({ data: curve_points, legend: legend })
|
108
|
+
else
|
109
|
+
hash.merge({ data: curve_points })
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
overlay(
|
115
|
+
formatted_data,
|
116
|
+
title: title,
|
117
|
+
x_label: "False positive rate",
|
118
|
+
y_label: "True positive rate",
|
119
|
+
legend: "bottomright",
|
120
|
+
filename: filename
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
84
124
|
def histogram(data, title: nil, x_label: "Bins", num_bins: false, bin_size: 1, x_arrow: false, relative: false, filename: false)
|
85
125
|
half = bin_size / 2.0
|
86
126
|
range = Range.new((data.min - half).floor, (data.max + half).ceil)
|
@@ -160,27 +200,6 @@ module ViennaRna
|
|
160
200
|
end
|
161
201
|
end
|
162
202
|
|
163
|
-
def roc(data, title = "", options = {})
|
164
|
-
# data = [[true_score_1, true_score_2, ...], [false_score_1, false_score_2, ...]]
|
165
|
-
|
166
|
-
if R.pull("ifelse('ROCR' %in% rownames(installed.packages()), 1, -1)") > 0
|
167
|
-
|
168
|
-
else
|
169
|
-
puts "Please install the ROCR package for R before using this function."
|
170
|
-
end
|
171
|
-
|
172
|
-
# roc_curve = ROC.curve_points({ 1 => data[0], -1 => data[1] }.inject([]) { |data, (truth, values)| data.concat(values.map { |i| [i, truth] })})
|
173
|
-
# area = roc_curve.each_cons(2).inject(0) do |sum, (a, b)|
|
174
|
-
# delta_x, delta_y = b[0] - a[0], b[1] - a[1]
|
175
|
-
# sum + (delta_x * delta_y / 2 + delta_x * [a[1], b[1]].min)
|
176
|
-
# end
|
177
|
-
|
178
|
-
# options.merge!(output: "file") if options[:filename]
|
179
|
-
# options.merge!({ plot: { title: "%s %s %.4f" % [title, "AUC:", area] } })
|
180
|
-
|
181
|
-
# plot([{ x: roc_curve.map(&:first), y: roc_curve.map(&:last), style: "lines" }], options)
|
182
|
-
end
|
183
|
-
|
184
203
|
private
|
185
204
|
|
186
205
|
def generate_graph(window_title = "ViennaRNA Graph in R", &block)
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# Maybe add something like flagsets so that common option groups can be combined together.
|
2
|
+
|
1
3
|
module ViennaRna
|
2
4
|
module Package
|
3
5
|
class Mfpt < Base
|
4
6
|
self.chains_from = ViennaRna::Package::EnergyGrid2d
|
5
|
-
self.default_flags = ->(context, flags) { { X: :empty, H: :empty, N: context.data.seq.length, Q: "1e-8" } }
|
7
|
+
self.default_flags = ->(context, flags) { { X: :empty, H: :empty, N: context.data.seq.length, D: context.data.bp_distance, Q: "1e-8" } }
|
6
8
|
# These flags aren't well setup for alternative options at the moment.
|
7
9
|
|
8
10
|
attr_reader :mfpt
|
@@ -10,11 +12,13 @@ module ViennaRna
|
|
10
12
|
def transform_for_chaining(previous_package)
|
11
13
|
previous_package.data.tap do |data|
|
12
14
|
data.instance_eval do
|
13
|
-
@
|
14
|
-
|
15
|
+
@previous_package = previous_package
|
16
|
+
|
17
|
+
def energy_grid_csv
|
18
|
+
Tempfile.new("rna").path.tap do |energy_grid_csv|
|
19
|
+
@previous_package.to_csv!(energy_grid_csv)
|
20
|
+
end
|
15
21
|
end
|
16
|
-
|
17
|
-
def energy_grid_csv; @energy_grid_csv; end
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ViennaRna
|
2
|
+
module Package
|
3
|
+
class TabuPath < Base
|
4
|
+
self.executable_name = "get_barrier_tabu"
|
5
|
+
self.default_flags = ->(context, flags) { { iterations: 10, min_weight: 10, max_weight: 70 } }
|
6
|
+
|
7
|
+
attr_reader :paths
|
8
|
+
|
9
|
+
def run_command(flags)
|
10
|
+
ViennaRna.debugger { "Running #{exec_name} on #{data.inspect}" }
|
11
|
+
|
12
|
+
[
|
13
|
+
exec_name,
|
14
|
+
data.seq.inspect,
|
15
|
+
data.str_1.inspect,
|
16
|
+
data.str_2.inspect,
|
17
|
+
flags[:iterations],
|
18
|
+
flags[:min_weight],
|
19
|
+
flags[:max_weight]
|
20
|
+
].join(" ")
|
21
|
+
end
|
22
|
+
|
23
|
+
def post_process
|
24
|
+
@paths = @response.split(data.str_1 + ?\n).reject(&:empty?).map { |path_string| Path.new(data, path_string) }
|
25
|
+
end
|
26
|
+
|
27
|
+
class Path
|
28
|
+
attr_reader :rna, :path, :barrier, :best_weight
|
29
|
+
|
30
|
+
def initialize(rna, output)
|
31
|
+
@rna = rna
|
32
|
+
@path = output.split(?\n)[0..-2].unshift(rna.str_1)
|
33
|
+
@barrier, _, @best_weight = output.split(?\n)[-1].gsub(/[^\d\.]/, " ").strip.split(/\s+/).map(&:to_f)
|
34
|
+
end
|
35
|
+
|
36
|
+
def length
|
37
|
+
path.length
|
38
|
+
end
|
39
|
+
|
40
|
+
def full_path?
|
41
|
+
rna.str_1 == path.first && rna.str_2 == path.last
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -27,7 +27,7 @@ module ViennaRna
|
|
27
27
|
sequence = log.split(/\n/).first.split(/\s+/)[1]
|
28
28
|
structure = log.split(/\n/).first.split(/\s+/)[2]
|
29
29
|
|
30
|
-
klass.bootstrap(RNA.from_string(sequence, structure), log)
|
30
|
+
klass.bootstrap(data: RNA.from_string(sequence, structure), output: log)
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.parse(response)
|
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.11.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-11-
|
11
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.0.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rroc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.1.1
|
55
69
|
description: A Ruby 2.0 API for interacting with command line tools involving RNA
|
56
70
|
molecules through a standard interface.
|
57
71
|
email: evansenter@gmail.com
|
@@ -70,12 +84,15 @@ files:
|
|
70
84
|
- lib/vienna_rna/package/eval.rb
|
71
85
|
- lib/vienna_rna/package/fftbor.rb
|
72
86
|
- lib/vienna_rna/package/fftbor2d.rb
|
87
|
+
- lib/vienna_rna/package/ffthairpin.rb
|
88
|
+
- lib/vienna_rna/package/fftmultiloop.rb
|
73
89
|
- lib/vienna_rna/package/fold.rb
|
74
90
|
- lib/vienna_rna/package/heat.rb
|
75
91
|
- lib/vienna_rna/package/mfpt.rb
|
76
92
|
- lib/vienna_rna/package/rna2dfold.rb
|
77
93
|
- lib/vienna_rna/package/rnabor.rb
|
78
94
|
- lib/vienna_rna/package/subopt.rb
|
95
|
+
- lib/vienna_rna/package/tabu_path.rb
|
79
96
|
- lib/vienna_rna/package/xbor.rb
|
80
97
|
- lib/vienna_rna.rb
|
81
98
|
- README.md
|
@@ -98,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
115
|
version: '0'
|
99
116
|
requirements: []
|
100
117
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.1.
|
118
|
+
rubygems_version: 2.1.11
|
102
119
|
signing_key:
|
103
120
|
specification_version: 4
|
104
121
|
summary: Bindings to the Vienna RNA package, and other major command line utilities
|