Module: RGFA::FieldValidator Private

Included in:
String
Defined in:
lib/rgfa/field_validator.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Methods to validate the string representations of the GFA fields data

Constant Summary collapse

DATASTRING_VALIDATION_REGEXP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Validation regular expressions, derived from the GFA specification

{
  :A => /^[!-~]$/,         # Printable character
  :i => /^[-+]?[0-9]+$/,   # Signed integer
  :f => /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/,
                         # Single-precision floating number
  :Z => /^[ !-~]+$/,       # Printable string, including space
  :J => /^[ !-~]+$/,       # JSON, excluding new-line and tab characters
  :H => /^[0-9A-F]+$/,     # Byte array in the Hex format
  :B => /^[cCsSiIf](,[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+$/,
                         # Integer or numeric array
  :lbl => /^[!-)+-<>-~][!-~]*$/,       # segment/path label
  :orn => /^\+|-$/,                    # segment orientation
  :lbs => /^[!-)+-<>-~][!-~]*[+-](,[!-)+-<>-~][!-~]*[+-])+$/,
                         # multiple labels with orientations, comma-sep
  :seq => /^\*$|^[A-Za-z=.]+$/,          # nucleotide sequence
  :pos => /^[0-9]*$/,                  # positive integer
  :cig => /^(\*|(([0-9]+[MIDNSHPX=])+))$/, # CIGAR string
  :cgs => /^(\*|(([0-9]+[MIDNSHPX=])+))(,(\*|(([0-9]+[MIDNSHPX=])+)))*$/,
                                     # multiple CIGARs, comma-sep
}

Instance Method Summary collapse

Instance Method Details

#validate_gfa_field!(datatype, fieldname = nil) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Validates the string according to the provided datatype

Parameters:

Raises:



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rgfa/field_validator.rb', line 39

def validate_gfa_field!(datatype, fieldname=nil)
  regexp = DATASTRING_VALIDATION_REGEXP[datatype]
  raise RGFA::FieldParser::UnknownDatatypeError if regexp.nil?
  if (regexp !~ self)
    fieldname ||= "Value"
    raise RGFA::FieldParser::FormatError,
      "Wrong format for field #{fieldname}: \n"+
      "Content: #{self.inspect}\n"+
      "Datatype: #{datatype}\n"+
      "Expected regex: #{regexp}\n"
  end
end