Class: String
- Includes:
- RGFA::FieldParser, RGFA::FieldValidator, RGFA::Sequence
- Defined in:
- lib/rgfa.rb,
lib/rgfa/line.rb,
lib/rgfa/cigar.rb,
lib/rgfa/sequence.rb,
lib/rgfa/byte_array.rb,
lib/rgfa/field_parser.rb,
lib/rgfa/numeric_array.rb,
lib/rgfa/field_validator.rb
Overview
Method to create a numeric array from a string
Constant Summary
Constants included from RGFA::FieldValidator
RGFA::FieldValidator::DATASTRING_VALIDATION_REGEXP
Constants included from RGFA::Sequence
Instance Method Summary collapse
-
#to_byte_array ⇒ RGFA::ByteArray
Convert a GFA string representation of a byte array to a byte array.
-
#to_cigar ⇒ RGFA::CIGAR
Parse CIGAR string and return an array of CIGAR operations.
-
#to_numeric_array(validate: true) ⇒ RGFA::NumericArray
Create a numeric array from a string.
-
#to_rgfa(validate: 2) ⇒ RGFA
Converts a
Stringinto aRGFAinstance. -
#to_rgfa_line(validate: 2) ⇒ subclass of RGFA::Line
Parses a line of a RGFA file and creates an object of the correct record type child class of RGFA::Line.
Methods included from RGFA::FieldValidator
Methods included from RGFA::FieldParser
#parse_gfa_field, #parse_gfa_optfield
Methods included from RGFA::Sequence
Instance Method Details
#to_byte_array ⇒ RGFA::ByteArray
Convert a GFA string representation of a byte array to a byte array
66 67 68 69 70 71 72 73 |
# File 'lib/rgfa/byte_array.rb', line 66 def to_byte_array if (size < 2) or (size % 2 == 1) raise RGFA::ByteArray::FormatError, "Invalid byte array string #{self}; "+ "each element must be represented by two letters [0-9A-F]" end scan(/..?/).map {|x|Integer(x,16)}.to_byte_array end |
#to_cigar ⇒ RGFA::CIGAR
Parse CIGAR string and return an array of CIGAR operations
153 154 155 |
# File 'lib/rgfa/cigar.rb', line 153 def to_cigar RGFA::CIGAR.from_string(self) end |
#to_numeric_array(validate: true) ⇒ RGFA::NumericArray
Create a numeric array from a string
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/rgfa/numeric_array.rb', line 167 def to_numeric_array(validate: true) elems = split(",") subtype = elems.shift integer = (subtype != "f") if integer range = RGFA::NumericArray::SUBTYPE_RANGE[subtype] elsif !RGFA::NumericArray::SUBTYPE.include?(subtype) raise RGFA::NumericArray::TypeError, "Subtype #{subtype} unknown" end elems.map do |e| begin if integer e = Integer(e) if validate and not range.include?(e) raise "NumericArray: "+ "value is outside of subtype #{subtype} range\n"+ "Value: #{e}\n"+ "Range: #{range.inspect}\n"+ "Content: #{inspect}" end e else Float(e) end rescue => msg raise RGFA::NumericArray::ValueError, msg end end end |
#to_rgfa(validate: 2) ⇒ RGFA
Converts a String into a RGFA instance. Each line of the string is added separately to the gfa.
353 354 355 356 357 358 |
# File 'lib/rgfa.rb', line 353 def to_rgfa(validate: 2) gfa = RGFA.new(validate: validate) split("\n").each {|line| gfa << line} gfa.validate! if validate >= 1 return gfa end |
#to_rgfa_line(validate: 2) ⇒ subclass of RGFA::Line
Parses a line of a RGFA file and creates an object of the correct
record type child class of {RGFA::Line}
698 699 700 |
# File 'lib/rgfa/line.rb', line 698 def to_rgfa_line(validate: 2) split(RGFA::Line::SEPARATOR).to_rgfa_line(validate: validate) end |