Skip to content

Commit

Permalink
Adding updated wonderdump.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
tjakobi committed Mar 7, 2023
1 parent d428fcb commit 8b6cd11
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions contrib/wonderdump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

#
# Wonderdump is a workaround to download SRA files directly
# when fastq-dump's internet connection does not work.
# Which can happen surprisingly frequently.
#
# Usage:
# wonderdump -X 10000 SRR1553500

# this is a slightly modified version of wonderdump
# please see http://data.biostarhandbook.com/scripts/README.html for the
# original version

set -ue

# This is where we will store the file.
SRA_DIR=./

# Make the directory if it does not exist.
mkdir -p $SRA_DIR

# All other parameters up to last.
PARAMS=${@:1:$(($# - 1))}

# The last parameter must be the SRR number.
SRR=${@:$#}

if [ -z "$SRR" ]
then
echo "*** Please specify an SRR number"
exit;
fi

echo "*** Getting SRR run: $SRR"

# Create the full path to the file.
SRA_FILE="$SRA_DIR/$SRR.sra"
TMP_FILE="$SRA_DIR/$SRR.tmp"

# Download only if it does not exist.
if [ ! -f $SRA_FILE ];
then
CLEAN_SRR=${SRR:0:10}
URL="https://sra-pub-run-odp.s3.amazonaws.com/sra/$CLEAN_SRR/$CLEAN_SRR"
echo "*** Downloading: $URL"
echo "*** Saving to: $SRA_FILE"
curl $URL > $TMP_FILE

# Move to local file only if successful.
mv $TMP_FILE $SRA_FILE
else
echo "*** SRA file found: $SRA_FILE"
fi

# Run the fastq-dump.
fastq-dump $PARAMS ${SRA_FILE}

0 comments on commit 8b6cd11

Please sign in to comment.