Class: HTS::Bcf
- 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,
lib/hts/bcf/header_record.rb
Overview
A class for working with VCF, BCF files.
Defined Under Namespace
Classes: Format, Header, HeaderRecord, Info, Record
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#index_name ⇒ Object
readonly
Returns the value of attribute index_name.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Class Method Summary collapse
Instance Method Summary collapse
-
#alt ⇒ Array
Get alt array.
-
#chrom ⇒ Array
Get chrom array.
- #create_index(index_name = nil) ⇒ Object
- #each(copy: false, &block) ⇒ Object
-
#each_alt ⇒ Object
Get alt iterator.
-
#each_chrom ⇒ Object
Get chrom iterator.
-
#each_endpos ⇒ Object
Get endpos iterator.
-
#each_filter ⇒ Object
Get filter iterator.
- #each_format(key) ⇒ Object
-
#each_id ⇒ Object
Get id iterator.
- #each_info(key) ⇒ Object
-
#each_pos ⇒ Object
Get pos iterator.
-
#each_qual ⇒ Object
Get qual iterator.
-
#each_ref ⇒ Object
Get ref iterator.
-
#endpos ⇒ Array
Get endpos array.
-
#filter ⇒ Array
Get filter array.
- #format(key = nil) ⇒ Object
-
#id ⇒ Array
Get id array.
- #index_loaded? ⇒ Boolean
- #info(key = nil) ⇒ Object
-
#initialize(file_name, mode = "r", index: nil, threads: nil, create_index: false) ⇒ Bcf
constructor
A new instance of Bcf.
- #load_index(index_name = nil) ⇒ Object
-
#nsamples ⇒ Object
Close the current file.
-
#pos ⇒ Array
Get pos array.
-
#qual ⇒ Array
Get qual array.
- #query ⇒ Object
-
#querys(region, copy: false, &block) ⇒ Object
def queryi end.
-
#ref ⇒ Array
Get ref array.
- #samples ⇒ Object
- #write(var) ⇒ Object
- #write_header ⇒ Object
Methods inherited from Hts
#close, #closed?, #file_format, #file_format_version, #rewind, #seek, #set_threads, #struct, #tell, #to_ptr
Constructor Details
#initialize(file_name, mode = "r", index: nil, threads: nil, create_index: false) ⇒ Bcf
Returns a new instance of Bcf.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hts/bcf.rb', line 30 def initialize(file_name, mode = "r", index: nil, threads: nil, create_index: false) if block_given? = "HTS::Bcf.new() dose not take block; Please use HTS::Bcf.open() instead" raise end # NOTE: Do not check for the existence of local files, since file_names may be remote URIs. @file_name = file_name @index_name = index @mode = mode @hts_file = LibHTS.hts_open(@file_name, mode) raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null? set_threads(threads) if threads return if @mode[0] == "w" @header = Bcf::Header.new(@hts_file) create_index(index) if create_index @idx = load_index(index) @start_position = tell super # do nothing end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
16 17 18 |
# File 'lib/hts/bcf.rb', line 16 def file_name @file_name end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
16 17 18 |
# File 'lib/hts/bcf.rb', line 16 def header @header end |
#index_name ⇒ Object (readonly)
Returns the value of attribute index_name.
16 17 18 |
# File 'lib/hts/bcf.rb', line 16 def index_name @index_name end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
16 17 18 |
# File 'lib/hts/bcf.rb', line 16 def mode @mode end |
Class Method Details
.open(*args, **kw) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hts/bcf.rb', line 18 def self.open(*args, **kw) file = new(*args, **kw) # do not yield return file unless block_given? begin yield file ensure file.close end file end |
Instance Method Details
#alt ⇒ Array
Get alt array
223 |
# File 'lib/hts/bcf.rb', line 223 define_getter :alt |
#chrom ⇒ Array
Get chrom array
218 |
# File 'lib/hts/bcf.rb', line 218 define_getter :chrom |
#create_index(index_name = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hts/bcf.rb', line 57 def create_index(index_name = nil) check_closed warn "Create index for #{@file_name} to #{index_name}" if index_name LibHTS.bcf_index_build2(@file_name, index_name, -1) else LibHTS.bcf_index_build(@file_name, -1) end end |
#each(copy: false, &block) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/hts/bcf.rb', line 113 def each(copy: false, &block) if copy each_record_copy(&block) else each_record_reuse(&block) end end |
#each_alt ⇒ Object
Get alt iterator
263 |
# File 'lib/hts/bcf.rb', line 263 define_iterator :alt |
#each_chrom ⇒ Object
Get chrom iterator
258 |
# File 'lib/hts/bcf.rb', line 258 define_iterator :chrom |
#each_endpos ⇒ Object
Get endpos iterator
260 |
# File 'lib/hts/bcf.rb', line 260 define_iterator :endpos |
#each_filter ⇒ Object
Get filter iterator
265 |
# File 'lib/hts/bcf.rb', line 265 define_iterator :filter |
#each_format(key) ⇒ Object
276 277 278 279 280 281 282 283 |
# File 'lib/hts/bcf.rb', line 276 def each_format(key) check_closed return to_enum(__method__, key) unless block each do |r| yield r.format(key) end end |
#each_id ⇒ Object
Get id iterator
261 |
# File 'lib/hts/bcf.rb', line 261 define_iterator :id |
#each_info(key) ⇒ Object
267 268 269 270 271 272 273 274 |
# File 'lib/hts/bcf.rb', line 267 def each_info(key) check_closed return to_enum(__method__, key) unless block each do |r| yield r.info(key) end end |
#each_pos ⇒ Object
Get pos iterator
259 |
# File 'lib/hts/bcf.rb', line 259 define_iterator :pos |
#each_qual ⇒ Object
Get qual iterator
264 |
# File 'lib/hts/bcf.rb', line 264 define_iterator :qual |
#each_ref ⇒ Object
Get ref iterator
262 |
# File 'lib/hts/bcf.rb', line 262 define_iterator :ref |
#endpos ⇒ Array
Get endpos array
220 |
# File 'lib/hts/bcf.rb', line 220 define_getter :endpos |
#filter ⇒ Array
Get filter array
225 |
# File 'lib/hts/bcf.rb', line 225 define_getter :filter |
#format(key = nil) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/hts/bcf.rb', line 241 def format(key = nil) check_closed position = tell if key ary = map { |r| r.format(key) } else raise NotImplementedError # ary = each_copy.map { |r| r.format } # ary = map { |r| r.format.clone } end seek(position) ary end |
#id ⇒ Array
Get id array
221 |
# File 'lib/hts/bcf.rb', line 221 define_getter :id |
#index_loaded? ⇒ Boolean
78 79 80 81 82 |
# File 'lib/hts/bcf.rb', line 78 def index_loaded? check_closed !@idx.null? end |
#info(key = nil) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/hts/bcf.rb', line 227 def info(key = nil) check_closed position = tell if key ary = map { |r| r.info(key) } else raise NotImplementedError # ary = each_copy.map { |r| r.info } # ary = map { |r| r.info.clone } end seek(position) ary end |
#load_index(index_name = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/hts/bcf.rb', line 68 def load_index(index_name = nil) check_closed if index_name LibHTS.bcf_index_load2(@file_name, index_name) else LibHTS.bcf_index_load3(@file_name, nil, 2) end end |
#nsamples ⇒ Object
Close the current file.
101 102 103 104 105 |
# File 'lib/hts/bcf.rb', line 101 def nsamples check_closed header.nsamples end |
#pos ⇒ Array
Get pos array
219 |
# File 'lib/hts/bcf.rb', line 219 define_getter :pos |
#qual ⇒ Array
Get qual array
224 |
# File 'lib/hts/bcf.rb', line 224 define_getter :qual |
#query ⇒ Object
144 145 146 |
# File 'lib/hts/bcf.rb', line 144 def query(...) querys(...) # Fixme end |
#querys(region, copy: false, &block) ⇒ Object
def queryi end
151 152 153 154 155 156 157 |
# File 'lib/hts/bcf.rb', line 151 def querys(region, copy: false, &block) if copy querys_copy(region, &block) else querys_reuse(region, &block) end end |
#ref ⇒ Array
Get ref array
222 |
# File 'lib/hts/bcf.rb', line 222 define_getter :ref |
#samples ⇒ Object
107 108 109 110 111 |
# File 'lib/hts/bcf.rb', line 107 def samples check_closed header.samples end |
#write(var) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/hts/bcf.rb', line 92 def write(var) check_closed var_dup = var.dup LibHTS.bcf_write(@hts_file, header, var_dup) > 0 || raise end |
#write_header ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/hts/bcf.rb', line 84 def write_header check_closed @header = header.dup LibHTS.hts_set_fai_filename(header, @file_name) LibHTS.bcf_hdr_write(@hts_file, header) end |