Skip to content

Commit

Permalink
add mibig v4.0 to mibig_downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
CunliangGeng committed Nov 27, 2024
1 parent 206703f commit 3fab02c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/nplinker/genomics/mibig/mibig_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"2.0": "843ce4677db6d11422f0e6d94dd03e81",
"3.0": "7c38b90f939086c03392d99a913baef9",
"3.1": "643d1349722a9437d8dcf558dac5f815",
"4.0": "70d1e7d573652ba62548b1fcfbdbf844",
}


Expand All @@ -31,6 +32,8 @@ def download_and_extract_mibig_metadata(
):
"""Download and extract MIBiG metadata json files.
The MIBiG metadata json files are available at https://mibig.secondarymetabolites.org/download.
Note that it does not matter whether the metadata json files are in nested folders or not in the archive,
all json files will be extracted to the same location, i.e. `extract_path`. The nested
folders will be removed if they exist. So the `extract_path` will have only json files.
Expand All @@ -39,7 +42,7 @@ def download_and_extract_mibig_metadata(
download_root: Path to the directory in which to place the downloaded archive.
extract_path: Path to an empty directory where the json files will be extracted.
The directory must be empty if it exists. If it doesn't exist, the directory will be created.
version: _description_. Defaults to "3.1".
version: MIBiG version.
Examples:
>>> download_and_extract_mibig_metadata("/data/download", "/data/mibig_metadata")
Expand All @@ -58,7 +61,7 @@ def download_and_extract_mibig_metadata(
raise ValueError(f'Nonempty directory: "{extract_path}"')

# download and extract
md5 = _MD5_MIBIG_METADATA[version]
md5 = _MD5_MIBIG_METADATA.get(version, None)
download_and_extract_archive(
url=MIBIG_METADATA_URL.format(version=version),
download_root=download_root,
Expand Down
27 changes: 11 additions & 16 deletions tests/unit/genomics/test_mibig_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@


class TestDownloadAndExtractMibigMetadata:
def test_default(self, tmp_path):
@pytest.mark.parametrize(
"version, expected",
[
["1.4", "mibig_json_1.4.tar.gz"],
["3.1", "mibig_json_3.1.tar.gz"],
["4.0", "mibig_json_4.0.tar.gz"],
],
)
def test_version(self, tmp_path, version, expected):
download_path = tmp_path / "download"
extract_path = tmp_path / "metadata"
download_path.mkdir()
extract_path.mkdir()
mibig.download_and_extract_mibig_metadata(download_path, extract_path)
archive = download_path / "mibig_json_3.1.tar.gz"
metadata = extract_path / "BGC0000002.json"
assert archive.exists()
assert archive.is_file()
assert metadata.exists()
assert metadata.is_file()

def test_version(self, tmp_path):
download_path = tmp_path / "download"
extract_path = tmp_path / "metadata"
download_path.mkdir()
extract_path.mkdir()
mibig.download_and_extract_mibig_metadata(download_path, extract_path, version="1.4")
archive = download_path / "mibig_json_1.4.tar.gz"
mibig.download_and_extract_mibig_metadata(download_path, extract_path, version=version)
archive = download_path / expected
metadata = extract_path / "BGC0000002.json"
assert archive.exists()
assert archive.is_file()
Expand Down

0 comments on commit 3fab02c

Please sign in to comment.