Class: Rbfam::Sequence
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Rbfam::Sequence
- Defined in:
- lib/rbfam/modules/sequence.rb
Instance Attribute Summary collapse
-
#accession ⇒ Object
readonly
Returns the value of attribute accession.
-
#coord_options ⇒ Object
readonly
Returns the value of attribute coord_options.
-
#family ⇒ Object
readonly
Returns the value of attribute family.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
- #coord_window ⇒ Object
- #description ⇒ Object
- #down_coord ⇒ Object
- #extend!(coord_options = {}) ⇒ Object
- #extended? ⇒ Boolean
-
#initialize(family, accession, from, to, options = {}) ⇒ Sequence
constructor
A new instance of Sequence.
- #inspect ⇒ Object
- #minus_strand? ⇒ Boolean
- #plus_strand? ⇒ Boolean
- #save!(options = {}) ⇒ Object
- #seq_from ⇒ Object
- #seq_to ⇒ Object
- #strand ⇒ Object
- #up_coord ⇒ Object
Constructor Details
#initialize(family, accession, from, to, options = {}) ⇒ Sequence
Returns a new instance of Sequence.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rbfam/modules/sequence.rb', line 5 def initialize(family, accession, from, to, = {}) @family = family @accession = accession @from = from @to = to @coord_options = [:autoload].is_a?(Hash) ? [:autoload] : {} if [:sequence] @raw_sequence = ([:sequence].is_a?(String) ? Bio::Sequence::NA.new([:sequence]) : [:sequence]).upcase end if [:autoload] sequence end end |
Instance Attribute Details
#accession ⇒ Object (readonly)
Returns the value of attribute accession.
3 4 5 |
# File 'lib/rbfam/modules/sequence.rb', line 3 def accession @accession end |
#coord_options ⇒ Object (readonly)
Returns the value of attribute coord_options.
3 4 5 |
# File 'lib/rbfam/modules/sequence.rb', line 3 def @coord_options end |
#family ⇒ Object (readonly)
Returns the value of attribute family.
3 4 5 |
# File 'lib/rbfam/modules/sequence.rb', line 3 def family @family end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
3 4 5 |
# File 'lib/rbfam/modules/sequence.rb', line 3 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
3 4 5 |
# File 'lib/rbfam/modules/sequence.rb', line 3 def to @to end |
Instance Method Details
#coord_window ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rbfam/modules/sequence.rb', line 91 def coord_window # Options from coord_options ex: { length: 300, extend: 3 }, or { length: 250, extend: :both } 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], [5, :minus] then Range.new(range.min, range.max + [:length]) when [5, :plus], [3, :minus] then Range.new(range.min - [:length], range.max) else puts "WARNING: value for :direction key in sequence retrieval needs to be one of 5, 3, :both - found (%s)" % [:direction].inspect end end else range end end |
#description ⇒ Object
74 75 76 |
# File 'lib/rbfam/modules/sequence.rb', line 74 def description ("%s %s %s" % [accession, from, to]).gsub(/\W+/, "_") end |
#down_coord ⇒ Object
45 46 47 |
# File 'lib/rbfam/modules/sequence.rb', line 45 def down_coord [from, to].max end |
#extend!(coord_options = {}) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/rbfam/modules/sequence.rb', line 78 def extend!( = {}) tap do @extended = true @coord_options = remove_instance_variable(:@raw_sequence) sequence end end |
#extended? ⇒ Boolean
87 88 89 |
# File 'lib/rbfam/modules/sequence.rb', line 87 def extended? @extended end |
#inspect ⇒ Object
110 111 112 |
# File 'lib/rbfam/modules/sequence.rb', line 110 def inspect "#<Rbfam::Sequence #{description} #{seq[0, 20] + ('...' if seq.length > 20)}>" end |
#minus_strand? ⇒ Boolean
65 66 67 |
# File 'lib/rbfam/modules/sequence.rb', line 65 def minus_strand? !plus_strand? end |
#plus_strand? ⇒ Boolean
61 62 63 |
# File 'lib/rbfam/modules/sequence.rb', line 61 def plus_strand? to > from end |
#save!(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rbfam/modules/sequence.rb', line 21 def save!( = {}) unless extended? Rbfam.script("sequences_in_mysql") SequenceTable.create({ family: family.family_name, accession: accession, sequence: sequence, sequence_length: sequence.length, from: from, to: to, seq_from: seq_from, seq_to: seq_to, seed: [:seed] }) else tap { puts "ERROR: at this time you can not save #{self.class.name}#extend! objects to protect against DB redundancy (and I'm lazy)." } end end |
#seq_from ⇒ Object
49 50 51 |
# File 'lib/rbfam/modules/sequence.rb', line 49 def seq_from up_coord + coord_window.min end |
#seq_to ⇒ Object
53 54 55 |
# File 'lib/rbfam/modules/sequence.rb', line 53 def seq_to up_coord + coord_window.max end |
#strand ⇒ Object
57 58 59 |
# File 'lib/rbfam/modules/sequence.rb', line 57 def strand plus_strand? ? :plus : :minus end |
#up_coord ⇒ Object
41 42 43 |
# File 'lib/rbfam/modules/sequence.rb', line 41 def up_coord [from, to].min end |