예제 #1
0
 def test_error_on_bad_config(self):
     with self.assertRaises(SystemExit) as err:
         main([
             SUBCOMMAND.SETUP, 'thing/that/doesnot/exist.cfg', '-o',
             self.temp_output
         ])
     self.assertEqual(2, err.exception.code)
예제 #2
0
    def test_marker_not_enough_args(self):
        with patch.object(sys, 'argv', [
                'mavis', SUBCOMMAND.OVERLAY, 'GAGE4', '--annotations',
                ANNOTATIONS, '--output', self.temp_output, '--marker', 'm'
        ]):
            try:
                returncode = main()
            except SystemExit as err:
                self.assertNotEqual(0, err.code)
            else:
                self.assertNotEqual(0, returncode)
                self.assertTrue(
                    glob_exists(os.path.join(self.temp_output, '*GAGE4*.svg')))

        with patch.object(sys, 'argv', [
                'mavis', SUBCOMMAND.OVERLAY, '--annotations', ANNOTATIONS,
                'GAGE4', '--output', self.temp_output, '--marker'
        ]):
            try:
                returncode = main()
            except SystemExit as err:
                self.assertNotEqual(0, err.code)
            else:
                self.assertNotEqual(0, returncode)
                self.assertTrue(
                    glob_exists(os.path.join(self.temp_output, '*GAGE4*.svg')))
예제 #3
0
    def test_clean_files(self):
        args = [
            'mavis', SUBCOMMAND.PIPELINE, CLEAN_CONFIG, '-o', self.temp_output
        ]
        with patch.object(sys, 'argv', args):
            self.assertEqual(0, main())

        # check that the subdirectories were built
        for lib in [MOCK_GENOME + '_*', MOCK_TRANS + '_*']:
            self.check_cluster(lib)

            # run validation
            self.assertTrue(
                glob_exists(self.temp_output, lib, SUBCOMMAND.VALIDATE))
            qsub = unique_exists(
                os.path.join(self.temp_output, lib, SUBCOMMAND.VALIDATE,
                             '*-1/submit.sh'))
            args = convert_qsub_to_args(
                qsub)  # read the arguments from the file
            print(args)
            with patch.object(sys, 'argv', args):
                self.assertEqual(0, main())

            for suffix in [
                    'evidence.bed', 'validation-failed.tab',
                    'validation-passed.tab'
            ]:
                self.assertTrue(
                    glob_exists(self.temp_output, lib,
                                SUBCOMMAND.VALIDATE + '/*-1', '*.' + suffix))
            for suffix in [
                    'contigs.bam',
                    'contigs.blat_out.pslx',
                    'contigs.fa',
                    'contigs.sorted.bam',
                    'contigs.sorted.bam.bai',
                    'igv.batch',
                    'raw_evidence.bam',
                    'raw_evidence.sorted.bam',
                    'raw_evidence.sorted.bam.bai',
            ]:
                self.assertFalse(
                    glob_exists(self.temp_output, lib,
                                SUBCOMMAND.VALIDATE + '/*-1', '*.' + suffix))
            self.assertTrue(
                glob_exists(self.temp_output, lib,
                            SUBCOMMAND.VALIDATE + '/*-1', '*.COMPLETE'))

            self.check_and_run_annotate(lib)
        # now run the pairing
        self.check_and_run_pairing()

        # now run the summary
        self.check_and_run_summary()

        with patch.object(
                sys, 'argv',
            ['mavis', SUBCOMMAND.CHECKER, '-o', self.temp_output]):
            self.assertEqual(0, main())
        self.assertTrue(glob_exists(self.temp_output, 'submit_pipeline*.sh'))
