require 'test/unit' require File.dirname(File.expand_path(__FILE__)) + '/load_bin_path' require 'fileutils' tmp = $VERBOSE $VERBOSE = 5 $XML_SANITY_LINES = ['', '', ''] $XML_SANITY_MATCHES = [//, / /, //, //, //, //, //, ] class BioworksToPepXMLTest < Test::Unit::TestCase def initialize(arg) super(arg) @tfiles = File.dirname(__FILE__) + '/tfiles/' @tfiles_l = File.dirname(__FILE__) + '/tfiles_large/' @tf_mzxml_path = @tfiles_l + "yeast_gly_mzXML" @tf_bioworks_xml = @tfiles + "bioworks_small.xml" @tf_params = @tfiles + "bioworks32.params" @no_delete = true @out_path = @tfiles + 'pepxml/' @cmd = "ruby -I#{File.join(File.dirname(__FILE__), "..", "lib")} -S bioworks_to_pepxml.rb " end def test_usage assert_match(/usage:/, `#{@cmd}`) end def _basic(cmd, prc) puts "Performing: #{cmd}" if $VERBOSE reply = `#{cmd}` puts reply if $VERBOSE %w(000 020).each do |file| ffile = @out_path + file + ".xml" prc.call(ffile) end end def test_basic if File.exist? @tfiles_l cmd = "#{@cmd} -p #{@tf_params} -o #{@out_path} #{@tf_bioworks_xml} -m #{@tf_mzxml_path} -d /work/special/path --copy_mzxml" ## FILES EXIST: prc = proc {|file| assert(File.exist?(file), "#{file} exists") beginning = IO.readlines(file)[0,50].join("\n") $XML_SANITY_LINES.each do |line| assert(beginning.include?(line), "xml includes line: #{line}") end $XML_SANITY_MATCHES.each do |match| assert_match(match, beginning, "matches") end } _basic(cmd, prc) ## COPY MZXML: %w(000 020).each do |file| mzxml_file = File.join(@out_path, "#{file}.mzXML") assert(File.exist?( mzxml_file ), "file: #{mzxml_file} exists") end ## CLEANUP: unless @no_delete then FileUtils.rm_rf(@out_path) end else assert_nil( puts("--SKIPPING TEST-- (missing dir: #{@tfiles_l})") ) end end def test_database if File.exist? @tfiles_l cmd = "#{@cmd} -p #{@tf_params} -o #{@out_path} #{@tf_bioworks_xml} -m #{@tf_mzxml_path}" db_re = /C:\\Xcalibur\\database\\ecoli_K12_ncbi_20060321.fasta/ assert_match(db_re, IO.read(@tf_params)) prc = proc {|file| assert(File.exist?(file)) assert_no_match(db_re, IO.read(file)) } _basic(cmd, prc) unless @no_delete then FileUtils.rm_rf(@out_path) end else assert_nil( puts("--SKIPPING TEST-- (missing dir: #{@tfiles_l})") ) end end end $VERBOSE = tmp