-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-from-ncbi-virus
executable file
·33 lines (26 loc) · 1.1 KB
/
fetch-from-ncbi-virus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
# usage: fetch-from-ncbi-virus <ncbi_taxon_id> <github_repo> [options]
#
# Fetch metadata and nucleotide sequences from [NCBI Virus](https://www.ncbi.nlm.nih.gov/labs/virus/vssi/#/)
# and output NDJSON records to stdout.
#
# [options] are passed directly to ncbi-virus-url. See that script for usage details.
#
# Originally copied from "bin/fetch-from-genbank" in nextstrain/ncov-ingest:
# https://github.com/nextstrain/ncov-ingest/blob/2a5f255329ee5bdf0cabc8b8827a700c92becbe4/bin/fetch-from-genbank
#
set -euo pipefail
bin="$(dirname "$0")"
main() {
local ncbi_taxon_id="${1:?NCBI taxon id is required.}"
local github_repo="${2:?A GitHub repository with owner and repository name is required as the second argument}"
# "${@:3}" represents all other options, if any.
ncbi_virus_url="$("$bin"/ncbi-virus-url --ncbi-taxon-id "$ncbi_taxon_id" "${@:3}")"
fetch "$ncbi_virus_url" "$github_repo" | "$bin"/csv-to-ndjson
}
fetch() {
curl "$1" \
--fail --silent --show-error --http1.1 \
--header "User-Agent: https://github.com/$2 (hello@nextstrain.org)"
}
main "$@"