예제 #4
0
 def test_reference_from_env(self):
     os.environ.update({
         'MAVIS_TEMPLATE_METADATA':
         get_data('cytoBand.txt'),
         'MAVIS_ANNOTATIONS':
         get_data('mock_annotations.json'),
         'MAVIS_MASKING':
         get_data('mock_masking.tab'),
         'MAVIS_REFERENCE_GENOME':
         get_data('mock_reference_genome.fa'),
         'MAVIS_ALIGNER_REFERENCE':
         get_data('mock_reference_genome.2bit'),
         'MAVIS_DGV_ANNOTATION':
         get_data('mock_dgv_annotation.txt'),
     })
     main([
         SUBCOMMAND.SETUP,
         get_data('reference_from_env.cfg'), '-o', self.temp_output
     ])
     self.assertTrue(glob_exists(self.temp_output, 'build.cfg'))
     main([SUBCOMMAND.SCHEDULE, '-o', self.temp_output, '--submit'])
     # check that the subdirectories were built
     for lib in [MOCK_GENOME + '_*']:
         self.check_cluster(lib)
         self.check_validate(lib)
         self.check_aligner_output_files(lib)
         self.check_annotate(lib)
     self.check_pairing()
     self.check_summary(count=2)
예제 #5
0
 def test_slurm_skip_cluster(self):
     os.environ['MAVIS_SCHEDULER'] = 'SLURM'
     args = [
         SUBCOMMAND.SETUP,
         CONFIG,
         '-o',
         self.temp_output,
         '--skip_stage',
         SUBCOMMAND.CLUSTER,
     ]
     main(args)
     self.assertTrue(glob_exists(self.temp_output, 'build.cfg'))
     self.assertTrue(
         glob_exists(self.temp_output,
                     '*',
                     SUBCOMMAND.VALIDATE,
                     'submit.sh',
                     n=2))
     self.assertTrue(
         glob_exists(self.temp_output,
                     '*',
                     SUBCOMMAND.ANNOTATE,
                     'submit.sh',
                     n=2))
     self.assertTrue(
         glob_exists(self.temp_output, SUBCOMMAND.PAIR, 'submit.sh'))
     self.assertTrue(
         glob_exists(self.temp_output, SUBCOMMAND.SUMMARY, 'submit.sh'))
예제 #6
0
    def test_no_optional_files(self):
        args = [
            'mavis', SUBCOMMAND.PIPELINE,
            data('no_opt_pipeline.cfg'), '-o', self.temp_output
        ]
        with patch.object(sys, 'argv', args):
            self.assertEqual(0, main())

        # check that the subdirectories were built
        for lib in [MOCK_GENOME + '_*', MOCK_TRANS + '_*']:
            self.check_cluster(lib)
            self.check_and_run_validate(lib)
            self.check_aligner_output_files(lib)
            self.check_and_run_annotate(lib)
        # now run the pairing
        self.check_and_run_pairing()

        # now run the summary
        self.check_and_run_summary()

        with patch.object(
                sys, 'argv',
            ['mavis', SUBCOMMAND.CHECKER, '-o', self.temp_output]):
            self.assertEqual(0, main())
        self.assertTrue(glob_exists(self.temp_output, 'submit_pipeline*.sh'))
예제 #7
0
 def test_missing_reference(self):
     args = [
         'mavis', SUBCOMMAND.PIPELINE,
         data('missing_reference.cfg'), '-o', self.temp_output
     ]
     with patch.object(sys, 'argv', args):
         with self.assertRaises(OSError):
             main()
예제 #8
0
 def test_error_on_bad_input_file(self):
     args = [
         'mavis', SUBCOMMAND.PIPELINE,
         data('bad_input_file.cfg'), '-o', self.temp_output
     ]
     with patch.object(sys, 'argv', args):
         with self.assertRaises(FileNotFoundError):
             main()
예제 #9
0
 def test_error_on_bad_config(self):
     args = [
         'mavis', SUBCOMMAND.PIPELINE, 'thing/that/doesnot/exist.cfg', '-o',
         self.temp_output
     ]
     with patch.object(sys, 'argv', args):
         print(sys.argv)
         try:
             main()
             raise AssertionError('should have thrown error')
         except SystemExit as err:
             self.assertEqual(2, err.code)
