Beispiel #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
Beispiel #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()
Beispiel #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)
Beispiel #4
0
    chunk_width: int = 1_000,
    temp_chunk_length: Optional[int] = None,
    tempdir: Optional[PathType] = None,
    tempdir_storage_options: Optional[Dict[str, str]] = None,
    dask_fuse_avg_width: int = 50,
    ploidy: int = 2,
    mixed_ploidy: bool = False,
    truncate_calls: bool = False,
) -> 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,
            ploidy=ploidy,
            mixed_ploidy=mixed_ploidy,
            truncate_calls=truncate_calls,
        )

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