Skip to content

Commit

Permalink
fix: better error handling for ensembl sequence download (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester committed Jul 19, 2022
1 parent 9157926 commit c289800
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions bio/reference/ensembl-sequence/wrapper.py
Expand Up @@ -48,17 +48,12 @@
"invalid datatype, to select a single chromosome the datatype must be dna"
)

spec = spec.format(build=build, release=release)
url_prefix = f"ftp://ftp.ensembl.org/pub/{branch}release-{release}/fasta/{species}/{datatype}/{species.capitalize()}.{spec}"

success = False
for suffix in suffixes:
url = "ftp://ftp.ensembl.org/pub/{branch}release-{release}/fasta/{species}/{datatype}/{species_cap}.{spec}.{suffix}".format(
release=release,
species=species,
datatype=datatype,
spec=spec.format(build=build, release=release),
suffix=suffix,
species_cap=species.capitalize(),
branch=branch,
)
url = f"{url_prefix}.{suffix}"

try:
shell("curl -sSf {url} > /dev/null 2> /dev/null")
Expand All @@ -70,9 +65,14 @@
break

if not success:
if len(suffixes) > 1:
url = f"{url_prefix}.[{'|'.join(suffixes)}]"
else:
url = f"{url_prefix}.{suffixes[0]}"
print(
"Unable to download requested sequence data from Ensembl. "
"Did you check that this combination of species, build, and release is actually provided?",
f"Unable to download requested sequence data from Ensembl ({url}). "
"Please check whether above URL is currently available (might be a temporal server issue). "
"Apart from that, did you check that this combination of species, build, and release is actually provided?",
file=sys.stderr,
)
exit(1)

0 comments on commit c289800

Please sign in to comment.