Last active
September 24, 2022 03:03
-
-
Save skchronicles/c609e7dc8dc4ac8b37d86577be57acbc to your computer and use it in GitHub Desktop.
Download the latest SARS-CoV-2 sequences from RefSeq and GenBank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Functions | |
download() { echo -e "Saving output to file: $1"; curl --http1.1 --retry 5 --verbose -L 'https://www.ncbi.nlm.nih.gov/genomes/VirusVariation/vvsearch2/?q=*:*&fq=%7B!tag=SeqType_s%7DSeqType_s:(%22Nucleotide%22)&fq=VirusLineageId_ss:(2697049)&cmd=download&sort=SourceDB_s%20desc,CreateDate_dt%20desc&dlfmt=fasta&fl=id,Definition_s,Nucleotide_seq' > "$1" || echo 'Download failed... please try again!'; } | |
echoerr() { cat <<< "$@" 1>&2; } | |
help() { cat << EOF | |
Download the latest SARS-CoV-2 sequence from GeneBank and RefSeq. Please note that providing | |
the output filename of the downloaded sequences is optional. | |
USAGE: | |
covid [OPTIONS] download [output_filename.fa] | |
Positional Arguments: | |
[1] download Downloads the latest SARS-CoV-2 sequences from GenBank and GenBank | |
[2] output_filename Optional output filename of the downloaded sequences | |
OPTIONS: | |
-h, --help Displays usage and help information | |
Examples: | |
covid download # output filename will default to covid-19_sequences_$timestamp.fa | |
covid download covid-19_latest_sequences.fa | |
EOF | |
} | |
# Main Method | |
timestamp=$(date '+%Y-%m-%d-%H-%M') | |
oname="${2:-covid-19_sequences_${timestamp}.fa}" # Setting default output fname to covid-19_sequences_${timestamp}.fa | |
# Trap to catch SIGINT and delete output file | |
trap "echo; rm -f $oname" INT | |
# Parse sub-commands | |
case "$1" in | |
download) download "$oname";; | |
help) help && exit 0;; | |
-h) help && exit 0;; | |
--help) help && exit 0;; | |
*) echoerr "ERROR: Failed to provide vaild usage of $0"; help; exit 1;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment