-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfasta-to-blast.rb
More file actions
executable file
·74 lines (63 loc) · 3.06 KB
/
fasta-to-blast.rb
File metadata and controls
executable file
·74 lines (63 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env ruby
# Copyright (c) 2010-2012 Michael Specht, Till Bald
#
# This file is part of Proteomatic.
#
# Proteomatic is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Proteomatic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Proteomatic. If not, see <http://www.gnu.org/licenses/>.
require './include/ruby/proteomatic'
require './include/ruby/fasta'
require 'fileutils'
class FastaToBlast < ProteomaticScript
def run()
@output.each do |inPath, outPath|
puts 'Converting database to BLAST format...'
if RUBY_PLATFORM.downcase.include?("mswin")
# make temp dir in user directory (necessary as network drives somehow cannot handle short names. Short names are necessary for formatdb as spaces are handled arkward.)
tempDir = Dir.mktmpdir('fasta-to-blast-')
elsif inPath.include?(" ")
# spaces do not work in non windows os either, so we need chose the temp dir
tempDir = Dir.mktmpdir('fasta-to-blast-')
else
# make temp dir in output directory
tempDir = tempFilename('fasta-to-blast-')
FileUtils::mkdir(tempDir)
end
FileUtils::cp(inPath, tempDir)
tempInputPath = File::join(tempDir, File::basename(inPath))
if RUBY_PLATFORM.downcase.include?("mswin")
tempInputPath = get_short_win32_filename(tempInputPath)
end
createBlastDatabase(tempInputPath)
# convert filenames on Windows (formatdb cannot handle spaces)
longName = File::basename(inPath)
filename = longName
if RUBY_PLATFORM.downcase.include?("mswin")
filename = File::basename(get_short_win32_filename(File::join(tempDir, filename)))
end
FileUtils::copy(File::join(tempDir, filename) + '.phr', File::join(File::dirname(outPath), longName) + '.phr');
FileUtils::copy(File::join(tempDir, filename) + '.pin', File::join(File::dirname(outPath), longName) + '.pin');
FileUtils::copy(File::join(tempDir, filename) + '.psq', File::join(File::dirname(outPath), longName) + '.psq');
FileUtils::rm_rf(tempDir)
end
end
def get_short_win32_filename(long_name)
require 'win32api'
win_func = Win32API.new("kernel32","GetShortPathName","PPL"," L")
buf = 0.chr * 256
buf[0..long_name.length-1] = long_name
win_func.call(long_name, buf, buf.length)
return buf.split(0.chr).first
end
end
script = FastaToBlast.new