wrnap 0.2.0 → 0.3.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/wrnap/global/rna.rb +32 -32
- data/lib/wrnap/package/fft_mfpt.rb +17 -9
- data/lib/wrnap/package/population.rb +21 -14
- data/lib/wrnap/package/spectral.rb +16 -15
- data/lib/wrnap/version.rb +1 -1
- data/lib/wrnap.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 886697f970124a5b27d1149141ebaadfd8f275c2
|
4
|
+
data.tar.gz: 19afc74cff392c61f3c84bf12b39db74252fcb96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd86a11763b4770bc7d4af245c36dc647b326870c0e2c9e3f0ab39b0c9a99cfd6db2722c5f72ee176635b4c5f99ffd33ea7cc8805fc24bf411f736eeef0efc0d
|
7
|
+
data.tar.gz: 085d7434dbe7669336a9e858e7dc11c6a12d856e837306bc703596539923a1919f97b819a2878173cb84f02995d585b2b134ab4d2bd7aaa22238753466d6dff0
|
data/lib/wrnap/global/rna.rb
CHANGED
@@ -2,39 +2,39 @@ module Wrnap
|
|
2
2
|
module Global
|
3
3
|
class Rna
|
4
4
|
include RnaExtensions
|
5
|
-
|
5
|
+
|
6
6
|
attr_accessor :comment
|
7
7
|
attr_reader :sequence, :structure, :second_structure
|
8
|
-
|
8
|
+
|
9
9
|
class << self
|
10
10
|
def init_from_string(sequence, structure = nil, second_structure = nil, comment = nil)
|
11
11
|
new(
|
12
|
-
sequence: sequence,
|
13
|
-
structure: structure,
|
12
|
+
sequence: sequence,
|
13
|
+
structure: structure,
|
14
14
|
second_structure: second_structure,
|
15
15
|
comment: comment
|
16
16
|
)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def init_from_hash(hash)
|
20
20
|
new(
|
21
|
-
sequence: hash[:sequence] || hash[:seq],
|
22
|
-
structure: hash[:structure] || hash[:str_1] || hash[:str],
|
23
|
-
second_structure: hash[:second_structure] || hash[:str_2],
|
21
|
+
sequence: hash[:sequence] || hash[:seq],
|
22
|
+
structure: hash[:structure] || hash[:str_1] || hash[:str],
|
23
|
+
second_structure: hash[:second_structure] || hash[:str_2],
|
24
24
|
comment: hash[:comment] || hash[:name]
|
25
25
|
)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def init_from_array(array)
|
29
29
|
init_from_string(*array)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def init_from_fasta(string)
|
33
33
|
if File.exist?(string)
|
34
34
|
comment = File.basename(string, string.include?(?.) ? ".%s" % string.split(?.)[-1] : "")
|
35
35
|
string = File.read(string).chomp
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
init_from_string(*string.split(/\n/).reject { |line| line.start_with?(">") }[0, 3]).tap do |rna|
|
39
39
|
if (line = string.split(/\n/).first).start_with?(">") && !(file_comment = line.gsub(/^>\s*/, "")).empty?
|
40
40
|
rna.comment = file_comment
|
@@ -43,35 +43,35 @@ module Wrnap
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def init_from_self(rna)
|
48
48
|
# This happens when you call a Wrnap library function with the output of something like Wrnap::Fold.run(...).mfe
|
49
49
|
new(
|
50
|
-
sequence: rna.sequence,
|
51
|
-
strucutre: rna.structure,
|
52
|
-
second_strucutre: rna.second_structure,
|
50
|
+
sequence: rna.sequence,
|
51
|
+
strucutre: rna.structure,
|
52
|
+
second_strucutre: rna.second_structure,
|
53
53
|
comment: rna.comment
|
54
54
|
)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
alias_method :placeholder, :new
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def initialize(sequence: "", structure: "", second_structure: "", comment: "")
|
61
61
|
@sequence, @comment = sequence.kind_of?(Rna) ? sequence.seq : sequence, comment
|
62
|
-
|
62
|
+
|
63
63
|
[:structure, :second_structure].each do |structure_symbol|
|
64
64
|
instance_variable_set(
|
65
|
-
:"@#{structure_symbol}",
|
65
|
+
:"@#{structure_symbol}",
|
66
66
|
case structure_value = eval("#{structure_symbol}")
|
67
67
|
when :empty then empty_structure
|
68
68
|
when :mfe then RNA(sequence).run(:fold).mfe_rna.structure
|
69
69
|
when String then structure_value
|
70
|
-
when Hash then
|
70
|
+
when Hash then
|
71
71
|
if structure_value.keys.count > 1
|
72
72
|
Wrnap.debugger { "The following options hash has more than one key. This will probably produce unpredictable results: %s" % structure_value.inspect }
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
RNA(sequence).run(*structure_value.keys, *structure_value.values).mfe_rna.structure
|
76
76
|
end
|
77
77
|
)
|
@@ -80,36 +80,36 @@ module Wrnap
|
|
80
80
|
if str && seq.length != str.length
|
81
81
|
Wrnap.debugger { "The sequence length (%d) doesn't match the structure length (%d)" % [seq, str].map(&:length) }
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
if str_2 && str_1.length != str_2.length
|
85
85
|
Wrnap.debugger { "The first structure length (%d) doesn't match the second structure length (%d)" % [str_1, str_2].map(&:length) }
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
alias :seq :sequence
|
90
90
|
alias :str :structure
|
91
91
|
alias :str_1 :structure
|
92
92
|
alias :str_2 :second_structure
|
93
93
|
alias :name :comment
|
94
|
-
|
94
|
+
|
95
95
|
def empty_structure
|
96
96
|
"." * seq.length
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
alias :empty_str :empty_structure
|
100
|
-
|
100
|
+
|
101
101
|
def one_structure(structure_1)
|
102
102
|
self.class.init_from_string(seq, structure_1.is_a?(Symbol) ? send(structure_1) : structure_1, nil, name)
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def two_structures(structure_1, structure_2)
|
106
106
|
self.class.init_from_string(
|
107
|
-
seq,
|
107
|
+
seq,
|
108
108
|
*[structure_1, structure_2].map { |argument| argument.is_a?(Symbol) ? send(argument) : argument },
|
109
109
|
name
|
110
110
|
)
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
def write_fa!(filename)
|
114
114
|
filename.tap do |filename|
|
115
115
|
File.open(filename, ?w) do |file|
|
@@ -120,7 +120,7 @@ module Wrnap
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def temp_fa_file!
|
125
125
|
write_fa!(Tempfile.new("rna")).path
|
126
126
|
end
|
@@ -128,7 +128,7 @@ module Wrnap
|
|
128
128
|
def run(package_name, options = {})
|
129
129
|
Wrnap::Package.lookup(package_name).run(self, options)
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
def method_missing(name, *args, &block)
|
133
133
|
if (name_str = "#{name}") =~ /^run_\w+$/
|
134
134
|
run(name_str.gsub(/^run_/, ""), *args)
|
@@ -145,4 +145,4 @@ module Wrnap
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
148
|
-
end
|
148
|
+
end
|
@@ -5,17 +5,25 @@ module Wrnap
|
|
5
5
|
module Package
|
6
6
|
class FftMfpt < Base
|
7
7
|
self.executable_name = "FFTmfpt"
|
8
|
-
|
8
|
+
|
9
|
+
self.default_flags = ->(context, flags) do
|
10
|
+
{
|
11
|
+
"-fftbor2d-i" => context.data.seq,
|
12
|
+
"-fftbor2d-j" => context.data.str_1,
|
13
|
+
"-fftbor2d-k" => context.data.str_2,
|
14
|
+
"-mfpt-x" => true
|
15
|
+
}
|
16
|
+
end
|
17
|
+
self.quote_flag_params = %w|-fftbor2d-i -fftbor2d-j -fftbor2d-k|
|
18
|
+
|
9
19
|
attr_reader :mfpt
|
10
|
-
|
11
|
-
def run_command(flags)
|
12
|
-
"
|
13
|
-
|
14
|
-
|
15
|
-
data.temp_fa_file!
|
16
|
-
]
|
20
|
+
|
21
|
+
def run_command(flags)
|
22
|
+
Wrnap.debugger { "Running #{exec_name} on #{data.inspect}" }
|
23
|
+
|
24
|
+
"%s %s" % [exec_name, stringify_flags(flags)]
|
17
25
|
end
|
18
|
-
|
26
|
+
|
19
27
|
def post_process
|
20
28
|
@mfpt = response.to_f
|
21
29
|
end
|
@@ -33,22 +33,29 @@ module Wrnap
|
|
33
33
|
def equilibrium(percentile: 95, window_size: 5, epsilon: 1e-4)
|
34
34
|
start = proportion_points.first
|
35
35
|
stop = proportion_points.last
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
|
37
|
+
if start != stop
|
38
|
+
sign = stop > start ? :increasing : :decreasing
|
39
|
+
# If the population is increasing over time, we want the 95%, otherwise we want the 5%
|
40
|
+
spread_100 = (start.zero? || stop.zero? ? [start, stop].max : (stop / start).abs) / 100
|
41
|
+
# Look for the first index at the percentile we're interested in, and scan to the right from there.
|
42
|
+
start_index = proportion_points.each_with_index.find do |proportion, i|
|
43
|
+
case sign
|
44
|
+
when :increasing then proportion > (stop - (spread_100 * (100 - percentile)))
|
45
|
+
when :decreasing then proportion < (stop + (spread_100 * (100 - percentile)))
|
46
|
+
end
|
47
|
+
end.last
|
48
|
+
|
49
|
+
# The first slice starting at x we find where abs(p(x + i), p(x)) < epslion for all 1 <= x < window_size is equilibrium,
|
50
|
+
# and we return that time point.
|
51
|
+
equilibrium_time = proportion_over_time[start_index..-1].each_cons(window_size).find do |proportion_slice|
|
52
|
+
proportion_slice.all? { |time, proportion| (proportion - proportion_slice.first.last).abs < epsilon }
|
44
53
|
end
|
45
|
-
end.last
|
46
54
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end.first.first
|
55
|
+
equilibrium_time ? 10 ** equilibrium_time.first.first : -1
|
56
|
+
else
|
57
|
+
-1
|
58
|
+
end
|
52
59
|
end
|
53
60
|
|
54
61
|
def time_points; proportion_over_time.map(&:first); end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
module Wrnap
|
2
2
|
module Package
|
3
|
-
class Spectral < Base
|
4
|
-
self.default_flags = ->(context, flags)
|
5
|
-
|
3
|
+
class Spectral < Base
|
4
|
+
self.default_flags = ->(context, flags) do
|
5
|
+
{
|
6
|
+
s: context.data.seq,
|
7
|
+
k: context.data.str_1,
|
8
|
+
l: context.data.str_2
|
9
|
+
}
|
10
|
+
end
|
11
|
+
self.quote_flag_params = %i|s k l|
|
12
|
+
|
6
13
|
attr_reader :eigenvalues, :time_kinetics
|
7
|
-
|
14
|
+
|
8
15
|
def run_command(flags)
|
9
|
-
"
|
10
|
-
|
11
|
-
|
12
|
-
]
|
16
|
+
Wrnap.debugger { "Running #{exec_name} on #{data.inspect}" }
|
17
|
+
|
18
|
+
"%s %s" % [exec_name, stringify_flags(flags)]
|
13
19
|
end
|
14
|
-
|
20
|
+
|
15
21
|
def post_process
|
16
|
-
if flags.keys.include?(:eigen_only)
|
17
|
-
@eigenvalues = response.split(?\n).map(&:to_f).sort_by(&:abs)
|
18
|
-
else
|
19
|
-
@time_kinetics = response.split(?\n).map { |line| line.split(?\t).map(&:to_f) }
|
20
|
-
end
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
24
|
-
end
|
25
|
+
end
|
data/lib/wrnap/version.rb
CHANGED
data/lib/wrnap.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrnap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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: 2014-04-
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|