Class: HTS::Bam::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/hts/bam/header.rb

Overview

A class for working with alignment header.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ Header

Returns a new instance of Header.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hts/bam/header.rb', line 13

def initialize(arg = nil)
  case arg
  when LibHTS::HtsFile
    @sam_hdr = LibHTS.sam_hdr_read(arg)
  when LibHTS::SamHdr
    @sam_hdr = arg
  when nil
    @sam_hdr = LibHTS.sam_hdr_init
  else
    raise TypeError, "Invalid argument"
  end
end

Class Method Details

.parse(str) ⇒ Object



9
10
11
# File 'lib/hts/bam/header.rb', line 9

def self.parse(str)
  new(LibHTS.sam_hdr_parse(str.size, str))
end

Instance Method Details

#add_line(type, *args) ⇒ Object

experimental



57
58
59
60
# File 'lib/hts/bam/header.rb', line 57

def add_line(type, *args)
  args = args.flat_map { |arg| [:string, arg] }
  LibHTS.sam_hdr_add_line(@sam_hdr, type, *args, :pointer, FFI::Pointer::NULL)
end

#add_lines(str) ⇒ Object

experimental



52
53
54
# File 'lib/hts/bam/header.rb', line 52

def add_lines(str)
  LibHTS.sam_hdr_add_lines(@sam_hdr, str, 0)
end

#find_line(type, key, value) ⇒ Object

experimental



63
64
65
66
67
# File 'lib/hts/bam/header.rb', line 63

def find_line(type, key, value)
  ks = LibHTS::KString.new
  r = LibHTS.sam_hdr_find_line_id(@sam_hdr, type, key, value, ks)
  r == 0 ? ks[:s] : nil
end

#find_line_at(type, pos) ⇒ Object

experimental



70
71
72
73
74
# File 'lib/hts/bam/header.rb', line 70

def find_line_at(type, pos)
  ks = LibHTS::KString.new
  r = LibHTS.sam_hdr_find_line_pos(@sam_hdr, type, pos, ks)
  r == 0 ? ks[:s] : nil
end

#remove_line(type, key, value) ⇒ Object

experimental



77
78
79
# File 'lib/hts/bam/header.rb', line 77

def remove_line(type, key, value)
  LibHTS.sam_hdr_remove_line_id(@sam_hdr, type, key, value)
end

#remove_line_at(type, pos) ⇒ Object

experimental



82
83
84
# File 'lib/hts/bam/header.rb', line 82

def remove_line_at(type, pos)
  LibHTS.sam_hdr_remove_line_pos(@sam_hdr, type, pos)
end

#structObject



26
27
28
# File 'lib/hts/bam/header.rb', line 26

def struct
  @sam_hdr
end

#target_countObject



34
35
36
37
# File 'lib/hts/bam/header.rb', line 34

def target_count
  # FIXME: sam_hdr_nref
  @sam_hdr[:n_targets]
end

#target_lenObject



45
46
47
48
49
# File 'lib/hts/bam/header.rb', line 45

def target_len
  Array.new(target_count) do |i|
    LibHTS.sam_hdr_tid2len(@sam_hdr, i)
  end
end

#target_namesObject



39
40
41
42
43
# File 'lib/hts/bam/header.rb', line 39

def target_names
  Array.new(target_count) do |i|
    LibHTS.sam_hdr_tid2name(@sam_hdr, i)
  end
end

#to_ptrObject



30
31
32
# File 'lib/hts/bam/header.rb', line 30

def to_ptr
  @sam_hdr.to_ptr
end

#to_sObject



86
87
88
# File 'lib/hts/bam/header.rb', line 86

def to_s
  LibHTS.sam_hdr_str(@sam_hdr)
end