예제 #10
0
    def test_pipeline_with_bwa(self):
        main([SUBCOMMAND.SETUP, BWA_CONFIG, '-o', self.temp_output])
        self.assertTrue(glob_exists(self.temp_output, 'build.cfg'))
        main([SUBCOMMAND.SCHEDULE, '-o', self.temp_output, '--submit'])
        # check that the subdirectories were built
        for lib in [MOCK_GENOME + '_*', MOCK_TRANS + '_*']:
            self.check_cluster(lib)
            self.check_validate(lib)
            self.check_aligner_output_files(lib, mem=True)
            self.check_annotate(lib)

        self.check_pairing()
        self.check_summary()
예제 #11
0
    def test_skip_clustering(self):
        main([
            SUBCOMMAND.SETUP, CONFIG, '-o', self.temp_output, '--skip_stage',
            SUBCOMMAND.CLUSTER
        ])
        self.assertTrue(glob_exists(self.temp_output, 'build.cfg'))
        main([SUBCOMMAND.SCHEDULE, '-o', self.temp_output, '--submit'])

        # check that the subdirectories were built
        for lib in [MOCK_GENOME + '_*', MOCK_TRANS + '_*']:
            self.check_cluster(lib, skipped=True)
            self.check_validate(lib)
            self.check_aligner_output_files(lib)
            self.check_annotate(lib)
        self.check_pairing()
        self.check_summary()
예제 #12
0
    def check_and_run_validate(self, lib):
        # run validation
        self.assertTrue(glob_exists(self.temp_output, lib,
                                    SUBCOMMAND.VALIDATE))
        qsub = unique_exists(
            os.path.join(self.temp_output, lib, SUBCOMMAND.VALIDATE,
                         '*-1/submit.sh'))
        args = convert_qsub_to_args(qsub)  # read the arguments from the file
        print(args)
        with patch.object(sys, 'argv', args):
            self.assertEqual(0, main())

        for suffix in [
                'contigs.bam', 'contigs.fa', 'contigs.sorted.bam',
                'contigs.sorted.bam.bai', 'evidence.bed', 'igv.batch',
                'raw_evidence.bam', 'raw_evidence.sorted.bam',
                'raw_evidence.sorted.bam.bai', 'validation-failed.tab',
                'validation-passed.tab'
        ]:
            self.assertTrue(
                glob_exists(self.temp_output, lib,
                            SUBCOMMAND.VALIDATE + '/*-1', '*.' + suffix))
        self.assertTrue(
            glob_exists(self.temp_output, lib, SUBCOMMAND.VALIDATE + '/*-1',
                        '*.COMPLETE'))
예제 #13
0
파일: test_overlay.py 프로젝트: bcgsc/mavis
 def test_read_depth_plot_not_binned_but_stranded(self, config_json,
                                                  output_dir):
     # no ymax
     with patch.object(
             sys,
             'argv',
         [
             'mavis',
             SUBCOMMAND.OVERLAY,
             'GAGE4',
             '--config',
             config_json,
             '--output',
             output_dir,
             '--read_depth_plot',
             'axis',
             BAM,
             '1',
             'none',
             'True',
         ],
     ):
         try:
             returncode = main()
         except SystemExit as err:
             assert err.code == 0
         else:
             assert returncode is None
             assert glob_exists(os.path.join(output_dir, '*GAGE4*.svg'))
예제 #14
0
파일: test_overlay.py 프로젝트: bcgsc/mavis
 def test_marker_range(self, config_json, output_dir):
     with patch.object(
             sys,
             'argv',
         [
             'mavis',
             SUBCOMMAND.OVERLAY,
             'GAGE4',
             '--config',
             config_json,
             '--output',
             output_dir,
             '--marker',
             'm',
             '49364900',
             '49365900',
         ],
     ):
         try:
             returncode = main()
         except SystemExit as err:
             assert err.code == 0
         else:
             assert returncode is None
             assert glob_exists(os.path.join(output_dir, '*GAGE4*.svg'))
