class Segment

A segment line of a RGFA file

Constants

DATATYPE
PREDEFINED_OPTFIELDS
RECORD_TYPE
REQFIELDS

Attributes

containments[W]
paths[W]

Public Instance Methods

all_connections() click to toggle source

All links and containments where the segment is involved. @!macro this_is_a_copy

# File lib/rgfa/line/segment.rb, line 87
def all_connections
  all_links + all_containments
end
all_containments() click to toggle source

All containments where a segment is involved. @!macro this_is_a_copy

@note the list shall be considered read-only, as this
  is a copy of the original arrays of references, concatenated
  to each other.
# File lib/rgfa/line/segment.rb, line 73
def all_containments
  l = self.containments
  l[:from][:+] + l[:from][:-] + l[:to][:+] + l[:to][:-]
end
all_paths() click to toggle source

All paths where the segment is involved. @!macro this_is_a_copy

# File lib/rgfa/line/segment.rb, line 93
def all_paths
  pt = self.paths
  pt[:+] + pt[:-]
end
all_references() click to toggle source

All paths, links and containments where the segment is involved. @!macro this_is_a_copy

# File lib/rgfa/line/segment.rb, line 100
def all_references
  all_connections + all_paths
end
containments() click to toggle source

References to the containments in which the segment is involved. @!macro references_table

@example

segment.containments[:from][:+]

@return [Hash{RGFA::Line::DIRECTION => Hash{RGFA::Line::ORIENTATION => Array<RGFA::Line::Containment>}}]

# File lib/rgfa/line/segment.rb, line 47
def containments
  @containments ||= {:from => {:+ => [], :- => []},
                     :to   => {:+ => [], :- => []}}
  @containments
end
coverage(count_tag: :RC, unit_length: 1) click to toggle source

@!macro [new] coverage

The coverage computed from a count_tag.
If unit_length is provided then: count/(length-unit_length+1),
otherwise: count/length.
The latter is a good approximation if length >>> unit_length.
@param [Symbol] count_tag <i>(defaults to +:RC+)</i>
  integer tag storing the count, usually :KC, :RC or :FC
@param [Integer] unit_length the (average) length of a read (for
  :RC), fragment (for :FC) or k-mer (for :KC)
@return [Integer] coverage, if count_tag and length are defined

@return [nil] otherwise @see coverage!

# File lib/rgfa/line/segment.rb, line 155
def coverage(count_tag: :RC, unit_length: 1)
  if optional_fieldnames.include?(count_tag) and self.length
    return (self.get(count_tag).to_f)/(self.length-unit_length+1)
  else
    return nil
  end
end
coverage!(count_tag: :RC, unit_length: 1) click to toggle source

@see coverage @!macro coverage @raise [RGFA::Line::TagMissingError] if segment does not have count_tag @!macro length_needed

# File lib/rgfa/line/segment.rb, line 167
def coverage!(count_tag: :RC, unit_length: 1)
  c = coverage(count_tag: count_tag, unit_length: unit_length)
  if c.nil?
    self.length!
    raise RGFA::Line::TagMissingError,
      "Tag #{count_tag} undefined for segment #{name}"
  else
    return c
  end
end
length() click to toggle source

@!macro [new] length

@return [Integer] value of LN tag, if segment has LN tag
@return [Integer] sequence length if no LN and sequence not "*"

@return [nil] if sequence is “*” @see length!

# File lib/rgfa/line/segment.rb, line 121
def length
  if self.LN
    self.LN
  elsif sequence != "*"
    sequence.length
  else
    nil
  end
end
length!() click to toggle source

@!macro length @!macro [new] length_needed

@raise [RGFA::Line::Segment::UndefinedLengthError] if not an LN tag and
  the sequence is "*"

@see length

# File lib/rgfa/line/segment.rb, line 136
def length!
  l = self.length()
  raise RGFA::Line::Segment::UndefinedLengthError,
    "No length information available" if l.nil?
  return l
end
paths() click to toggle source

References to the containments in which the segment is involved.

The references are in two arrays which are accessed from a hash table. The key is the orientation (+ or -).

@example

segment.paths[:+]

@return [Hash{RGFA::Line::ORIENTATION => Array<RGFA::Line::Path>}]

# File lib/rgfa/line/segment.rb, line 63
def paths
  @paths ||= {:+ => [], :- => []}
  @paths
end
to_gfa_field(datatype: nil) click to toggle source

@!macro to_gfa_field

# File lib/rgfa/field_writer.rb, line 107
def to_gfa_field(datatype: nil); to_sym.to_s; end
to_s(without_sequence: false) click to toggle source

@return string representation of the segment @param [Boolean] without_sequence if true, output “*” instead of sequence

Calls superclass method
# File lib/rgfa/line/segment.rb, line 180
def to_s(without_sequence: false)
  if !without_sequence
    return super()
  else
    saved = self.sequence
    self.sequence = "*"
    retval = super()
    self.sequence = saved
    return retval
  end
end
to_sym() click to toggle source

@return [Symbol] name of the segment as symbol

# File lib/rgfa/line/segment.rb, line 193
def to_sym
  name.to_sym
end
validate_gfa_field!(datatype, fieldname=nil) click to toggle source

@!macro validate_gfa_field

# File lib/rgfa/field_validator.rb, line 247
def validate_gfa_field!(datatype, fieldname=nil)
  if datatype != :lbl
    raise RGFA::FieldParser::FormatError,
        "Wrong type (#{self.class}) for field #{fieldname}\n"+
        "Content: <RGFA::Segment:#{self.to_s}>\n"+
        "Datatype: #{datatype}"
  end
end
validate_length!() click to toggle source

@raise [RGFA::Line::Segment::InconsistentLengthError]

if sequence length and LN tag are not consistent.
# File lib/rgfa/line/segment.rb, line 106
def validate_length!
  if sequence != "*" and optional_fieldnames.include?(:LN)
    if self.LN != sequence.length
      raise RGFA::Line::Segment::InconsistentLengthError,
        "Length in LN tag (#{self.LN}) "+
        "is different from length of sequence field (#{sequence.length})"
    end
  end
end

Private Instance Methods

validate_record_type_specific_info!() click to toggle source
# File lib/rgfa/line/segment.rb, line 199
def validate_record_type_specific_info!
  validate_length!
end