Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 30, 2024
1 parent 564e57c commit dc69e02
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion geneplexus/_geneplexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _initial_id_convert(input_genes, file_loc, species):
agene,
converted_gene or "Could Not be mapped to Entrez",
converted_gene_name or "Could Not be mapped to Entrez",
]
],
)

column_names = ["Original ID", "Entrez ID", "Gene Name"]
Expand Down
19 changes: 10 additions & 9 deletions geneplexus/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import io
import os
import os.path as osp
import tarfile
import time
from concurrent.futures import ThreadPoolExecutor
from itertools import repeat
Expand All @@ -11,18 +12,17 @@
from typing import Union
from urllib.parse import urljoin
from zipfile import ZipFile
import tarfile

import requests
from requests.sessions import Session

from . import util
from ._config import logger
from ._config.config import ALL_SPECIES
from ._config.config import SPECIES_SELECTION_TYPE
from ._config.config import SPECIES_TYPE
from ._config.config import LOG_LEVEL_TYPE
from ._config.config import MAX_RETRY
from ._config.config import SPECIES_SELECTION_TYPE
from ._config.config import SPECIES_TYPE
from ._config.config import URL_DICT
from ._config.logger_util import file_handler_context
from ._config.logger_util import stream_level_context
Expand Down Expand Up @@ -66,7 +66,6 @@ def download_select_data(
logger.warn(
f"Files already downloaded for {aspecies}",
)



def _get_species_list(
Expand All @@ -83,13 +82,14 @@ def _get_species_list(
if i not in ALL_SPECIES:
raise ValueError(f"Unexpected species {i!r}")
return species



def _check_all_files(
data_dir: str,
aspecies: str,
):
fn_end = f"data_filenames_{aspecies}.txt"
fn_full = osp.join(data_dir,fn_end)
fn_full = osp.join(data_dir, fn_end)
# check if filenames file is present
if not osp.exists(fn_full):
return False
Expand All @@ -102,7 +102,8 @@ def _check_all_files(
if len(files_missing) > 0:
return False
else:
return True
return True


def _download_and_extract(data_dir, aspecies, fn_download, data_loc, retry):
session = requests.Session()
Expand All @@ -116,9 +117,9 @@ def _download_and_extract(data_dir, aspecies, fn_download, data_loc, retry):
with tarfile.open(fileobj=io.BytesIO(r.content), mode="r:gz") as tf:
for member in tf.getmembers():
member.name = os.path.basename(member.name)
tf.extract(member,data_dir)
tf.extract(member, data_dir)
logger.info(f"Downloaded {member.name}")
if _check_all_files(data_dir, aspecies):
if _check_all_files(data_dir, aspecies):
break
else:
logger.warning(f"Not all files downloaded, trying again")
Expand Down
2 changes: 1 addition & 1 deletion geneplexus/geneplexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(
elif self.auto_download:
download_select_data(
self.file_loc,
list(set([self.sp_trn,self.sp_tst])),
list({self.sp_trn, self.sp_tst}),
log_level=log_level,
)

Expand Down

0 comments on commit dc69e02

Please sign in to comment.