Skip to content

Commit

Permalink
Improved elm server error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraluebbert committed Feb 4, 2025
1 parent 8df12a7 commit 40e0f7e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/src/en/updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
`type="orthologs"` is now the default, removing the need to specify the `type` argument when calling orthologs
- [`gget diamond`](diamond.md):
Now supports translated alignment of nucleotide sequences to amino acid reference sequences using the `--translated` flag.
- [`gget elm`](elm.md):
Improved server error handling.

**Version ≥ 0.29.0** (Sep 25, 2024):
- **New modules:**
Expand Down
27 changes: 23 additions & 4 deletions gget/gget_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import subprocess
import platform
import uuid
from platform import python_version

from .utils import set_up_logger
from .utils import set_up_logger, check_file_for_error_message

logger = set_up_logger()

Expand Down Expand Up @@ -183,28 +182,48 @@ def setup(module, verbose=True, out=None):

# Check if files are present
if os.path.exists(elm_instances_fasta):
# Check that file does not just contain an error message
check_file_for_error_message(
elm_instances_fasta,
"ELM instances fasta file",
ELM_INSTANCES_FASTA_DOWNLOAD,
)
if verbose:
logger.info(f"ELM sequences file present.")
else:
logger.error("ELM FASTA file missing.")

if os.path.exists(elm_classes_tsv):
# Check that file does not just contain an error message
check_file_for_error_message(
elm_classes_tsv, "ELM classes tsv file", ELM_CLASSES_TSV_DOWNLOAD
)
if verbose:
logger.info("ELM classes file present.")
else:
logger.error("ELM classes file missing.")

if os.path.exists(elm_instances_tsv):
# Check that file does not just contain an error message
check_file_for_error_message(
elm_instances_tsv, "ELM instances tsv file", ELM_INSTANCES_TSV_DOWNLOAD
)
if verbose:
logger.info("ELM instances file present.")
else:
logger.error("ELM instances file missing.")

if os.path.exists(elm_intdomains_tsv):
# Check that file does not just contain an error message
check_file_for_error_message(
elm_intdomains_tsv,
"ELM interaction domains tsv file",
ELM_INTDOMAINS_TSV_DOWNLOAD,
)
if verbose:
logger.info("ELM interactions domains file present.")
logger.info("ELM interaction domains file present.")
else:
logger.error("ELM interactions domains file missing.")
logger.error("ELM interaction domains file missing.")

elif module == "alphafold":
if platform.system() == "Windows":
Expand Down
25 changes: 25 additions & 0 deletions gget/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ def get_latest_cosmic():
return int(soup.find("div", class_="news").get("id").split("v")[-1])


def check_file_for_error_message(filepath, filename, download_path):
with open(filepath, "r", encoding="utf-8") as file:
content = file.read().strip()

# Define common error indicators
error_keywords = [
"Internal Server Error",
"Bad Gateway",
"Service Unavailable",
"502 Bad Gateway",
"500 Internal Server Error",
]

# Check if the file contains an error message and raise ValueError + print error message if so
if any(keyword in content for keyword in error_keywords):
raise ValueError(
f"""
The {filename} downloaded from {download_path}
contains an error message instead of valid data.\n
Error message:\n{content}\n
Please try again. If the problem persists, please report it here: https://github.com/pachterlab/gget/issues/new?template=issue_report.yml
"""
)


def read_fasta(fasta):
"""
Args:
Expand Down

0 comments on commit 40e0f7e

Please sign in to comment.