Class: Bio::DB::Fasta::Index

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bio/db/fastadb.rb

Overview

This class contains the entries in a fasta, as generated by samtools faidx

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIndex

Returns a new instance of Index.



9
10
11
12
# File 'lib/bio/db/fastadb.rb', line 9

def initialize
  @entries=[]
  @entries_map = Hash.new
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



7
8
9
# File 'lib/bio/db/fastadb.rb', line 7

def entries
  @entries
end

Instance Method Details

#<<(entry) ⇒ Object

This doesnt validate if you are adding the same entry twice. I may add a validation for that.



16
17
18
19
# File 'lib/bio/db/fastadb.rb', line 16

def <<(entry)
  @entries << entry
  @entries_map[entry.id] = entry
end

#[](args) ⇒ Object

Returns a new Index just with the specified range, as if it was an Array. The return object is of type Index.



32
33
34
35
36
37
38
# File 'lib/bio/db/fastadb.rb', line 32

def [](args)
  tmp = @entries[args]
  @new_index = Index.new
  tmp.each do | entry |
    @new_index << entry
  end       
end

#each(&block) ⇒ Object



21
22
23
# File 'lib/bio/db/fastadb.rb', line 21

def each(&block)
  @entries.entries(&block)
end

#lengthObject Also known as: size

Total number of entries



25
26
27
# File 'lib/bio/db/fastadb.rb', line 25

def length
  @entries.length
end

#region_for_entry(entry) ⇒ Object

Gets the Region object for the full length of the sequence name queried.



42
43
44
# File 'lib/bio/db/fastadb.rb', line 42

def region_for_entry(entry)
  @entries_map[entry]
end