Class: Bio::Sam::File

Inherits:
Object
  • Object
show all
Includes:
FileExistenceChecker
Defined in:
lib/bio-sambamba/samfile.rb

Overview

Class providing access to SAM files

Instance Method Summary collapse

Methods included from FileExistenceChecker

#check_file_existence

Constructor Details

#initialize(filename) ⇒ File

Creates an object for access to SAM file



11
12
13
14
# File 'lib/bio-sambamba/samfile.rb', line 11

def initialize(filename)
  @filename = filename
  check_file_existence filename
end

Instance Method Details

#alignmentsObject

Returns an AlignmentIterator object for iterating over all alignments in the file



22
23
24
25
# File 'lib/bio-sambamba/samfile.rb', line 22

def alignments
  cmdline = ['sambamba', 'view', '--format', 'msgpack', '-S', @filename],
  Bio::Bam::AlignmentIterator.new(cmdline, reference_sequences)
end

#headerObject

SAM header



17
18
19
# File 'lib/bio-sambamba/samfile.rb', line 17

def header
  @header ||= Bio::Bam::SamHeader.new(@filename, ['-S'])
end

#reference_sequencesObject



27
28
29
# File 'lib/bio-sambamba/samfile.rb', line 27

def reference_sequences
  @reference_sequences ||= Oj.load(Bio::Command.query_command ['sambamba', 'view', '-I', '-S', @filename])
end