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
(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 254 def char2octal(x) 255 x.enum_for(:each_byte).collect { |y| 256 sprintf("%03o", y) }.join("\\") 257 end
(private) escapes GFF2
attribute tag string
# File lib/bio/db/gff.rb 289 def escape_gff2_attribute_tag(str) 290 str = str.to_s 291 str = str.empty? ? '.' : str 292 str = str.gsub(PROHIBITED_GFF2_TAGS) do |x| 293 "\\" + (CHAR2BACKSLASH[x] || char2octal(x)) 294 end 295 if str[0, 1] == '#' then 296 str[0, 1] = "\\043" 297 end 298 str 299 end
(private) escapes GFF2
attribute value string
# File lib/bio/db/gff.rb 260 def escape_gff2_attribute_value(str) 261 freetext?(str) ? escape_gff2_freetext(str) : str 262 end
(private) escapes GFF2
free text string
# File lib/bio/db/gff.rb 245 def escape_gff2_freetext(str) 246 '"' + str.gsub(UNSAFE_GFF2) do |x| 247 "\\" + (CHAR2BACKSLASH_EXTENDED[x] || char2octal(x)) 248 end + '"' 249 end
(private) check if the given string is a free text to be quoted by double-qoute.
# File lib/bio/db/gff.rb 266 def freetext?(str) 267 if IDENTIFIER_GFF2 =~ str or 268 NUMERIC_GFF2 =~ str then 269 false 270 else 271 true 272 end 273 end
(private) escapes normal columns in GFF2
# File lib/bio/db/gff.rb 276 def gff2_column_to_s(str) 277 str = str.to_s 278 str = str.empty? ? '.' : str 279 str = str.gsub(PROHIBITED_GFF2_COLUMNS) do |x| 280 "\\" + (CHAR2BACKSLASH[x] || char2octal(x)) 281 end 282 if str[0, 1] == '#' then 283 str[0, 1] = "\\043" 284 end 285 str 286 end
(private) dummy method, will be redefined in GFF3
.
# File lib/bio/db/gff.rb 302 def unescape(str) 303 str 304 end