Class: Scaffolder::Region::Sequence
- Inherits:
-
Scaffolder::Region
- Object
- Scaffolder::Region
- Scaffolder::Region::Sequence
- Defined in:
- lib/scaffolder/region/sequence.rb
Overview
Class for inserting fasta sequence into the genome scaffold. The #raw_sequence method is also responsible for applying each of the sequence inserts to the original sequence. The following example specifies the insertion of a sequence identified by the fasta header ‘sequence1’. The example also outlines and insert to be added to the sequence in the region between 3 and 10.
- sequence:
source: 'sequence1'
inserts:
-
source: 'insert1'
open: 3
close: 10
Instance Method Summary collapse
-
#inserts(inserts = nil) ⇒ Array
Array of inserts to add to this sequence.
-
#sequence_hook ⇒ String
Adds each of the sequence inserts to the raw sequence.
-
#source ⇒ String
Fasta identifier for this sequence.
Methods inherited from Scaffolder::Region
[], attribute, #entry_type, generate, #raw_sequence, #reverse, #sequence, #start, #stop
Instance Method Details
#inserts(inserts = nil) ⇒ Array
Array of inserts to add to this sequence. Each array entry may be either a Scaffolder::Region:Inserts or a corresponding to the attributes of an Insert. In the case of the latter each hash is used to generate a new Scaffolder::Region::Insert instance.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/scaffolder/region/sequence.rb', line 31 def inserts(inserts=nil) if inserts.nil? @inserts || Array.new else @inserts = inserts.map do |insert| if insert.instance_of? Insert insert else Insert.generate(insert) end end end end |
#sequence_hook ⇒ String
Adds each of the sequence inserts to the raw sequence. Updates the sequence length each time an insert is added to reflect the change.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/scaffolder/region/sequence.rb', line 56 def sequence_hook # Set the sequence stop positon if not defined as the stop # position is updated as each insert is added @stop ||= raw_sequence.length return inserts.sort.reverse.inject(raw_sequence) do |seq,insert| raise CoordinateError if insert.open > raw_sequence.length raise CoordinateError if insert.close < 1 raise CoordinateError if insert.open > insert.close before_size = seq.length seq[insert.position] = insert.sequence diff = seq.length - before_size stop(stop + diff) seq end end |
#source ⇒ String
Fasta identifier for this sequence
21 |
# File 'lib/scaffolder/region/sequence.rb', line 21 attribute :source |