@@ -27,6 +27,25 @@ def self.open(*args, **kw)
2727 file
2828 end
2929
30+ def self . build_index ( file_name , index_name = nil , min_shift = 14 , threads = 0 , verbose = true )
31+ if verbose
32+ if index_name
33+ warn "Create index for #{ file_name } to #{ index_name } "
34+ else
35+ warn "Create index for #{ file_name } "
36+ end
37+ end
38+
39+ case LibHTS . bcf_index_build3 ( file_name , index_name , min_shift , threads )
40+ when 0 # successful
41+ when -1 then raise "indexing failed"
42+ when -2 then raise "opening #{ file_name } failed"
43+ when -3 then raise "format not indexable"
44+ when -4 then raise "failed to create and/or save the index"
45+ else raise "unknown error"
46+ end
47+ end
48+
3049 def initialize ( file_name , mode = "r" , index : nil , threads : nil ,
3150 build_index : false )
3251 if block_given?
@@ -54,22 +73,10 @@ def initialize(file_name, mode = "r", index: nil, threads: nil,
5473 @start_position = tell
5574 end
5675
57- def build_index ( index_name = nil , min_shift : 14 , threads : 2 )
76+ def build_index ( index_name = nil , min_shift : 14 , verbose : true )
5877 check_closed
5978
60- if index_name
61- warn "Create index for #{ @file_name } to #{ index_name } "
62- else
63- warn "Create index for #{ @file_name } "
64- end
65- case LibHTS . bcf_index_build3 ( @file_name , index_name , min_shift , @nthreads || threads )
66- when 0 # successful
67- when -1 then raise "indexing failed"
68- when -2 then raise "opening #{ @file_name } failed"
69- when -3 then raise "format not indexable"
70- when -4 then raise "failed to create and/or save the index"
71- else raise "unknown error"
72- end
79+ self . class . build_index ( @file_name , index_name , min_shift , @nthreads || 0 , verbose )
7380 self # for method chaining
7481 end
7582
0 commit comments