Class: Scaffolder::Region
- Inherits:
-
Object
- Object
- Scaffolder::Region
- Extended by:
- Errors
- Includes:
- Errors
- Defined in:
- lib/scaffolder/region.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Insert, Sequence, Unresolved
Class Method Summary collapse
-
.[](type) ⇒ Scaffolder::Region
Returns subclassed instances of Scaffolder::Region by name.
-
.attribute(name, options = {}) ⇒ Object
Links the specification of values in the scaffold file to the assignment of instance variables.
-
.generate(region_data) ⇒ Scaffolder::Region
Parse each key-value pair in the scaffold hash calling the corresponding attribute method for the key and passing the value as an argument.
Instance Method Summary collapse
-
#entry_type ⇒ Symbol
The name of the class.
-
#raw_sequence ⇒ String
The raw sequence for this region.
-
#reverse ⇒ Boolean
Should the sequence be reverse complemented.
-
#sequence ⇒ String
Returns the value of the Scaffolder::Region#raw_sequence after subsequencing and reverse complementation (if specified in the scaffold file).
-
#sequence_hook ⇒ String
Override this to manipulate the sequence before it’s subsequenced, reverse complemented etc.
-
#start ⇒ Interger
Trim the start of sequence to this position.
-
#stop ⇒ Interger
Trim the end of sequence to this position.
Class Method Details
.[](type) ⇒ Scaffolder::Region
Returns subclassed instances of Scaffolder::Region by name
11 12 13 |
# File 'lib/scaffolder/region.rb', line 11 def [](type) self.const_get(type.capitalize) end |
.attribute(name, options = {}) ⇒ Object
Links the specification of values in the scaffold file to the assignment of instance variables.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/scaffolder/region.rb', line 34 def attribute(name, = {}) define_method(name) do |*arg| var = "@#{name}" default = [:default] unless arg.first # Is an argument is passed to the method? value = instance_variable_get(var) return value if value return default.respond_to?(:call) ? default.call(self) : default end instance_variable_set(var,arg.first) end end |
.generate(region_data) ⇒ Scaffolder::Region
Parse each key-value pair in the scaffold hash calling the corresponding attribute method for the key and passing the value as an argument.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/scaffolder/region.rb', line 58 def generate(region_data) region = self.new region_data.each_pair do |attribute,value| begin region.send(attribute.to_sym,value) rescue NoMethodError => e raise UnknownAttributeError.new(e) end end region end |
Instance Method Details
#entry_type ⇒ Symbol
The name of the class. Useful for selecting specific region types.
110 111 112 |
# File 'lib/scaffolder/region.rb', line 110 def entry_type self.class.name.split('::').last.downcase.to_sym end |
#raw_sequence ⇒ String
The raw sequence for this region.
76 |
# File 'lib/scaffolder/region.rb', line 76 attribute :raw_sequence |
#reverse ⇒ Boolean
Should the sequence be reverse complemented. Reverse complementation is performed after the start and end of the sequence has been trimmed.
96 |
# File 'lib/scaffolder/region.rb', line 96 attribute :reverse |
#sequence ⇒ String
Returns the value of the Scaffolder::Region#raw_sequence after subsequencing and reverse complementation (if specified in the scaffold file).
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/scaffolder/region.rb', line 124 def sequence seq = sequence_hook raise CoordinateError.new if start < 1 raise CoordinateError.new if stop > seq.length raise CoordinateError.new if start > stop seq = seq[(start-1)..(stop-1)] seq = Bio::Sequence::NA.new(seq).reverse_complement if reverse seq.to_s.upcase end |
#sequence_hook ⇒ String
Override this to manipulate the sequence before it’s subsequenced, reverse complemented etc. by Scaffolder::Region#sequence.
103 104 105 |
# File 'lib/scaffolder/region.rb', line 103 def sequence_hook raw_sequence end |
#start ⇒ Interger
Trim the start of sequence to this position. Default is 1.
82 |
# File 'lib/scaffolder/region.rb', line 82 attribute :start, :default => 1 |
#stop ⇒ Interger
Trim the end of sequence to this position. Default is the sequence length..
88 |
# File 'lib/scaffolder/region.rb', line 88 attribute :stop, :default => lambda{|s| s.sequence_hook.length} |