| 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: esearch |
| 28 |
# |
| 29 |
# Author: Jonathan Kans, Aaron Ucko |
| 30 |
# |
| 31 |
# Version Creation Date: 06/15/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 |
isFilter=false |
| 69 |
|
| 70 |
query="" |
| 71 |
spell=false |
| 72 |
transl=false |
| 73 |
tstack=false |
| 74 |
|
| 75 |
sort="" |
| 76 |
|
| 77 |
# initialize shortcuts |
| 78 |
|
| 79 |
pub="" |
| 80 |
titl="" |
| 81 |
jour="" |
| 82 |
rlsd="" |
| 83 |
|
| 84 |
ctry="" |
| 85 |
feat="" |
| 86 |
locn="" |
| 87 |
mol="" |
| 88 |
orgn="" |
| 89 |
sorc="" |
| 90 |
divn="" |
| 91 |
kywd="" |
| 92 |
prps="" |
| 93 |
|
| 94 |
stts="" |
| 95 |
type="" |
| 96 |
|
| 97 |
clss="" |
| 98 |
|
| 99 |
kind="" |
| 100 |
ptwy="" |
| 101 |
|
| 102 |
# check for deprecated arguments |
| 103 |
|
| 104 |
for elm in "$@" |
| 105 |
do |
| 106 |
case "$elm" in |
| 107 |
-count | -subset | -uids ) |
| 108 |
# forward entire request to ecollect |
| 109 |
ecollect "$@" |
| 110 |
exit 0 |
| 111 |
;; |
| 112 |
esac |
| 113 |
done |
| 114 |
|
| 115 |
# read command-line arguments |
| 116 |
|
| 117 |
while [ $# -gt 0 ] |
| 118 |
do |
| 119 |
tag="$1" |
| 120 |
rem="$#" |
| 121 |
case "$tag" in |
| 122 |
-internal ) |
| 123 |
internal=true |
| 124 |
shift |
| 125 |
;; |
| 126 |
-newmode | -oldmode ) |
| 127 |
shift |
| 128 |
;; |
| 129 |
-db ) |
| 130 |
CheckForArgumentValue "$tag" "$rem" |
| 131 |
shift |
| 132 |
db="$1" |
| 133 |
shift |
| 134 |
;; |
| 135 |
-query ) |
| 136 |
shift |
| 137 |
if [ $# -gt 0 ] |
| 138 |
then |
| 139 |
if [ -z "$query"] |
| 140 |
then |
| 141 |
query="$1" |
| 142 |
shift |
| 143 |
else |
| 144 |
DisplayError "Multiple -query arguments" |
| 145 |
exit 1 |
| 146 |
fi |
| 147 |
else |
| 148 |
DisplayError "Missing -query argument" |
| 149 |
exit 1 |
| 150 |
fi |
| 151 |
;; |
| 152 |
-filter ) |
| 153 |
# efilter is implemented as esearch -filter "$@" |
| 154 |
isFilter=true |
| 155 |
shift |
| 156 |
;; |
| 157 |
# -query VARIANTS |
| 158 |
-spell ) |
| 159 |
spell=true |
| 160 |
shift |
| 161 |
if [ $# -gt 0 ] && [ -z "$query" ] |
| 162 |
then |
| 163 |
case "$1" in |
| 164 |
-* ) |
| 165 |
# do not advance, will process next command time through the while loop |
| 166 |
;; |
| 167 |
* ) |
| 168 |
# query string is immediately after -spell flag (undocumented) |
| 169 |
query="$1" |
| 170 |
shift |
| 171 |
;; |
| 172 |
esac |
| 173 |
fi |
| 174 |
;; |
| 175 |
-translate | -transl | -translation ) |
| 176 |
shift |
| 177 |
transl=true |
| 178 |
if [ $# -gt 0 ] |
| 179 |
then |
| 180 |
if [ -z "$query"] |
| 181 |
then |
| 182 |
case "$1" in |
| 183 |
-* ) |
| 184 |
# just set flag if next argument starts with hyphen |
| 185 |
;; |
| 186 |
* ) |
| 187 |
query="$1" |
| 188 |
shift |
| 189 |
;; |
| 190 |
esac |
| 191 |
else |
| 192 |
DisplayError "Multiple -query arguments" |
| 193 |
exit 1 |
| 194 |
fi |
| 195 |
else |
| 196 |
DisplayError "Missing -query argument" |
| 197 |
exit 1 |
| 198 |
fi |
| 199 |
;; |
| 200 |
-component | -components | -stack ) |
| 201 |
shift |
| 202 |
tstack=true |
| 203 |
if [ $# -gt 0 ] |
| 204 |
then |
| 205 |
if [ -z "$query"] |
| 206 |
then |
| 207 |
case "$1" in |
| 208 |
-* ) |
| 209 |
# just set flag if next argument starts with hyphen |
| 210 |
;; |
| 211 |
* ) |
| 212 |
query="$1" |
| 213 |
shift |
| 214 |
;; |
| 215 |
esac |
| 216 |
else |
| 217 |
DisplayError "Multiple -query arguments" |
| 218 |
exit 1 |
| 219 |
fi |
| 220 |
else |
| 221 |
DisplayError "Missing -query argument" |
| 222 |
exit 1 |
| 223 |
fi |
| 224 |
;; |
| 225 |
# SORT |
| 226 |
-sort ) |
| 227 |
CheckForArgumentValue "$tag" "$rem" |
| 228 |
shift |
| 229 |
sort="$1" |
| 230 |
shift |
| 231 |
;; |
| 232 |
# DATE RESTRICTION |
| 233 |
-days | -reldate ) |
| 234 |
CheckForArgumentValue "$tag" "$rem" |
| 235 |
shift |
| 236 |
reldate=$(( $1 )) |
| 237 |
shift |
| 238 |
;; |
| 239 |
-mindate ) |
| 240 |
CheckForArgumentValue "$tag" "$rem" |
| 241 |
shift |
| 242 |
mindate="$1" |
| 243 |
shift |
| 244 |
;; |
| 245 |
-maxdate ) |
| 246 |
CheckForArgumentValue "$tag" "$rem" |
| 247 |
shift |
| 248 |
maxdate="$1" |
| 249 |
shift |
| 250 |
;; |
| 251 |
-datetype ) |
| 252 |
CheckForArgumentValue "$tag" "$rem" |
| 253 |
shift |
| 254 |
datetype="$1" |
| 255 |
shift |
| 256 |
;; |
| 257 |
# FILTERS |
| 258 |
-pub ) |
| 259 |
CheckForArgumentValue "$tag" "$rem" |
| 260 |
shift |
| 261 |
pub="$1" |
| 262 |
shift |
| 263 |
;; |
| 264 |
-title ) |
| 265 |
CheckForArgumentValue "$tag" "$rem" |
| 266 |
shift |
| 267 |
titl="$1" |
| 268 |
shift |
| 269 |
;; |
| 270 |
-journal ) |
| 271 |
CheckForArgumentValue "$tag" "$rem" |
| 272 |
shift |
| 273 |
jour="$1" |
| 274 |
shift |
| 275 |
;; |
| 276 |
-released ) |
| 277 |
CheckForArgumentValue "$tag" "$rem" |
| 278 |
shift |
| 279 |
rlsd="$1" |
| 280 |
shift |
| 281 |
;; |
| 282 |
-country | -geo_loc_name ) |
| 283 |
CheckForArgumentValue "$tag" "$rem" |
| 284 |
shift |
| 285 |
ctry="$1" |
| 286 |
shift |
| 287 |
;; |
| 288 |
-feature ) |
| 289 |
CheckForArgumentValue "$tag" "$rem" |
| 290 |
shift |
| 291 |
feat="$1" |
| 292 |
shift |
| 293 |
;; |
| 294 |
-location ) |
| 295 |
CheckForArgumentValue "$tag" "$rem" |
| 296 |
shift |
| 297 |
locn="$1" |
| 298 |
shift |
| 299 |
;; |
| 300 |
-molecule ) |
| 301 |
CheckForArgumentValue "$tag" "$rem" |
| 302 |
shift |
| 303 |
mol="$1" |
| 304 |
shift |
| 305 |
;; |
| 306 |
-organism ) |
| 307 |
CheckForArgumentValue "$tag" "$rem" |
| 308 |
shift |
| 309 |
orgn="$1" |
| 310 |
shift |
| 311 |
;; |
| 312 |
-source ) |
| 313 |
CheckForArgumentValue "$tag" "$rem" |
| 314 |
shift |
| 315 |
sorc="$1" |
| 316 |
shift |
| 317 |
;; |
| 318 |
-division ) |
| 319 |
CheckForArgumentValue "$tag" "$rem" |
| 320 |
shift |
| 321 |
divn="$1" |
| 322 |
shift |
| 323 |
;; |
| 324 |
-keyword ) |
| 325 |
CheckForArgumentValue "$tag" "$rem" |
| 326 |
shift |
| 327 |
kywd="$1" |
| 328 |
shift |
| 329 |
;; |
| 330 |
-purpose ) |
| 331 |
CheckForArgumentValue "$tag" "$rem" |
| 332 |
shift |
| 333 |
prps="$1" |
| 334 |
shift |
| 335 |
;; |
| 336 |
-status ) |
| 337 |
CheckForArgumentValue "$tag" "$rem" |
| 338 |
shift |
| 339 |
stts="$1" |
| 340 |
shift |
| 341 |
;; |
| 342 |
-type ) |
| 343 |
CheckForArgumentValue "$tag" "$rem" |
| 344 |
shift |
| 345 |
type="$1" |
| 346 |
shift |
| 347 |
;; |
| 348 |
-class ) |
| 349 |
CheckForArgumentValue "$tag" "$rem" |
| 350 |
shift |
| 351 |
clss="$1" |
| 352 |
shift |
| 353 |
;; |
| 354 |
-kind ) |
| 355 |
CheckForArgumentValue "$tag" "$rem" |
| 356 |
shift |
| 357 |
kind="$1" |
| 358 |
shift |
| 359 |
;; |
| 360 |
-pathway ) |
| 361 |
CheckForArgumentValue "$tag" "$rem" |
| 362 |
shift |
| 363 |
ptwy="$1" |
| 364 |
shift |
| 365 |
;; |
| 366 |
# HELP |
| 367 |
-h | -help | --help | help ) |
| 368 |
newVersion=$( NewerEntrezDirectVersion ) |
| 369 |
if [ "$isFilter" = true ] |
| 370 |
then |
| 371 |
echo "efilter $version" |
| 372 |
echo "" |
| 373 |
if [ -n "$newVersion" ] |
| 374 |
then |
| 375 |
DisplayNote "EDirect version ${newVersion} is now available" |
| 376 |
echo "" >&2 |
| 377 |
cat "$pth/help/efilter-help.txt" |
| 378 |
echo "" |
| 379 |
DisplayNote "EDirect version ${newVersion} is now available" |
| 380 |
echo "" >&2 |
| 381 |
else |
| 382 |
cat "$pth/help/efilter-help.txt" |
| 383 |
echo "" |
| 384 |
fi |
| 385 |
else |
| 386 |
echo "esearch $version" |
| 387 |
echo "" |
| 388 |
if [ -n "$newVersion" ] |
| 389 |
then |
| 390 |
DisplayNote "EDirect version ${newVersion} is now available" |
| 391 |
echo "" >&2 |
| 392 |
cat "$pth/help/esearch-help.txt" |
| 393 |
echo "" |
| 394 |
DisplayNote "EDirect version ${newVersion} is now available" |
| 395 |
echo "" >&2 |
| 396 |
else |
| 397 |
cat "$pth/help/esearch-help.txt" |
| 398 |
echo "" |
| 399 |
fi |
| 400 |
fi |
| 401 |
exit 0 |
| 402 |
;; |
| 403 |
# OTHER COMMON ARGUMENTS |
| 404 |
-* ) |
| 405 |
ParseCommonArgs "$@" |
| 406 |
if [ "$argsConsumed" -gt 0 ] |
| 407 |
then |
| 408 |
shift "$argsConsumed" |
| 409 |
else |
| 410 |
DisplayError "Unrecognized option $1" |
| 411 |
exit 1 |
| 412 |
fi |
| 413 |
;; |
| 414 |
* ) |
| 415 |
DisplayError "Unrecognized argument $1" |
| 416 |
shift |
| 417 |
;; |
| 418 |
esac |
| 419 |
done |
| 420 |
|
| 421 |
FinishSetup |
| 422 |
|
| 423 |
# check for ENTREZ_DIRECT message from stdin (for combining independent queries) |
| 424 |
|
| 425 |
ParseStdin |
| 426 |
|
| 427 |
# prefer -db argument over WebEnv value |
| 428 |
|
| 429 |
if [ -n "$db" ] |
| 430 |
then |
| 431 |
dbase="$db" |
| 432 |
fi |
| 433 |
|
| 434 |
if [ -z "$ids$rest$qury$query$input" ] |
| 435 |
then |
| 436 |
needHistory=true |
| 437 |
fi |
| 438 |
|
| 439 |
if [ "$dbase" = "nucleotide" ] |
| 440 |
then |
| 441 |
dbase="nuccore" |
| 442 |
fi |
| 443 |
|
| 444 |
# check for missing database argument |
| 445 |
|
| 446 |
if [ -z "$dbase" ] |
| 447 |
then |
| 448 |
DisplayError "Missing -db argument" |
| 449 |
exit 1 |
| 450 |
fi |
| 451 |
|
| 452 |
# normalize to lower-case (e.g., SRA -> sra) |
| 453 |
|
| 454 |
dbase=$( echo "$dbase" | tr '[:upper:]' '[:lower:]' ) |
| 455 |
|
| 456 |
# take optional days and datetype arguments from message |
| 457 |
|
| 458 |
if [ -z "$reldate" ] && [ -n "$reldatex" ] |
| 459 |
then |
| 460 |
reldate="$reldatex" |
| 461 |
fi |
| 462 |
if [ -z "$mindate" ] && [ -n "$mindatex" ] |
| 463 |
then |
| 464 |
mindate="$mindatex" |
| 465 |
fi |
| 466 |
if [ -z "$maxdate" ] && [ -n "$maxdatex" ] |
| 467 |
then |
| 468 |
maxdate="$maxdatex" |
| 469 |
fi |
| 470 |
if [ -z "$datetype" ] && [ -n "$datetypex" ] |
| 471 |
then |
| 472 |
datetype="$datetypex" |
| 473 |
fi |
| 474 |
|
| 475 |
# -titl argument can be used in lieu of an explicit -query |
| 476 |
|
| 477 |
AddTitleArg() { |
| 478 |
|
| 479 |
qry="$1" |
| 480 |
arg="$2" |
| 481 |
|
| 482 |
sep="" |
| 483 |
|
| 484 |
if [ -n "$qry" ] |
| 485 |
then |
| 486 |
sep=" AND " |
| 487 |
fi |
| 488 |
|
| 489 |
trm=$( |
| 490 |
echo "$arg" | |
| 491 |
word-at-a-time | |
| 492 |
filter-stop-words | |
| 493 |
sort -f | |
| 494 |
uniq -i | |
| 495 |
sed -e 's/$/ [TITL]/' | |
| 496 |
tr '\n' ',' | |
| 497 |
sed -e 's/,$//g' | |
| 498 |
sed -e 's/,/ AND /g' |
| 499 |
) |
| 500 |
|
| 501 |
if [ -n "$trm" ] |
| 502 |
then |
| 503 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 504 |
fi |
| 505 |
echo "$qry" |
| 506 |
} |
| 507 |
|
| 508 |
if [ -n "$titl" ] |
| 509 |
then |
| 510 |
query=$( AddTitleArg "$query" "$titl" ) |
| 511 |
fi |
| 512 |
|
| 513 |
# remove internal apostrophes - otherwise can lead to discrepancy between expected and observed count |
| 514 |
|
| 515 |
if [ -n "$query" ] |
| 516 |
then |
| 517 |
query=$( echo "$query" | sed -e "s/\'/'/g" -e "s/'//g" ) |
| 518 |
fi |
| 519 |
|
| 520 |
# check for missing esearch query argument |
| 521 |
|
| 522 |
if [ -z "$query" ] && [ "$isFilter" = false ] |
| 523 |
then |
| 524 |
DisplayError "Missing -query argument" |
| 525 |
exit 1 |
| 526 |
fi |
| 527 |
|
| 528 |
# convert labels in query to history access numbers |
| 529 |
|
| 530 |
ConvertLabels() { |
| 531 |
|
| 532 |
qry="$1" |
| 533 |
echo "$labels" | |
| 534 |
xtract -pattern Label -element Key Val | |
| 535 |
while read key val |
| 536 |
do |
| 537 |
# do successive conversions one at a time |
| 538 |
qry=$( echo "$qry" | sed -e "s/(#${key})/(#${val})/g" ) |
| 539 |
echo "$qry" |
| 540 |
done | |
| 541 |
# only report last line with all conversions done |
| 542 |
tail -n 1 |
| 543 |
} |
| 544 |
|
| 545 |
if [ -n "$query" ] && [ -n "$labels" ] |
| 546 |
then |
| 547 |
conv=$( ConvertLabels "$query" ) |
| 548 |
if [ -n "$conv" ] |
| 549 |
then |
| 550 |
query="$conv" |
| 551 |
fi |
| 552 |
fi |
| 553 |
|
| 554 |
# shortcut functions |
| 555 |
|
| 556 |
AddPubArg() { |
| 557 |
|
| 558 |
qry="$1" |
| 559 |
arg="$2" |
| 560 |
|
| 561 |
sep="" |
| 562 |
if [ -n "$qry" ] |
| 563 |
then |
| 564 |
sep=" AND " |
| 565 |
fi |
| 566 |
|
| 567 |
echo "$arg" | |
| 568 |
word-at-a-time | |
| 569 |
( |
| 570 |
while read itm |
| 571 |
do |
| 572 |
trm="" |
| 573 |
case "$itm" in |
| 574 |
abstract ) |
| 575 |
trm="has abstract [FILT]" |
| 576 |
;; |
| 577 |
clinical ) |
| 578 |
trm="clinical trial [FILT]" |
| 579 |
;; |
| 580 |
english ) |
| 581 |
trm="english [FILT]" |
| 582 |
;; |
| 583 |
free ) |
| 584 |
trm="freetext [FILT]" |
| 585 |
;; |
| 586 |
historical ) |
| 587 |
trm="historical article [FILT]" |
| 588 |
;; |
| 589 |
journal ) |
| 590 |
trm="journal article [FILT]" |
| 591 |
;; |
| 592 |
last_month | "last month" ) |
| 593 |
trm="published last month [FILT]" |
| 594 |
;; |
| 595 |
last_week | "last week" ) |
| 596 |
trm="published last week [FILT]" |
| 597 |
;; |
| 598 |
last_year | "last year" ) |
| 599 |
trm="published last year [FILT]" |
| 600 |
;; |
| 601 |
medline ) |
| 602 |
trm="medline [FILT]" |
| 603 |
;; |
| 604 |
preprint ) |
| 605 |
trm="ahead of print [FILT]" |
| 606 |
;; |
| 607 |
published ) |
| 608 |
trm="ahead of print [FILT]" |
| 609 |
sep=" NOT " |
| 610 |
;; |
| 611 |
retracted ) |
| 612 |
trm="retracted publication [PTYP]" |
| 613 |
;; |
| 614 |
retraction ) |
| 615 |
trm="retraction of publication [PTYP]" |
| 616 |
;; |
| 617 |
review ) |
| 618 |
trm="review [FILT]" |
| 619 |
;; |
| 620 |
structured ) |
| 621 |
trm="hasstructuredabstract [WORD]" |
| 622 |
;; |
| 623 |
trial ) |
| 624 |
trm="clinical trial [FILT]" |
| 625 |
;; |
| 626 |
* ) |
| 627 |
DisplayError "Unrecognized -pub option $itm" |
| 628 |
exit 1 |
| 629 |
;; |
| 630 |
esac |
| 631 |
if [ -n "$trm" ] |
| 632 |
then |
| 633 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 634 |
fi |
| 635 |
sep=" AND " |
| 636 |
done |
| 637 |
echo "$qry" |
| 638 |
) |
| 639 |
} |
| 640 |
|
| 641 |
AddReleasedArg() { |
| 642 |
|
| 643 |
qry="$1" |
| 644 |
arg="$2" |
| 645 |
|
| 646 |
sep="" |
| 647 |
|
| 648 |
if [ -n "$qry" ] |
| 649 |
then |
| 650 |
sep=" AND " |
| 651 |
fi |
| 652 |
|
| 653 |
trm="" |
| 654 |
case "$arg" in |
| 655 |
last_month | "last month" ) |
| 656 |
trm="published last month [FILT]" |
| 657 |
;; |
| 658 |
last_week | "last week" ) |
| 659 |
trm="published last week [FILT]" |
| 660 |
;; |
| 661 |
last_year | "last year" ) |
| 662 |
trm="published last year [FILT]" |
| 663 |
;; |
| 664 |
prev_years | "prev years" ) |
| 665 |
trm="published last year [FILT]" |
| 666 |
sep=" NOT " |
| 667 |
;; |
| 668 |
* ) |
| 669 |
DisplayError "Unrecognized -released option $arg" |
| 670 |
exit 1 |
| 671 |
;; |
| 672 |
esac |
| 673 |
if [ -n "$trm" ] |
| 674 |
then |
| 675 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 676 |
fi |
| 677 |
echo "$qry" |
| 678 |
} |
| 679 |
|
| 680 |
AddJournalArg() { |
| 681 |
|
| 682 |
qry="$1" |
| 683 |
arg="$2" |
| 684 |
|
| 685 |
sep="" |
| 686 |
|
| 687 |
if [ -n "$qry" ] |
| 688 |
then |
| 689 |
sep=" AND " |
| 690 |
fi |
| 691 |
|
| 692 |
qry=$( echo "${qry}${sep}${arg} [JOUR]" ) |
| 693 |
|
| 694 |
echo "$qry" |
| 695 |
} |
| 696 |
|
| 697 |
AddCountryArg() { |
| 698 |
|
| 699 |
qry="$1" |
| 700 |
arg="$2" |
| 701 |
|
| 702 |
sep="" |
| 703 |
|
| 704 |
if [ -n "$qry" ] |
| 705 |
then |
| 706 |
sep=" AND " |
| 707 |
fi |
| 708 |
|
| 709 |
qry=$( echo "${qry}${sep}country ${arg} [TEXT]" ) |
| 710 |
|
| 711 |
echo "$qry" |
| 712 |
} |
| 713 |
|
| 714 |
AddFeatureArg() { |
| 715 |
|
| 716 |
qry="$1" |
| 717 |
arg="$2" |
| 718 |
|
| 719 |
sep="" |
| 720 |
|
| 721 |
if [ -n "$qry" ] |
| 722 |
then |
| 723 |
sep=" AND " |
| 724 |
fi |
| 725 |
|
| 726 |
echo "$arg" | |
| 727 |
sed "s/[^a-zA-Z0-9_.'-]/ /g; s/^ *//" | |
| 728 |
tr 'A-Z' 'a-z' | |
| 729 |
fmt -w 1 | |
| 730 |
( |
| 731 |
while read itm |
| 732 |
do |
| 733 |
if [ -n "$itm" ] |
| 734 |
then |
| 735 |
qry=$( echo "${qry}${sep}${itm} [FKEY]" ) |
| 736 |
fi |
| 737 |
sep=" AND " |
| 738 |
done |
| 739 |
echo "$qry" |
| 740 |
) |
| 741 |
} |
| 742 |
|
| 743 |
AddLocationArg() { |
| 744 |
|
| 745 |
qry="$1" |
| 746 |
arg="$2" |
| 747 |
|
| 748 |
sep="" |
| 749 |
|
| 750 |
if [ -n "$qry" ] |
| 751 |
then |
| 752 |
sep=" AND " |
| 753 |
fi |
| 754 |
|
| 755 |
trm="" |
| 756 |
case "$arg" in |
| 757 |
mitochondria | mitochondrial | mitochondrion ) |
| 758 |
trm="mitochondrion [FILT]" |
| 759 |
;; |
| 760 |
chloroplast ) |
| 761 |
trm="chloroplast [FILT]" |
| 762 |
;; |
| 763 |
plasmid ) |
| 764 |
trm="plasmid [FILT]" |
| 765 |
;; |
| 766 |
plastid ) |
| 767 |
trm="plastid [FILT]" |
| 768 |
;; |
| 769 |
* ) |
| 770 |
DisplayError "Unrecognized -location option $arg" |
| 771 |
exit 1 |
| 772 |
;; |
| 773 |
esac |
| 774 |
if [ -n "$trm" ] |
| 775 |
then |
| 776 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 777 |
fi |
| 778 |
echo "$qry" |
| 779 |
} |
| 780 |
|
| 781 |
AddMoleculeArg() { |
| 782 |
|
| 783 |
qry="$1" |
| 784 |
arg="$2" |
| 785 |
|
| 786 |
sep="" |
| 787 |
|
| 788 |
if [ -n "$qry" ] |
| 789 |
then |
| 790 |
sep=" AND " |
| 791 |
fi |
| 792 |
|
| 793 |
trm="" |
| 794 |
case "$arg" in |
| 795 |
genomic ) |
| 796 |
trm="biomol genomic [PROP]" |
| 797 |
;; |
| 798 |
mrna ) |
| 799 |
trm="biomol mrna [PROP]" |
| 800 |
;; |
| 801 |
trna ) |
| 802 |
trm="biomol trna [PROP]" |
| 803 |
;; |
| 804 |
rrna ) |
| 805 |
trm="biomol rrna [PROP]" |
| 806 |
;; |
| 807 |
ncrna ) |
| 808 |
trm="biomol ncrna [PROP]" |
| 809 |
;; |
| 810 |
* ) |
| 811 |
DisplayError "Unrecognized -molecule option $arg" |
| 812 |
exit 1 |
| 813 |
;; |
| 814 |
esac |
| 815 |
if [ -n "$trm" ] |
| 816 |
then |
| 817 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 818 |
fi |
| 819 |
echo "$qry" |
| 820 |
} |
| 821 |
|
| 822 |
AddOrganismArg() { |
| 823 |
|
| 824 |
qry="$1" |
| 825 |
arg="$2" |
| 826 |
|
| 827 |
sep="" |
| 828 |
|
| 829 |
if [ -n "$qry" ] |
| 830 |
then |
| 831 |
sep=" AND " |
| 832 |
fi |
| 833 |
|
| 834 |
trm="" |
| 835 |
case "$arg" in |
| 836 |
animal | animals | metazoa ) |
| 837 |
trm="animals [FILT]" |
| 838 |
;; |
| 839 |
archaea | archaeal | archaebacteria | archaebacterial ) |
| 840 |
trm="archaea [FILT]" |
| 841 |
;; |
| 842 |
bacteria | bacterial | bacterium | eubacteria | eubacterial ) |
| 843 |
trm="bacteria [FILT]" |
| 844 |
;; |
| 845 |
eukaryota | eukaryote | eukaryotes ) |
| 846 |
trm="eukaryota [ORGN]" |
| 847 |
;; |
| 848 |
fungal | fungi | fungus ) |
| 849 |
trm="fungi [FILT]" |
| 850 |
;; |
| 851 |
human | humans | man ) |
| 852 |
trm="human [ORGN]" |
| 853 |
;; |
| 854 |
insect | insecta | insects ) |
| 855 |
trm="insecta [ORGN]" |
| 856 |
;; |
| 857 |
mammal | mammalia | mammalian | mammals ) |
| 858 |
trm="mammals [FILT]" |
| 859 |
;; |
| 860 |
metaphyta | plant | plants ) |
| 861 |
trm="plants [FILT]" |
| 862 |
;; |
| 863 |
prokaryota | prokaryote | prokaryotes ) |
| 864 |
trm="prokaryota [ORGN]" |
| 865 |
;; |
| 866 |
protist | protista | protists ) |
| 867 |
trm="protists [FILT]" |
| 868 |
;; |
| 869 |
rodent | rodentia | rodents ) |
| 870 |
trm="rodents [ORGN]" |
| 871 |
;; |
| 872 |
viral | virus | viruses ) |
| 873 |
trm="viruses [FILT]" |
| 874 |
;; |
| 875 |
* ) |
| 876 |
# allow any organism |
| 877 |
trm="$arg [ORGN]" |
| 878 |
;; |
| 879 |
esac |
| 880 |
if [ -n "$trm" ] |
| 881 |
then |
| 882 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 883 |
fi |
| 884 |
echo "$qry" |
| 885 |
} |
| 886 |
|
| 887 |
AddSourceArg() { |
| 888 |
|
| 889 |
qry="$1" |
| 890 |
arg="$2" |
| 891 |
|
| 892 |
sep="" |
| 893 |
|
| 894 |
if [ -n "$qry" ] |
| 895 |
then |
| 896 |
sep=" AND " |
| 897 |
fi |
| 898 |
|
| 899 |
trm="" |
| 900 |
case "$arg" in |
| 901 |
ddbj ) |
| 902 |
trm="srcdb ddbj [PROP]" |
| 903 |
;; |
| 904 |
embl ) |
| 905 |
trm="srcdb embl [PROP]" |
| 906 |
;; |
| 907 |
genbank ) |
| 908 |
trm="srcdb genbank [PROP]" |
| 909 |
;; |
| 910 |
insd ) |
| 911 |
trm="srcdb ddbj/embl/genbank [PROP]" |
| 912 |
;; |
| 913 |
pdb ) |
| 914 |
trm="srcdb pdb [PROP]" |
| 915 |
;; |
| 916 |
pir ) |
| 917 |
trm="srcdb pir [PROP]" |
| 918 |
;; |
| 919 |
refseq ) |
| 920 |
trm="srcdb refseq [PROP]" |
| 921 |
;; |
| 922 |
"select" ) |
| 923 |
trm="refseq select [FILT]" |
| 924 |
;; |
| 925 |
swissprot ) |
| 926 |
trm="srcdb swiss prot [PROP]" |
| 927 |
;; |
| 928 |
tpa ) |
| 929 |
trm="srcdb tpa ddbj/embl/genbank [PROP]" |
| 930 |
;; |
| 931 |
* ) |
| 932 |
DisplayError "Unrecognized -source option $arg" |
| 933 |
exit 1 |
| 934 |
;; |
| 935 |
esac |
| 936 |
if [ -n "$trm" ] |
| 937 |
then |
| 938 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 939 |
fi |
| 940 |
echo "$qry" |
| 941 |
} |
| 942 |
|
| 943 |
AddDivisionArg() { |
| 944 |
|
| 945 |
qry="$1" |
| 946 |
arg="$2" |
| 947 |
|
| 948 |
sep="" |
| 949 |
|
| 950 |
if [ -n "$qry" ] |
| 951 |
then |
| 952 |
sep=" AND " |
| 953 |
fi |
| 954 |
|
| 955 |
divs="" |
| 956 |
seps="" |
| 957 |
for itm in $( echo $arg | sed "s/,/ /g" ) |
| 958 |
do |
| 959 |
trm="" |
| 960 |
case "$itm" in |
| 961 |
bct | con | env | est | gss | htc | htg | inv | mam | pat | phg | pln | pri | rod | sts | syn | una | vrl | vrt ) |
| 962 |
trm="gbdiv $itm [PROP]" |
| 963 |
;; |
| 964 |
* ) |
| 965 |
DisplayError "Unrecognized -division option $itm" |
| 966 |
exit 1 |
| 967 |
;; |
| 968 |
esac |
| 969 |
if [ -n "$trm" ] |
| 970 |
then |
| 971 |
divs=$( echo "${divs}${seps}${trm}" ) |
| 972 |
seps=" OR " |
| 973 |
fi |
| 974 |
done |
| 975 |
if [ -n "$divs" ] |
| 976 |
then |
| 977 |
qry=$( echo "${qry}${sep} ( ${divs} )" ) |
| 978 |
fi |
| 979 |
echo "$qry" |
| 980 |
} |
| 981 |
|
| 982 |
AddKeywordArg() { |
| 983 |
|
| 984 |
qry="$1" |
| 985 |
arg="$2" |
| 986 |
|
| 987 |
sep="" |
| 988 |
|
| 989 |
if [ -n "$qry" ] |
| 990 |
then |
| 991 |
sep=" AND " |
| 992 |
fi |
| 993 |
|
| 994 |
trm="" |
| 995 |
case "$arg" in |
| 996 |
purpose ) |
| 997 |
trm="purpose* [KYWD]" |
| 998 |
;; |
| 999 |
* ) |
| 1000 |
DisplayError "Unrecognized -keyword option $arg" |
| 1001 |
exit 1 |
| 1002 |
;; |
| 1003 |
esac |
| 1004 |
if [ -n "$trm" ] |
| 1005 |
then |
| 1006 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 1007 |
fi |
| 1008 |
echo "$qry" |
| 1009 |
} |
| 1010 |
|
| 1011 |
AddPurposeArg() { |
| 1012 |
|
| 1013 |
qry="$1" |
| 1014 |
arg="$2" |
| 1015 |
|
| 1016 |
sep="" |
| 1017 |
|
| 1018 |
if [ -n "$qry" ] |
| 1019 |
then |
| 1020 |
sep=" AND " |
| 1021 |
fi |
| 1022 |
|
| 1023 |
trm="" |
| 1024 |
case "$arg" in |
| 1025 |
baseline ) |
| 1026 |
trm="( purposeofsampling baselinesurveillance [KYWD] OR purpose of sequencing baselinesurveillance [KYWD] )" |
| 1027 |
;; |
| 1028 |
targeted ) |
| 1029 |
trm="purposeofsampling targetedefforts [KYWD]" |
| 1030 |
;; |
| 1031 |
* ) |
| 1032 |
DisplayError "Unrecognized -purpose option $arg" |
| 1033 |
exit 1 |
| 1034 |
;; |
| 1035 |
esac |
| 1036 |
if [ -n "$trm" ] |
| 1037 |
then |
| 1038 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 1039 |
fi |
| 1040 |
echo "$qry" |
| 1041 |
} |
| 1042 |
|
| 1043 |
AddStatusArg() { |
| 1044 |
|
| 1045 |
qry="$1" |
| 1046 |
arg="$2" |
| 1047 |
dbs="$3" |
| 1048 |
|
| 1049 |
sep="" |
| 1050 |
|
| 1051 |
if [ -n "$qry" ] |
| 1052 |
then |
| 1053 |
sep=" AND " |
| 1054 |
fi |
| 1055 |
|
| 1056 |
trm="" |
| 1057 |
case "$dbs" in |
| 1058 |
gene ) |
| 1059 |
case "$arg" in |
| 1060 |
alive | live | living ) |
| 1061 |
trm="alive [PROP]" |
| 1062 |
;; |
| 1063 |
* ) |
| 1064 |
DisplayError "Unrecognized -status option $arg" |
| 1065 |
exit 1 |
| 1066 |
;; |
| 1067 |
esac |
| 1068 |
;; |
| 1069 |
assembly ) |
| 1070 |
case "$arg" in |
| 1071 |
latest ) |
| 1072 |
trm="latest [PROP]" |
| 1073 |
;; |
| 1074 |
replaced ) |
| 1075 |
trm="replaced [PROP]" |
| 1076 |
;; |
| 1077 |
* ) |
| 1078 |
DisplayError "Unrecognized -status option $arg" |
| 1079 |
exit 1 |
| 1080 |
;; |
| 1081 |
esac |
| 1082 |
;; |
| 1083 |
* ) |
| 1084 |
DisplayError "Unrecognized -status option $arg" |
| 1085 |
exit 1 |
| 1086 |
;; |
| 1087 |
esac |
| 1088 |
if [ -n "$trm" ] |
| 1089 |
then |
| 1090 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 1091 |
fi |
| 1092 |
echo "$qry" |
| 1093 |
} |
| 1094 |
|
| 1095 |
AddTypeArg() { |
| 1096 |
|
| 1097 |
qry="$1" |
| 1098 |
arg="$2" |
| 1099 |
|
| 1100 |
sep="" |
| 1101 |
|
| 1102 |
if [ -n "$qry" ] |
| 1103 |
then |
| 1104 |
sep=" AND " |
| 1105 |
fi |
| 1106 |
|
| 1107 |
trm="" |
| 1108 |
case "$arg" in |
| 1109 |
coding ) |
| 1110 |
trm="genetype protein coding [PROP]" |
| 1111 |
;; |
| 1112 |
pseudo ) |
| 1113 |
trm="genetype pseudo [PROP]" |
| 1114 |
;; |
| 1115 |
* ) |
| 1116 |
DisplayError "Unrecognized -type option $arg" |
| 1117 |
exit 1 |
| 1118 |
;; |
| 1119 |
esac |
| 1120 |
if [ -n "$trm" ] |
| 1121 |
then |
| 1122 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 1123 |
fi |
| 1124 |
echo "$qry" |
| 1125 |
} |
| 1126 |
|
| 1127 |
AddClassArg() { |
| 1128 |
|
| 1129 |
qry="$1" |
| 1130 |
arg="$2" |
| 1131 |
|
| 1132 |
sep="" |
| 1133 |
|
| 1134 |
if [ -n "$qry" ] |
| 1135 |
then |
| 1136 |
sep=" AND " |
| 1137 |
fi |
| 1138 |
|
| 1139 |
trm="" |
| 1140 |
case "$arg" in |
| 1141 |
acceptor ) |
| 1142 |
trm="splice acceptor variant [FXN]" |
| 1143 |
;; |
| 1144 |
donor ) |
| 1145 |
trm="splice donor variant [FXN]" |
| 1146 |
;; |
| 1147 |
coding ) |
| 1148 |
trm="coding sequence variant [FXN]" |
| 1149 |
;; |
| 1150 |
frameshift ) |
| 1151 |
trm="frameshift variant [FXN]" |
| 1152 |
;; |
| 1153 |
indel ) |
| 1154 |
trm="inframe indel [FXN]" |
| 1155 |
;; |
| 1156 |
intron ) |
| 1157 |
trm="intron variant [FXN]" |
| 1158 |
;; |
| 1159 |
missense ) |
| 1160 |
trm="missense variant [FXN]" |
| 1161 |
;; |
| 1162 |
nonsense ) |
| 1163 |
trm="terminator codon variant [FXN]" |
| 1164 |
;; |
| 1165 |
synonymous ) |
| 1166 |
trm="synonymous variant [FXN]" |
| 1167 |
;; |
| 1168 |
* ) |
| 1169 |
DisplayError "Unrecognized -class option $arg" |
| 1170 |
exit 1 |
| 1171 |
;; |
| 1172 |
esac |
| 1173 |
if [ -n "$trm" ] |
| 1174 |
then |
| 1175 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 1176 |
fi |
| 1177 |
echo "$qry" |
| 1178 |
} |
| 1179 |
|
| 1180 |
AddKindArg() { |
| 1181 |
|
| 1182 |
qry="$1" |
| 1183 |
arg="$2" |
| 1184 |
|
| 1185 |
sep="" |
| 1186 |
|
| 1187 |
if [ -n "$qry" ] |
| 1188 |
then |
| 1189 |
sep=" AND " |
| 1190 |
fi |
| 1191 |
|
| 1192 |
trm="" |
| 1193 |
case "$arg" in |
| 1194 |
pathway ) |
| 1195 |
trm="pathway [TYPE]" |
| 1196 |
;; |
| 1197 |
* ) |
| 1198 |
DisplayError "Unrecognized -kind option $arg" |
| 1199 |
exit 1 |
| 1200 |
;; |
| 1201 |
esac |
| 1202 |
if [ -n "$trm" ] |
| 1203 |
then |
| 1204 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 1205 |
fi |
| 1206 |
echo "$qry" |
| 1207 |
} |
| 1208 |
|
| 1209 |
AddPathwayArg() { |
| 1210 |
|
| 1211 |
qry="$1" |
| 1212 |
arg="$2" |
| 1213 |
|
| 1214 |
sep="" |
| 1215 |
|
| 1216 |
if [ -n "$qry" ] |
| 1217 |
then |
| 1218 |
sep=" AND " |
| 1219 |
fi |
| 1220 |
|
| 1221 |
trm="" |
| 1222 |
case "$arg" in |
| 1223 |
reactome ) |
| 1224 |
trm="src reactome [FILT]" |
| 1225 |
;; |
| 1226 |
wikipathways ) |
| 1227 |
trm="src wikipathways [FILT]" |
| 1228 |
;; |
| 1229 |
* ) |
| 1230 |
DisplayError "Unrecognized -pathway option $arg" |
| 1231 |
exit 1 |
| 1232 |
;; |
| 1233 |
esac |
| 1234 |
if [ -n "$trm" ] |
| 1235 |
then |
| 1236 |
qry=$( echo "${qry}${sep}${trm}" ) |
| 1237 |
fi |
| 1238 |
echo "$qry" |
| 1239 |
} |
| 1240 |
|
| 1241 |
# warn on mismatch between filter argument and database |
| 1242 |
|
| 1243 |
case "$dbase" in |
| 1244 |
nucleotide | nuccore | protein ) |
| 1245 |
;; |
| 1246 |
* ) |
| 1247 |
if [ "$dbase" != "gene" ] || [ -z "$orgn" ] |
| 1248 |
then |
| 1249 |
if [ -n "$ctry" ] || [ -n "$feat" ] || [ -n "$locn" ] || [ -n "$mol" ] || [ -n "$orgn" ] || [ -n "$sorc" ] || [ -n "$divn" ] || [ -n "$kywd" ] || [ -n "$prps" ] |
| 1250 |
then |
| 1251 |
DisplayError "Unexpected use of sequence filter argument" |
| 1252 |
exit 1 |
| 1253 |
fi |
| 1254 |
fi |
| 1255 |
;; |
| 1256 |
esac |
| 1257 |
|
| 1258 |
# spell check each query word |
| 1259 |
|
| 1260 |
if [ "$spell" = true ] |
| 1261 |
then |
| 1262 |
spl=$( RunWithCommonArgs nquire -url "$base" espell.fcgi -db "$dbase" -term "$query" | |
| 1263 |
xtract -pattern eSpellResult -element CorrectedQuery ) |
| 1264 |
if [ -n "$spl" ] |
| 1265 |
then |
| 1266 |
query="$spl" |
| 1267 |
fi |
| 1268 |
fi |
| 1269 |
|
| 1270 |
# add shortcuts to query |
| 1271 |
|
| 1272 |
if [ -n "$pub" ] |
| 1273 |
then |
| 1274 |
query=$( AddPubArg "$query" "$pub" ) |
| 1275 |
fi |
| 1276 |
|
| 1277 |
if [ -n "$rlsd" ] |
| 1278 |
then |
| 1279 |
query=$( AddReleasedArg "$query" "$rlsd" ) |
| 1280 |
fi |
| 1281 |
|
| 1282 |
if [ -n "$jour" ] |
| 1283 |
then |
| 1284 |
query=$( AddJournalArg "$query" "$jour" ) |
| 1285 |
fi |
| 1286 |
|
| 1287 |
if [ -n "$ctry" ] |
| 1288 |
then |
| 1289 |
query=$( AddCountryArg "$query" "$ctry" ) |
| 1290 |
fi |
| 1291 |
|
| 1292 |
if [ -n "$feat" ] |
| 1293 |
then |
| 1294 |
query=$( AddFeatureArg "$query" "$feat" ) |
| 1295 |
fi |
| 1296 |
|
| 1297 |
if [ -n "$locn" ] |
| 1298 |
then |
| 1299 |
query=$( AddLocationArg "$query" "$locn" ) |
| 1300 |
fi |
| 1301 |
|
| 1302 |
if [ -n "$mol" ] |
| 1303 |
then |
| 1304 |
query=$( AddMoleculeArg "$query" "$mol" ) |
| 1305 |
fi |
| 1306 |
|
| 1307 |
if [ -n "$orgn" ] |
| 1308 |
then |
| 1309 |
query=$( AddOrganismArg "$query" "$orgn" ) |
| 1310 |
fi |
| 1311 |
|
| 1312 |
if [ -n "$sorc" ] |
| 1313 |
then |
| 1314 |
query=$( AddSourceArg "$query" "$sorc" ) |
| 1315 |
fi |
| 1316 |
|
| 1317 |
if [ -n "$divn" ] |
| 1318 |
then |
| 1319 |
query=$( AddDivisionArg "$query" "$divn" ) |
| 1320 |
fi |
| 1321 |
|
| 1322 |
if [ -n "$kywd" ] |
| 1323 |
then |
| 1324 |
query=$( AddKeywordArg "$query" "$kywd" ) |
| 1325 |
fi |
| 1326 |
|
| 1327 |
if [ -n "$prps" ] |
| 1328 |
then |
| 1329 |
query=$( AddPurposeArg "$query" "$prps" ) |
| 1330 |
fi |
| 1331 |
|
| 1332 |
if [ -n "$stts" ] |
| 1333 |
then |
| 1334 |
query=$( AddStatusArg "$query" "$stts" "$dbase" ) |
| 1335 |
fi |
| 1336 |
|
| 1337 |
if [ -n "$type" ] |
| 1338 |
then |
| 1339 |
query=$( AddTypeArg "$query" "$type" ) |
| 1340 |
fi |
| 1341 |
|
| 1342 |
if [ -n "$clss" ] |
| 1343 |
then |
| 1344 |
query=$( AddClassArg "$query" "$clss" ) |
| 1345 |
fi |
| 1346 |
|
| 1347 |
if [ -n "$kind" ] |
| 1348 |
then |
| 1349 |
query=$( AddKindArg "$query" "$kind" ) |
| 1350 |
fi |
| 1351 |
|
| 1352 |
if [ -n "$ptwy" ] |
| 1353 |
then |
| 1354 |
query=$( AddPathwayArg "$query" "$ptwy" ) |
| 1355 |
fi |
| 1356 |
|
| 1357 |
# remove leading, trailing, and multiple spaces |
| 1358 |
|
| 1359 |
if [ -n "$query" ] |
| 1360 |
then |
| 1361 |
query=$( echo "$query" | sed -e 's/^ *//g; s/ *$//g; s/ */ /g' ) |
| 1362 |
fi |
| 1363 |
|
| 1364 |
# adjust for -db assembly ACCN field inconsistency |
| 1365 |
|
| 1366 |
if [ "$dbase" = "assembly" ] |
| 1367 |
then |
| 1368 |
query=$( echo "$query" | sed -e 's/\[ACCN\]/[ASAC]/g' ) |
| 1369 |
fi |
| 1370 |
|
| 1371 |
# -query string required for esearch |
| 1372 |
|
| 1373 |
if [ -z "$query" ] && [ "$isFilter" = false ] |
| 1374 |
then |
| 1375 |
# warn on insufficient arguments |
| 1376 |
DisplayError "Missing -query argument" |
| 1377 |
exit 1 |
| 1378 |
fi |
| 1379 |
|
| 1380 |
# -query or -days or -mindate and -maxdate arguments sufficient for efilter |
| 1381 |
|
| 1382 |
ok=false |
| 1383 |
if [ -n "$query" ] |
| 1384 |
then |
| 1385 |
ok=true |
| 1386 |
elif [ -n "$reldate" ] |
| 1387 |
then |
| 1388 |
ok=true |
| 1389 |
elif [ -n "$mindate" ] && [ -n "$maxdate" ] |
| 1390 |
then |
| 1391 |
ok=true |
| 1392 |
fi |
| 1393 |
|
| 1394 |
if [ "$ok" != true ] |
| 1395 |
then |
| 1396 |
DisplayError "Missing -query argument" |
| 1397 |
exit 1 |
| 1398 |
fi |
| 1399 |
|
| 1400 |
# no key if combining independent queries |
| 1401 |
|
| 1402 |
if [ "$isFilter" = false ] |
| 1403 |
then |
| 1404 |
qry_key="" |
| 1405 |
fi |
| 1406 |
|
| 1407 |
# adjustments on search variables |
| 1408 |
|
| 1409 |
if [ -n "$sort" ] && [ "$sort" = "Relevance" ] |
| 1410 |
then |
| 1411 |
sort="relevance" |
| 1412 |
fi |
| 1413 |
|
| 1414 |
# normalize date arguments |
| 1415 |
|
| 1416 |
FixDateConstraints |
| 1417 |
|
| 1418 |
# protect embedded 'and', 'or', and 'not' terms in single token filter, |
| 1419 |
# properties, and organism fields, in select biological databases, since |
| 1420 |
# lower-case Boolean operators will be replaced with AND according to: |
| 1421 |
# https://www.nlm.nih.gov/pubs/techbull/ja97/ja97_pubmed.html |
| 1422 |
# although only 'or' and 'not' actually cause misinterpretation of: |
| 1423 |
# -db biosample -query "package metagenome or environmental version 1 0 [PROP]" |
| 1424 |
|
| 1425 |
# changed to replace all internal spaces with underscore, except leaving one |
| 1426 |
# space before field bracket, and added assembly to list of databases given |
| 1427 |
# this special processing of FILT, PROP, and ORGN controlled vocabularies |
| 1428 |
|
| 1429 |
ProtectWithUnderscores() { |
| 1430 |
|
| 1431 |
echo "$1" | sed -e 's/ \[/\[/g; s/ /_/g; s/\[/ \[/g; s/\[/ \[/g; s/_ \[/ \[/g' |
| 1432 |
} |
| 1433 |
|
| 1434 |
ProcessEntrezQuery() { |
| 1435 |
|
| 1436 |
echo "$1" | |
| 1437 |
sed -e 's/(/ | ( | /g' \ |
| 1438 |
-e 's/)/ | ) | /g' | |
| 1439 |
sed -e "s/ AND / | AND | /g" \ |
| 1440 |
-e "s/ OR / | OR | /g" \ |
| 1441 |
-e "s/ NOT / | NOT | /g" | |
| 1442 |
tr '|' '\n' | |
| 1443 |
while read item |
| 1444 |
do |
| 1445 |
item=$( echo "$item" | sed -e 's/^ *//g; s/ *$//g; s/ */ /g' ) |
| 1446 |
opt=$( echo "$item" | tr '[:upper:]' '[:lower:]' ) |
| 1447 |
case "$opt" in |
| 1448 |
"" ) |
| 1449 |
;; |
| 1450 |
*"[filt]" | *"[filter]" ) |
| 1451 |
ProtectWithUnderscores "$item" |
| 1452 |
;; |
| 1453 |
*"[prop]" | *"[properties]" ) |
| 1454 |
ProtectWithUnderscores "$item" |
| 1455 |
;; |
| 1456 |
*"[orgn]" | *"[organism]" ) |
| 1457 |
ProtectWithUnderscores "$item" |
| 1458 |
;; |
| 1459 |
* ) |
| 1460 |
echo "$item" |
| 1461 |
;; |
| 1462 |
esac |
| 1463 |
done |
| 1464 |
} |
| 1465 |
|
| 1466 |
case "$dbase" in |
| 1467 |
nuc* | prot* | gene | genome | taxonomy | assembly | clinvar | cdd | sra | ipg | bio* ) |
| 1468 |
case "$query" in |
| 1469 |
*\|* ) |
| 1470 |
# skip if query contains an embedded vertical bar, reserved for splitting in ProcessEntrezQuery |
| 1471 |
;; |
| 1472 |
* ) |
| 1473 |
query=$( ProcessEntrezQuery "$query" | tr '\n' ' ' | sed -e 's/^ *//g; s/ *$//g; s/ */ /g' ) |
| 1474 |
;; |
| 1475 |
esac |
| 1476 |
;; |
| 1477 |
esac |
| 1478 |
|
| 1479 |
# if "$query" argument and "$qry_key" history, parentheses around $query ensures "AND" on any internal expression |
| 1480 |
|
| 1481 |
if [ -n "$qry_key" ] && [ -n "$query" ] |
| 1482 |
then |
| 1483 |
query=$( echo "( $query )" ) |
| 1484 |
fi |
| 1485 |
|
| 1486 |
# helper function adds search-specific arguments (if set) |
| 1487 |
|
| 1488 |
RunWithSearchArgs() { |
| 1489 |
|
| 1490 |
AddIfNotEmpty -WebEnv "$web_env" \ |
| 1491 |
AddIfNotEmpty -query_key "$qry_key" \ |
| 1492 |
AddIfNotEmpty -sort "$sort" \ |
| 1493 |
AddIfNotEmpty -reldate "$reldate" \ |
| 1494 |
AddIfNotEmpty -mindate "$mindate" \ |
| 1495 |
AddIfNotEmpty -maxdate "$maxdate" \ |
| 1496 |
AddIfNotEmpty -datetype "$datetype" \ |
| 1497 |
AddIfNotEmpty -term "$query" \ |
| 1498 |
RunWithCommonArgs "$@" |
| 1499 |
} |
| 1500 |
|
| 1501 |
if [ "$log" = true ] |
| 1502 |
then |
| 1503 |
if [ "$isFilter" = true ] |
| 1504 |
then |
| 1505 |
printf "EFilter\n" >&2 |
| 1506 |
else |
| 1507 |
printf "ESearch\n" >&2 |
| 1508 |
fi |
| 1509 |
fi |
| 1510 |
|
| 1511 |
# specialized query variants |
| 1512 |
|
| 1513 |
if [ "$transl" = true ] |
| 1514 |
then |
| 1515 |
RunWithSearchArgs nquire -url "$base" esearch.fcgi -db "$dbase" | |
| 1516 |
xtract -pattern eSearchResult -element QueryTranslation |
| 1517 |
|
| 1518 |
exit 0 |
| 1519 |
fi |
| 1520 |
|
| 1521 |
if [ "$tstack" = true ] |
| 1522 |
then |
| 1523 |
if [ "$dbase" = "pubmed" ] |
| 1524 |
then |
| 1525 |
RunWithSearchArgs nquire -url "$base" esearch.fcgi -db "$dbase" | |
| 1526 |
xtract -mixed -pattern eSearchResult -element QueryTranslation | |
| 1527 |
sed -e 's/(/ /g' -e 's/)/ /g' | |
| 1528 |
sed -e 's/ AND /\n/g' -e 's/ OR /\n/g' -e 's/ NOT /\n/g' | |
| 1529 |
grep '.' |
| 1530 |
else |
| 1531 |
RunWithSearchArgs nquire -url "$base" esearch.fcgi -db "$dbase" | |
| 1532 |
xtract -pattern eSearchResult -group TranslationStack -block TermSet -tab "\n" -element Term |
| 1533 |
fi |
| 1534 |
|
| 1535 |
exit 0 |
| 1536 |
fi |
| 1537 |
|
| 1538 |
# future PubMed SOLR server query |
| 1539 |
|
| 1540 |
RunWithFilterArgs() { |
| 1541 |
|
| 1542 |
AddIfNotEmpty -reldate "$reldate" \ |
| 1543 |
AddIfNotEmpty -mindate "$mindate" \ |
| 1544 |
AddIfNotEmpty -maxdate "$maxdate" \ |
| 1545 |
AddIfNotEmpty -datetype "$datetype" \ |
| 1546 |
AddIfNotEmpty -term "$query" \ |
| 1547 |
RunWithCommonArgs "$@" |
| 1548 |
} |
| 1549 |
|
| 1550 |
FilterSOLR() { |
| 1551 |
|
| 1552 |
tranquil=true |
| 1553 |
|
| 1554 |
GetUIDs | |
| 1555 |
join-into-groups-of 1000 | |
| 1556 |
while read uids |
| 1557 |
do |
| 1558 |
if [ "$log" = true ] |
| 1559 |
then |
| 1560 |
printf "." >&2 |
| 1561 |
fi |
| 1562 |
|
| 1563 |
uids=$( echo "$uids" | tr ',' ' ' ) |
| 1564 |
res=$( RunWithCommonArgs nquire -url "$base" epost.fcgi -db "$dbase" -id "$uids" ) |
| 1565 |
if [ -n "$res" ] |
| 1566 |
then |
| 1567 |
err="" |
| 1568 |
wenv="" |
| 1569 |
qkey="" |
| 1570 |
ParseMessage "$res" ePostResult wenv WebEnv qkey QueryKey |
| 1571 |
sch=$( RunWithFilterArgs nquire -url "$base" esearch.fcgi -db "$dbase" \ |
| 1572 |
-WebEnv "$wenv" -query_key "$qkey" -usehistory y -retmax 9999 < /dev/null ) |
| 1573 |
if [ -n "$sch" ] |
| 1574 |
then |
| 1575 |
echo "$sch" | xtract -pattern eSearchResult -block IdList -sep "\n" -element Id |
| 1576 |
fi |
| 1577 |
fi |
| 1578 |
done | |
| 1579 |
sort -n | uniq |
| 1580 |
} |
| 1581 |
|
| 1582 |
# ( will also be used to handle <Id> fields in message for any database ) |
| 1583 |
if [ -n "$rest" ] && [ "$isFilter" = true ] |
| 1584 |
then |
| 1585 |
|
| 1586 |
uids=$( FilterSOLR ) |
| 1587 |
|
| 1588 |
if [ "$log" = true ] |
| 1589 |
then |
| 1590 |
printf "\n" >&2 |
| 1591 |
fi |
| 1592 |
|
| 1593 |
nm="" |
| 1594 |
if [ -n "$uids" ] |
| 1595 |
then |
| 1596 |
nm=$( echo "$uids" | wc -l | tr -d ' ' ) |
| 1597 |
fi |
| 1598 |
|
| 1599 |
seconds_end=$(date "+%s") |
| 1600 |
seconds_elapsed=$((seconds_end - seconds_start)) |
| 1601 |
|
| 1602 |
echo "<ENTREZ_DIRECT>" |
| 1603 |
if [ -n "$dbase" ] |
| 1604 |
then |
| 1605 |
echo " <Db>${dbase}</Db>" |
| 1606 |
fi |
| 1607 |
if [ -n "$nm" ] |
| 1608 |
then |
| 1609 |
echo " <Count>${nm}</Count>" |
| 1610 |
else |
| 1611 |
echo " <Count>0</Count>" |
| 1612 |
fi |
| 1613 |
if [ -n "$stp" ] |
| 1614 |
then |
| 1615 |
stp=$(( stp + 1 )) |
| 1616 |
echo " <Step>${stp}</Step>" |
| 1617 |
fi |
| 1618 |
if [ -n "$err" ] |
| 1619 |
then |
| 1620 |
echo " <Error>${err}</Error>" |
| 1621 |
fi |
| 1622 |
if [ "$timer" = true ] && [ -n "$seconds_elapsed" ] |
| 1623 |
then |
| 1624 |
echo " <Elapsed>${seconds_elapsed}</Elapsed>" |
| 1625 |
fi |
| 1626 |
|
| 1627 |
# instantiate UIDs within ENTREZ_DIRECT message |
| 1628 |
echo "$uids" | |
| 1629 |
grep '.' | |
| 1630 |
while read uid |
| 1631 |
do |
| 1632 |
echo " <Id>${uid}</Id>" |
| 1633 |
done |
| 1634 |
|
| 1635 |
echo "</ENTREZ_DIRECT>" |
| 1636 |
|
| 1637 |
exit 0 |
| 1638 |
fi |
| 1639 |
|
| 1640 |
if [ "$dbase" = "pubmed" ] && [ "$isFilter" = true ] |
| 1641 |
then |
| 1642 |
|
| 1643 |
if [ -n "$query" ] && [ -n "$qury" ] |
| 1644 |
then |
| 1645 |
qury=$( echo "(${qury}) AND ${query}" ) |
| 1646 |
fi |
| 1647 |
|
| 1648 |
num=$( ecollect -db pubmed -count "${qury}" -reldate "$reldate" -mindate "$mindate" -maxdate "$maxdate" -datetype "$datetype" -tranquil < /dev/null ) |
| 1649 |
|
| 1650 |
echo "<ENTREZ_DIRECT>" |
| 1651 |
if [ -n "$dbase" ] |
| 1652 |
then |
| 1653 |
echo " <Db>${dbase}</Db>" |
| 1654 |
fi |
| 1655 |
echo " <Query>${qury}</Query>" |
| 1656 |
if [ -n "$mindate" ] |
| 1657 |
then |
| 1658 |
echo " <MinDate>${mindate}</MinDate>" |
| 1659 |
fi |
| 1660 |
if [ -n "$maxdate" ] |
| 1661 |
then |
| 1662 |
echo " <MaxDate>${maxdate}</MaxDate>" |
| 1663 |
fi |
| 1664 |
if [ -n "$reldate" ] |
| 1665 |
then |
| 1666 |
echo " <RelDate>${reldate}</RelDate>" |
| 1667 |
fi |
| 1668 |
if [ -n "$datetype" ] |
| 1669 |
then |
| 1670 |
echo " <DateType>${datetype}</DateType>" |
| 1671 |
fi |
| 1672 |
if [ -n "$num" ] |
| 1673 |
then |
| 1674 |
echo " <Count>${num}</Count>" |
| 1675 |
else |
| 1676 |
echo " <Count>0</Count>" |
| 1677 |
fi |
| 1678 |
if [ -n "$stp" ] |
| 1679 |
then |
| 1680 |
stp=$(( stp + 1 )) |
| 1681 |
echo " <Step>${stp}</Step>" |
| 1682 |
fi |
| 1683 |
if [ -n "$err" ] |
| 1684 |
then |
| 1685 |
echo " <Error>${err}</Error>" |
| 1686 |
fi |
| 1687 |
if [ "$timer" = true ] && [ -n "$seconds_elapsed" ] |
| 1688 |
then |
| 1689 |
echo " <Elapsed>${seconds_elapsed}</Elapsed>" |
| 1690 |
fi |
| 1691 |
|
| 1692 |
echo "</ENTREZ_DIRECT>" |
| 1693 |
|
| 1694 |
exit 0 |
| 1695 |
fi |
| 1696 |
|
| 1697 |
if [ "$dbase" = "pubmed" ] |
| 1698 |
then |
| 1699 |
num="0" |
| 1700 |
# count is accurate even for SOLR-based PubMed server |
| 1701 |
tranquil=true |
| 1702 |
res=$( RunWithSearchArgs nquire -url "$base" esearch.fcgi -retmax 0 -db "$dbase" ) |
| 1703 |
if [ -n "$res" ] |
| 1704 |
then |
| 1705 |
res=$( |
| 1706 |
echo "$res" | |
| 1707 |
sed -e 's|<QueryTranslation>.*</QueryTranslation>||' | |
| 1708 |
sed -e 's|<TranslationSet>.*</TranslationSet>||' | |
| 1709 |
sed -e 's|<TranslationStack>.*</TranslationStack>||' | |
| 1710 |
grep '.' | sed -e "s|$(printf '\t')| |" |
| 1711 |
) |
| 1712 |
num=$( echo "$res" | xtract -pattern eSearchResult -element Count ) |
| 1713 |
|
| 1714 |
# decodeXML, then encodeXML (but do not reencode double-quote as ") |
| 1715 |
query=$( echo "$query" | sed -e "s/\&/\&/; s/\>/>/; s/\</</; s/\'/'/g" -e 's/\"/"/g' ) |
| 1716 |
query=$( echo "$query" | sed -e "s/\&/\&/; s/>/\>/; s/</\</; s/'/\'/g" ) |
| 1717 |
|
| 1718 |
# WriteEDirect with Query field |
| 1719 |
|
| 1720 |
seconds_end=$(date "+%s") |
| 1721 |
seconds_elapsed=$((seconds_end - seconds_start)) |
| 1722 |
|
| 1723 |
echo "<ENTREZ_DIRECT>" |
| 1724 |
echo " <Db>${dbase}</Db>" |
| 1725 |
echo " <Query>${query}</Query>" |
| 1726 |
if [ -n "$mindate" ] |
| 1727 |
then |
| 1728 |
echo " <MinDate>${mindate}</MinDate>" |
| 1729 |
fi |
| 1730 |
if [ -n "$maxdate" ] |
| 1731 |
then |
| 1732 |
echo " <MaxDate>${maxdate}</MaxDate>" |
| 1733 |
fi |
| 1734 |
if [ -n "$reldate" ] |
| 1735 |
then |
| 1736 |
echo " <RelDate>${reldate}</RelDate>" |
| 1737 |
fi |
| 1738 |
if [ -n "$datetype" ] |
| 1739 |
then |
| 1740 |
echo " <DateType>${datetype}</DateType>" |
| 1741 |
fi |
| 1742 |
if [ -n "$num" ] |
| 1743 |
then |
| 1744 |
echo " <Count>${num}</Count>" |
| 1745 |
else |
| 1746 |
echo " <Count>0</Count>" |
| 1747 |
fi |
| 1748 |
if [ -n "$stp" ] |
| 1749 |
then |
| 1750 |
stp=$(( stp + 1 )) |
| 1751 |
echo " <Step>${stp}</Step>" |
| 1752 |
fi |
| 1753 |
if [ -n "$err" ] |
| 1754 |
then |
| 1755 |
echo " <Error>${err}</Error>" |
| 1756 |
fi |
| 1757 |
if [ "$quick" = true ] || [ "$quickx" = "Y" ] |
| 1758 |
then |
| 1759 |
echo " <Quick>Y</Quick>" |
| 1760 |
fi |
| 1761 |
if [ "$debug" = true ] || [ "$debugx" = "Y" ] |
| 1762 |
then |
| 1763 |
echo " <Debug>Y</Debug>" |
| 1764 |
fi |
| 1765 |
if [ "$log" = true ] || [ "$logx" = "Y" ] |
| 1766 |
then |
| 1767 |
echo " <Log>Y</Log>" |
| 1768 |
fi |
| 1769 |
if [ "$timer" = true ] && [ -n "$seconds_elapsed" ] |
| 1770 |
then |
| 1771 |
echo " <Elapsed>${seconds_elapsed}</Elapsed>" |
| 1772 |
fi |
| 1773 |
echo "</ENTREZ_DIRECT>" |
| 1774 |
fi |
| 1775 |
|
| 1776 |
exit 0 |
| 1777 |
fi |
| 1778 |
|
| 1779 |
# normal query |
| 1780 |
|
| 1781 |
err="" |
| 1782 |
num="" |
| 1783 |
res=$( RunWithSearchArgs nquire -url "$base" esearch.fcgi -retmax 0 -usehistory y -db "$dbase" ) |
| 1784 |
|
| 1785 |
if [ -n "$res" ] |
| 1786 |
then |
| 1787 |
res=$( echo "$res" | sed -e 's|<TranslationStack>.*</TranslationStack>||' ) |
| 1788 |
ParseMessage "$res" eSearchResult web_env WebEnv qry_key QueryKey num Count |
| 1789 |
fi |
| 1790 |
|
| 1791 |
WriteEDirect "$dbase" "$web_env" "$qry_key" "$num" "$stp" "$err" |
| 1792 |
|
| 1793 |
exit 0 |
| 1794 |
|