コード例 #1
0
def test_temporary_directory__no_permission():
    # create a local temporary directory using Python tempfile
    with tempfile.TemporaryDirectory() as dir:
        os.chmod(dir, 0o444)  # make it read-only
        with pytest.raises(PermissionError):
            with temporary_directory(dir=dir):
                pass  # pragma: no cover
コード例 #2
0
def test_temporary_directory(dir):
    prefix = "prefix-"
    suffix = "-suffix"
    with temporary_directory(suffix=suffix, prefix=prefix, dir=dir) as tmpdir:
        if tmpdir.startswith("file:///"):
            tmpdir = tmpdir[7:]
        dir = Path(tmpdir)
        assert dir.exists()
        assert dir.name.startswith(prefix)
        assert dir.name.endswith(suffix)

        with open(dir / "file.txt", "w") as file:
            file.write("Hello")

    assert not dir.exists()
コード例 #3
0
def test_non_local_filesystem(mocker):
    # mock out fsspec calls
    mock = mocker.patch("fsspec.filesystem")
    myfs = mocker.MagicMock()
    mock.return_value = myfs

    # call function
    with temporary_directory(
        prefix="mytmp", dir="myfs://path/file", storage_options=dict(a="b")
    ):
        pass

    # check expected called were made
    fsspec.filesystem.assert_called_once_with("myfs", a="b")
    myfs.mkdir.assert_called_once_with(StartsWith("myfs://path/file/mytmp"))
    myfs.rm.assert_called_once_with(
        StartsWith("myfs://path/file/mytmp"), recursive=True
    )
コード例 #4
0
    input: Union[PathType, Sequence[PathType]],
    output: Union[PathType, MutableMapping[str, bytes]],
    regions: Union[None, Sequence[str], Sequence[Optional[Sequence[str]]]],
    chunk_length: int = 10_000,
    chunk_width: int = 1_000,
    temp_chunk_length: Optional[int] = None,
    tempdir: Optional[PathType] = None,
    tempdir_storage_options: Optional[Dict[str, str]] = None,
) -> None:
    """Convert specified regions of one or more VCF files to zarr files, then concat, rechunk, write to zarr"""

    if temp_chunk_length is None:
        temp_chunk_length = chunk_length

    with temporary_directory(
        prefix="vcf_to_zarr_", dir=tempdir, storage_options=tempdir_storage_options
    ) as tmpdir:

        paths = vcf_to_zarrs(
            input,
            tmpdir,
            regions,
            temp_chunk_length,
            chunk_width,
            tempdir_storage_options,
        )

        ds = zarrs_to_dataset(paths, chunk_length, chunk_width, tempdir_storage_options)

        # Ensure Dask task graph is efficient, see https://github.com/dask/dask/issues/5105
        with dask.config.set({"optimization.fuse.ave-width": 50}):