Skip to content
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

Add retry for reads prefetch in import-sra #1320

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Added
- Add ``samtools-depth-single`` process
- Add gene body coverage plot from ``qorts-qc`` process to MultiQC
report
- Add retry for reads prefetch in ``import-sra-single`` and ``import-sra-paired``

Changed
-------
Expand Down
42 changes: 28 additions & 14 deletions resolwe_bio/processes/import_data/sra_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ def run_fastqc(fastqs, output_dir):
return stderr


def prefetch_reads(self, max_size_prefetch, srr, retry_counts=3):
"""Prefetch reads from SRA. Retry if prefetch fails."""
for _ in range(retry_counts):
return_code, _, _ = Cmd["prefetch"][
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this is deployed make sure to validate that the prefetch messages and errors are getting printed to stdout. The tests do not cover that because it takes too long to fetch data.

"-p", "--max-size", max_size_prefetch, srr
] & TEE(retcode=None)
if return_code == 0:
return
else:
self.warning(f"Prefetch of {srr} reads failed. Retrying...")

self.error(f"Prefetch of {srr} reads failed {retry_counts} times.")


class ImportSra(Process):
"""Import reads from SRA.

Expand Down Expand Up @@ -145,7 +159,7 @@ class ImportSraSingle(Process):
slug = "import-sra-single"
name = "SRA data (single-end)"
process_type = "data:reads:fastq:single"
version = "1.6.1"
version = "1.7.0"
category = "Import"
scheduling_class = SchedulingClass.BATCH
persistence = Persistence.RAW
Expand Down Expand Up @@ -207,12 +221,12 @@ def run(self, inputs, outputs):
for srr in inputs.sra_accession:
if inputs.advanced.prefetch:
# prefetch the SRR bundle
return_code, _, _ = Cmd["prefetch"][
"-p", "--max-size", inputs.advanced.max_size_prefetch, srr
] & TEE(retcode=None)
if return_code:
self.error(f"Prefetch of {srr} reads failed.")

prefetch_reads(
self=self,
max_size_prefetch=inputs.advanced.max_size_prefetch,
srr=srr,
retry_counts=3,
)
# Convert the SRR bundle to FASTQ format
cmd = Cmd["fastq-dump"]["--gzip"]
if inputs.advanced.min_spot_id:
Expand Down Expand Up @@ -317,7 +331,7 @@ class ImportSraPaired(Process):
slug = "import-sra-paired"
name = "SRA data (paired-end)"
process_type = "data:reads:fastq:paired"
version = "1.6.1"
version = "1.7.0"
category = "Import"
scheduling_class = SchedulingClass.BATCH
persistence = Persistence.RAW
Expand Down Expand Up @@ -395,12 +409,12 @@ def run(self, inputs, outputs):
for srr in inputs.sra_accession:
if inputs.advanced.prefetch:
# prefetch the SRR bundle
return_code, _, _ = Cmd["prefetch"][
"-p", "--max-size", inputs.advanced.max_size_prefetch, srr
] & TEE(retcode=None)
if return_code:
self.error(f"Prefetch of {srr} reads failed.")

prefetch_reads(
self=self,
max_size_prefetch=inputs.advanced.max_size_prefetch,
srr=srr,
retry_counts=3,
)
# Convert the SRR bundle to FASTQ format
cmd = Cmd["fastq-dump"]["--gzip"]["--split-files"]
if inputs.advanced.min_spot_id:
Expand Down