Sha256: a273e4837f81a21714ce6d66ee8215982e2165ab2f3ebc69c57266b9af5b8f9b

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

#!/usr/bin/env ruby

require 'benchmark'
require 'bio-maf'
require 'optparse'
require 'ostruct'

PRINTERS = {
  'flat' => :FlatPrinter,
  'stack' => :CallStackPrinter,
  'graph' => :GraphHtmlPrinter
}

$options = OpenStruct.new
$options.mode = :build
$options.reader = Bio::MAF::ChunkReader

def build_index(maf, index)
  parser = Bio::MAF::Parser.new(maf,
                                :chunk_reader => $options.reader,
                                :parse_extended => false)
  idx = Bio::MAF::KyotoIndex.build(parser, index)
  idx.close
end

op = OptionParser.new do |opts|
  opts.banner = "Usage: maf_index [options] <maf> <index>"
  #opts.separator ""
  #opts.separator "Options:"
  opts.on("--time", "print elapsed time") do
    $options.bench = true
  end
  opts.on("-d", "--dump") do
    $options.mode = :dump
  end
  opts.on("-t", "--threaded") do
    $options.reader = Bio::MAF::ThreadedChunkReader
  end
  opts.on("--ruby-prof PATH", "Profile with ruby-prof") do |pspec|
    require 'ruby-prof'
    if pspec =~ /(\w+):(.+)/
      $options.ruby_prof_printer = RubyProf.const_get(PRINTERS.fetch($1))
      $options.ruby_prof_path = $2
    else
      $options.ruby_prof_printer = Ruby_Prof::FlatPrinter
      $options.ruby_prof_path = pspec
    end
  end
end

op.parse!(ARGV)

maf_p = ARGV.shift if $options.mode == :build
index_p = ARGV.shift

unless (maf_p || $options.mode == :dump) && index_p
  $stderr.puts op
  exit 1
end

if $options.ruby_prof_path
  RubyProf.start
end

case $options.mode
when :build
  if ! $options.bench
    build_index(maf_p, index_p)
  else
    bm_res = Benchmark.measure do
      build_index(maf_p, index_p)
    end
    puts bm_res
  end
when :dump
  idx = Bio::MAF::KyotoIndex.open(index_p)
  idx.dump
else
  raise "Unsupported mode: #{$options.mode}"
end

if $options.ruby_prof_path
  res = RubyProf.stop
  printer = $options.ruby_prof_printer.new(res)
  File.open($options.ruby_prof_path, 'w') do |f|
    printer.print(f)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bio-maf-0.3.0-java bin/maf_index
bio-maf-0.3.0 bin/maf_index
bio-maf-0.2.0-java bin/maf_index
bio-maf-0.2.0 bin/maf_index
bio-maf-0.1.0 bin/maf_index
bio-maf-0.1.0-java bin/maf_index