예제 #15
0
    def test_skip_validation(self):
        main([
            SUBCOMMAND.SETUP, CONFIG, '-o', self.temp_output, '--skip_stage',
            SUBCOMMAND.VALIDATE
        ])

        self.assertTrue(glob_exists(self.temp_output, 'build.cfg'))
        main([SUBCOMMAND.SCHEDULE, '-o', self.temp_output, '--submit'])

        # check that the subdirectories were built
        for lib in [MOCK_GENOME + '_*', MOCK_TRANS + '_*']:
            self.check_cluster(lib)
            self.assertFalse(
                glob_exists(self.temp_output, lib, SUBCOMMAND.VALIDATE))
            self.check_annotate(lib)
        self.check_pairing()
        self.check_summary()
예제 #16
0
 def test_convert(self):
     with patch.object(sys, 'argv', ['mavis', SUBCOMMAND.CONVERT, '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             assert err.code == 0
         else:
             assert returncode == 0
예제 #17
0
 def test_main(self):
     with patch.object(sys, 'argv', ['mavis', '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             assert err.code == 0
         else:
             assert returncode == 0
예제 #18
0
 def test_summary(self):
     with patch.object(sys, 'argv', ['mavis', SUBCOMMAND.SUMMARY, '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             assert err.code == 0
         else:
             assert returncode == 0
예제 #19
0
 def test_bad_option(self):
     with patch.object(sys, 'argv', ['mavis', SUBCOMMAND.SETUP, '--blargh']):
         try:
             returncode = main()
         except SystemExit as err:
             self.assertNotEqual(0, err.code)
         else:
             self.assertNotEqual(0, returncode)
예제 #20
0
파일: test_help.py 프로젝트: shenjia1/mavis
 def test_pipeline(self):
     with patch.object(sys, 'argv', ['mavis', SUBCOMMAND.PIPELINE, '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             self.assertEqual(0, err.code)
         else:
             self.assertEqual(0, returncode)
예제 #21
0
 def test_overlay(self):
     with patch.object(sys, 'argv', ['mavis', SUBCOMMAND.OVERLAY, '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             self.assertEqual(0, err.code)
         else:
             self.assertEqual(0, returncode)
예제 #22
0
 def test_annotate(self):
     with patch.object(sys, 'argv', ['mavis', SUBCOMMAND.ANNOTATE, '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             self.assertEqual(0, err.code)
         else:
             self.assertEqual(0, returncode)
예제 #23
0
 def test_validate(self):
     with patch.object(sys, 'argv', ['mavis', SUBCOMMAND.VALIDATE, '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             assert err.code == 0
         else:
             assert returncode == 0
예제 #24
0
 def test_ref_alt_count(self):
     with patch.object(sys, 'argv', ['calculate_ref_alt_counts', '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             self.assertEqual(0, err.code)
         else:
             self.assertEqual(0, returncode)
예제 #25
0
 def test_cluster(self):
     with patch.object(sys, 'argv', ['mavis', SUBCOMMAND.CLUSTER, '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             self.assertEqual(0, err.code)
         else:
             self.assertEqual(0, returncode)
예제 #26
0
 def test_main(self):
     with patch.object(sys, 'argv', ['mavis', '-h']):
         try:
             returncode = main()
         except SystemExit as err:
             self.assertEqual(0, err.code)
         else:
             self.assertEqual(0, returncode)
예제 #27
0
 def test_bad_option(self):
     with patch.object(sys, 'argv',
                       ['mavis', SUBCOMMAND.SETUP, '--blargh']):
         try:
             returncode = main()
         except SystemExit as err:
             assert err.code != 0
         else:
             assert returncode != 0
예제 #28
0
 def run_main(self, exit_status=0):
     outputfile = os.path.join(self.temp_output, 'config.cfg')
     self.args.extend(['-w', outputfile])
     with mock.patch.object(sys, 'argv', [str(a) for a in self.args]):
         print('sys.argv', sys.argv)
         try:
             return_code = main()
         except SystemExit as ex:
             return_code = ex.code
         self.assertEqual(exit_status, return_code)
예제 #29
0
    def test_clean_files(self):
        main([SUBCOMMAND.SETUP, CLEAN_CONFIG, '-o', self.temp_output])

        self.assertTrue(glob_exists(self.temp_output, 'build.cfg'))
        main([SUBCOMMAND.SCHEDULE, '-o', self.temp_output, '--submit'])

        # check that the subdirectories were built
        for lib in [MOCK_GENOME + '_*', MOCK_TRANS + '_*']:
            self.check_cluster(lib)
            self.assertTrue(
                glob_exists(self.temp_output, lib, SUBCOMMAND.VALIDATE))

            for suffix in [
                    'evidence.bed', 'validation-failed.tab',
                    'validation-passed.tab'
            ]:
                self.assertTrue(
                    glob_exists(self.temp_output, lib,
                                SUBCOMMAND.VALIDATE + '/*-1', suffix))
            for suffix in [
                    'contigs.bam',
                    'contigs.blat_out.pslx',
                    'contigs.fa',
                    'contigs.sorted.bam',
                    'contigs.sorted.bam.bai',
                    'igv.batch',
                    'raw_evidence.bam',
                    'raw_evidence.sorted.bam',
                    'raw_evidence.sorted.bam.bai',
            ]:
                self.assertFalse(
                    glob_exists(self.temp_output, lib,
                                SUBCOMMAND.VALIDATE + '/*-1', suffix),
                    msg=suffix,
                )
            self.assertTrue(
                glob_exists(self.temp_output, lib,
                            SUBCOMMAND.VALIDATE + '/*-1', 'MAVIS-*.COMPLETE'))

            self.check_annotate(lib)
        self.check_pairing()
        self.check_summary()
예제 #30
0
    def test_reference_from_env(self):
        args = [
            'mavis', SUBCOMMAND.PIPELINE,
            data('reference_from_env.cfg'), '-o', self.temp_output
        ]
        env = {k: v for k, v in os.environ.items()}
        env.update({
            'MAVIS_TEMPLATE_METADATA':
            'tests/integration/data/cytoBand.txt',
            'MAVIS_ANNOTATIONS':
            'tests/integration/data/mock_annotations.json',
            'MAVIS_MASKING':
            'tests/integration/data/mock_masking.tab',
            'MAVIS_REFERENCE_GENOME':
            'tests/integration/data/mock_reference_genome.fa',
            'MAVIS_ALIGNER_REFERENCE':
            'tests/integration/data/mock_reference_genome.2bit',
            'MAVIS_DGV_ANNOTATION':
            'tests/integration/data/mock_dgv_annotation.txt',
        })
        with patch.object(os, 'environ', env):
            with patch.object(sys, 'argv', args):
                self.assertEqual(0, main())

            # check that the subdirectories were built
            for lib in [MOCK_GENOME + '_*']:
                self.check_cluster(lib)
                self.check_and_run_validate(lib)
                self.check_aligner_output_files(lib)
                self.check_and_run_annotate(lib)
            # now run the pairing
            self.check_and_run_pairing()

            # now run the summary
            self.check_and_run_summary(count=2)

            with patch.object(
                    sys, 'argv',
                ['mavis', SUBCOMMAND.CHECKER, '-o', self.temp_output]):
                self.assertEqual(0, main())
            self.assertTrue(
                glob_exists(self.temp_output, 'submit_pipeline*.sh'))