Module: RGFA::FieldParser Private
- Included in:
- String
- Defined in:
- lib/rgfa/field_parser.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 parse the string representations of the GFA fields
Defined Under Namespace
Classes: FormatError, UnknownDatatypeError
Instance Method Summary collapse
-
#parse_gfa_field(datatype: nil, validate_strings: true, fieldname: nil, frozen: false) ⇒ Object
private
Parse a string representation of a GFA field value.
-
#parse_gfa_optfield ⇒ Array(Symbol, RGFA::Line::FIELD_DATATYPE, String)
private
Parses an optional field in the form tagname:datatype:value and parses the value according to the datatype.
Instance Method Details
#parse_gfa_field(datatype: nil, validate_strings: true, fieldname: nil, frozen: false) ⇒ Object
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.
Parse a string representation of a GFA field value
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rgfa/field_parser.rb', line 17 def parse_gfa_field(datatype: nil, validate_strings: true, fieldname: nil, frozen: false) case datatype when :cmt return self when :A, :Z, :seq validate_gfa_field!(datatype, fieldname: fieldname) if validate_strings self.freeze if frozen return self when :lbl validate_segment_name! validate_gfa_field!(datatype, fieldname: fieldname) if validate_strings return to_sym.freeze when :orn validate_gfa_field!(datatype, fieldname: fieldname) if validate_strings return to_sym.freeze when :i return Integer(self) when :pos value = Integer(self) raise RGFA::FieldParser::FormatError if value < 0 return value when :f return Float(self) when :H value = to_byte_array value.freeze if frozen return value when :B value = to_numeric_array value.freeze if frozen return value when :J value = JSON.parse(self) # RGFA convention for array of fields if value.kind_of?(Array) and value.rgfa_field_array? value = value.to_rgfa_field_array end # no need to freeze, as any Hash or Array will be valid return value when :cig value = to_cigar value.freeze if frozen return value when :cgs value = split(",").map do |c| c = c.to_cigar c.freeze if frozen c end value.freeze if frozen return value when :lbs value = split(",").map do |l| o = l[-1].to_sym l = l[0..-2] if validate_strings l.validate_gfa_field!(:lbl, fieldname: "#{fieldname} "+ "(entire field content: #{self})" ) end os = [l.to_sym, o].to_oriented_segment os.freeze if frozen os end value.freeze if frozen return value else raise RGFA::FieldParser::UnknownDatatypeError, "Datatype unknown: #{datatype.inspect}" end end |
#parse_gfa_optfield ⇒ Array(Symbol, RGFA::Line::FIELD_DATATYPE, String)
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.
Parses an optional field in the form tagname:datatype:value and parses the value according to the datatype
97 98 99 100 101 102 103 104 |
# File 'lib/rgfa/field_parser.rb', line 97 def parse_gfa_optfield if self =~ /^([A-Za-z][A-Za-z0-9]):([AifZJHB]):(.+)$/ return $1.to_sym, $2.to_sym, $3 else raise RGFA::FieldParser::FormatError, "Expected optional field, found: #{self.inspect}" end end |