Class: Minibwa::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/minibwa/index.rb,
ext/minibwa/mb_index.c

Overview

A minibwa index -- the FM-index plus the 2-bit reference -- and the object you map reads against.

The class comes from mb_index.c and mb_index_build.c; this file reopens it for checking paths and permissions before calling in. That check is not cosmetic: upstream reports bad input to the index builder with kom_assert(), which abort()s the whole process instead of returning an error.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(fasta, prefix, **kwargs) ⇒ Object

Validates that the FASTA file exists and is readable before calling the C extension (which would abort() on bad input).

Raises:



36
37
38
39
40
41
42
43
# File 'lib/minibwa/index.rb', line 36

def build(fasta, prefix, **kwargs)
  raise Error, "cannot read FASTA file: #{fasta}" unless File.readable?(fasta)

  dir = File.dirname(prefix)
  raise Error, "cannot write to directory: #{dir}" unless File.writable?(dir)

  _build(fasta, prefix, **kwargs)
end

.load(*args) ⇒ Object

Wraps Index.load with path validation.



46
47
48
49
# File 'lib/minibwa/index.rb', line 46

def load(prefix, **kwargs)
  check_prefix(prefix)
  _load(prefix, **kwargs)
end

.load_mmap(*args) ⇒ Object

Wraps Index.load_mmap with path validation.



52
53
54
55
# File 'lib/minibwa/index.rb', line 52

def load_mmap(prefix, **kwargs)
  check_prefix(prefix)
  _load_mmap(prefix, **kwargs)
end

Instance Method Details

#ctg_len(tid_val) ⇒ Object



180
181
182
183
184
185
186
187
188
# File 'ext/minibwa/mb_index.c', line 180

static VALUE
rb_minibwa_idx_ctg_len(VALUE self, VALUE tid_val)
{
    mb_idx_t *idx = rb_minibwa_get_idx(self);
    int32_t tid = NUM2INT(tid_val);
    int64_t len = mb_idx_ctg_len(idx, tid);
    if (len < 0) return Qnil;
    return LL2NUM(len);
}

#ctg_name(tid_val) ⇒ Object



163
164
165
166
167
168
169
170
171
# File 'ext/minibwa/mb_index.c', line 163

static VALUE
rb_minibwa_idx_ctg_name(VALUE self, VALUE tid_val)
{
    mb_idx_t *idx = rb_minibwa_get_idx(self);
    int32_t tid = NUM2INT(tid_val);
    const char *name = mb_idx_ctg_name(idx, tid);
    if (!name) return Qnil;
    return rb_str_new_cstr(name);
}

#map(*args) ⇒ Object

Convenience method: map a single sequence with keyword arguments.



68
69
70
# File 'lib/minibwa/index.rb', line 68

def map(seq, name: nil, opt: nil, buf: nil, meth: 0)
  _map(seq, name: name, opt: opt, buf: buf, meth: meth)
end

#map_batch(*args) ⇒ Object

Convenience method: map a batch with keyword arguments.



73
74
75
# File 'lib/minibwa/index.rb', line 73

def map_batch(seqs, names: nil, opt: nil, buf: nil)
  _map_batch(seqs, names: names, opt: opt, buf: buf)
end