module Bio::GFF::GFF2::Escape

Private methods for GFF2 escaping characters. Internal only. Users should not use this module directly.

Constants

BACKSLASH

List of 1-letter special backslash code. The letters other than listed here are the same as those of without backslash, except for “x” and digits. (Note that u (unicode) is not supported.)

CHAR2BACKSLASH

inverted hash of BACKSLASH

CHAR2BACKSLASH_EXTENDED

inverted hash of BACKSLASH, including double quote and backslash

IDENTIFIER_GFF2

GFF2 standard identifier

NUMERIC_GFF2

GFF2 numeric value

PROHIBITED_GFF2_COLUMNS

prohibited characters in GFF2 columns

PROHIBITED_GFF2_TAGS

prohibited characters in GFF2 attribute tags

UNSAFE_GFF2

unsafe characters to be escaped

Private Instance Methods

char2octal(x) click to toggle source

(private) “x” => “\oXXX” “x” must be a letter. If “x” is consisted of two bytes or more, joined with “\”.

# File lib/bio/db/gff.rb, line 254
def char2octal(x)
  x.enum_for(:each_byte).collect { |y|
    sprintf("%03o", y) }.join("\\")
end
escape_gff2_attribute_tag(str) click to toggle source

(private) escapes GFF2 attribute tag string

# File lib/bio/db/gff.rb, line 289
def escape_gff2_attribute_tag(str)
  str = str.to_s
  str = str.empty? ? '.' : str
  str = str.gsub(PROHIBITED_GFF2_TAGS) do |x|
    "\\" + (CHAR2BACKSLASH[x] || char2octal(x))
  end
  if str[0, 1] == '#' then
    str[0, 1] = "\\043"
  end
  str
end
escape_gff2_attribute_value(str) click to toggle source

(private) escapes GFF2 attribute value string

# File lib/bio/db/gff.rb, line 260
def escape_gff2_attribute_value(str)
  freetext?(str) ? escape_gff2_freetext(str) : str
end
escape_gff2_freetext(str) click to toggle source

(private) escapes GFF2 free text string

# File lib/bio/db/gff.rb, line 245
def escape_gff2_freetext(str)
  '"' + str.gsub(UNSAFE_GFF2) do |x|
    "\\" + (CHAR2BACKSLASH_EXTENDED[x] || char2octal(x))
  end + '"'
end
freetext?(str) click to toggle source

(private) check if the given string is a free text to be quoted by double-qoute.

# File lib/bio/db/gff.rb, line 266
def freetext?(str)
  if IDENTIFIER_GFF2 =~ str or
      NUMERIC_GFF2 =~ str then
    false
  else
    true
  end
end
gff2_column_to_s(str) click to toggle source

(private) escapes normal columns in GFF2

# File lib/bio/db/gff.rb, line 276
def gff2_column_to_s(str)
  str = str.to_s
  str = str.empty? ? '.' : str
  str = str.gsub(PROHIBITED_GFF2_COLUMNS) do |x|
    "\\" + (CHAR2BACKSLASH[x] || char2octal(x))
  end
  if str[0, 1] == '#' then
    str[0, 1] = "\\043"
  end
  str
end
unescape(str) click to toggle source

(private) dummy method, will be redefined in GFF3.

# File lib/bio/db/gff.rb, line 302
def unescape(str)
  str
end