-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: get ensembl-reference wrapper to download more than one chromosome #3432
base: master
Are you sure you want to change the base?
Changes from 5 commits
8d30eea
dfdd743
8fae1dd
249d5e4
23b8788
19536bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,15 +47,15 @@ | |
if chromosome: | ||
if not datatype == "dna": | ||
raise ValueError( | ||
"invalid datatype, to select a single chromosome the datatype must be dna" | ||
"Invalid datatype. To select individual chromosomes, the datatype must be dna." | ||
) | ||
|
||
url = snakemake.params.get("url", "ftp://ftp.ensembl.org/pub") | ||
spec = spec.format(build=build, release=release) | ||
url_prefix = f"{url}/{branch}release-{release}/fasta/{species}/{datatype}/{species.capitalize()}.{spec}" | ||
|
||
success = False | ||
for suffix in suffixes: | ||
success = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Track download success for each chromosome separately. The current implementation resets the success flag for each suffix, which could mask failures of individual chromosome downloads. Consider tracking success per chromosome: -success = False
+successes = set() # Track successful downloads Then update the success tracking after download: -success = True
+successes.add(suffix) # Record successful download And modify the final check: -if not success:
+if not successes: This change will help identify which specific chromosomes failed to download.
|
||
url = f"{url_prefix}.{suffix}" | ||
|
||
try: | ||
|
@@ -65,7 +65,8 @@ | |
|
||
shell("(curl -L {url} | gzip -d >> {snakemake.output[0]}) {log}") | ||
success = True | ||
break | ||
if not chromosome: | ||
break | ||
|
||
if not success: | ||
if len(suffixes) > 1: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be outside the loop to check if at least one suffix was successful? This way it will only check the last suffix, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is outside of the loop, and we are requesting multiple chromosomes, this will turn true on any working chromosome, and then stay that way. So we will not get any debugging output and error thrown, in case any of the chromosomes is not available. So for the chromosomes case, we should reset this for every
suffix in suffixes
. For the other case, checking whether"dna.primary_assembly.fa.gz"
or"dna.toplevel.fa.gz"
is available, it willbreak
out of thesuffix in suffixes
loop right after settingsuccess = True
and will otherwise be left withsuccess = False
after the last suffix that runs into theexcept:
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this way it only checks if the last chromosome was available, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, you are right. Very good catch. Let me think about what the best solution is...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe moving the error checking directly to the try/except?