Class: FastaDB

Inherits:
Object
  • Object
show all
Defined in:
lib/protk/fastadb.rb

Overview

Warning: Uses Bio::Command which is a private API of the Bio package

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blast_database_file_path) ⇒ FastaDB

Returns a new instance of FastaDB.


10
11
12
13
14
15
# File 'lib/protk/fastadb.rb', line 10

def initialize(blast_database_file_path)
  env = Constants.instance
  @database = blast_database_file_path
  @makedbcmd = env.makeblastdb
  @searchdbcmd = env.blastdbcmd
end

Class Method Details

.create(blast_database_file_path, input_fasta_filepath, type = 'nucl') ⇒ Object


17
18
19
20
21
# File 'lib/protk/fastadb.rb', line 17

def self.create(blast_database_file_path,input_fasta_filepath,type='nucl')
  db = FastaDB.new(blast_database_file_path)
  db.make_index(input_fasta_filepath,type)
  db
end

Instance Method Details

#fetch(list) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/protk/fastadb.rb', line 34

def fetch(list)
  if list.respond_to?(:join)
    entry_id = list.join(",")
  else
    entry_id = list
  end

  cmd = [ @searchdbcmd, '-db', @database, '-entry', entry_id ]
  Bio::Command.call_command(cmd) do |io|
    io.close_write
    Bio::FlatFile.new(Bio::FastaFormat, io).to_a
  end
end

#get_by_id(entry_id) ⇒ Object


23
24
25
# File 'lib/protk/fastadb.rb', line 23

def get_by_id(entry_id)
  fetch(entry_id).shift
end

#make_index(input_fasta, dbtype) ⇒ Object


27
28
29
30
31
32
# File 'lib/protk/fastadb.rb', line 27

def make_index(input_fasta,dbtype)
  cmd = [ @makedbcmd, '-in', input_fasta, '-parse_seqids','-out',@database,'-dbtype',dbtype]
  res = Bio::Command.call_command(cmd) do |io|
    puts io.read
  end
end