https://github.com/csw/bioruby-maf
Tip revision: 1f84378965e9bfd16e984372c73628bbedc126ff authored by Clayton Wheeler on 21 August 2012, 17:17:35 UTC
Fixed interval syntax in maf_tile specs.
Fixed interval syntax in maf_tile specs.
Tip revision: 1f84378
maf_count
#!/usr/bin/env ruby
require 'bio-maf'
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