https://github.com/csw/bioruby-maf
Raw File
Tip revision: bd2abbeee59894b53ec133cbd592027140052c65 authored by Clayton Wheeler on 03 August 2012, 01:02:57 UTC
Version 1.0.0.
Tip revision: bd2abbe
maf_to_fasta
#!/usr/bin/env ruby

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

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

OptionParser.new do |opts|
  opts.banner = "Usage: maf_to_fasta [options] <maf> <fasta>"
  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 |path|
    options.ruby_prof = path
  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
end.parse!(ARGV)

src_path = ARGV.shift
dst_path = ARGV.shift

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

if options.profile_gc
  GC::Profiler.enable
end

parser = options.parser.new(src_path)
File.open(dst_path, 'w') do |outf|
  writer = Bio::MAF::FASTAWriter.new(outf)

  parser.each_block do |block|
    writer.write_block(block)
  end
end

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

if options.prof
  PerfTools::CpuProfiler.stop
elsif options.ruby_prof
  res = RubyProf.stop
  printer = RubyProf::FlatPrinter.new(res)
  File.open(options.ruby_prof, 'w') do |f|
    printer.print(f)
  end
end
back to top