Class: RGFA::CIGAR
- Defined in:
- lib/rgfa/cigar.rb,
lib/rgfa/field_validator.rb
Overview
Array of CIGAR operations. Represents the contents of a CIGAR string.
Defined Under Namespace
Classes: Operation, ValueError
Class Method Summary collapse
-
.from_string(str) ⇒ RGFA::CIGAR
Parse a CIGAR string into an array of CIGAR operations.
Instance Method Summary collapse
-
#clone ⇒ RGFA::CIGAR
Create a copy.
-
#complement ⇒ RGFA::CIGAR
Compute the CIGAR for the segments when these are switched.
-
#to_cigar ⇒ RGFA::CIGAR
Self.
-
#to_s ⇒ String
String representation of the CIGAR.
-
#validate! ⇒ void
Validate the instance.
-
#validate_gfa_field!(datatype, fieldname = nil) ⇒ void
private
Validates the object according to the provided datatype.
Methods inherited from Array
#default_gfa_datatype, #rgfa_field_array?, #to_byte_array, #to_cigar_operation, #to_gfa_field, #to_numeric_array, #to_oriented_segment, #to_rgfa, #to_rgfa_field_array, #to_rgfa_line, #to_segment_end
Class Method Details
.from_string(str) ⇒ RGFA::CIGAR
Parse a CIGAR string into an array of CIGAR operations.
Each operation is represented by a Operation, i.e. a tuple of operation length and operation symbol (one of MIDNSHPX=).
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rgfa/cigar.rb', line 44 def self.from_string(str) a = RGFA::CIGAR.new if str != "*" raise RGFA::CIGAR::ValueError if str !~ /^([0-9]+[MIDNSHPX=])+$/ str.scan(/[0-9]+[MIDNSHPX=]/).each do |op| len = op[0..-2].to_i code = op[-1..-1].to_sym a << RGFA::CIGAR::Operation.new(len, code) end end return a end |
Instance Method Details
#clone ⇒ RGFA::CIGAR
Create a copy
83 84 85 |
# File 'lib/rgfa/cigar.rb', line 83 def clone map{|x|x.clone} end |
#complement ⇒ RGFA::CIGAR
Compute the CIGAR for the segments when these are switched.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rgfa/cigar.rb', line 25 def complement reverse.map do |op| if op.code == :I op.code = :D elsif op.code == :D op.code = :I end op end end |
#to_cigar ⇒ RGFA::CIGAR
Returns self.
77 78 79 |
# File 'lib/rgfa/cigar.rb', line 77 def to_cigar self end |
#to_s ⇒ String
String representation of the CIGAR
59 60 61 62 63 64 65 |
# File 'lib/rgfa/cigar.rb', line 59 def to_s if empty? return "*" else map(&:to_s).join end end |
#validate! ⇒ void
This method returns an undefined value.
Validate the instance
70 71 72 73 74 |
# File 'lib/rgfa/cigar.rb', line 70 def validate! any? do |op| op.to_cigar_operation.validate! end 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
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/rgfa/field_validator.rb', line 176 def validate_gfa_field!(datatype, fieldname=nil) if datatype != :cig 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 |