Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Nov 1, 2023
1 parent 9bc4643 commit e0b189a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 71 deletions.
14 changes: 2 additions & 12 deletions src/wags_tails/chembl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
import tarfile
from pathlib import Path
from typing import Optional

import requests

Expand All @@ -14,17 +13,8 @@
class ChemblData(DataSource):
"""Provide access to ChEMBL database."""

def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None:
"""Set common class parameters.
:param data_dir: direct location to store data files in, if specified. See
``get_data_dir()`` in the ``storage_utils`` module for further configuration
details.
:param silent: if True, don't print any info/updates to console
"""
self._src_name = "chembl"
self._filetype = "db"
super().__init__(data_dir, silent)
_src_name = "chembl"
_filetype = "db"

@staticmethod
def _get_latest_version() -> str:
Expand Down
16 changes: 3 additions & 13 deletions src/wags_tails/do.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import tarfile
from datetime import datetime
from pathlib import Path
from typing import Optional

import requests

Expand All @@ -15,18 +14,9 @@
class DoData(GitHubDataSource):
"""Provide access to human disease ontology data."""

def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None:
"""Set common class parameters.
:param data_dir: direct location to store data files in, if specified. See
``get_data_dir()`` in the ``storage_utils`` module for further configuration
details.
:param silent: if True, don't print any info/updates to console
"""
self._src_name = "do"
self._filetype = "owl"
self._repo = "DiseaseOntology/HumanDiseaseOntology"
super().__init__(data_dir, silent)
_src_name = "do"
_filetype = "owl"
_repo = "DiseaseOntology/HumanDiseaseOntology"

@staticmethod
def _asset_handler(dl_path: Path, outfile_path: Path) -> None:
Expand Down
16 changes: 4 additions & 12 deletions src/wags_tails/mondo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from datetime import datetime
from pathlib import Path
from typing import Optional, Tuple
from typing import Tuple

import requests

Expand All @@ -17,17 +17,9 @@
class MondoData(GitHubDataSource):
"""Provide access to Mondo disease ontology data."""

def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None:
"""Set common class parameters.
:param data_dir: direct location to store data files in, if specified. See
``get_data_dir()`` in the ``storage_utils`` module for further configuration
details.
:param silent: if True, don't print any info/updates to console
"""
self._src_name = "mondo"
self._repo = "monarch-initiative/mondo"
super().__init__(data_dir, silent)
_src_name = "mondo"
_filetype = "owl"
_repo = "monarch-initiative/mondo"

@staticmethod
def _get_latest_version() -> Tuple[str, str]:
Expand Down
14 changes: 2 additions & 12 deletions src/wags_tails/ncit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Provide source fetching for NCI Thesaurus."""
import re
from pathlib import Path
from typing import Optional

import requests

Expand All @@ -12,17 +11,8 @@
class NcitData(DataSource):
"""Provide access to NCI Thesaurus database."""

def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None:
"""Set common class parameters.
:param data_dir: direct location to store data files in, if specified. See
``get_data_dir()`` in the ``storage_utils`` module for further configuration
details.
:param silent: if True, don't print any info/updates to console
"""
self._src_name = "ncit"
self._filetype = "owl"
super().__init__(data_dir, silent)
_src_name = "ncit"
_filetype = "owl"

@staticmethod
def _get_latest_version() -> str:
Expand Down
19 changes: 2 additions & 17 deletions src/wags_tails/oncotree.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
"""Provide access to Oncotree data."""
import logging
from datetime import datetime
from pathlib import Path
from typing import Optional

import requests

from .base_source import DataSource, RemoteDataError
from .utils.downloads import download_http
from .utils.versioning import DATE_VERSION_PATTERN

_logger = logging.getLogger(__name__)


class OncoTreeData(DataSource):
"""Provide access to OncoTree data."""

def __init__(self, data_dir: Optional[Path] = None, silent: bool = False) -> None:
"""Set common class parameters.
:param data_dir: direct location to store data files in. If not provided, tries
to find a "oncotree" subdirectory within the path at environment variable
$WAGS_TAILS_DIR, or within a "wags_tails" subdirectory under environment
variables $XDG_DATA_HOME or $XDG_DATA_DIRS, or finally, at
``~/.local/share/``
:param silent: if True, don't print any info/updates to console
"""
self._src_name = "oncotree"
self._filetype = "json"
super().__init__(data_dir, silent)
_src_name = "oncotree"
_filetype = "json"

def _get_latest_version(self) -> str:
"""Retrieve latest version value
Expand Down
11 changes: 6 additions & 5 deletions src/wags_tails/utils/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def handle_zip(dl_path: Path, outfile_path: Path) -> None:
"""Provide simple callback function to extract the largest file within a given
zipfile and save it within the appropriate data directory.
:param Path dl_path: path to temp data file
:param Path outfile_path: path to save file within
:param dl_path: path to temp data file
:param outfile_path: path to save file within
"""
with zipfile.ZipFile(dl_path, "r") as zip_ref:
if len(zip_ref.filelist) > 1:
Expand Down Expand Up @@ -46,6 +46,7 @@ def download_http(
:param headers: Any needed HTTP headers to include in request
:param handler: provide if downloaded file requires additional action, e.g.
it's a zip file.
:param tqdm_params: Optional TQDM configuration.
"""
if not tqdm_params:
tqdm_params = {}
Expand All @@ -60,12 +61,12 @@ def download_http(
total_size = int(r.headers.get("content-length", 0))
with open(dl_path, "wb") as h:
if not tqdm_params["disable"]:
if "apiKey" in url:
if "apiKey" in url: # don't print RxNorm API key
pattern = r"&apiKey=.{8}-.{4}-.{4}-.{4}-.{12}"
print_url = re.sub(pattern, "", os.path.basename(url))
print(f"Downloading {print_url}")
print(f"Downloading {print_url}...")
else:
print(f"Downloading {os.path.basename(url)}")
print(f"Downloading {os.path.basename(url)}...")
with tqdm(
total=total_size,
**tqdm_params,
Expand Down

0 comments on commit e0b189a

Please sign in to comment.