Exemplo n.º 1
0
    def test_convert_mod_mrc_files_labels_not_file(self):
        temp_dir = tempfile.mkdtemp()
        try:
            images_file = os.path.join(temp_dir, 'images.mrc')
            labels_file = os.path.join(temp_dir, 'labels.mod')
            os.makedirs(os.path.join(temp_dir, 'tmp'), mode=0o755)
            open(images_file, 'a').close()

            mrc2tif = os.path.join(temp_dir, 'mrc2tif')
            f = open(mrc2tif, 'w')
            f.write('#!/usr/bin/env python\nimport sys;sys.exit(0)\n')
            f.flush()
            f.close()
            os.chmod(mrc2tif, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)

            params = createchmtrainjob._parse_arguments(
                'hi', [
                    images_file, labels_file, temp_dir, '--cluster', 'rocce',
                    '--imodbindir', temp_dir
                ])

            createchmtrainjob._convert_mod_mrc_files(params)
            self.fail('Expected IMODConversionError')
        except IMODConversionError as e:
            self.assertTrue(labels_file + ' is not a file, '
                            'cannot convert' in str(e))

        finally:
            shutil.rmtree(temp_dir)
Exemplo n.º 2
0
    def test_create_submit_script_rocce_cluster(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = createchmtrainjob._parse_arguments(
                'hi', ['./images', './labels', temp_dir, '--cluster', 'rocce'])

            script = os.path.join(temp_dir,
                                  createchmtrainjob.RUNTRAIN + 'rocce')
            ucmd = createchmtrainjob._create_submit_script(params)
            self.assertEqual(
                ucmd, 'To submit run: cd ' + temp_dir + '; qsub ' + script)

            f = open(script, 'r')
            data = f.read()
            f.close()
            self.assertTrue('-N chmtrainjob' in data)
            cwd = os.getcwd()

            labelsdir = os.path.abspath(os.path.join(cwd, 'labels'))
            imgdir = os.path.abspath(os.path.join(cwd, 'images'))
            tmpdir = os.path.abspath(os.path.join(temp_dir, 'tmp'))
            mystr = ('.img train ' + imgdir + ' ' + labelsdir +
                     ' -S 2 -L 4 -m ' + tmpdir)

            self.assertTrue(mystr in data)

            # check the submit command got appended to end of readme file
            f = open(os.path.join(temp_dir, createchmtrainjob.README_FILE),
                     'r')
            data = f.read()
            self.assertTrue('To submit run: cd ' + temp_dir in data)
            f.close()
        finally:
            shutil.rmtree(temp_dir)
Exemplo n.º 3
0
 def test_parse_arguments(self):
     params = createchmtrainjob._parse_arguments(
         'hi', ['images', 'labels', 'outdir'])
     self.assertEqual(params.images, 'images')
     self.assertEqual(params.labels, 'labels')
     self.assertEqual(params.outdir, 'outdir')
     self.assertEqual(params.chmbin, './chm-0.1.0.img')
     self.assertEqual(params.stage, 2)
     self.assertEqual(params.level, 4)
     self.assertEqual(params.cluster, 'rocce')
     self.assertEqual(params.account, '')
     self.assertEqual(params.jobname, 'chmtrainjob')
     self.assertEqual(params.walltime, '24:00:00')
     self.assertEqual(params.maxmem, 90)
     self.assertEqual(params.cluster, 'rocce')
     self.assertEqual(params.loglevel, 'WARNING')
     self.assertEqual(params.imodbindir, '')
Exemplo n.º 4
0
    def test_convert_mod_mrc_files_images_is_not_a_dir_or_file(self):
        temp_dir = tempfile.mkdtemp()
        try:
            images_file = os.path.join(temp_dir, 'images.mrc')
            labels_file = os.path.join(temp_dir, 'labels.mod')
            params = createchmtrainjob._parse_arguments(
                'hi', [
                    images_file, labels_file, temp_dir, '--cluster', 'rocce',
                    '--imodbindir', temp_dir
                ])

            createchmtrainjob._convert_mod_mrc_files(params)
            self.fail('Expected InvalidInputDataError')
        except InvalidInputDataError as e:
            self.assertTrue(images_file + ' does not exist' in str(e))

        finally:
            shutil.rmtree(temp_dir)
Exemplo n.º 5
0
    def test_convert_mod_mrc_files_second_mrc2tif_fails(self):
        temp_dir = tempfile.mkdtemp()
        try:
            images_file = os.path.join(temp_dir, 'images.mrc')
            labels_file = os.path.join(temp_dir, 'labels.mod')
            os.makedirs(os.path.join(temp_dir, createchmtrainjob.TMP_DIR),
                        mode=0o755)
            open(images_file, 'a').close()
            open(labels_file, 'a').close()
            mrc2tif = os.path.join(temp_dir, 'mrc2tif')
            f = open(mrc2tif, 'w')
            f.write('#!/usr/bin/env python\nimport sys\n')
            f.write('if "tmp.mrc" in sys.argv[2]:\n sys.exit(2)\n'
                    'sys.exit(0)\n')
            f.flush()
            f.close()
            os.chmod(mrc2tif, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)

            imodmop = os.path.join(temp_dir, 'imodmop')
            f = open(imodmop, 'w')
            f.write('#!/usr/bin/env python\nimport sys;sys.exit(0)\n')
            f.flush()
            f.close()
            os.chmod(imodmop, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)

            params = createchmtrainjob._parse_arguments(
                'hi', [
                    images_file, labels_file, temp_dir, '--cluster', 'rocce',
                    '--imodbindir', temp_dir
                ])

            createchmtrainjob._convert_mod_mrc_files(params)
            self.fail('Expected IMODConversionError')
        except IMODConversionError as e:
            self.assertTrue('Non zero exit code from '
                            'mrc2tif: 2 :  :' in str(e))

        finally:
            shutil.rmtree(temp_dir)
Exemplo n.º 6
0
    def test_convert_mod_mrc_files_success(self):
        temp_dir = tempfile.mkdtemp()
        try:
            images_file = os.path.join(temp_dir, 'images.mrc')
            labels_file = os.path.join(temp_dir, 'labels.mod')
            os.makedirs(os.path.join(temp_dir, createchmtrainjob.TMP_DIR),
                        mode=0o755)
            open(images_file, 'a').close()
            open(labels_file, 'a').close()
            mrc2tif = os.path.join(temp_dir, 'mrc2tif')
            f = open(mrc2tif, 'w')
            f.write('#!/usr/bin/env python\nimport sys\n')
            f.write('sys.exit(0)\n')
            f.flush()
            f.close()
            os.chmod(mrc2tif, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)

            imodmop = os.path.join(temp_dir, 'imodmop')
            f = open(imodmop, 'w')
            f.write('#!/usr/bin/env python\nimport sys;sys.exit(0)\n')
            f.flush()
            f.close()
            os.chmod(imodmop, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)

            params = createchmtrainjob._parse_arguments(
                'hi', [
                    images_file, labels_file, temp_dir, '--cluster', 'rocce',
                    '--imodbindir', temp_dir
                ])

            img, lbl = createchmtrainjob._convert_mod_mrc_files(params)
            self.assertEqual(
                img, os.path.join(temp_dir, createchmtrainjob.IMAGES_DIR))
            self.assertEqual(
                lbl, os.path.join(temp_dir, createchmtrainjob.LABELS_DIR))

        finally:
            shutil.rmtree(temp_dir)