class Bio::Bam::SamHeader

Represents SAM header

Public Class Methods

new(filename, opts=[]) click to toggle source

Creates a new SamHeader object for a specified file, specifying additional options to pass to sambamba tool

# File lib/bio-sambamba/samheader.rb, line 10
def initialize(filename, opts=[])
  @filename = filename
  @opts = opts
end

Public Instance Methods

pg_lines() click to toggle source

An array of PGLine objects

# File lib/bio-sambamba/samheader.rb, line 48
def pg_lines
  @pg_lines ||= obj[4].map{|rec| PGLine.new(rec)}
end
raw_contents() click to toggle source

Raw text of SAM header

# File lib/bio-sambamba/samheader.rb, line 16
def raw_contents
  if @raw_contents.nil? then
    cmd = ['sambamba', 'view', '-H', @filename] + @opts
    Bio::Command.call_command_open3(cmd) do |pin, pout, perr|
      @raw_contents = pout.read
      raise_exception_if_stderr_is_not_empty(perr)
    end
  end
  @raw_contents
end
rg_lines() click to toggle source

An array of RGLine objects

# File lib/bio-sambamba/samheader.rb, line 43
def rg_lines
  @rg_lines ||= obj[3].map{|rec| RGLine.new(rec)}
end
sorting_order() click to toggle source

Sorting order

# File lib/bio-sambamba/samheader.rb, line 33
def sorting_order
  obj[1]
end
sq_lines() click to toggle source

An array of SQLine objects

# File lib/bio-sambamba/samheader.rb, line 38
def sq_lines
  @sq_lines ||= obj[2].map{|rec| SQLine.new(rec)}
end
version() click to toggle source

Format version

# File lib/bio-sambamba/samheader.rb, line 28
def version
  obj[0]
end

Private Instance Methods

obj() click to toggle source
# File lib/bio-sambamba/samheader.rb, line 53
def obj
  return @obj unless @obj.nil?
  cmd = ['sambamba', 'view', '-H', '--format', 'msgpack', @filename] + @opts
  line = ''
  Bio::Command.call_command_open3(cmd) do |pin, pout, perr|
    @obj = MessagePack.unpack(pout.read)
    raise_exception_if_stderr_is_not_empty(perr)
  end
  @obj
end