Class: RGFA::ByteArray

Inherits:
Array show all
Defined in:
lib/rgfa/byte_array.rb,
lib/rgfa/field_writer.rb,
lib/rgfa/field_validator.rb

Overview

Array of positive integers <= 255; representation of the data contained in an H field

Defined Under Namespace

Classes: FormatError, ValueError

Instance Method Summary collapse

Methods inherited from Array

#rgfa_field_array?, #to_cigar, #to_cigar_operation, #to_gfa_field, #to_numeric_array, #to_oriented_segment, #to_rgfa, #to_rgfa_field_array, #to_rgfa_line, #to_segment_end

Instance Method Details

#default_gfa_datatypeRGFA::Line::FIELD_DATATYPE

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.

Optional field GFA datatype to use, if none is provided



97
# File 'lib/rgfa/field_writer.rb', line 97

def default_gfa_datatype; :H; end

#to_byte_arrayRGFA::ByteArray

Returns self

Returns:



27
28
29
# File 'lib/rgfa/byte_array.rb', line 27

def to_byte_array
  self
end

#to_sString

GFA datatype H representation of the byte array

Returns:

Raises:



35
36
37
38
39
40
41
# File 'lib/rgfa/byte_array.rb', line 35

def to_s
  validate!
  map do |elem|
    str = elem.to_s(16).upcase
    elem < 16 ? "0#{str}" : str
  end.join
end

#validate!void

This method returns an undefined value.

Validates the byte array content

Raises:



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rgfa/byte_array.rb', line 13

def validate!
  each do |x|
    unless x.kind_of?(Integer) and (0..255).include?(x)
      raise RGFA::ByteArray::ValueError,
        "Value incompatible with byte array: #{x.inspect}\n"+
        "in array: #{self.inspect}"
    end
  end
  self.trust
  return nil
end

#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 object according to the provided datatype

Parameters:

Raises:



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/rgfa/field_validator.rb', line 155

def validate_gfa_field!(datatype, fieldname=nil)
  if datatype != :H
    raise RGFA::FieldParser::FormatError,
        "Wrong type (#{self.class}) for field #{fieldname}\n"+
        "Content: #{self.inspect}\n"+
        "Datatype: #{datatype}"
  end
  begin
    validate!
  rescue => err
    raise RGFA::FieldParser::FormatError,
      "Invalid content for field #{fieldname}\n"+
      "Content: #{self.inspect}\n"+
      "Datatype: #{datatype}\n"+
      "Error: #{err}"
  end
end