| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# =========================================================================== |
| 4 |
# |
| 5 |
# PUBLIC DOMAIN NOTICE |
| 6 |
# National Center for Biotechnology Information (NCBI) |
| 7 |
# |
| 8 |
# This software/database is a "United States Government Work" under the |
| 9 |
# terms of the United States Copyright Act. It was written as part of |
| 10 |
# the author's official duties as a United States Government employee and |
| 11 |
# thus cannot be copyrighted. This software/database is freely available |
| 12 |
# to the public for use. The National Library of Medicine and the U.S. |
| 13 |
# Government do not place any restriction on its use or reproduction. |
| 14 |
# We would, however, appreciate having the NCBI and the author cited in |
| 15 |
# any work or product based on this material. |
| 16 |
# |
| 17 |
# Although all reasonable efforts have been taken to ensure the accuracy |
| 18 |
# and reliability of the software and data, the NLM and the U.S. |
| 19 |
# Government do not and cannot warrant the performance or results that |
| 20 |
# may be obtained by using this software or data. The NLM and the U.S. |
| 21 |
# Government disclaim all warranties, express or implied, including |
| 22 |
# warranties of performance, merchantability or fitness for any particular |
| 23 |
# purpose. |
| 24 |
# |
| 25 |
# =========================================================================== |
| 26 |
# |
| 27 |
# File Name: einfo |
| 28 |
# |
| 29 |
# Author: Jonathan Kans, Aaron Ucko |
| 30 |
# |
| 31 |
# Version Creation Date: 04/04/2020 |
| 32 |
# |
| 33 |
# ========================================================================== |
| 34 |
|
| 35 |
pth=$( dirname "$0" ) |
| 36 |
|
| 37 |
case "$pth" in |
| 38 |
/* ) |
| 39 |
;; # already absolute |
| 40 |
* ) |
| 41 |
pth=$(cd "$pth" && pwd) |
| 42 |
;; |
| 43 |
esac |
| 44 |
|
| 45 |
case ":$PATH:" in |
| 46 |
*:"$pth":* ) |
| 47 |
;; |
| 48 |
* ) |
| 49 |
PATH="$PATH:$pth" |
| 50 |
export PATH |
| 51 |
;; |
| 52 |
esac |
| 53 |
|
| 54 |
# handle common flags - dot command is equivalent of "source" |
| 55 |
|
| 56 |
if [ ! -f "$pth"/ecommon.sh ] |
| 57 |
then |
| 58 |
echo "ERROR: Unable to find '$pth/ecommon.sh' file" >&2 |
| 59 |
exit 1 |
| 60 |
fi |
| 61 |
|
| 62 |
. "$pth"/ecommon.sh |
| 63 |
|
| 64 |
# initialize specific flags |
| 65 |
|
| 66 |
internal=false |
| 67 |
|
| 68 |
db="" |
| 69 |
dbs=false |
| 70 |
|
| 71 |
fields=false |
| 72 |
links=false |
| 73 |
|
| 74 |
test=false |
| 75 |
repeats=1 |
| 76 |
|
| 77 |
# read command-line arguments |
| 78 |
|
| 79 |
while [ $# -gt 0 ] |
| 80 |
do |
| 81 |
tag="$1" |
| 82 |
rem="$#" |
| 83 |
case "$tag" in |
| 84 |
-internal ) |
| 85 |
internal=true |
| 86 |
shift |
| 87 |
;; |
| 88 |
-newmode | -oldmode ) |
| 89 |
shift |
| 90 |
;; |
| 91 |
-db ) |
| 92 |
CheckForArgumentValue "$tag" "$rem" |
| 93 |
shift |
| 94 |
db="$1" |
| 95 |
shift |
| 96 |
;; |
| 97 |
-dbs ) |
| 98 |
dbs=true |
| 99 |
shift |
| 100 |
;; |
| 101 |
-field | -fields ) |
| 102 |
fields=true |
| 103 |
shift |
| 104 |
;; |
| 105 |
-link | -links ) |
| 106 |
links=true |
| 107 |
shift |
| 108 |
;; |
| 109 |
-test | -tests ) |
| 110 |
test=true |
| 111 |
shift |
| 112 |
;; |
| 113 |
-repeat | -repeats ) |
| 114 |
shift |
| 115 |
if [ $# -gt 0 ] |
| 116 |
then |
| 117 |
repeats="$1" |
| 118 |
shift |
| 119 |
if [ "$repeats" -lt 1 ] || [ "$repeats" -gt 20 ] |
| 120 |
then |
| 121 |
repeats=1 |
| 122 |
fi |
| 123 |
fi |
| 124 |
;; |
| 125 |
-h | -help | --help | help ) |
| 126 |
echo "einfo $version" |
| 127 |
echo "" |
| 128 |
sfx="" |
| 129 |
if [ "$external" = true ] |
| 130 |
then |
| 131 |
sfx=" - external" |
| 132 |
elif [ "$internal" = true ] |
| 133 |
then |
| 134 |
sfx=" - internal" |
| 135 |
fi |
| 136 |
echo "$( uname -s ) - $( uname -m )${sfx}" |
| 137 |
echo "" |
| 138 |
cat "$pth/help/einfo-help.txt" |
| 139 |
echo "" |
| 140 |
exit 0 |
| 141 |
;; |
| 142 |
-error | -errors ) |
| 143 |
echo "einfo $version" |
| 144 |
echo "" |
| 145 |
cat "$pth/help/einfo-errors.txt" |
| 146 |
echo "" |
| 147 |
exit 0 |
| 148 |
;; |
| 149 |
-* ) |
| 150 |
ParseCommonArgs "$@" |
| 151 |
if [ "$argsConsumed" -gt 0 ] |
| 152 |
then |
| 153 |
shift "$argsConsumed" |
| 154 |
else |
| 155 |
DisplayError "'$1' is not a recognized einfo option" |
| 156 |
exit 1 |
| 157 |
fi |
| 158 |
;; |
| 159 |
* ) |
| 160 |
# allows while loop to check for multiple flags |
| 161 |
break |
| 162 |
;; |
| 163 |
esac |
| 164 |
done |
| 165 |
|
| 166 |
FinishSetup |
| 167 |
|
| 168 |
# take database from dbase value (not expected for einfo) or -db argument |
| 169 |
|
| 170 |
if [ -z "$dbase" ] |
| 171 |
then |
| 172 |
dbase="$db" |
| 173 |
fi |
| 174 |
|
| 175 |
if [ "$dbase" = "nucleotide" ] |
| 176 |
then |
| 177 |
dbase="nuccore" |
| 178 |
fi |
| 179 |
|
| 180 |
# check for missing database argument |
| 181 |
|
| 182 |
if [ -z "$dbase" ] && [ "$dbs" = false ] |
| 183 |
then |
| 184 |
DisplayError "Missing -db argument" |
| 185 |
exit 1 |
| 186 |
fi |
| 187 |
|
| 188 |
# normalize to lower-case (e.g., SRA -> sra) |
| 189 |
|
| 190 |
dbase=$( echo "$dbase" | tr '[:upper:]' '[:lower:]' ) |
| 191 |
|
| 192 |
# -dbs |
| 193 |
|
| 194 |
if [ "$dbs" = true ] |
| 195 |
then |
| 196 |
res=$( RunWithCommonArgs nquire -get "$base" einfo.fcgi ) |
| 197 |
echo "$res" | |
| 198 |
xtract -pattern DbList -sep "\n" -element DbName | |
| 199 |
sort -f |
| 200 |
|
| 201 |
exit 0 |
| 202 |
fi |
| 203 |
|
| 204 |
# -db |
| 205 |
|
| 206 |
if [ -n "$dbase" ] |
| 207 |
then |
| 208 |
res=$( RunWithCommonArgs nquire -get "$base" einfo.fcgi -db "$dbase" -version "2.0" ) |
| 209 |
|
| 210 |
if [ -z "$res" ] |
| 211 |
then |
| 212 |
DisplayError "einfo.fcgi query failed" |
| 213 |
exit 1 |
| 214 |
fi |
| 215 |
|
| 216 |
# shortcut for fields |
| 217 |
|
| 218 |
if [ "$fields" = true ] |
| 219 |
then |
| 220 |
echo "$res" | |
| 221 |
xtract -pattern DbInfo -block Field -tab "\n" -element Name,FullName | |
| 222 |
sort -f |
| 223 |
fi |
| 224 |
|
| 225 |
# shortcut for links |
| 226 |
|
| 227 |
if [ "$links" = true ] |
| 228 |
then |
| 229 |
echo "$res" | |
| 230 |
xtract -pattern DbInfo -block Link -tab "\n" -element Name,Menu | |
| 231 |
sort -f |
| 232 |
fi |
| 233 |
|
| 234 |
# if neither -fields nor -links, print cleaned-up XML result, keeping original DOCTYPE line |
| 235 |
|
| 236 |
if [ "$fields" = false ] && [ "$links" = false ] |
| 237 |
then |
| 238 |
echo "$res" | transmute -format indent -doctype "" |
| 239 |
fi |
| 240 |
|
| 241 |
exit 0 |
| 242 |
fi |
| 243 |
|
| 244 |
# -test (undocumented) |
| 245 |
|
| 246 |
RunTests() { |
| 247 |
|
| 248 |
res=$( |
| 249 |
nquire -get https://eutils.ncbi.nlm.nih.gov/entrez/eutils esummary.fcgi -db pubmed -id 2539356 -version 2.0 | tr '\n' ' ' |
| 250 |
) |
| 251 |
case "$res" in |
| 252 |
*"Nucleotide sequences required for Tn3 transposition immunity"* ) |
| 253 |
;; |
| 254 |
* ) |
| 255 |
echo "FAIL: esummary.fcgi -db pubmed -id 2539356 -version 2.0" >&2 |
| 256 |
;; |
| 257 |
esac |
| 258 |
|
| 259 |
res=$( |
| 260 |
nquire -get https://eutils.ncbi.nlm.nih.gov/entrez/eutils esearch.fcgi -db pubmed -term "tn3 transposition immunity" | tr '\n' ' ' |
| 261 |
) |
| 262 |
case "$res" in |
| 263 |
*"QueryTranslation>tn3"* ) |
| 264 |
;; |
| 265 |
* ) |
| 266 |
echo "FAIL: esearch.fcgi -db pubmed -term \"tn3 transposition immunity\"" >&2 |
| 267 |
;; |
| 268 |
esac |
| 269 |
|
| 270 |
for sym in ATP6 ATP7B CBD DMD HFE PAH PRNP TTN |
| 271 |
do |
| 272 |
res=$( esearch -db gene -query "$sym [GENE]" -organism human | |
| 273 |
efetch -format docsum | |
| 274 |
xtract -pattern DocumentSummary -def "-" -lbl "${sym}" \ |
| 275 |
-element NomenclatureSymbol Id Description CommonName ) |
| 276 |
if [ -z "$res" ] |
| 277 |
then |
| 278 |
echo "FAIL: $sym" >&2 |
| 279 |
fi |
| 280 |
done |
| 281 |
} |
| 282 |
|
| 283 |
if [ "$test" = true ] |
| 284 |
then |
| 285 |
for i in $(seq 1 $repeats) |
| 286 |
do |
| 287 |
RunTests |
| 288 |
|
| 289 |
sleep 5 |
| 290 |
done |
| 291 |
|
| 292 |
exit 0 |
| 293 |
fi |
| 294 |
|
| 295 |
# warn on insufficient arguments |
| 296 |
|
| 297 |
DisplayError "einfo requires either -db or -dbs on command line" |
| 298 |
exit 1 |