wrnap 0.4.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62bce1f01b0068d45befe18bcb9bb5b6891de764
4
- data.tar.gz: 2ec02f8b44890f19b75995949b9146776642da9f
3
+ metadata.gz: cced186ba484ebc70d540fe101ff4759d2eb3c47
4
+ data.tar.gz: 7fd6be4f1939b038711422c97a070baab330303c
5
5
  SHA512:
6
- metadata.gz: 28e711a4fd54857a15fa5ce3beac1f3b3d5e99824883d44b20ec5a73deff48e6191ef38f64c4d85a8198e481736c0a467ca1b88bea2f1fb243610913d47e79e7
7
- data.tar.gz: 0dcdb3c401989fe413270b27334a91ee5a21f27c4f7ec9307251e2549c7bdde12c950c2757764a1d27e82618883245d56557fc3aea4550828e597fff0ca4cf18
6
+ metadata.gz: c02bfb4374a250c235e9f31f35aad4fe495398e867f1584efe446fda114b873904864c165f7b19c13d129935df2b9f0037af8a7f17b14f04f896e306e57076fc
7
+ data.tar.gz: 37674ca85c4a31fe90dc97a032358735b7aad243a5a2507433ea227828170f9647ef4afa52fe9e22c96aae7353784714dd40d353fc6da47db1c3d2abf52a228a
@@ -44,8 +44,8 @@ module Wrnap
44
44
  end
45
45
  end
46
46
 
47
- def init_from_context(context: [], rna: [])
48
- init_from_string(Context.init_from_entrez(*context), *rna)
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 Context < Rna
4
- attr_reader :accession, :from, :to, :coord_options
5
-
6
- class << self
7
- def init_from_entrez(accession, from, to, coord_options = {})
8
- new(
9
- accession: accession,
10
- from: from,
11
- to: to,
12
- coord_options: coord_options
13
- )
14
- end
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
- def init_from_string(sequence, accession, from, to, coord_options = {})
17
- new(
18
- sequence: sequence,
19
- accession: accession,
20
- from: from,
21
- to: to,
22
- coord_options: coord_options
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
- def initialize(sequence: nil, accession: nil, from: nil, to: nil, coord_options: {})
28
- @accession, @from, @to, @coord_options = accession, from, to, coord_options
28
+ def initialize(sequence: nil, accession: nil, from: nil, to: nil, options: {})
29
+ options = { coords: {}, rna: {} }.merge(options)
29
30
 
30
- validate_coord_options
31
+ @accession, @from, @to, @coord_options = accession, from, to, options[:coords]
31
32
 
32
- if sequence
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
- def validate_coord_options
38
- unless coord_options.empty?
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
- unless (length = coord_options[:length]).is_a?(Integer) && length > 0
44
- raise ArgumentError.new("coord_options length must be greater than 0, found: %d" % length)
45
- end
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
- unless [:up, :down, :both, 5, 3].include?(direction = coord_options[:direction])
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
- def up_coord
54
- [from, to].min
55
- end
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
- def down_coord
58
- [from, to].max
59
- end
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
- def seq_from
62
- up_coord + coord_window.min
63
- end
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
- def seq_to
66
- up_coord + coord_window.max
67
- end
65
+ def up_coord
66
+ [from, to].min
67
+ end
68
68
 
69
- def strand
70
- plus_strand? ? :plus : :minus
71
- end
69
+ def down_coord
70
+ [from, to].max
71
+ end
72
72
 
73
- def plus_strand?
74
- to > from
75
- end
73
+ def seq_from
74
+ up_coord + coord_window.min
75
+ end
76
76
 
77
- def minus_strand?
78
- !plus_strand?
79
- end
77
+ def seq_to
78
+ up_coord + coord_window.max
79
+ end
80
80
 
81
- def sequence
82
- @raw_sequence ||= Entrez.rna_sequence_from_entrez(accession, up_coord, coord_window)
83
- @raw_sequence = minus_strand? ? @raw_sequence.complement : @raw_sequence
84
- end
81
+ def strand
82
+ plus_strand? ? :plus : :minus
83
+ end
85
84
 
86
- alias :seq :sequence
85
+ def plus_strand?
86
+ to > from
87
+ end
87
88
 
88
- def extend!(coord_options = {})
89
- tap do
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
- def extended?
98
- @extended
99
- end
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
- def coord_window
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
- if coord_options[:length] && coord_options[:direction]
107
- if coord_options[:direction] == :both
108
- Range.new(range.min - coord_options[:length], range.max + coord_options[:length])
109
- else
110
- case [coord_options[:direction], strand]
111
- when [3, :plus], [:down, :plus], [5, :minus], [:up, :minus] then Range.new(range.min, range.max + coord_options[:length])
112
- when [5, :plus], [:up, :plus], [3, :minus], [:down, :minus] then Range.new(range.min - coord_options[:length], range.max)
113
- 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 }
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
- else
117
- range
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
@@ -1,3 +1,3 @@
1
1
  module Wrnap
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Senter