class Bio::GFF::GFF3::Record::Gap

Bio:GFF::GFF3::Record::Gap is a class to store data of “Gap” attribute.

Constants

Code

Code is a class to store length of single-letter code.

Attributes

data[R]

Internal data. Users must not use it.

Public Class Methods

new(str = nil) click to toggle source

Creates a new Gap object.


Arguments:

  • str: a formatted string, or nil.

# File lib/bio/db/gff.rb, line 1274
def initialize(str = nil)
  if str then
    @data = str.split(/ +/).collect do |x|
      if /\A([A-Z])([0-9]+)\z/ =~ x.strip then
        Code.new($1.intern, $2.to_i)
      else
        warn "ignored unknown token: #{x}.inspect" if $VERBOSE
        nil
      end
    end
    @data.compact!
  else
    @data = []
  end
end
new_from_sequences_na(reference, target, gap_regexp = /[^a-zA-Z]/) click to toggle source

Creates a new Gap object from given sequence alignment.

Note that sites of which both reference and target are gaps are silently removed.


Arguments:

  • reference: reference sequence (nucleotide sequence)

  • target: target sequence (nucleotide sequence)

  • gap_regexp: regexp to identify gap

# File lib/bio/db/gff.rb, line 1390
def self.new_from_sequences_na(reference, target,
                               gap_regexp = /[^a-zA-Z]/)
  gap = self.new
  gap.instance_eval { 
    __initialize_from_sequences_na(reference, target,
                                   gap_regexp)
  }
  gap
end
new_from_sequences_na_aa(reference, target, gap_regexp = /[^a-zA-Z]/, space_regexp = /\s/, forward_frameshift_regexp = /\>/, reverse_frameshift_regexp = /\ click to toggle source

Creates a new Gap object from given sequence alignment.

Note that sites of which both reference and target are gaps are silently removed.

For incorrect alignments that break 3:1 rule, gap positions will be moved inside codons, unwanted gaps will be removed, and some forward or reverse frameshift will be inserted.

For example,

atgg-taagac-att
M  V  K  -  I

is treated as:

atggt<aagacatt
M  V  K  >>I

Incorrect combination of frameshift with frameshift or gap may cause undefined behavior.

Forward frameshifts are recomended to be indicated in the target sequence. Reverse frameshifts can be indicated in the reference sequence or the target sequence.

Priority of regular expressions:

space > forward/reverse frameshift > gap

Arguments:

  • reference: reference sequence (nucleotide sequence)

  • target: target sequence (amino acid sequence)

  • gap_regexp: regexp to identify gap

  • space_regexp: regexp to identify space character which is completely ignored

  • forward_frameshift_regexp: regexp to identify forward frameshift

  • reverse_frameshift_regexp: regexp to identify reverse frameshift

# File lib/bio/db/gff.rb, line 1586
def self.new_from_sequences_na_aa(reference, target,
                                  gap_regexp = /[^a-zA-Z]/,
                                  space_regexp = /\s/,
                                  forward_frameshift_regexp = /\>/,
                                  reverse_frameshift_regexp = /\</)
  gap = self.new
  gap.instance_eval { 
    __initialize_from_sequences_na_aa(reference, target,
                                      gap_regexp,
                                      space_regexp,
                                      forward_frameshift_regexp,
                                      reverse_frameshift_regexp)
  }
  gap
end
parse(str) click to toggle source

Same as new(str).

# File lib/bio/db/gff.rb, line 1291
def self.parse(str)
  self.new(str)
end

Public Instance Methods

==(other) click to toggle source

If self == other, returns true. otherwise, returns false.

# File lib/bio/db/gff.rb, line 1614
def ==(other)
  if other.class == self.class and
      @data == other.data then
    true
  else
    false
  end
end
process_sequences_na(reference, target, gap_char = '-') click to toggle source

Processes nucleotide sequences and returns gapped sequences as an array of sequences.

Note for forward/reverse frameshift: Forward/Reverse_frameshift is simply treated as gap insertion to the target/reference sequence.


Arguments:

  • reference: reference sequence (nucleotide sequence)

  • target: target sequence (nucleotide sequence)

  • gap_char: gap character

# File lib/bio/db/gff.rb, line 1714
def process_sequences_na(reference, target, gap_char = '-')
  s_ref, s_tgt = dup_seqs(reference, target)

  s_ref, s_tgt = __process_sequences(s_ref, s_tgt,
                                     gap_char, gap_char,
                                     1, 1,
                                     gap_char, gap_char)

  if $VERBOSE and s_ref.length != s_tgt.length then
    warn "returned sequences not equal length"
  end
  return s_ref, s_tgt
end
process_sequences_na_aa(reference, target, gap_char = '-', space_char = ' ', forward_frameshift = '>', reverse_frameshift = '<') click to toggle source

Processes sequences and returns gapped sequences as an array of sequences. reference must be a nucleotide sequence, and target must be an amino acid sequence.

Note for reverse frameshift: Reverse_frameshift characers are inserted in the reference sequence. For example, alignment of “Gap=M3 R1 M2” is:

atgaagat<aatgtc
M  K  I  N  V

Alignment of “Gap=M3 R3 M3” is:

atgaag<<<attaatgtc
M  K  I  I  N  V

Arguments:

  • reference: reference sequence (nucleotide sequence)

  • target: target sequence (amino acid sequence)

  • gap_char: gap character

  • space_char: space character inserted to amino sequence for matching na-aa alignment

  • forward_frameshift: forward frameshift character

  • reverse_frameshift: reverse frameshift character

# File lib/bio/db/gff.rb, line 1751
def process_sequences_na_aa(reference, target,
                            gap_char = '-',
                            space_char = ' ',
                            forward_frameshift = '>',
                            reverse_frameshift = '<')
  s_ref, s_tgt = dup_seqs(reference, target)
  s_tgt = s_tgt.gsub(/./, "\\0#{space_char}#{space_char}")
  ref_increment = 3
  tgt_increment = 1 + space_char.length * 2
  ref_gap = gap_char * 3
  tgt_gap = "#{gap_char}#{space_char}#{space_char}"
  return __process_sequences(s_ref, s_tgt,
                             ref_gap, tgt_gap,
                             ref_increment, tgt_increment,
                             forward_frameshift,
                             reverse_frameshift)
end
to_s() click to toggle source

string representation

# File lib/bio/db/gff.rb, line 1603
def to_s
  @data.collect { |x| x.to_s }.join(" ")
end