require 'test/unit' require 'spec_id/protein_summary' require File.dirname(__FILE__) + '/test_helper' class ProphProtSummaryTest < Test::Unit::TestCase NODELETE = false def initialize(arg) super(arg) @tfiles = File.dirname(__FILE__) + '/tfiles/' @tfiles_l = File.dirname(__FILE__) + '/tfiles_large/' @tf_proph = @tfiles_l + "opd1/000_020-prot.xml" @tf_summary = @tfiles_l + "opd1/000_020-prot.summary.html" @tf_bioworks_small = @tfiles + 'bioworks_small.xml' @tf_bioworks_small_summary_html = @tfiles + 'bioworks_small.summary.html' @tf_proph_cat_inv = @tfiles + 'opd1/opd1_cat_inv_small-prot.xml' @tf_proph_cat_inv_summary_html = @tfiles + 'opd1/opd1_cat_inv_small-prot.summary.html' @tf_proph_cat_inv_summary_png = @tfiles + 'opd1/opd1_cat_inv_small-prot.summary.png' @tf_peptide_count = @tfiles + "peptide_counts.tmp.txt" end def runit(string_or_args) args = if string_or_args.is_a? String string_or_args.split(/\s+/) else string_or_args end ProteinSummary.new.create_from_command_line_args(args) end def test_usage output = capture_stdout { runit('') } assert_match(/usage:/, output) end def test_proph_basic if File.exist? @tfiles_l runit "-c 5.0 #{@tf_proph}" ProteinSummary.new.create_from_command_line_args([@tf_proph, '-c', '5.0']) assert(File.exist?(@tf_summary), "file #{@tf_summary} exists") string = IO.read(@tf_summary) assert_match(/gi\|16132176\|ref\|NP_418775\.1\|/, string) assert_match(/16132176/, string) File.unlink(@tf_summary) unless NODELETE else assert_nil( puts("--SKIPPING TEST-- (missing dir: #{@tfiles_l})") ) end end def test_bioworks_basic runit "#{@tf_bioworks_small}" assert(File.exist?(@tf_bioworks_small_summary_html), "file #{@tf_bioworks_small_summary_html} exists") File.unlink @tf_bioworks_small_summary_html unless NODELETE # @TODO: need to freeze the output here end def test_bioworks_with_precision ## Could reimplement a separate file approach? #reply = `#{@cmd} -f #{@tf_bioworks_small} #{@tf_bioworks_small} --precision` runit "#{@tf_bioworks_small} --precision" assert_match(/# hits.*106/m, IO.read(@tf_bioworks_small_summary_html)) #assert_match(/False Positive Rate.*: 0.500/, IO.read(@tf_bioworks_small_summary_html)) #assert_match(/False Positive Rate.*: 0.500/, IO.read(@tf_bioworks_small_summary_html)) assert(File.exist?(@tf_bioworks_small_summary_html), "file #{@tf_bioworks_small_summary_html} exists") File.unlink @tf_bioworks_small_summary_html unless NODELETE end def test_proph_with_precision #puts @cmd runit "#{@tf_proph_cat_inv} -f INV_ --prefix --precision" html = IO.read(@tf_proph_cat_inv_summary_html) assert_match(/# hits/, html, "in #{@tf_proph_cat_inv_summary_html}") assert_match(/2.*0\.0000/m, html, "in #{@tf_proph_cat_inv_summary_html}") assert_match(/3.*0\.3333/m, html, "in #{@tf_proph_cat_inv_summary_html}") assert_match(/7.*0\.5714/m, html, "in #{@tf_proph_cat_inv_summary_html}") File.unlink @tf_proph_cat_inv_summary_html unless NODELETE File.unlink @tf_proph_cat_inv_summary_png unless NODELETE end def test_peptide_count if File.exist? @tfiles_l runit "-c 5.0 #{@tf_proph} --peptide_count #{@tf_peptide_count}" assert(File.exist?(@tf_peptide_count), "file #{@tf_peptide_count} exists") file = IO.read(@tf_peptide_count) assert_match("gi|16132176|ref|NP_418775.1|\t2", file) assert_match("gi|16131996|ref|NP_418595.1|\t1", file) assert_match("gi|16131692|ref|NP_418288.1|\t4", file) File.unlink @tf_peptide_count unless NODELETE else assert_nil( puts("--SKIPPING TEST-- (missing dir: #{@tfiles_l})") ) end end end