vienna_rna 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vienna_rna/modules/base.rb +6 -0
- data/lib/vienna_rna/modules/rna.rb +69 -1
- data/lib/vienna_rna/modules/utils.rb +6 -5
- data/lib/vienna_rna/modules/xbor.rb +8 -0
- data/lib/vienna_rna.rb +4 -0
- metadata +36 -4
@@ -24,6 +24,12 @@ module ViennaRna
|
|
24
24
|
new(data).run(flags)
|
25
25
|
end
|
26
26
|
|
27
|
+
def bootstrap(data, output)
|
28
|
+
new(data).tap do |object|
|
29
|
+
object.instance_variable_set(:@response, output)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
27
33
|
def batch(fastas = [])
|
28
34
|
ViennaRna::Batch.new(self, fastas).tap do |batch|
|
29
35
|
if const_defined?(:Batch)
|
@@ -3,7 +3,7 @@ module ViennaRna
|
|
3
3
|
attr_reader :sequence, :structure
|
4
4
|
|
5
5
|
def initialize(sequence, structure = nil)
|
6
|
-
@sequence = sequence
|
6
|
+
@sequence = sequence.upcase
|
7
7
|
@structure = (structure == :mfe ? ViennaRna::Fold.run(seq).structure : structure)
|
8
8
|
end
|
9
9
|
|
@@ -17,5 +17,73 @@ module ViennaRna
|
|
17
17
|
def empty_structure
|
18
18
|
"." * seq.length
|
19
19
|
end
|
20
|
+
|
21
|
+
def bp_distance(other_structure)
|
22
|
+
self.class.bp_distance(structure, other_structure)
|
23
|
+
end
|
24
|
+
|
25
|
+
def base_pairs
|
26
|
+
self.class.base_pairs(structure)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_pairings
|
30
|
+
self.class.get_pairings(structure)
|
31
|
+
end
|
32
|
+
|
33
|
+
def dishuffle
|
34
|
+
self.class.shuffle(sequence, 2)
|
35
|
+
end
|
36
|
+
|
37
|
+
def inspect
|
38
|
+
"#<ViennaRna::#{self.class.name} #{seq[0, 20] + ('...' if seq.length > 20)} #{str[0, 20] + ('[truncated]' if seq.length > 20)}>"
|
39
|
+
end
|
40
|
+
|
41
|
+
class << self
|
42
|
+
def generate_sequence(sequence_length)
|
43
|
+
# 0th order Markov chain w/ uniform probability distribution
|
44
|
+
sequence_length.times.inject("") { |string, _| string + %w[A U C G][rand(4)] }
|
45
|
+
end
|
46
|
+
|
47
|
+
def shuffle(sequence, token_length = 2)
|
48
|
+
Shuffle.new(sequence).shuffle(token_length)
|
49
|
+
end
|
50
|
+
|
51
|
+
def bp_distance(structure_1, structure_2)
|
52
|
+
raise "The two structures are not the same length" unless structure_1.length == structure_2.length
|
53
|
+
|
54
|
+
bp_set_1, bp_set_2 = base_pairs(structure_1), base_pairs(structure_2)
|
55
|
+
|
56
|
+
((bp_set_1 - bp_set_2) + (bp_set_2 - bp_set_1)).count
|
57
|
+
end
|
58
|
+
|
59
|
+
def base_pairs(structure)
|
60
|
+
get_pairings(structure).each_with_index.inject(Set.new) do |set, (j, i)|
|
61
|
+
j >= 0 ? set << Set[i, j] : set
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_pairings(structure)
|
66
|
+
stack = []
|
67
|
+
|
68
|
+
structure.each_char.each_with_index.inject(Array.new(structure.length, -1)) do |array, (symbol, index)|
|
69
|
+
array.tap do
|
70
|
+
case symbol
|
71
|
+
when "(" then stack.push(index)
|
72
|
+
when ")" then
|
73
|
+
if stack.empty?
|
74
|
+
raise "Too many ')' in '#{structure}'"
|
75
|
+
else
|
76
|
+
stack.pop.tap do |opening|
|
77
|
+
array[opening] = index
|
78
|
+
array[index] = opening
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end.tap do
|
84
|
+
raise "Too many '(' in '#{structure}'" unless stack.empty?
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
20
88
|
end
|
21
89
|
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require "matrix"
|
2
|
-
require "gnuplot"
|
3
|
-
|
4
1
|
module ViennaRna
|
5
2
|
module Utils
|
6
3
|
class << self
|
@@ -57,11 +54,15 @@ module ViennaRna
|
|
57
54
|
end
|
58
55
|
|
59
56
|
def quick_plot(title, data, filename = false)
|
60
|
-
|
57
|
+
quick_overlay(title, [{ data: data }], filename)
|
58
|
+
end
|
59
|
+
|
60
|
+
def quick_overlay(title, data, filename = false)
|
61
|
+
# [{ data: [[x_0, y_0], [x_1, y_1], ...], label: "Label" }, { data: [[x_0, y_0], [x_1, y_1], ...] }]
|
61
62
|
options = { title: title }
|
62
63
|
options.merge!(output: "file", filename: filename) if filename
|
63
64
|
|
64
|
-
plot(
|
65
|
+
plot(data.map { |hash| { title: hash[:label], x: hash[:data].map(&:first), y: hash[:data].map(&:last), style: "linespoints" } }, options)
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
@@ -35,11 +35,19 @@ module ViennaRna
|
|
35
35
|
full_distribution.each_with_index.to_a.map(&:reverse)[0..data.seq.length]
|
36
36
|
end
|
37
37
|
|
38
|
+
def expected_k
|
39
|
+
k_p_points.map { |array| array.inject(&:*) }.inject(&:+)
|
40
|
+
end
|
41
|
+
|
38
42
|
def quick_plot(title = nil)
|
39
43
|
ViennaRna::Utils.quick_plot(
|
40
44
|
title || "%s\\n%s\\n%s" % [self.class.name, data.seq, data.safe_structure],
|
41
45
|
k_p_points
|
42
46
|
)
|
43
47
|
end
|
48
|
+
|
49
|
+
def inspect
|
50
|
+
"#<ViennaRna::#{self.class.name} #{data.inspect}>"
|
51
|
+
end
|
44
52
|
end
|
45
53
|
end
|
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.1.
|
4
|
+
version: 0.1.7
|
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-
|
12
|
+
date: 2012-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bio
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 3.2
|
37
|
+
version: '3.2'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,39 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 3.2
|
45
|
+
version: '3.2'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shuffle
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.1.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: gnuplot
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.5.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.5.0
|
46
78
|
description: A Ruby API for interacting with the Vienna RNA package.
|
47
79
|
email: evansenter@gmail.com
|
48
80
|
executables: []
|