Skip to content

Commit

Permalink
enhance error handling and logging for biosample ID or SRA fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
fraser-combe committed Nov 22, 2024
1 parent f9de101 commit 26d8c49
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tasks/utilities/data_handling/task_fetch_srr_accession.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ task fetch_srr_accession {
volatile: true
}

command <<<
command <<<
set -euo pipefail

# Output the current date and fastq-dl version for debugging
Expand All @@ -21,7 +21,7 @@ task fetch_srr_accession {

# Fetch metadata for the sample accession
echo "Fetching metadata for valid biosample ID or SRA: ~{sample_accession}"
if fastq-dl --accession ~{sample_accession} --only-download-metadata --verbose; then
if fastq-dl --accession ~{sample_accession} --only-download-metadata --verbose 2> stderr; then
if [[ -f fastq-run-info.tsv ]]; then
echo "Metadata written for valid biosample ID or SRA: ~{sample_accession}"
cat fastq-run-info.tsv
Expand All @@ -30,22 +30,31 @@ task fetch_srr_accession {
SRR_accessions=$(awk -F'\t' 'NR>1 {print $1}' fastq-run-info.tsv | paste -sd ',' -)

if [[ -z "${SRR_accessions}" ]]; then
# Valid biosample ID or SRA, but no SRR accessions found
echo "No SRR accession found for valid biosample ID or SRA: ~{sample_accession}" > srr_accession.txt
else
# Valid biosample ID or SRA with SRR accessions
echo "Extracted SRR accessions: ${SRR_accessions}"
echo "${SRR_accessions}" > srr_accession.txt
fi
else
# No metadata file generated, treat as no SRRs found for valid biosample
echo "No metadata file found for valid biosample ID or SRA: ~{sample_accession}"
echo "No SRR accession found" > srr_accession.txt
fi
else
# Handle cases where fastq-dl exits with an error
if grep -q "No results found" stderr || [[ ! -f fastq-run-info.tsv ]]; then
echo "No SRR accession found for valid biosample ID or SRA: ~{sample_accession}"
# Check stderr for specific error messages
if grep -q "Query was successful, but received an empty response" stderr; then
# Valid biosample ID or SRA, but no data found output No SRR accession found
echo "No SRR accession found for valid biosample ID or SRA: ~{sample_accession} -Query was successful, but received an empty response" > srr_accession.txt
echo "No SRR accession found" > srr_accession.txt
elif grep -q "is not a Study, Sample, Experiment, or Run accession" stderr; then
# Invalid accession ID or SRA Fail workflow
echo "Invalid biosample ID or SRA: ~{sample_accession}"
exit 1
else
echo "fastq-dl failed for ~{sample_accession}, invalid biosample ID or SRA"
# Unexpected error
echo "fastq-dl failed for ~{sample_accession} due to an unknown error."
exit 1
fi
fi
Expand Down

0 comments on commit 26d8c49

Please sign in to comment.