Class: InstallDatabase

Inherits:
Object
  • Object
show all
Defined in:
lib/seqtrimnext/classes/install_database.rb

Instance Method Summary collapse

Constructor Details

#initialize(type, db_path) ⇒ InstallDatabase

Returns a new instance of InstallDatabase.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/seqtrimnext/classes/install_database.rb', line 6

def initialize(type,db_path)
  
  
  types=['core','cont_bacteria','cont_fungi','cont_mitochondrias','cont_plastids','cont_ribosome','cont_viruses','adapters_illumina']
  
  if types.include?(type)
    
    if !File.exists?(db_path)
      FileUtils.mkdir_p(db_path)
    end
    
    remote_db_url="http://www.scbi.uma.es/downloads/#{type}_db.zip"
    local_path=File.join(db_path,'core_db.zip')
    puts "Install databases: #{type}"
  
    download_and_unzip(remote_db_url,local_path)
    
  else
    puts "Unknown database #{type}"
    puts "Available databases:"
    puts types.join("\n")
  end
end

Instance Method Details

#download_and_unzip(from_url, to_file) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/seqtrimnext/classes/install_database.rb', line 30

def download_and_unzip(from_url,to_file)
  puts "Downloading databases from #{from_url} to #{to_file}"
  
  open(to_file, "w+") { |f| f.write(open(from_url).read)}
  
  puts "Unzipping #{to_file}"
  
  # unzip and remove
  # `cd #{File.dirname(to_file)};unzip #{to_file}; rm #{to_file}`
  `cd #{File.dirname(to_file)};unzip #{to_file}; rm #{to_file}`
  
end