Class: GFA::Record::Segment

Inherits:
GFA::Record show all
Defined in:
lib/gfa/record/segment.rb

Constant Summary collapse

CODE =
:S
REQ_FIELDS =
%i[name sequence]
OPT_FIELDS =
{
  LN: :i, # Segment length
  RC: :i, # Read count
  FC: :i, # Fragment count
  KC: :i, # k-mer count
  SH: :H, # SHA-256 checksum of the sequence
  UR: :Z, # URI or local file-system path of the sequence
  # Non-cannonical but uppercase (thus, reserved)
  DP: :f, # SAM
  SN: :Z, # rGFA: Name of stable sequence from which the segment is derived
  SO: :i, # rGFA: Offset on the stable sequence
  SR: :i  # rGFA: Rank. 0 if on a linear reference genome; >0 otherwise
}

Constants inherited from GFA::Record

CODES, TYPES

Instance Attribute Summary

Attributes inherited from GFA::Record

#fields

Instance Method Summary collapse

Methods inherited from GFA::Record

#[], [], #code, code_class, #dup, #empty?, #eql?, #hash, name_class, #to_s, #type

Constructor Details

#initialize(name, sequence, *opt_fields) ⇒ Segment

Returns a new instance of Segment.



23
24
25
26
27
28
# File 'lib/gfa/record/segment.rb', line 23

def initialize(name, sequence, *opt_fields)
  @fields = {}
  add_field(2, :Z, name,     /[!-)+-<>-~][!-~]*/)
  add_field(3, :Z, sequence, /\*|[A-Za-z=.]+/)
  opt_fields.each { |f| add_opt_field(f, OPT_FIELDS) }
end

Instance Method Details

#lengthObject

Returns the length of the sequence represented in this segment



32
33
34
# File 'lib/gfa/record/segment.rb', line 32

def length
  sequence.value.length
end

#rcObject

Returns the reverse-complement of the sequence (as a Z field)



38
39
40
41
42
# File 'lib/gfa/record/segment.rb', line 38

def rc
  GFA::Field::String.new(
    sequence.value.upcase.reverse.tr('ACGTURYSWKMBDHVN', 'TGCAAYRSWMKVHDBN')
  )
end