Class: Array
- Defined in:
- lib/rgfa.rb,
lib/rgfa/line.rb,
lib/rgfa/cigar.rb,
lib/rgfa/byte_array.rb,
lib/rgfa/field_array.rb,
lib/rgfa/field_writer.rb,
lib/rgfa/segment_info.rb,
lib/rgfa/numeric_array.rb,
lib/rgfa/field_validator.rb
Overview
Method to create a numeric array from an array
Direct Known Subclasses
RGFA::ByteArray, RGFA::CIGAR, RGFA::FieldArray, RGFA::NumericArray, RGFA::SegmentEndsPath, RGFA::SegmentInfo
Instance Method Summary collapse
-
#default_gfa_datatype ⇒ RGFA::Line::FIELD_DATATYPE
private
Optional field GFA datatype to use, if none is provided.
-
#rgfa_field_array? ⇒ Boolean
Is this possibly a RGFA::FieldArray instance?.
-
#to_byte_array ⇒ RGFA::ByteArray
Create a RGFA::ByteArray from an Array instance.
-
#to_cigar ⇒ RGFA::CIGAR
Create a RGFA::CIGAR instance from the content of the array.
-
#to_cigar_operation ⇒ RGFA::CIGAR::Operation
Create a RGFA::CIGAR::Operation instance from the content of the array.
-
#to_gfa_field(datatype: default_gfa_datatype) ⇒ String
private
Representation of the data for GFA fields; this method does not (in general) validate the string.
-
#to_numeric_array(validate: true) ⇒ RGFA::NumericArray
Create a numeric array from an Array instance.
-
#to_oriented_segment ⇒ RGFA::OrientedSegment
Create and validate a segment end from an array.
-
#to_rgfa(validate: 2) ⇒ RGFA
Converts an
Array
of strings or RGFA::Line instances into aRGFA
instance. -
#to_rgfa_field_array(datatype = nil) ⇒ Object
Create a RGFA::FieldArray from an array.
-
#to_rgfa_line(validate: 2) ⇒ subclass of RGFA::Line
Parses an array containing the fields of a RGFA file line and creates an object of the correct record type child class of RGFA::Line.
-
#to_segment_end ⇒ RGFA::SegmentEnd
Create and validate a segment end from an array.
-
#validate_gfa_field!(datatype, fieldname = nil) ⇒ void
private
Validates the object according to the provided datatype.
Instance Method Details
#default_gfa_datatype ⇒ RGFA::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
90 91 92 |
# File 'lib/rgfa/field_writer.rb', line 90 def default_gfa_datatype (all?{|i|i.kind_of?(Integer)} or all?{|i|i.kind_of?(Float)}) ? :B : :J end |
#rgfa_field_array? ⇒ Boolean
Is this possibly a RGFA::FieldArray instance?
(i.e. are the two last elements a datatype symbol and a zero byte?)
71 72 73 74 |
# File 'lib/rgfa/field_array.rb', line 71 def rgfa_field_array? self[-1] == "\0" and RGFA::Line::OPTFIELD_DATATYPE.include?(self[-2].to_sym) end |
#to_byte_array ⇒ RGFA::ByteArray
Create a RGFA::ByteArray from an Array instance
55 56 57 |
# File 'lib/rgfa/byte_array.rb', line 55 def to_byte_array RGFA::ByteArray.new(self) end |
#to_cigar ⇒ RGFA::CIGAR
Create a RGFA::CIGAR instance from the content of the array.
139 140 141 |
# File 'lib/rgfa/cigar.rb', line 139 def to_cigar RGFA::CIGAR.new(self) end |
#to_cigar_operation ⇒ RGFA::CIGAR::Operation
Create a RGFA::CIGAR::Operation instance from the content of the array.
144 145 146 |
# File 'lib/rgfa/cigar.rb', line 144 def to_cigar_operation RGFA::CIGAR::Operation.new(Integer(self[0]), self[1].to_sym) end |
#to_gfa_field(datatype: default_gfa_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.
Representation of the data for GFA fields; this method does not (in general) validate the string. The method can be overwritten for a given class, and may take the #default_gfa_datatype into consideration.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rgfa/field_writer.rb', line 70 def to_gfa_field(datatype: default_gfa_datatype) case datatype when :B to_numeric_array.to_s when :J to_json when :cig to_cigar.to_s when :cgs map{|cig|cig.to_cigar.to_s}.join(",") when :lbs map{|os|os.to_oriented_segment.to_s}.join(",") when :H to_byte_array.to_s else map(&:to_s).join(",") end end |
#to_numeric_array(validate: true) ⇒ RGFA::NumericArray
Create a numeric array from an Array instance
148 149 150 151 152 |
# File 'lib/rgfa/numeric_array.rb', line 148 def to_numeric_array(validate: true) na = RGFA::NumericArray.new(self) na.validate! if validate na end |
#to_oriented_segment ⇒ RGFA::OrientedSegment
Create and validate a segment end from an array
145 146 147 |
# File 'lib/rgfa/segment_info.rb', line 145 def to_oriented_segment to_segment_info(RGFA::OrientedSegment) end |
#to_rgfa(validate: 2) ⇒ RGFA
Converts an Array
of strings or RGFA::Line instances into a RGFA
instance.
369 370 371 372 373 374 |
# File 'lib/rgfa.rb', line 369 def to_rgfa(validate: 2) gfa = RGFA.new(validate: validate) each {|line| gfa << line} gfa.validate! if validate >= 1 return gfa end |
#to_rgfa_field_array(datatype = nil) ⇒ Object
Create a RGFA::FieldArray from an array
78 79 80 81 82 83 84 85 86 |
# File 'lib/rgfa/field_array.rb', line 78 def to_rgfa_field_array(datatype=nil) if self.rgfa_field_array? RGFA::FieldArray.new(self[-2].to_sym, self[0..-3]) elsif datatype.nil? raise RGFA::FieldArray::Error, "no datatype specified" else RGFA::FieldArray.new(datatype, self) end end |
#to_rgfa_line(validate: 2) ⇒ subclass of RGFA::Line
This method modifies the content of the array; if you still need the array, you must create a copy before calling it
Parses an array containing the fields of a RGFA file line and creates an object of the correct record type child class of RGFA::Line
723 724 725 |
# File 'lib/rgfa/line.rb', line 723 def to_rgfa_line(validate: 2) RGFA::Line.subclass(shift).new(self, validate: validate) end |
#to_segment_end ⇒ RGFA::SegmentEnd
Create and validate a segment end from an array
138 139 140 |
# File 'lib/rgfa/segment_info.rb', line 138 def to_segment_end to_segment_info(RGFA::SegmentEnd) 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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/rgfa/field_validator.rb', line 116 def validate_gfa_field!(datatype, fieldname=nil) begin case datatype when :J return when :Z return when :lbs map!(&:to_oriented_segment).each(&:validate!) return when :cig to_cigar.validate! return when :cgs map(&:to_cigar).each(&:validate!) return when :B to_numeric_array.validate! return when :H to_byte_array.validate! return end rescue => err raise RGFA::FieldParser::FormatError, "Invalid content for field #{fieldname}\n"+ "Content: #{self.inspect}\n"+ "Datatype: #{datatype}\n"+ "Error: #{err}" end raise RGFA::FieldParser::FormatError, "Wrong type (#{self.class}) for field #{fieldname}\n"+ "Content: #{self.inspect}\n"+ "Datatype: #{datatype}" end |