Esempio n. 1
0
    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')
Esempio n. 2
0
    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')
Esempio n. 3
0
    def test_check_arguments(self):
        """Tests the "check_arguments" method of the BWA base class.

        Arguments passed to certain parameters of the various subcommands can
        take only certain values. The check_arguments function enforces these
        constraints. This function ensures that the rules are being enforced
        as expected.
        """

        # set up test parameters
        # should pass
        index_params_is = {'-a': 'is'}
        # should pass
        index_params_bwtsw = {'-a': 'bwtsw'}
        # should fail, -a must be one of "is" or "bwtsw"
        index_params_invalid = {'-a': 'invalid'}
        # should fail, -p must specify a prefix that is an absolute path
        index_params_invalid_prefix = {'-p': 'invalid'}
        # should pass
        index_params_valid_prefix = {'-p': '/prefix'}

        # instantiate objects built from the above parameters
        index_is = BWA_index(params=index_params_is, HALT_EXEC=True)
        index_bwtsw = BWA_index(params=index_params_bwtsw, HALT_EXEC=True)
        index_invalid = BWA_index(params=index_params_invalid, HALT_EXEC=True)
        index_invalid_prefix = BWA_index(params=index_params_invalid_prefix, \
        HALT_EXEC=True)
        index_valid_prefix = BWA_index(params=index_params_valid_prefix, \
        HALT_EXEC=True)

        # Should not be allowed
        self.assertRaisesRegexp(ApplicationError, "Invalid argument", 
                                index_invalid.check_arguments)
        self.assertRaisesRegexp(ApplicationError, "Invalid argument",
                                index_invalid_prefix.check_arguments)

        # Should execute and not raise any exceptions
        index_is.check_arguments()
        index_bwtsw.check_arguments()
        index_valid_prefix.check_arguments()

        # The rest of the _valid_arguments are for checking is_int and is_float
        # and they all use the same function from the base-class, so testing
        # just one of the subcommands should suffice

        # -n must be a float (expressed either as a float or as a string)
        # -o must be an int (expressed either as an int or as a string)
        # pass, both valid
        aln_params_valid = {'-n': 3.0, '-o': 5, '-f':'/sai_out'} 
        # fail, second invalid
        aln_params_invalid1 = {'-n': 3.0, '-o': 'nope', '-f':'/sai_out'} 
        # fail, first invalid
        aln_params_invalid2 = {'-n': '3.5.1', '-o': 4, '-f':'/sai_out'} 
        # fail, did not specify -f
        aln_params_invalid3 = {'-n': 3.0, '-o': 5}

        # instantiate objects
        aln_valid = BWA_aln(params=aln_params_valid, HALT_EXEC=True)
        aln_invalid1 = BWA_aln(params=aln_params_invalid1, HALT_EXEC=True)
        aln_invalid2 = BWA_aln(params=aln_params_invalid2, HALT_EXEC=True)
        aln_invalid3 = BWA_aln(params=aln_params_invalid3, HALT_EXEC=True)

        test_paths = {'prefix': '/fa_in', 'fastq_in': '/fq_in'}

        # Should Halt Exec (AssertionError) right before execution
        self.assertRaisesRegexp(AssertionError, 'Halted exec', aln_valid, 
                                test_paths)
        # also need to make sure the base command is correct
        self.assertIn('; bwa aln -f /sai_out -n 3.0 -o 5 /fa_in /fq_in',
                     aln_valid.BaseCommand)

        # Should fail
        self.assertRaisesRegexp(ApplicationError, 
                                "Invalid argument", aln_invalid1,
                                test_paths)

        self.assertRaisesRegexp(ApplicationError, 
                                "Invalid argument", aln_invalid2,
                                test_paths)

        self.assertRaisesRegexp(ApplicationError, 
                                "Please specify an output file",
                                aln_invalid3, test_paths)
Esempio n. 4
0
    def test_check_arguments(self):
        """Tests the "check_arguments" method of the BWA base class.

        Arguments passed to certain parameters of the various subcommands can
        take only certain values. The check_arguments function enforces these
        constraints. This function ensures that the rules are being enforced
        as expected.
        """

        # set up test parameters
        # should pass
        index_params_is = {'-a': 'is'}
        # should pass
        index_params_bwtsw = {'-a': 'bwtsw'}
        # should fail, -a must be one of "is" or "bwtsw"
        index_params_invalid = {'-a': 'invalid'}
        # should fail, -p must specify a prefix that is an absolute path
        index_params_invalid_prefix = {'-p': 'invalid'}
        # should pass
        index_params_valid_prefix = {'-p': '/prefix'}

        # instantiate objects built from the above parameters
        index_is = BWA_index(params=index_params_is, HALT_EXEC=True)
        index_bwtsw = BWA_index(params=index_params_bwtsw, HALT_EXEC=True)
        index_invalid = BWA_index(params=index_params_invalid, HALT_EXEC=True)
        index_invalid_prefix = BWA_index(params=index_params_invalid_prefix, \
        HALT_EXEC=True)
        index_valid_prefix = BWA_index(params=index_params_valid_prefix, \
        HALT_EXEC=True)

        # Should not be allowed
        self.assertRaisesRegexp(ApplicationError, "Invalid argument",
                                index_invalid.check_arguments)
        self.assertRaisesRegexp(ApplicationError, "Invalid argument",
                                index_invalid_prefix.check_arguments)

        # Should execute and not raise any exceptions
        index_is.check_arguments()
        index_bwtsw.check_arguments()
        index_valid_prefix.check_arguments()

        # The rest of the _valid_arguments are for checking is_int and is_float
        # and they all use the same function from the base-class, so testing
        # just one of the subcommands should suffice

        # -n must be a float (expressed either as a float or as a string)
        # -o must be an int (expressed either as an int or as a string)
        # pass, both valid
        aln_params_valid = {'-n': 3.0, '-o': 5, '-f': '/sai_out'}
        # fail, second invalid
        aln_params_invalid1 = {'-n': 3.0, '-o': 'nope', '-f': '/sai_out'}
        # fail, first invalid
        aln_params_invalid2 = {'-n': '3.5.1', '-o': 4, '-f': '/sai_out'}
        # fail, did not specify -f
        aln_params_invalid3 = {'-n': 3.0, '-o': 5}

        # instantiate objects
        aln_valid = BWA_aln(params=aln_params_valid, HALT_EXEC=True)
        aln_invalid1 = BWA_aln(params=aln_params_invalid1, HALT_EXEC=True)
        aln_invalid2 = BWA_aln(params=aln_params_invalid2, HALT_EXEC=True)
        aln_invalid3 = BWA_aln(params=aln_params_invalid3, HALT_EXEC=True)

        test_paths = {'prefix': '/fa_in', 'fastq_in': '/fq_in'}

        # Should Halt Exec (AssertionError) right before execution
        self.assertRaisesRegexp(AssertionError, 'Halted exec', aln_valid,
                                test_paths)
        # also need to make sure the base command is correct
        self.assertIn('; bwa aln -f /sai_out -n 3.0 -o 5 /fa_in /fq_in',
                      aln_valid.BaseCommand)

        # Should fail
        self.assertRaisesRegexp(ApplicationError, "Invalid argument",
                                aln_invalid1, test_paths)

        self.assertRaisesRegexp(ApplicationError, "Invalid argument",
                                aln_invalid2, test_paths)

        self.assertRaisesRegexp(ApplicationError,
                                "Please specify an output file", aln_invalid3,
                                test_paths)