Skip to content

Instantly share code, notes, and snippets.

@mojaveazure
Last active September 2, 2015 16:27
Show Gist options
  • Save mojaveazure/e1dd059b5b8430240a57 to your computer and use it in GitHub Desktop.
Save mojaveazure/e1dd059b5b8430240a57 to your computer and use it in GitHub Desktop.
A simple shell script to download samples from the SRA
#!/bin/bash
set -e
set -u
set -o pipefail
if ! `command -v fastq-dump > /dev/null 2> /dev/null`
then
echo "Can't find fastq-dump!"
exit 1
fi
if [[ "$#" -lt 1 ]]
then
echo -e "\
Usage: ./downloadSRA.sh sample_info [out_directory] \n\
Where: 'sample_info' is a list of SRA accessions to be downloaded \n\
\n\
'out-directory' is an optional argument specifying where \n\
to put downloaded files, defaulting to: \n\
`pwd` \n\
" >&2
exit 1
fi
SAMPLE_INFO=$1
OUTDIR=${2:-`pwd`}
# Download reads from the SRA
# --split-files Split into forward and reverse files for paired end data
# -I Add _1 and _2 naming
# -F Use original sample naming within the file rather than SRA numbers
cd ${OUTDIR}
if `command -v parallel > /dev/null 2> /dev/null`
then
parallel "fastq-dump -I --split-file -F {1}" :::: "${SAMPLE_INFO}" # Use the four dots to say 'read this file and use it as arguments'
else
for sample in `cat "${SAMPLE_READS}"`
do
fastq-dump -I --split-files -F "$sample"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment