コード例 #1
0
ファイル: test_filterlfn.py プロジェクト: aitgon/vtam
    def setUpClass(cls):

        cmd = '{} -m pip install . -q --upgrade --use-feature=in-tree-build'.format(
            sys.executable)
        if sys.platform.startswith("win"):
            args = cmd
        else:
            args = shlex.split(cmd)
        subprocess.run(args=args, cwd=PathManager.get_project_path())

        cls.package_path = os.path.join(PathManager.get_package_path())
        cls.test_path = os.path.join(PathManager.get_test_path())
        cls.outdir_path = os.path.join(cls.test_path, 'outdir')
        cls.outdir_data_path = os.path.join(cls.outdir_path, 'data')
        shutil.rmtree(cls.outdir_path, ignore_errors=True)
        pathlib.Path(cls.outdir_data_path).mkdir(parents=True, exist_ok=True)

        ############################################################################################
        #
        # Download sorted reads dataset
        #
        ############################################################################################

        sorted_tar_path = os.path.join(cls.outdir_data_path, "sorted.tar.gz")
        pathlib.Path(os.path.dirname(sorted_tar_path)).mkdir(parents=True,
                                                             exist_ok=True)
        # Test first in local dir, otherwise in the remote URLs
        if not os.path.isfile(sorted_tar_path) or pathlib.Path(
                sorted_tar_path).stat().st_size < 1000000:
            try:
                # urllib.request.urlretrieve(sorted_tar_gz_url1, sorted_tar_path, MyProgressBar())
                with tqdm(...) as t:
                    t.set_description(os.path.basename(sorted_tar_path))
                    urllib.request.urlretrieve(sorted_tar_gz_url1,
                                               sorted_tar_path,
                                               reporthook=tqdm_hook(t))
            except Exception:
                try:
                    # urllib.request.urlretrieve(sorted_tar_gz_url2, sorted_tar_path, MyProgressBar())
                    with tqdm(...) as t:
                        t.set_description(os.path.basename(sorted_tar_path))
                        urllib.request.urlretrieve(sorted_tar_gz_url2,
                                                   sorted_tar_path,
                                                   reporthook=tqdm_hook(t))
                except Exception:
                    # urllib.request.urlretrieve(sorted_tar_gz_url3, sorted_tar_path, MyProgressBar())
                    with tqdm(...) as t:
                        t.set_description(os.path.basename(sorted_tar_path))
                        urllib.request.urlretrieve(sorted_tar_gz_url3,
                                                   sorted_tar_path,
                                                   reporthook=tqdm_hook(t))
        tar = tarfile.open(sorted_tar_path, "r:gz")
        tar.extractall(path=cls.outdir_data_path)
        tar.close()
コード例 #2
0
    def setUp(self):

        # vtam needs to be in the tsv_path
        cmd = '{} -m pip install . -q --upgrade --use-feature=in-tree-build'.format(
            sys.executable)
        if sys.platform.startswith("win"):
            args = cmd
        else:
            args = shlex.split(cmd)
        subprocess.run(args=args, cwd=PathManager.get_project_path())

        self.package_path = os.path.join(PathManager.get_package_path())
        self.test_path = os.path.join(PathManager.get_test_path())
        self.outdir_path = os.path.join(self.test_path, 'outdir')
        self.outdir_data_path = os.path.join(self.outdir_path, 'data')
        # during development of the test, this prevents errors
        shutil.rmtree(self.outdir_path, ignore_errors=True)
        pathlib.Path(self.outdir_data_path).mkdir(parents=True, exist_ok=True)
        os.environ['VTAM_LOG_VERBOSITY'] = str(10)

        ############################################################################################
        #
        # Download sorted fasta test dataset
        #
        ############################################################################################

        sorted_tar_path = os.path.join(self.outdir_data_path, "sorted.tar.gz")
        # Test first in local dir, otherwise in the remote URLs
        if not os.path.isfile(sorted_tar_path) or pathlib.Path(
                sorted_tar_path).stat().st_size < 1000000:
            try:
                # urllib.request.urlretrieve(sorted_tar_gz_url1, sorted_tar_path, MyProgressBar())
                with tqdm(...) as t:
                    t.set_description(os.path.basename(sorted_tar_path))
                    urllib.request.urlretrieve(sorted_tar_gz_url1,
                                               sorted_tar_path,
                                               reporthook=tqdm_hook(t))
            except Exception:
                try:
                    # urllib.request.urlretrieve(sorted_tar_gz_url2, sorted_tar_path, MyProgressBar())
                    with tqdm(...) as t:
                        t.set_description(os.path.basename(sorted_tar_path))
                        urllib.request.urlretrieve(sorted_tar_gz_url2,
                                                   sorted_tar_path,
                                                   reporthook=tqdm_hook(t))
                except Exception:
                    # urllib.request.urlretrieve(sorted_tar_gz_url3, sorted_tar_path, MyProgressBar())
                    with tqdm(...) as t:
                        t.set_description(os.path.basename(sorted_tar_path))
                        urllib.request.urlretrieve(sorted_tar_gz_url3,
                                                   sorted_tar_path,
                                                   reporthook=tqdm_hook(t))
        tar = tarfile.open(sorted_tar_path, "r:gz")
        tar.extractall(path=self.outdir_path)
        tar.close()

        ############################################################################################
        #
        # Paths
        #
        ############################################################################################

        self.asvtable_path = os.path.join(self.outdir_path,
                                          "asvtable_default.tsv")

        self.args = {}
        self.args['sortedinfo'] = os.path.join(os.path.dirname(__file__),
                                               "sortedinfo.tsv")
        self.args['params'] = os.path.join(os.path.dirname(__file__),
                                           "params_min_replicate_number1.yml")
        self.args['params_lfn_variant'] = os.path.join(
            os.path.dirname(__file__), "params_lfn_variant.yml")
        self.args['params_lfn_variant_replicate'] = os.path.join(
            os.path.dirname(__file__), "params_lfn_variant_replicate.yml")