Sha256: 35a2d0f9f8bc2020b25b282910f834dd7f462df35a71f21da6e83a4805c49bdf

Contents?: true

Size: 1.87 KB

Versions: 6

Compression:

Stored size: 1.87 KB

Contents

#!/usr/bin/env ruby

require 'bio-maf'
require 'bigbio'
require 'optparse'
require 'ostruct'

options = OpenStruct.new
options.parser = Bio::MAF::Parser
options.reader = Bio::MAF::ChunkReader

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

OptionParser.new do |opts|
  opts.banner = "Usage: maf_count [options] <maf>"
  opts.separator ""
  opts.separator "Options:"
  opts.on("-p", "--profile PROF", "Profile with PerfTools") do |prof|
    options.prof = prof
  end
  opts.on("--ruby-prof PATH", "Profile with ruby-prof") do |pspec|
    if pspec =~ /(\w+):(.+)/
      require 'ruby-prof'
      options.ruby_prof_printer = RubyProf.const_get(PRINTERS.fetch($1))
      options.ruby_prof_path = $2
    else
      options.ruby_prof_printer = RubyProf::FlatPrinter
      options.ruby_prof_path = pspec
    end
  end
  opts.on("--profile-gc", "Profile GC") do |prof|
    options.profile_gc = true
  end
  opts.on("--parser PARSER", "parser") do |name|
    options.parser = Bio::MAF.const_get(name)
  end
  opts.on("-t", "--threaded") do
    options.reader = Bio::MAF::ThreadedChunkReader
  end
end.parse!(ARGV)

src_path = ARGV.shift

if options.prof
  require 'perftools'
  PerfTools::CpuProfiler.start(options.prof)
elsif options.ruby_prof_path
  require 'ruby-prof'
  RubyProf.start
end

if options.profile_gc
  GC::Profiler.enable
end

parser = options.parser.new(src_path,
                            :chunk_reader => options.reader,
                            :parse_extended => false)

n = 0
parser.each_block do |block|
  n += 1
end
puts "Parsed #{n} MAF alignment blocks."

if options.profile_gc
  $stderr.puts GC::Profiler.result
  GC::Profiler.disable
end

if options.prof
  PerfTools::CpuProfiler.stop
elsif 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_count
bio-maf-0.3.0 bin/maf_count
bio-maf-0.2.0-java bin/maf_count
bio-maf-0.2.0 bin/maf_count
bio-maf-0.1.0 bin/maf_count
bio-maf-0.1.0-java bin/maf_count