def test_get_result_paths(self): """Tests the function that retrieves the result paths. aln, sampe, samse, bwasw return only one file. BWA_index returns 5 files, and the name depends on whether or not the -p option is on or not """ # instantiate objects index = BWA_index(params={}, HALT_EXEC=True) index2 = BWA_index(params={'-p': '/prefix'}, HALT_EXEC=True) aln = BWA_aln(params={'-f': '/sai_out'}, HALT_EXEC=True) samse = BWA_samse(params={'-f': '/sam_out'}, HALT_EXEC=True) sampe = BWA_sampe(params={'-f': '/sam_out'}, HALT_EXEC=True) bwasw = BWA_bwasw(params={'-f': '/sam_out'}, HALT_EXEC=True) # pass in the data, and make sure the output paths are as expected. # -p is off here index_data = {'fasta_in': '/fa_in'} results = index._get_result_paths(index_data) self.assertEqual(results['.amb'].Path, '/fa_in.amb') self.assertEqual(results['.ann'].Path, '/fa_in.ann') self.assertEqual(results['.bwt'].Path, '/fa_in.bwt') self.assertEqual(results['.pac'].Path, '/fa_in.pac') self.assertEqual(results['.sa'].Path, '/fa_in.sa') # pass in the data, and make sure the output paths are as expected. # -p is on here results = index2._get_result_paths(index_data) self.assertEqual(results['.amb'].Path, '/prefix.amb') self.assertEqual(results['.ann'].Path, '/prefix.ann') self.assertEqual(results['.bwt'].Path, '/prefix.bwt') self.assertEqual(results['.pac'].Path, '/prefix.pac') self.assertEqual(results['.sa'].Path, '/prefix.sa') # pass in the data, and make sure the output path is as expected aln_data = {'prefix': '/fa_in', 'fastq_in': '/fq_in'} results = aln._get_result_paths(aln_data) self.assertEqual(results['output'].Path, '/sai_out') samse_data = { 'prefix': '/fa_in', 'sai_in': '/sai_in', 'fastq_in': '/fq_in' } results = samse._get_result_paths(samse_data) self.assertEqual(results['output'].Path, '/sam_out') sampe_data = { 'prefix': '/fa_in', 'sai1_in': '/sai1_in', 'sai2_in': '/sai2_in', 'fastq1_in': '/fq1_in', 'fastq2_in': '/fq2_in' } results = sampe._get_result_paths(sampe_data) self.assertEqual(results['output'].Path, '/sam_out')
def test_input_as_dict(self): """Tests the input handler (_input_as_dict) The input handler should throw exceptions if there are not enough arguments, or if there are unrecognized arguments, or if a file path appears to be a relative filepath. """ # Arguments for BWA_bwasw, which was chosen since it is the only one # that also has an optional argument (optional arguments are denoted # by a leading underscore) missing = {'prefix': '/fa_in', '_query_fasta_2': '/mate'} extra = { 'prefix': '/fa_in', 'query_fasta': '/query_fasta', 'extra': '/param' } rel_fp = {'prefix': 'fa_in', 'query_fasta': '/query_fasta'} valid = {'prefix': '/fa_in', 'query_fasta': '/query_fasta'} valid_with_mate = { 'prefix': '/fa_in', 'query_fasta': '/query_fasta', '_query_fasta_2': '/mate' } # instantiate the object bwasw = BWA_bwasw(params={'-f': '/sam_out'}, HALT_EXEC=True) # should raise ApplicationError for wrong I/O files; failure self.assertRaisesRegexp(ApplicationError, "Missing required input", bwasw, missing) self.assertRaisesRegexp(ApplicationError, "Invalid input arguments", bwasw, extra) self.assertRaisesRegexp(ApplicationError, "Only absolute paths", bwasw, rel_fp) # should raise AssertionError (Halt Exec); success # tests valid arguments with and without the optional # _query_fasta_2 argument self.assertRaisesRegexp(AssertionError, 'Halted exec', bwasw, valid) self.assertRaisesRegexp(AssertionError, 'Halted exec', bwasw, valid_with_mate)