Skip to content

Commit

Permalink
change parameter output_dir to file for to_json method
Browse files Browse the repository at this point in the history
  • Loading branch information
CunliangGeng committed Jul 5, 2023
1 parent b2d88d0 commit 6f4e123
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/nplinker/pairedomics/podp_antismash_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def read_json(file: str | PathLike) -> dict[str, 'GenomeStatus']:

@staticmethod
def to_json(genome_status_dict: dict[str, 'GenomeStatus'],
output_dir: str | PathLike) -> None:
file: str | PathLike) -> None:
"""Save the given genome status dictionary to a JSON file.
The JSON file will be saved to the given output directory with the name
Expand All @@ -82,15 +82,14 @@ def to_json(genome_status_dict: dict[str, 'GenomeStatus'],
Args:
genome_status_dict (dict[str, 'GenomeStatus']): A dictionary of genome
status objects to be saved to a JSON file.
output_dir(str | PathLike): The path to the directory where the JSON
file will be saved.
file(str | PathLike): The path to the output JSON file.
"""
json_data = {
"genome_status":
[gs._to_dict() for gs in genome_status_dict.values()],
"version": "1.0"
}
with open(Path(output_dir) / GENOME_STATUS_FILENAME, "w") as f:
with open(file, "w") as f:
json.dump(json_data, f)

def _to_dict(self) -> dict:
Expand Down Expand Up @@ -192,7 +191,7 @@ def podp_download_and_extract_antismash_data(
f' (from a total of {len(genome_records)}).')

# save updated genome status to json file
GenomeStatus.to_json(gs_dict, project_download_root)
GenomeStatus.to_json(gs_dict, gs_file)

if missing == len(genome_records):
logger.warning('Failed to successfully retrieve ANY genome data!')
Expand Down
2 changes: 1 addition & 1 deletion tests/pairedomics/test_podp_antismash_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_genome_status_to_json(tmp_path):
"genome1": GenomeStatus("genome1", "refseq1", True, "/path/to/bgc1"),
"genome2": GenomeStatus("genome2", "", False, "")
}
GenomeStatus.to_json(genome_status_dict, tmp_path)
GenomeStatus.to_json(genome_status_dict, tmp_path / GENOME_STATUS_FILENAME)
with open(tmp_path / GENOME_STATUS_FILENAME, "r") as f:
loaded_data = json.load(f)

Expand Down

0 comments on commit 6f4e123

Please sign in to comment.