Class: Wrnap::Rna::Context
- Inherits:
-
Wrnap::Rna
- Object
- Wrnap::Rna
- Wrnap::Rna::Context
- Extended by:
- Forwardable
- Defined in:
- lib/wrnap/rna/context.rb
Constant Summary
Constants inherited from Wrnap::Rna
Instance Attribute Summary collapse
-
#accession ⇒ Object
readonly
Returns the value of attribute accession.
-
#coord_options ⇒ Object
readonly
Returns the value of attribute coord_options.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Attributes inherited from Wrnap::Rna
#comment, #metadata, #sequence, #structures
Class Method Summary collapse
- .init_from_entrez(accession, from, to, options = {}, &block) ⇒ Object
- .init_from_string(sequence, accession, from, to, options = {}, &block) ⇒ Object
Instance Method Summary collapse
- #_id ⇒ Object
- #coord_window ⇒ Object
- #down_coord ⇒ Object
- #extend!(coord_options = {}) ⇒ Object
- #identifier ⇒ Object
-
#initialize(sequence: nil, accession: nil, from: nil, to: nil, options: {}, &block) ⇒ Context
constructor
A new instance of Context.
- #inspect ⇒ Object
- #minus_strand? ⇒ Boolean
- #plus_strand? ⇒ Boolean
- #seq_from ⇒ Object
- #seq_to ⇒ Object
- #strand ⇒ Object
- #up_coord ⇒ Object
- #validate_coord_options ⇒ Object
Methods inherited from Wrnap::Rna
#==, #copy_name_from, #eql?, #formatted_string, init_from_array, init_from_context, init_from_hash, parse_rna_attributes, #pp, #run, #temp_fa_file!, #write_fa!
Methods included from Constraints
Methods included from TreeFunctions
Methods included from Metadata
Methods included from Wrnapper
Methods included from Extensions
Methods included from Global::Yaml
Constructor Details
#initialize(sequence: nil, accession: nil, from: nil, to: nil, options: {}, &block) ⇒ Context
Returns a new instance of Context.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wrnap/rna/context.rb', line 31 def initialize(sequence: nil, accession: nil, from: nil, to: nil, options: {}, &block) = { coords: {}, rna: {} }.merge() @accession, @from, @to, = accession, from, to, [:coords] if sequence @raw_sequence = (sequence.is_a?(String) ? Bio::Sequence::NA.new(sequence) : sequence).upcase end super( sequence: self.sequence, structures: [:rna][:structures] || [:rna][:structure] || [:rna][:strs] || [:rna][:str], comment: [:rna][:comment] || [:rna][:name] || identifier, &block ) remove_instance_variable(:@sequence) end |
Instance Attribute Details
#accession ⇒ Object (readonly)
Returns the value of attribute accession.
6 7 8 |
# File 'lib/wrnap/rna/context.rb', line 6 def accession @accession end |
#coord_options ⇒ Object (readonly)
Returns the value of attribute coord_options.
6 7 8 |
# File 'lib/wrnap/rna/context.rb', line 6 def end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
6 7 8 |
# File 'lib/wrnap/rna/context.rb', line 6 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
6 7 8 |
# File 'lib/wrnap/rna/context.rb', line 6 def to @to end |
Class Method Details
.init_from_entrez(accession, from, to, options = {}, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/wrnap/rna/context.rb', line 9 def init_from_entrez(accession, from, to, = {}, &block) new( accession: accession, from: from.to_i, to: to.to_i, options: , &block ) end |
.init_from_string(sequence, accession, from, to, options = {}, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wrnap/rna/context.rb', line 19 def init_from_string(sequence, accession, from, to, = {}, &block) new( sequence: sequence, accession: accession, from: from.to_i, to: to.to_i, options: , &block ) end |
Instance Method Details
#_id ⇒ Object
135 136 137 |
# File 'lib/wrnap/rna/context.rb', line 135 def _id identifier.gsub(/[^A-Z0-9]/, ?_).gsub(/__+/, ?_) end |
#coord_window ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/wrnap/rna/context.rb', line 111 def coord_window # This does not support extending the range in both directions, though it should be easy to do. # Options from coord_options ex: { length: 300, direction: 3 }, { length: 250, direction: :both }, { length: 200, direction: :down } range = 0..(down_coord - up_coord) if [:length] && [:direction] if [:direction] == :both Range.new(range.min - [:length], range.max + [:length]) else case [[:direction], strand] when [3, :plus], [:down, :plus], [5, :minus], [:up, :minus] then Range.new(range.min, range.max + [:length]) when [5, :plus], [:up, :plus], [3, :minus], [:down, :minus] then Range.new(range.min - [:length], range.max) else Wrnap.debugger { "WARNING: value for :direction key in sequence retreival needs to be one of 5, 3, :both - found (%s)" % [:direction].inspect } end end else range end end |
#down_coord ⇒ Object
72 73 74 |
# File 'lib/wrnap/rna/context.rb', line 72 def down_coord [from, to].max end |
#extend!(coord_options = {}) ⇒ Object
107 108 109 |
# File 'lib/wrnap/rna/context.rb', line 107 def extend!( = {}) self.class.init_from_entrez(accession, from, to, coords: ) end |
#identifier ⇒ Object
131 132 133 |
# File 'lib/wrnap/rna/context.rb', line 131 def identifier "%s %d %s %d" % [accession, seq_from, plus_strand? ? ?+ : ?-, seq_to] end |
#inspect ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/wrnap/rna/context.rb', line 139 def inspect if super.match(/Wrnap::(\w+(::)?)+>$/) super.sub(/([\w:]+)>$/) { |_| "%s %s>" % [identifier, $1] } else super end end |
#minus_strand? ⇒ Boolean
92 93 94 |
# File 'lib/wrnap/rna/context.rb', line 92 def minus_strand? !plus_strand? end |
#plus_strand? ⇒ Boolean
88 89 90 |
# File 'lib/wrnap/rna/context.rb', line 88 def plus_strand? to > from end |
#seq_from ⇒ Object
76 77 78 |
# File 'lib/wrnap/rna/context.rb', line 76 def seq_from up_coord + coord_window.min end |
#seq_to ⇒ Object
80 81 82 |
# File 'lib/wrnap/rna/context.rb', line 80 def seq_to up_coord + coord_window.max end |
#strand ⇒ Object
84 85 86 |
# File 'lib/wrnap/rna/context.rb', line 84 def strand plus_strand? ? :plus : :minus end |
#up_coord ⇒ Object
68 69 70 |
# File 'lib/wrnap/rna/context.rb', line 68 def up_coord [from, to].min end |
#validate_coord_options ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wrnap/rna/context.rb', line 52 def unless .empty? unless Set.new(.keys) == Set.new(i|direction length|) raise ArgumentError.new("coord_options keys must contain only [:direction, :length], found: %s" % .keys) end unless (length = [:length]).is_a?(Integer) && length > 0 raise ArgumentError.new("coord_options length must be greater than 0, found: %d" % length) end unless [:up, :down, :both, 5, 3].include?(direction = [:direction]) raise ArgumentError.new("coord_options directions is not a valid key, found: %s" % direction) end end end |