Class: Scaffolder::Region::Sequence

Inherits:
Scaffolder::Region show all
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

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.

Parameters:

  • inserts (Array) (defaults to: nil)

    Accepts an array of either Scaffolder::Region::Insert or a hash of insert keyword data.

Returns:

  • (Array)

    Array of Scaffolder::Region::Insert



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_hookString

Adds each of the sequence inserts to the raw sequence. Updates the sequence length each time an insert is added to reflect the change.

Returns:

  • (String)

    original sequence with inserts added.

Raises:

  • (CoordinateError)

    if any insert open position is greater than the length of the original sequence

  • (CoordinateError)

    if any insert close position is less than one

  • (CoordinateError)

    if any insert open position is greater than the close position



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

#sourceString

Fasta identifier for this sequence

Parameters:

  • (String)

Returns:

  • (String)


21
# File 'lib/scaffolder/region/sequence.rb', line 21

attribute :source