require_relative '../../macroape' require 'yaml' require 'shellwords' module Macroape module CLI module PreprocessCollection def self.main(argv) doc = <<-EOS.strip_doc Command-line format: #{run_tool_cmd} [options] Options: [-p ] - comma separated(no spaces allowed) list of P-values to precalculate thresholds [-d ,] - set discretization rates, comma delimited (no spaces allowed), order doesn't matter [--silent] - hide current progress information during scan (printed to stderr by default) [--pcm] - treat the input file as Position Count Matrix. PCM-to-PWM transformation to be done internally. [--boundary lower|upper] Upper boundary (default) means that the obtained P-value is greater than or equal to the requested P-value [-b (pvalue, threshold, real_pvalue) do if real_pvalue == 0 $stderr.puts "#{pwm.name} at pvalue #{pvalue} has threshold that yields real-pvalue 0 in rough mode. Rough calculation will be skipped" else info.rough[pvalue] = threshold / rough_discretization end end fill_precise_infos = ->(pvalue, threshold, real_pvalue) do if real_pvalue == 0 $stderr.puts "#{pwm.name} at pvalue #{pvalue} has threshold that yields real-pvalue 0 in precise mode. Motif will be excluded from collection" skip_motif = true else info.precise[pvalue] = threshold / precise_discretization end end if pvalue_boundary == :lower pwm.discrete(rough_discretization).thresholds(*pvalues, &fill_rough_infos) else pwm.discrete(rough_discretization).weak_thresholds(*pvalues, &fill_rough_infos) end if pvalue_boundary == :lower pwm.discrete(precise_discretization).thresholds(*pvalues, &fill_precise_infos) else pwm.discrete(precise_discretization).weak_thresholds(*pvalues,&fill_precise_infos) end collection.add_pm(pwm, info) unless skip_motif end $stderr.puts "100% complete. Saving results" unless silent File.open(output_file, 'w') do |f| f.puts(collection.to_yaml) end puts OutputInformation.new{|infos| infos.add_parameter('P', 'P-value list', pvalues.join(',')) infos.add_parameter('VR', 'discretization value, rough', rough_discretization) infos.add_parameter('VP', 'discretization value, precise', precise_discretization) infos.add_parameter('PB', 'P-value boundary', pvalue_boundary) infos.background_parameter('B', 'background', background) }.result rescue => err $stderr.puts "\n#{err}\n#{err.backtrace.first(5).join("\n")}\n\nUse --help option for help\n\n#{doc}" end end end end