wrnap 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wrnap/global/rna.rb +3 -3
- data/lib/wrnap/global/rna/context.rb +101 -89
- data/lib/wrnap/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cced186ba484ebc70d540fe101ff4759d2eb3c47
|
4
|
+
data.tar.gz: 7fd6be4f1939b038711422c97a070baab330303c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c02bfb4374a250c235e9f31f35aad4fe495398e867f1584efe446fda114b873904864c165f7b19c13d129935df2b9f0037af8a7f17b14f04f896e306e57076fc
|
7
|
+
data.tar.gz: 37674ca85c4a31fe90dc97a032358735b7aad243a5a2507433ea227828170f9647ef4afa52fe9e22c96aae7353784714dd40d353fc6da47db1c3d2abf52a228a
|
data/lib/wrnap/global/rna.rb
CHANGED
@@ -44,8 +44,8 @@ module Wrnap
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def init_from_context(context:
|
48
|
-
|
47
|
+
def init_from_context(*context, coords: {}, rna: {})
|
48
|
+
Context.init_from_entrez(*context, coords: coords, rna: rna)
|
49
49
|
end
|
50
50
|
|
51
51
|
def init_from_self(rna)
|
@@ -62,7 +62,7 @@ module Wrnap
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def initialize(sequence: "", structure: "", second_structure: "", comment: "")
|
65
|
-
@sequence, @comment = sequence.kind_of?(Rna) ? sequence.seq : sequence, comment
|
65
|
+
@sequence, @comment = (sequence.kind_of?(Rna) ? sequence.seq : sequence).upcase, comment
|
66
66
|
|
67
67
|
[:structure, :second_structure].each do |structure_symbol|
|
68
68
|
instance_variable_set(
|
@@ -1,120 +1,132 @@
|
|
1
1
|
module Wrnap
|
2
2
|
module Global
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
class Rna
|
4
|
+
class Context < Rna
|
5
|
+
attr_reader :accession, :from, :to, :coord_options
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def init_from_entrez(accession, from, to, options = {})
|
9
|
+
new(
|
10
|
+
accession: accession,
|
11
|
+
from: from,
|
12
|
+
to: to,
|
13
|
+
options: options
|
14
|
+
)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def init_from_string(sequence, accession, from, to, options = {})
|
18
|
+
new(
|
19
|
+
sequence: sequence,
|
20
|
+
accession: accession,
|
21
|
+
from: from,
|
22
|
+
to: to,
|
23
|
+
options: options
|
24
|
+
)
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
def initialize(sequence: nil, accession: nil, from: nil, to: nil, options: {})
|
29
|
+
options = { coords: {}, rna: {} }.merge(options)
|
29
30
|
|
30
|
-
|
31
|
+
@accession, @from, @to, @coord_options = accession, from, to, options[:coords]
|
31
32
|
|
32
|
-
|
33
|
-
@raw_sequence = (sequence.is_a?(String) ? Bio::Sequence::NA.new(sequence) : sequence).upcase
|
34
|
-
end
|
35
|
-
end
|
33
|
+
validate_coord_options
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
unless coord_options.keys == Set.new(%i|direction length|)
|
40
|
-
raise ArgumentError.new("coord_options keys must contain only :direction, :length, found: %s" % coord_options.keys)
|
35
|
+
if sequence
|
36
|
+
@raw_sequence = (sequence.is_a?(String) ? Bio::Sequence::NA.new(sequence) : sequence).upcase
|
41
37
|
end
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
super({
|
40
|
+
sequence: self.sequence,
|
41
|
+
structure: options[:rna][:structure] || options[:rna][:str_1] || options[:rna][:str],
|
42
|
+
second_structure: options[:rna][:second_structure] || options[:rna][:str_2],
|
43
|
+
comment: options[:rna][:comment] || options[:rna][:name]
|
44
|
+
})
|
46
45
|
|
47
|
-
|
48
|
-
raise ArgumentError.new("coord_options directions is not a valid key, found: %s" % direction)
|
49
|
-
end
|
46
|
+
remove_instance_variable(:@sequence)
|
50
47
|
end
|
51
|
-
end
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
def validate_coord_options
|
50
|
+
unless coord_options.empty?
|
51
|
+
unless Set.new(coord_options.keys) == Set.new(%i|direction length|)
|
52
|
+
raise ArgumentError.new("coord_options keys must contain only [:direction, :length], found: %s" % coord_options.keys)
|
53
|
+
end
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
unless (length = coord_options[:length]).is_a?(Integer) && length > 0
|
56
|
+
raise ArgumentError.new("coord_options length must be greater than 0, found: %d" % length)
|
57
|
+
end
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
unless [:up, :down, :both, 5, 3].include?(direction = coord_options[:direction])
|
60
|
+
raise ArgumentError.new("coord_options directions is not a valid key, found: %s" % direction)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
def up_coord
|
66
|
+
[from, to].min
|
67
|
+
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
def down_coord
|
70
|
+
[from, to].max
|
71
|
+
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
def seq_from
|
74
|
+
up_coord + coord_window.min
|
75
|
+
end
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
def seq_to
|
78
|
+
up_coord + coord_window.max
|
79
|
+
end
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
81
|
+
def strand
|
82
|
+
plus_strand? ? :plus : :minus
|
83
|
+
end
|
85
84
|
|
86
|
-
|
85
|
+
def plus_strand?
|
86
|
+
to > from
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
@coord_options = coord_options unless coord_options.empty?
|
91
|
-
validate_coord_options
|
92
|
-
@extended = true
|
93
|
-
remove_instance_variable(:@raw_sequence)
|
89
|
+
def minus_strand?
|
90
|
+
!plus_strand?
|
94
91
|
end
|
95
|
-
end
|
96
92
|
|
97
|
-
|
98
|
-
|
99
|
-
|
93
|
+
def sequence
|
94
|
+
if @raw_sequence
|
95
|
+
@raw_sequence
|
96
|
+
else
|
97
|
+
entrez_sequence = Entrez.rna_sequence_from_entrez(accession, up_coord, coord_window)
|
98
|
+
@raw_sequence = (minus_strand? ? entrez_sequence.complement : entrez_sequence).upcase
|
99
|
+
end
|
100
|
+
end
|
100
101
|
|
101
|
-
|
102
|
-
# This does not support extending the range in both directions, though it should be easy to do.
|
103
|
-
# Options from coord_options ex: { length: 300, direction: 3 }, { length: 250, direction: :both }, { length: 200, direction: :down }
|
104
|
-
range = 0..(down_coord - up_coord)
|
102
|
+
alias :seq :sequence
|
105
103
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
104
|
+
def extend!(coord_options = {})
|
105
|
+
self.class.init_from_entrez(accession, from, to, coords: coord_options)
|
106
|
+
end
|
107
|
+
|
108
|
+
def coord_window
|
109
|
+
# This does not support extending the range in both directions, though it should be easy to do.
|
110
|
+
# Options from coord_options ex: { length: 300, direction: 3 }, { length: 250, direction: :both }, { length: 200, direction: :down }
|
111
|
+
range = 0..(down_coord - up_coord)
|
112
|
+
|
113
|
+
if coord_options[:length] && coord_options[:direction]
|
114
|
+
if coord_options[:direction] == :both
|
115
|
+
Range.new(range.min - coord_options[:length], range.max + coord_options[:length])
|
116
|
+
else
|
117
|
+
case [coord_options[:direction], strand]
|
118
|
+
when [3, :plus], [:down, :plus], [5, :minus], [:up, :minus] then Range.new(range.min, range.max + coord_options[:length])
|
119
|
+
when [5, :plus], [:up, :plus], [3, :minus], [:down, :minus] then Range.new(range.min - coord_options[:length], range.max)
|
120
|
+
else Wrnap.debugger { "WARNING: value for :direction key in sequence retreival needs to be one of 5, 3, :both - found (%s)" % coord_options[:direction].inspect }
|
121
|
+
end
|
114
122
|
end
|
123
|
+
else
|
124
|
+
range
|
115
125
|
end
|
116
|
-
|
117
|
-
|
126
|
+
end
|
127
|
+
|
128
|
+
def inspect
|
129
|
+
super.gsub(/((\w(::)?)+)>$/) { |_| "%s %d %s %d %s>" % [accession, from, plus_strand? ? ?+ : ?-, to, $1] }
|
118
130
|
end
|
119
131
|
end
|
120
132
|
end
|
data/lib/wrnap/version.rb
CHANGED