Skip to content

Commit

Permalink
* lib/bio/io/flatfile/indexer.rb is included in bio.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
ktym authored and ngoto committed Sep 15, 2017
1 parent 00cf41f commit 1b022f6
Showing 1 changed file with 61 additions and 67 deletions.
128 changes: 61 additions & 67 deletions bin/br_bioflat.rb
Expand Up @@ -18,87 +18,81 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: br_bioflat.rb,v 1.2 2002/08/21 18:01:26 ng Exp $
# $Id: br_bioflat.rb,v 1.3 2002/08/26 06:08:20 k Exp $
#

require 'bio'
require 'bio/io/flatfile/indexer'

#if __FILE__ == $0
if true

def create_index(is_bdb, dbname, format, *files)
case format
when /genbank/i
dbclass = Bio::GenBank
add_secondary = nil
when /genpept/i
dbclass = Bio::GenPept
add_secondary = nil
when /embl/i
dbclass = Bio::EMBL
add_secondary = [ 'DR' ]
when /sptr/i
dbclass = Bio::SPTR
add_secondary = [ 'DR' ]
else
raise "Unsupported format : #{format}"
end
if is_bdb then
Bio::FlatFileIndex::Indexer::makeindexBDB(dbname, dbclass, nil, nil, add_secondary, *files)
else
Bio::FlatFileIndex::Indexer::makeindexFlat(dbname, dbclass, nil, nil, add_secondary, *files)
end
def create_index(is_bdb, dbname, format, *files)
case format
when /genbank/i
dbclass = Bio::GenBank
add_secondary = nil
when /genpept/i
dbclass = Bio::GenPept
add_secondary = nil
when /embl/i
dbclass = Bio::EMBL
add_secondary = [ 'DR' ]
when /sptr/i
dbclass = Bio::SPTR
add_secondary = [ 'DR' ]
else
raise "Unsupported format : #{format}"
end

def do_index
is_bdb = (/bdb/i).match(ARGV[0]) ? Bio::FlatFileIndex::MAGIC_BDB : nil
dbname = ARGV[1]
format = ARGV[3]
files = ARGV[4..-1]
files.shift if files[0] == '--files'
create_index(is_bdb, dbname, format, *files)
if is_bdb then
Bio::FlatFileIndex::Indexer::makeindexBDB(dbname, dbclass, nil, nil, add_secondary, *files)
else
Bio::FlatFileIndex::Indexer::makeindexFlat(dbname, dbclass, nil, nil, add_secondary, *files)
end
end


def do_search
ARGV.shift if ARGV[0] == '--search'
dbname = ARGV.shift
db = Bio::FlatFileIndex.open(dbname)
ARGV.each do |key|
STDERR.print "Searching for \'#{key}\'...\n"
r = db.search(key)
STDERR.print "OK, #{r.size} entry found\n"
if r.size > 0 then
print r
end
end
db.close
end
def do_index
is_bdb = (/bdb/i).match(ARGV[0]) ? Bio::FlatFileIndex::MAGIC_BDB : nil
dbname = ARGV[1]
format = ARGV[3]
files = ARGV[4..-1]
files.shift if files[0] == '--files'
create_index(is_bdb, dbname, format, *files)
end


def usage
print "Create index: \n"
print "#{$0} --makeindex DBNAME --format CLASS [--files] FILENAME...\n"
print "#{$0} --makeindexBDB DBNAME --format CLASS [--files] FILENAME...\n"
print "Search: \n"
print "#{$0} [--search] DBNAME KEYWORD...\n"
def do_search
ARGV.shift if ARGV[0] == '--search'
dbname = ARGV.shift
db = Bio::FlatFileIndex.open(dbname)
ARGV.each do |key|
STDERR.print "Searching for \'#{key}\'...\n"
r = db.search(key)
STDERR.print "OK, #{r.size} entry found\n"
if r.size > 0 then
print r
end
end
db.close
end


if ARGV.size > 1
case ARGV[0]
when /--make/
do_index
when /--search/
do_search
else #default is search
do_search
end
else
usage
end
def usage
print "Create index: \n"
print "#{$0} --makeindex DBNAME --format CLASS [--files] FILENAME...\n"
print "#{$0} --makeindexBDB DBNAME --format CLASS [--files] FILENAME...\n"
print "Search: \n"
print "#{$0} [--search] DBNAME KEYWORD...\n"
end


if ARGV.size > 1
case ARGV[0]
when /--make/
do_index
when /--search/
do_search
else #default is search
do_search
end
else
usage
end

0 comments on commit 1b022f6

Please sign in to comment.