Skip to content

Instantly share code, notes, and snippets.

@skchronicles
Last active September 24, 2022 03:03
Show Gist options
  • Save skchronicles/c609e7dc8dc4ac8b37d86577be57acbc to your computer and use it in GitHub Desktop.
Save skchronicles/c609e7dc8dc4ac8b37d86577be57acbc to your computer and use it in GitHub Desktop.

Revisions

  1. skchronicles revised this gist Apr 30, 2020. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions covid.sh
    Original file line number Diff line number Diff line change
    @@ -25,13 +25,9 @@ Examples:
    EOF
    }



    # Main Method

    timestamp=$(date '+%Y-%m-%d-%H-%M')
    # Setting default output filename to covid-19_sequences_${timestamp}.fa
    oname="${2:-covid-19_sequences_${timestamp}.fa}"
    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
  2. skchronicles created this gist Apr 30, 2020.
    46 changes: 46 additions & 0 deletions covid.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/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')
    # Setting default output filename to covid-19_sequences_${timestamp}.fa
    oname="${2:-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