Class: HTS::Bcf
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/hts/bcf.rb,
lib/hts/bcf/info.rb,
lib/hts/bcf/format.rb,
lib/hts/bcf/header.rb,
lib/hts/bcf/record.rb
Defined Under Namespace
Classes: Format, Header, Info, Record
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(filename, mode = "r", threads: nil) ⇒ Bcf
Returns a new instance of Bcf.
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/hts/bcf.rb', line 29
def initialize(filename, mode = "r", threads: nil)
raise "HTS::Bcf.new() dose not take block; Please use HTS::Bcf.open() instead" if block_given?
@file_path = filename == "-" ? "-" : File.expand_path(filename)
if mode[0] == "r" && !File.exist?(file_path)
message = "No such VCF/BCF file - #{file_path}"
raise message
end
@mode = mode
@hts_file = LibHTS.hts_open(file_path, mode)
if threads&.> 0
r = LibHTS.hts_set_threads(@hts_file, threads)
raise "Failed to set number of threads: #{threads}" if r < 0
end
return if mode[0] == "w"
@header = Bcf::Header.new(@hts_file)
end
|
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
15
16
17
|
# File 'lib/hts/bcf.rb', line 15
def file_path
@file_path
end
|
Returns the value of attribute header.
15
16
17
|
# File 'lib/hts/bcf.rb', line 15
def
@header
end
|
#mode ⇒ Object
Returns the value of attribute mode.
15
16
17
|
# File 'lib/hts/bcf.rb', line 15
def mode
@mode
end
|
Class Method Details
.open ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/hts/bcf.rb', line 17
def self.open(...)
file = new(...)
return file unless block_given?
begin
yield file
ensure
file.close
end
file
end
|
Instance Method Details
#close ⇒ Object
72
73
74
75
|
# File 'lib/hts/bcf.rb', line 72
def close
LibHTS.hts_close(@hts_file)
@hts_file = nil
end
|
#closed? ⇒ Boolean
77
78
79
|
# File 'lib/hts/bcf.rb', line 77
def closed?
@hts_file.nil?
end
|
#each ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/hts/bcf.rb', line 89
def each
return to_enum(__method__) unless block_given?
while LibHTS.bcf_read(@hts_file, , bcf1 = LibHTS.bcf_init) != -1
record = Record.new(bcf1, )
yield record
end
self
end
|
#sample_count ⇒ Object
81
82
83
|
# File 'lib/hts/bcf.rb', line 81
def sample_count
.sample_count
end
|
#sample_names ⇒ Object
85
86
87
|
# File 'lib/hts/bcf.rb', line 85
def sample_names
.sample_names
end
|
#struct ⇒ Object
52
53
54
|
# File 'lib/hts/bcf.rb', line 52
def struct
@hts_file
end
|
#to_ptr ⇒ Object
56
57
58
|
# File 'lib/hts/bcf.rb', line 56
def to_ptr
@hts_file.to_ptr
end
|
#write(var) ⇒ Object
66
67
68
69
|
# File 'lib/hts/bcf.rb', line 66
def write(var)
var_dup = var.dup = var.dup
LibHTS.bcf_write(@hts_file, , var_dup) > 0 || raise
end
|
60
61
62
63
64
|
# File 'lib/hts/bcf.rb', line 60
def
@header = .dup
LibHTS.hts_set_fai_filename(, @file_path)
LibHTS.bcf_hdr_write(@hts_file, .struct)
end
|