Debian Codegraph @

archive-pubmed

raw
1 #!/bin/bash
2
3 # Public domain notice for all NCBI EDirect scripts is located at:
4 # https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.Public_Domain_Notice
5
6 # archive-pubmed
7
8 total_start=$(date "+%s")
9
10 pth=$( dirname "$0" )
11
12 case "$pth" in
13 /* )
14 ;; # already absolute
15 * )
16 pth=$(cd "$pth" && pwd)
17 ;;
18 esac
19
20 case ":$PATH:" in
21 *:"$pth":* )
22 ;;
23 * )
24 PATH="$PATH:$pth"
25 export PATH
26 ;;
27 esac
28
29 # database-specific parameters
30
31 dbase="pubmed"
32 recname="PubmedArticle"
33 dotmaxIdx="200"
34 dotmaxInv="10"
35 fields="AUTH FAUT LAUT ANUM INVR INUM CSRT JOUR LANG VOL ISS PAGE DATE YEAR DOI MESH CODE TREE SUBH SUBS KYWD PAIR PROP PTYP RDAT SIZE TIAB TITL UID"
36
37 # control flags set by command-line arguments
38
39 useFtp=true
40 useHttps=false
41 noAspera=false
42 stem=false
43
44 info=false
45
46 clean=false
47 scrap=false
48 scrub=false
49 scour=false
50 erase=false
51 zap=false
52
53 datafiles=true
54 download=true
55 populate=true
56
57 justtest=false
58 justmiss=false
59
60 e2index=false
61 e2invert=false
62 e2collect=false
63 e2merge=false
64 e2post=false
65
66 while [ $# -gt 0 ]
67 do
68 case "$1" in
69 download | -download )
70 download=true
71 populate=false
72 shift
73 ;;
74 verify | -verify )
75 datafiles=false
76 download=false
77 populate=false
78 justtest=true
79 shift
80 ;;
81 missing | -missing )
82 datafiles=false
83 download=false
84 populate=false
85 justmiss=true
86 shift
87 ;;
88 daily | -daily )
89 e2index=true
90 e2invert=true
91 datafiles=true
92 shift
93 ;;
94 index | -index | reindex | -reindex )
95 e2index=true
96 e2invert=true
97 e2collect=true
98 e2merge=true
99 e2post=true
100 datafiles=true
101 shift
102 ;;
103 stem | -stem | stemmed | -stemmed )
104 stem=true
105 shift
106 ;;
107 clean | -clean | clear | -clear )
108 # delete Indices contents and Increment files
109 clean=true
110 shift
111 ;;
112 scrap | -scrap )
113 # only delete Postings directories
114 scrap=true
115 shift
116 ;;
117 scrub | -scrub )
118 clean=true
119 # and delete Postings directories
120 scrub=true
121 shift
122 ;;
123 scour | -scour )
124 clean=true
125 scrub=true
126 # and delete Data, Archive, and Sentinels directories
127 scour=true
128 shift
129 ;;
130 erase | -erase )
131 clean=true
132 scrub=true
133 scour=true
134 # and delete Extras directory contents
135 erase=true
136 shift
137 ;;
138 zap | -zap )
139 clean=true
140 scrub=true
141 scour=true
142 erase=true
143 # and delete Source records and all remaining directories
144 zap=true
145 shift
146 ;;
147 -info )
148 info=true
149 shift
150 ;;
151 -ftp )
152 useFtp=true
153 useHttps=false
154 noAspera=true
155 export EDIRECT_NO_ASPERA=true
156 shift
157 ;;
158 -http | -https )
159 useFtp=false
160 useHttps=true
161 shift
162 ;;
163 * )
164 break
165 ;;
166 esac
167 done
168
169 if [ "$clean" == true ] && [ "$e2index" == true ]
170 then
171 echo "ERROR: Cleaning and indexing must be done in separate commands, EXITING" >&2
172 exit 1
173 fi
174
175 if [ "$zap" = true ]
176 then
177 pm-clean -db "$dbase" -zap
178 exit 0
179 fi
180
181 if [ "$erase" = true ]
182 then
183 pm-clean -db "$dbase" -erase
184 exit 0
185 fi
186
187 if [ "$scour" = true ]
188 then
189 pm-clean -db "$dbase" -scour
190 exit 0
191 fi
192
193 if [ "$scrub" = true ]
194 then
195 pm-clean -db "$dbase" -scrub
196 exit 0
197 fi
198
199 if [ "$scrap" = true ]
200 then
201 pm-clean -db "$dbase" -scrap
202 exit 0
203 fi
204
205 if [ "$clean" = true ]
206 then
207 pm-clean -db "$dbase" -clean
208 exit 0
209 fi
210
211 if [ "$stem" = true ]
212 then
213 fields=$( echo "$fields STEM" )
214 fi
215
216 # get path to local folder
217
218 osname=$( uname -s | sed -e 's/_NT-.*$/_NT/; s/^MINGW[0-9]*/CYGWIN/' )
219
220 GetLocalArchiveFolder() {
221
222 dbs="$1"
223 fld="$2"
224
225 # find selected local archive folder from environment variables or configuration file
226 target=$( rchive -local "$dbs" "$fld" )
227
228 if [ -z "$target" ] || [ "$target" = "" ]
229 then
230 echo "ERROR: Must supply path to local data by setting EDIRECT_LOCAL_ARCHIVE environment variable" >&2
231 exit 1
232 fi
233
234 if [ -n "$osname" ] && [ "$osname" = "CYGWIN_NT" -a -x /bin/cygpath ]
235 then
236 target=$( cygpath -w "$target" )
237 fi
238
239 # remove trailing slash
240 target=${target%/}
241
242 echo "$target"
243 }
244
245 date >&2
246 echo "" >&2
247
248 pm-setup -db "$dbase"
249
250 echo "Preparing Drives" >&2
251 pm-prepare -db "$dbase"
252 echo "" >&2
253
254 archiveBase=$( GetLocalArchiveFolder "$dbase" "Archive" )
255 dataBase=$( GetLocalArchiveFolder "$dbase" "Data" )
256 extrasBase=$( GetLocalArchiveFolder "$dbase" "Extras" )
257 indexBase=$( GetLocalArchiveFolder "$dbase" "Index" )
258 invertBase=$( GetLocalArchiveFolder "$dbase" "Invert" )
259 mergedBase=$( GetLocalArchiveFolder "$dbase" "Merged" )
260 postingsBase=$( GetLocalArchiveFolder "$dbase" "Postings" )
261 sourceBase=$( GetLocalArchiveFolder "$dbase" "Source" )
262
263 DAT=""
264 DWN=""
265 POP=""
266
267 IDX=""
268 INV=""
269 COL=""
270 MRG=""
271 PST=""
272
273 DoInfo() {
274
275 ret="0"
276
277 if [ -d "${sourceBase}" ]
278 then
279 cd "${sourceBase}"
280
281 current=$(
282 ls *.xml.gz 2>/dev/null |
283 cut -c 7-8 | sort -n | tail -n 1
284 )
285
286 latest=$(
287 nquire -lst ftp://ftp.ncbi.nlm.nih.gov/pubmed/baseline |
288 grep ".xml.gz" | grep -v ".md5" |
289 cut -c 7-8 | sort -n | tail -n 1
290 )
291
292 if [ -n "$current" ] && [ -n "$latest" ]
293 then
294 if [ "$current" != "$latest" ]
295 then
296 echo "ERROR: Need to update PubMed release files from 20${current} to 20${latest} by first running archive-pubmed -zap" >&2
297 ret="1"
298 else
299 echo "PubMed files for 20${current} are using current release" >&2
300 fi
301 elif [ -z "$current" ]
302 then
303 echo "Missing current files" >&2
304 elif [ -z "$latest" ]
305 then
306 echo "Missing latest files" >&2
307 fi
308 fi
309
310 echo "$ret"
311 }
312
313 if [ "$info" = true ]
314 then
315
316 ignore=$( DoInfo )
317
318 exit 0
319 fi
320
321 oldyear=$( DoInfo )
322
323 if [ -n "$oldyear" ] && [ "$oldyear" != "0" ]
324 then
325 echo "" >&2
326 echo "Unable to proceed with mixed years, run archive-pubmed -zap first" >&2
327 echo "" >&2
328 exit 1
329 fi
330
331 DoMeSHTree() {
332
333 year=$(
334 nquire -get https://nlmpubs.nlm.nih.gov projects/mesh/MESH_FILES/xmlmesh |
335 xtract -mixed -pattern body -block a -if a -contains ".xml" -tab "\n" -terms a |
336 sort -Vr | head -n 1 | sed 's/[a-z.]//g'
337 )
338
339 if [ -z "$year" ]
340 then
341 year="$(date +%Y)"
342 fi
343
344 if [ ! -f "desc${year}.xml" ]
345 then
346 echo "desc${year}.xml"
347 if [ "$useFtp" = true ]
348 then
349 nquire -dwn "ftp://nlmpubs.nlm.nih.gov" "online/mesh/MESH_FILES/xmlmesh" "desc${year}.gz"
350 elif [ "$useHttps" = true ]
351 then
352 nquire -bulk -get https://nlmpubs.nlm.nih.gov projects/mesh/MESH_FILES/xmlmesh desc${year}.gz > desc${year}.gz
353 fi
354 sleep 1
355 if [ ! -f "desc${year}.gz" ]
356 then
357 echo "ERROR - Problem downloading desc${year}.gz" >&2
358 else
359 gunzip -q desc${year}.gz
360 fi
361 sleep 1
362 if [ ! -f "desc${year}.xml" ] && [ -f "desc${year}" ]
363 then
364 mv desc${year} desc${year}.xml
365 fi
366 if [ ! -f "desc${year}.xml" ]
367 then
368 echo "ERROR - Problem converting desc${year}.xml" >&2
369 else
370 chmod og-wx desc${year}.xml
371 chmod u-x desc${year}.xml
372 fi
373 fi
374
375 if [ ! -f "pa${year}.xml" ]
376 then
377 echo "pa${year}.xml"
378 if [ "$useFtp" = true ]
379 then
380 nquire -dwn "ftp://nlmpubs.nlm.nih.gov" "online/mesh/MESH_FILES/xmlmesh" "pa${year}.xml"
381 elif [ "$useHttps" = true ]
382 then
383 nquire -bulk -get https://nlmpubs.nlm.nih.gov/projects mesh/MESH_FILES/xmlmesh pa${year}.xml > pa${year}.xml
384 fi
385 fi
386
387 if [ ! -f "qual${year}.xml" ]
388 then
389 echo "qual${year}.xml"
390 if [ "$useFtp" = true ]
391 then
392 nquire -dwn "ftp://nlmpubs.nlm.nih.gov" "online/mesh/MESH_FILES/xmlmesh" "qual${year}.xml"
393 elif [ "$useHttps" = true ]
394 then
395 nquire -bulk -get https://nlmpubs.nlm.nih.gov/projects mesh/MESH_FILES/xmlmesh qual${year}.xml > qual${year}.xml
396 fi
397 fi
398
399 if [ ! -f "supp${year}.xml" ]
400 then
401 echo "supp${year}.xml"
402 if [ "$useFtp" = true ]
403 then
404 nquire -dwn "ftp://nlmpubs.nlm.nih.gov" "online/mesh/MESH_FILES/xmlmesh" "supp${year}.zip"
405 elif [ "$useHttps" = true ]
406 then
407 nquire -bulk -get https://nlmpubs.nlm.nih.gov/projects mesh/MESH_FILES/xmlmesh supp${year}.zip > supp${year}.zip
408 fi
409
410 if [ -f "supp${year}.zip" ]
411 then
412 unzip -qq supp${year}.zip
413 rm supp${year}.zip
414 chmod og-wx supp${year}.xml
415 chmod u-x supp${year}.xml
416 fi
417 fi
418
419 if [ ! -f "meshconv.xml" ]
420 then
421 rm -f meshtemp.xml
422 if [ -f "supp${year}.xml" ]
423 then
424 cat supp${year}.xml |
425 xtract -wrp "Set,Rec" -pattern SupplementalRecord \
426 -if "SupplementalRecord@SCRClass" -eq 1 \
427 -or "SupplementalRecord@SCRClass" -eq 3 \
428 -wrp "Code" -element "SupplementalRecord/SupplementalRecordUI" \
429 -wrp "Name" -encode "SupplementalRecordName/String" \
430 -wrp "Term" -encode "Term/String" > meshtemp.xml
431 fi
432
433 if [ -f "desc${year}.xml" ]
434 then
435 cat desc${year}.xml |
436 xtract -wrp "Set,Rec" -pattern DescriptorRecord \
437 -wrp "Code" -element "DescriptorRecord/DescriptorUI" \
438 -wrp "Name" -first "DescriptorName/String" \
439 -wrp "Term" -encode "Term/String" \
440 -wrp "Tree" -element "TreeNumberList/TreeNumber" >> meshtemp.xml
441 fi
442
443 if [ -f "meshtemp.xml" ]
444 then
445 cat meshtemp.xml | xtract -wrp Set -pattern Rec -sort Code |
446 transmute -format indent > meshconv.xml
447 rm meshtemp.xml
448 fi
449 fi
450
451 if [ -f "meshconv.xml" ]
452 then
453 if [ ! -f "meshtree.txt" ]
454 then
455 cat meshconv.xml |
456 xtract -pattern Rec -if Tree -element Code -sep "," -element Tree > meshtree.txt
457 fi
458
459 if [ ! -f "meshname.txt" ]
460 then
461 cat meshconv.xml |
462 xtract -pattern Rec -if Name -element Code -sep "," -element Name > meshname.txt
463 fi
464 fi
465 }
466
467 DoSerials() {
468
469 year=""
470
471 files=$(
472 # obtain names of base and update files for several years
473 nquire -bulk -get https://ftp.nlm.nih.gov projects/serfilelease |
474 sed -ne 's,.* href="\([^/"]*\)".*,\1,p' | grep -v marcxml
475 )
476
477 if [ -n "$files" ]
478 then
479 year=$(
480 # get latest year embedded in file names
481 echo "$files" | grep serfilebase | sort -Vr | head -n 1 |
482 sed -e 's/serfilebase.//' -e 's/.xml//'
483 )
484 if [ -n "$year" ]
485 then
486 # limit to serfilebase and serfile updates for current year
487 files=$( echo "$files" | grep "$year" )
488 fi
489 fi
490
491 basefile="serfilebase.${year}.xml"
492 updates=$( echo "$files" | grep -v serfilebase | sort -V )
493
494 if [ ! -f "serials.txt" ] && [ ! -s "$basefile" ]
495 then
496 echo "$basefile" >&2
497 nquire -bulk -get https://ftp.nlm.nih.gov projects/serfilelease "${basefile}" > $basefile
498 fi
499
500 if [ ! -f "serials.txt" ] && [ -s "$basefile" ]
501 then
502 echo "# ${basefile}" >> serials.txt
503 cat "$basefile" |
504 xtract -pattern NLMCatalogRecord -def "-" -element NlmUniqueID PublicationInfo/Country >> serials.txt
505 cat "$basefile" |
506 xtract -pattern DeleteCatalogRecord -block NlmUniqueID -element NlmUniqueID -lbl "-" -deq "\n" >> serials.txt
507 fi
508
509 if [ -f "serials.txt" ] && [ -n "$updates" ]
510 then
511 echo "$updates" |
512 while read serfile
513 do
514 if [ ! -s "$serfile" ]
515 then
516 echo "$serfile" >&2
517 nquire -bulk -get https://ftp.nlm.nih.gov projects/serfilelease "${serfile}" > $serfile
518 fi
519 if [ -s "$serfile" ]
520 then
521 if ! grep -Fq "$serfile" serials.txt
522 then
523 echo "# ${serfile}" >> serials.txt
524 cat "$serfile" |
525 xtract -pattern NLMCatalogRecord -def "-" -element NlmUniqueID PublicationInfo/Country >> serials.txt
526 cat "$serfile" |
527 xtract -pattern DeleteCatalogRecord -block NlmUniqueID -element NlmUniqueID -lbl "-" -deq "\n" >> serials.txt
528 fi
529 fi
530 done
531 fi
532 }
533
534 finish_jtas() {
535
536 tr -s ' ' |
537 sed -e 's/^ *//g' -e 's/ *$//g' |
538 sort-table -k 1,1f -k 3,3n -k 4,4nr -k 2,2f |
539 uniq -i |
540 awk -F '\t' '(NR == 1 || $1 != prev_key) { if (NR > 1) { print prev_line }; prev_key = $1; prev_line = $0 } END { print prev_line }' |
541 cut -f 1,2
542 }
543
544 multi_jtas() {
545
546 tr -s ' ' |
547 sed -e 's/^ *//g' -e 's/ *$//g' |
548 sort-table -k 1,1f -k 3,3n -k 4,4nr -k 2,2f |
549 uniq -i |
550 awk -F '\t' '(NR > 1 && $1 == prev_key && $4 == prev_flag) { print } (NR == 1 || $1 != prev_key) { print; prev_key = $1; prev_flag = $4 }' |
551 cut -f 1,2 | sort | uniq |
552 awk -F '\t' '{ if (NR == 1 || $1 != prev_key) { if (NR > 1) { print saved }; prev_key = $1; saved = $1 "\t" $2 } else { saved = saved " | " $2 } } END { print saved }'
553 }
554
555 JourCache() {
556
557 if [ "$useFtp" = true ]
558 then
559 nquire -ftp ftp.ncbi.nlm.nih.gov pubmed jourcache.xml
560 elif [ "$useHttps" = true ]
561 then
562 nquire -bulk -get https://ftp.ncbi.nlm.nih.gov pubmed jourcache.xml
563 fi
564 }
565
566 DoJournals() {
567
568 if [ ! -f "jourconv.xml" ]
569 then
570 if [ ! -f "jourcache.xml" ]
571 then
572 if [ -f "serials.txt" ]
573 then
574 JourCache |
575 grep -v DOCTYPE | grep -v ELEMENT | grep -v ATTLIST |
576 xtract -transfigure serials.txt \
577 -head "<JournalCache>" -tail "</JournalCache>" \
578 -pattern Journal -pkg Journal \
579 -block "Journal/*" -element "*" \
580 -block Journal -wrp Country -translate NlmUniqueID |
581 transmute -format > jourcache.xml
582 else
583 JourCache |
584 grep -v DOCTYPE | grep -v ELEMENT | grep -v ATTLIST |
585 transmute -format > jourcache.xml
586 fi
587 fi
588
589 if [ -f "jourcache.xml" ]
590 then
591 cat jourcache.xml |
592 xtract -set Set -pattern Journal \
593 -if Name -and MedAbbr \
594 -NAME Name -ABRV MedAbbr -ACTV ActivityFlag \
595 -group Name -pkg Rec \
596 -wrp Key -jour Name -wrp Abrv -jour "&ABRV" \
597 -wrp Indx -jour "&NAME" -wrp Name -element "&NAME" \
598 -wrp Type -lbl "1" -wrp Flag -element "&ACTV" \
599 -group MedAbbr -pkg Rec \
600 -wrp Key -jour MedAbbr -wrp Abrv -jour "&ABRV" \
601 -wrp Indx -jour "&NAME" -wrp Name -element "&NAME" \
602 -wrp Type -lbl "2" -wrp Flag -element "&ACTV" \
603 -group Alias \
604 -block Alias -pkg Rec \
605 -wrp Key -jour Alias -wrp Abrv -jour "&ABRV" \
606 -wrp Indx -jour "&NAME" -wrp Name -element "&NAME" \
607 -wrp Type -lbl "3" -wrp Flag -element "&ACTV" \
608 -group Journal -if "&ABRV" -equals "bioRxiv" \
609 -block Journal -pkg Rec \
610 -wrp Key -lbl "biorxiv.org" -wrp Abrv -jour "&ABRV" \
611 -wrp Indx -jour "&NAME" -wrp Name -element "&NAME" \
612 -wrp Type -lbl "3" -wrp Flag -element "&ACTV" \
613 -block Journal -pkg Rec \
614 -wrp Key -lbl "biorxivorg" -wrp Abrv -jour "&ABRV" \
615 -wrp Indx -jour "&NAME" -wrp Name -element "&NAME" \
616 -wrp Type -lbl "3" -wrp Flag -element "&ACTV" |
617 xtract -set Set -pattern Rec \
618 -group Rec \
619 -block Rec -pkg Rec \
620 -wrp Key -lower Key -wrp Abrv -element Abrv \
621 -wrp Indx -element Indx -wrp Name -element Name \
622 -wrp Type -element Type -wrp Flag -element Flag |
623 xtract -set Set -pattern Rec \
624 -group Rec \
625 -block Rec -pkg Rec \
626 -wrp Key -element Key -wrp Abrv -element Abrv \
627 -wrp Indx -element Indx -wrp Name -element Name \
628 -wrp Type -element Type -wrp Flag -element Flag \
629 -block Rec -if Key -starts-with "journal " -pkg Rec \
630 -wrp Key -pfx "<Key>the " -element Key -wrp Abrv -element Abrv \
631 -wrp Indx -element Indx -wrp Name -element Name \
632 -wrp Type -element Type -wrp Flag -element Flag \
633 -block Rec -if Key -starts-with "the journal " -pkg Rec \
634 -wrp Key -element "Key[5:]" -wrp Abrv -element Abrv \
635 -wrp Indx -element Indx -wrp Name -element Name \
636 -wrp Type -element Type -wrp Flag -element Flag |
637 transmute -format > jourconv.xml
638 fi
639 fi
640
641 if [ -f "jourconv.xml" ]
642 then
643 if [ ! -f "jourabrv.txt" ]
644 then
645 cat jourconv.xml | xtract -pattern Rec -element Key Abrv Type Flag | finish_jtas > jourabrv.txt
646 fi
647 if [ ! -f "jourindx.txt" ]
648 then
649 cat jourconv.xml | xtract -pattern Rec -element Key Indx Type Flag | finish_jtas > jourindx.txt
650 fi
651 if [ ! -f "journame.txt" ]
652 then
653 cat jourconv.xml | xtract -pattern Rec -element Key Name Type Flag | finish_jtas > journame.txt
654 fi
655 if [ ! -f "joursets.txt" ]
656 then
657 cat jourconv.xml | xtract -pattern Rec -element Key Name Type Flag | multi_jtas > joursets.txt
658 fi
659 if [ ! -f "jourmaps.xml" ] && [ -f "jourindx.txt" ]
660 then
661 cat jourindx.txt | tbl2xml -set JournalMaps -rec Journal Key Indx > jourmaps.xml
662 fi
663 fi
664 }
665
666 if [ "$datafiles" = true ]
667 then
668 seconds_start=$(date "+%s")
669
670 if [ -d "${extrasBase}" ]
671 then
672 cd "${extrasBase}"
673
674 echo "Downloading MeSH Tree" >&2
675 DoMeSHTree
676
677 echo "Downloading Serials" >&2
678 DoSerials
679
680 echo "Downloading Journals" >&2
681 DoJournals
682 fi
683
684 echo "Copying to Data Directory"
685 for fl in jourabrv.txt jourindx.txt journame.txt joursets.txt meshconv.xml meshname.txt meshtree.txt
686 do
687 if [ ! -f "${dataBase}/$fl" ] && [ -f "${extrasBase}/$fl" ]
688 then
689 cp "${extrasBase}/$fl" "${dataBase}/$fl"
690 fi
691 done
692
693 seconds_end=$(date "+%s")
694 seconds=$((seconds_end - seconds_start))
695 DAT=$seconds
696 echo "" >&2
697 echo "DAT $DAT seconds" >&2
698 echo "" >&2
699 sleep 1
700 fi
701
702 DownloadFTPorASP() {
703
704 fl="$1"
705 url="$2"
706
707 if [ "$noAspera" = true ]
708 then
709 echo "$fl" | nquire -dwn "${url}"
710 else
711 echo "$fl" | nquire -asp "${url}"
712 fi
713 }
714
715 DownloadOneByFTP() {
716
717 dir="$1"
718 fl="$2"
719
720 url="ftp.ncbi.nlm.nih.gov/pubmed/${dir}"
721
722 DownloadFTPorASP "$fl" "${url}"
723
724 # delete if file is present but empty
725 if [ -f "$fl" ] && [ ! -s "$fl" ]
726 then
727 rm -f "$fl"
728 fi
729
730 # retry if no file
731 if [ ! -f "$fl" ]
732 then
733 sleep 10
734 echo "First Failed Download Retry" >&2
735 DownloadFTPorASP "$fl" "${url}"
736 fi
737
738 # retry again if still no file
739 if [ ! -f "$fl" ]
740 then
741 sleep 20
742 echo "Second Failed Download Retry" >&2
743 DownloadFTPorASP "$fl" "${url}"
744 fi
745
746 # retry once more if still no file, using -dwn instead of -asp
747 if [ ! -f "$fl" ]
748 then
749 sleep 30
750 echo "Third Failed Download Retry" >&2
751 echo "$fl" | nquire -dwn "${url}"
752 fi
753
754 # verify contents
755 if [ -s "$fl" ]
756 then
757 errs=$( (gunzip -c "$fl" | xtract -mixed -verify) 2>&1 )
758 if [ -n "$errs" ]
759 then
760 # delete and retry one more time
761 rm -f "$fl"
762 sleep 10
763 echo "Invalid Contents Retry" >&2
764 DownloadFTPorASP "$fl" "${url}"
765 if [ -s "$fl" ]
766 then
767 errs=$( (gunzip -c "$fl" | xtract -mixed -verify) 2>&1 )
768 if [ -n "$errs" ]
769 then
770 rm -f "$fl"
771 frst=$( echo "$errs" | head -n 1 )
772 echo "ERROR invalid file '$fl' deleted, errors start with '$frst'" >&2
773 fi
774 else
775 echo "Download Attempts Failed" >&2
776 fi
777 fi
778 else
779 rm -f "$fl"
780 echo "Download of '$fl' Failed" >&2
781 fi
782 }
783
784 DownloadOneByHTTPS() {
785
786 dir="$1"
787 fl="$2"
788
789 url="https://ftp.ncbi.nlm.nih.gov/pubmed/${dir}"
790
791 nquire -bulk -get "${url}" "$fl" > "$fl"
792
793 # delete if file is present but empty
794 if [ -f "$fl" ] && [ ! -s "$fl" ]
795 then
796 rm -f "$fl"
797 fi
798
799 # retry if no file
800 if [ ! -f "$fl" ]
801 then
802 sleep 10
803 echo "First Failed Download Retry" >&2
804 nquire -bulk -get "${url}" "$fl" > "$fl"
805 fi
806
807 # retry again if still no file
808 if [ ! -f "$fl" ]
809 then
810 sleep 20
811 echo "Second Failed Download Retry" >&2
812 nquire -bulk -get "${url}" "$fl" > "$fl"
813 fi
814
815 # retry once more if still no file
816 if [ ! -f "$fl" ]
817 then
818 sleep 30
819 echo "Third Failed Download Retry" >&2
820 nquire -bulk -get "${url}" "$fl" > "$fl"
821 fi
822
823 # verify contents
824 if [ -s "$fl" ]
825 then
826 errs=$( (gunzip -c "$fl" | xtract -mixed -verify) 2>&1 )
827 if [ -n "$errs" ]
828 then
829 # delete and retry one more time
830 rm -f "$fl"
831 sleep 10
832 echo "Invalid Contents Retry" >&2
833 nquire -bulk -get "${url}" "$fl" > "$fl"
834 if [ -s "$fl" ]
835 then
836 errs=$( (gunzip -c "$fl" | xtract -mixed -verify) 2>&1 )
837 if [ -n "$errs" ]
838 then
839 rm -f "$fl"
840 frst=$( echo "$errs" | head -n 1 )
841 echo "ERROR invalid file '$fl' deleted, errors start with '$frst'" >&2
842 fi
843 fi
844 fi
845 else
846 rm -f "$fl"
847 echo "Download of '$fl' Failed" >&2
848 fi
849 }
850
851 DownloadSection() {
852
853 dir="$1"
854
855 if [ "$useFtp" = true ]
856 then
857 nquire -lst ftp.ncbi.nlm.nih.gov pubmed "$dir" |
858 grep -v ".md5" | grep "xml.gz" |
859 skip-if-file-exists |
860 while read fl
861 do
862 sleep 1
863 echo "$fl" >&2
864 DownloadOneByFTP "$dir" "$fl"
865 done
866 elif [ "$useHttps" = true ]
867 then
868 nquire -get https://ftp.ncbi.nlm.nih.gov pubmed "$dir" |
869 xtract -pattern a -if a -starts-with pubmed -and a -ends-with ".xml.gz" -element a |
870 skip-if-file-exists |
871 while read fl
872 do
873 sleep 1
874 echo "$fl" >&2
875 DownloadOneByHTTPS "$dir" "$fl"
876 done
877 fi
878 }
879
880 if [ "$download" = true ]
881 then
882 seconds_start=$(date "+%s")
883 echo "Downloading New PubMed Files" >&2
884
885 if [ -d "${sourceBase}" ]
886 then
887 cd "${sourceBase}"
888
889 DownloadSection "baseline"
890 if [ $? -ne 0 ]
891 then
892 DownloadSection "baseline"
893 fi
894 DownloadSection "updatefiles"
895 if [ $? -ne 0 ]
896 then
897 DownloadSection "updatefiles"
898 fi
899 fi
900
901 seconds_end=$(date "+%s")
902 seconds=$((seconds_end - seconds_start))
903 DWN=$seconds
904 echo "" >&2
905 echo "DWN $DWN seconds" >&2
906 echo "" >&2
907 sleep 1
908 fi
909
910 CheckSection() {
911
912 dir="$1"
913
914 if [ "$useFtp" = true ]
915 then
916 nquire -lst ftp.ncbi.nlm.nih.gov pubmed "$dir" |
917 grep -v ".md5" | grep "xml.gz" |
918 skip-if-file-exists |
919 while read fl
920 do
921 echo "$fl" >&2
922 done
923 elif [ "$useHttps" = true ]
924 then
925 nquire -get https://ftp.ncbi.nlm.nih.gov pubmed "$dir" |
926 xtract -pattern a -if a -starts-with pubmed -and a -ends-with ".xml.gz" -element a |
927 skip-if-file-exists |
928 while read fl
929 do
930 echo "$fl" >&2
931 done
932 fi
933 }
934
935 if [ "$justmiss" = true ]
936 then
937 seconds_start=$(date "+%s")
938 echo "Looking for Missing PubMed Files" >&2
939
940 if [ -d "${sourceBase}" ]
941 then
942 cd "${sourceBase}"
943
944 CheckSection "baseline"
945 CheckSection "updatefiles"
946 fi
947
948 seconds_end=$(date "+%s")
949 seconds=$((seconds_end - seconds_start))
950 echo "" >&2
951 echo "$seconds seconds" >&2
952 echo "" >&2
953 exit 0
954 fi
955
956 if [ "$justtest" = true ]
957 then
958 seconds_start=$(date "+%s")
959 echo "Verifing PubMed Archive" >&2
960
961 if [ -d "${sourceBase}" ]
962 then
963 cd "${sourceBase}"
964
965 for fl in *.xml.gz
966 do
967 printf "."
968 # verify contents
969 if [ -s "$fl" ]
970 then
971 errs=$( (gunzip -c "$fl" | xtract -mixed -verify) 2>&1 )
972 if [ -n "$errs" ]
973 then
974 printf "\n"
975 echo "Invalid Contents '$fl'" >&2
976 fi
977 else
978 printf "\n"
979 echo "Empty file '$fl'" >&2
980 fi
981 done
982 printf "\n"
983 fi
984
985 seconds_end=$(date "+%s")
986 seconds=$((seconds_end - seconds_start))
987 echo "" >&2
988 echo "$seconds seconds" >&2
989 echo "" >&2
990 exit 0
991 fi
992
993 ReportVersioned() {
994 inp="$1"
995 pmidlist=.TO-REPORT
996 xtract -input "$inp" -pattern PubmedArticle \
997 -block MedlineCitation/PMID -if "@Version" -gt 1 -element "PMID" < /dev/null |
998 sort -n | uniq > $pmidlist
999 if [ -s $pmidlist ]
1000 then
1001 cat "$pmidlist" >> "${archiveBase}/versioned.uid"
1002 fi
1003 rm $pmidlist
1004 }
1005
1006 PMStash() {
1007
1008 fl="$1"
1009
1010 rm -f "versioned.xml.gz"
1011 rm -f "versioned.snt"
1012
1013 needToReport=true
1014 timeout=100
1015 if [ "$pma2pme" = true ]
1016 then
1017 timeout=200
1018 fi
1019
1020 base=${fl%.xml.gz}
1021 secnds_start=$(date "+%s")
1022 echo "$base.xml"
1023
1024 gunzip -c "$fl" |
1025 transmute -strict -normalize pubmed |
1026 transmute -compress -strict -wrp PubmedArticleSet \
1027 -pattern "PubmedArticleSet/*" -format flush > "$base.xml"
1028 rchive -gzip -db "$dbase" -input "$base.xml" \
1029 -archive "${archiveBase}" "${indexBase}" "${invertBase}" \
1030 -index MedlineCitation/PMID^Version -pattern PubmedArticle < /dev/null
1031
1032 cat "$base.xml" |
1033 xtract -pattern DeleteCitation -block PMID -tab "\n" -sep "." -element "PMID" |
1034 sort -n | uniq |
1035 rchive -gzip -db "$dbase" -delete "${archiveBase}" "${indexBase}" "${invertBase}"
1036
1037 ReportVersioned "$base.xml"
1038
1039 touch "${archiveBase}/Sentinels/$base.snt"
1040 rm "$base.xml"
1041
1042 secnds_end=$(date "+%s")
1043 secnds=$((secnds_end - secnds_start))
1044 if [ "$needToReport" = true ]
1045 then
1046 if [ "$secnds" -gt "$timeout" ]
1047 then
1048 echo ""
1049 echo "ARCHIVING IS SLOWER THAN EXPECTED."
1050 echo ""
1051 echo "PLEASE ENSURE THAT ANTIVIRUS SCANNING AND CONTENT INDEXING ARE DISABLED,"
1052 echo "AND THAT TRIM SUPPORT IS ENABLED FOR THE SOLID STATE DRIVE."
1053 echo ""
1054 if [ "$osname" = "Darwin" ]
1055 then
1056 master=${archive%/Archive/}
1057 echo " sudo mdutil -i off ${master}"
1058 echo " sudo mdutil -E ${master}"
1059 echo " sudo touch ${master}/.fseventsd/no_log"
1060 echo ""
1061 fi
1062 needToReport=false
1063 fi
1064 fi
1065 }
1066
1067 if [ "$populate" = true ]
1068 then
1069 seconds_start=$(date "+%s")
1070 echo "Populating PubMed Archive" >&2
1071
1072 if [ -d "${sourceBase}" ]
1073 then
1074 cd "${sourceBase}"
1075
1076 first=""
1077 last=""
1078
1079 for fl in *.xml.gz
1080 do
1081 base=${fl%.xml.gz}
1082 if [ -z "$first" ]
1083 then
1084 first="$base"
1085 fi
1086 last="$base"
1087 done
1088
1089 if [ -n "$first" ] && [ -n "$last" ]
1090 then
1091 fst=$( echo "$first" | cut -c 7-8 )
1092 lst=$( echo "$last" | cut -c 7-8 )
1093 if [ -n "$fst" ] && [ -n "$lst" ] && [ "$fst" != "$lst" ]
1094 then
1095 echo "" >&2
1096 echo "ERROR: Local PubMed archive contains a mixture of years, from 20${fst} to 20${lst}" >&2
1097 echo "Please remove files from previous years, and run archive-pubmed -scour to clear stale data," >&2
1098 echo "before rerunning archive-pubmed -index" >&2
1099 echo "" >&2
1100 fi
1101 fi
1102
1103 for fl in *.xml.gz
1104 do
1105 base=${fl%.xml.gz}
1106 # skip if sentinel present or if file is present but empty
1107 if [ ! -f "${archiveBase}/Sentinels/$base.snt" ] && [ -s "$fl" ]
1108 then
1109 PMStash "$fl"
1110 fi
1111 done
1112 fi
1113
1114 echo "Refreshing Versioned Records"
1115 pm-refresh "${archiveBase}" "${indexBase}" "${invertBase}"
1116
1117 seconds_end=$(date "+%s")
1118 seconds=$((seconds_end - seconds_start))
1119 POP=$seconds
1120 echo "" >&2
1121 echo "POP $POP seconds" >&2
1122 echo "" >&2
1123 sleep 1
1124 fi
1125
1126 # check archive, printing "OK" from "OK Adeyemo" if record is successfully retrieved
1127 okay=$( echo 18810966 |
1128 xfetch -db pubmed |
1129 xtract -pattern Author -if Affiliation -contains Medicine -element Initials )
1130 if [ "$okay" = "OK" ]
1131 then
1132 echo "Archive is $okay" >&2
1133 echo "" >&2
1134 fi
1135
1136 currentDate=$(date +%Y)
1137
1138 # variable contains pubmed-database-specific xtract indexing instructions
1139 # do not quote EOS, or it will suppress expansion of currentDate variable within the "here" document
1140 # no double quotes needed around $currentDate
1141 read -r -d '' idxtxt <<- EOS
1142 xtract -set IdxDocumentSet -rec IdxDocument \
1143 -pattern PubmedArticle -UID MedlineCitation/PMID -LEN -len "*" -YR "()" -HS "()" \
1144 -wrp IdxUid -element "&UID" -clr -rst -tab "" \
1145 -group PubmedArticle -pkg IdxSearchFields \
1146 -block PubmedArticle -wrp UID -pad "&UID" \
1147 -block PubmedArticle -wrp SIZE -inc "&LEN" \
1148 -block PubmedArticle -YR -year "PubDate/*" \
1149 -block PubmedData/History -MN -min Year \
1150 -block PubmedArticle -wrp YEAR -first "&YR,&MN" \
1151 -block PubmedArticle -if PubDate/Month -unit PubDate -wrp DATE -reg "/" -exp " " -date "*" \
1152 -block PubmedArticle -unless PubDate/Month \
1153 -subset PubMedPubDate -if "@PubStatus" -equals pubmed -unit PubMedPubDate -wrp DATE -reg "/" -exp " " -date "*" \
1154 -block PubmedArticle -unit DateRevised -wrp RDAT -reg "/" -exp " " -date "*" \
1155 -block MedlineJournalInfo -wrp JOUR -element MedlineTA NlmUniqueID ISSNLinking \
1156 -block Article/Journal -wrp JOUR -jour Title ISOAbbreviation -element ISSN -wrp VOL -element Volume -wrp ISS -element Issue \
1157 -block Article/Pagination -wrp PAGE -page MedlinePgn \
1158 -block Article/Language -wrp LANG -element Language \
1159 -block AuthorList -wrp ANUM -num Author/LastName \
1160 -block AuthorList/Author -position first -wrp FAUT -sep " " -author LastName,Initials \
1161 -block AuthorList/Author -if LastName -sep " " -LAST LastName,Initials \
1162 -block PubmedArticle -if "&LAST" -wrp LAUT -author "&LAST" \
1163 -block AuthorList/Author -wrp CSRT -prose CollectiveName \
1164 -block AuthorList/Author -wrp AUTH -sep " " -author LastName,Initials \
1165 -block InvestigatorList/Investigator -wrp INVR -sep " " -author LastName,Initials \
1166 -block PubmedArticle -wrp TITL -indexer ArticleTitle \
1167 -block PubmedArticle -wrp TIAB -indexer ArticleTitle,Abstract/AbstractText \
1168 -block PubmedArticle -wrp KYWD -element KeywordList/Keyword \
1169 -block PubmedArticle -wrp PAIR -pairx ArticleTitle \
1170 -block PublicationType -wrp PTYP -element PublicationType \
1171 -block PubmedData/ArticleIdList \
1172 -subset ArticleId -if "@IdType" -equals doi -ALN -alnum ArticleId -wrp DOI -mirror "&ALN" \
1173 -subset ArticleId -if "@IdType" -equals pmc -wrp PMCID -element "ArticleId[PMC|]" \
1174 -block CommentsCorrections -wrp PROP -prop "@RefType" \
1175 -block PublicationStatus -wrp PROP -prop PublicationStatus \
1176 -block Abstract -if AbstractText -wrp PROP -lbl "Has Abstract" \
1177 -block MedlineCitation -if CoiStatement -wrp PROP -lbl "Conflict of Interest Statement" \
1178 -block Journal -if MedlineDate -wrp PROP -lbl "Medline Date" \
1179 -subset MedlineDate -if "%MedlineDate" -lt 4 -wrp PROP -lbl "Bad Date" \
1180 -subset MedlineDate -if "%MedlineDate" -eq 9 -and "MedlineDate[5:5]" -equals " " \
1181 -and "MedlineDate[1:4]" -consists-of "0123456789" -and "MedlineDate[6:9]" -consists-of "0123456789" \
1182 -wrp PROP -lbl "Suspicious Date" \
1183 -block PubDate -if Year -and "%Year" -lt 4 -wrp PROP -lbl "Bad Date" \
1184 -block PubMedPubDate -if "%Year" -lt 4 -wrp PROP -lbl "Bad Date" \
1185 -block JournalIssue -if "@CitedMedium" -is-not Internet \
1186 -subset PubDate -if Year -gt $currentDate -wrp PROP -lbl "Future Date" \
1187 -block PubMedPubDate -if Year -gt $currentDate -and "@PubStatus" -is-not pmc-release -wrp PROP -lbl "Future Date" \
1188 -block MedlineCitation -if "PMID@Version" -gt 1 -wrp PROP -lbl "Versioned" \
1189 -block Reference/ArticleIdList/ArticleId \
1190 -if "@IdType" -equals pubmed -and "%ArticleId" -gt 8 -and ArticleId -consists-of "0123456789" \
1191 -wrp PROP -lbl "Bad Reference" \
1192 -block PubmedArticle -meshcode "MeshHeading/DescriptorName@UI,Chemical/NameOfSubstance@UI,SupplMeshName@UI" \
1193 -block MeshHeading/QualifierName -wrp SUBH -element QualifierName \
1194 -block MeshHeading/DescriptorName -wrp MESH -element DescriptorName \
1195 -block Chemical/NameOfSubstance -wrp SUBS -element NameOfSubstance
1196 EOS
1197
1198 wait
1199
1200 if [ "$e2index" = true ]
1201 then
1202 seconds_start=$(date "+%s")
1203 echo "Incremental Indexing" >&2
1204
1205 if [ "$stem" = true ]
1206 then
1207 idxtxt=$( echo "$idxtxt -block PubmedArticle -wrp STEM -indexer ArticleTitle,Abstract/AbstractText" )
1208 fi
1209
1210 temp=$(mktemp /tmp/INDEX_TEMP.XXXXXXXXX)
1211 # generate file with xtract indexing arguments, split onto separate lines, skipping past xtract command itself
1212 echo "${idxtxt}" | xargs -n1 echo | tail -n +2 > $temp
1213 ( rchive -db "$dbase" -e2incIndex "${archiveBase}" "${indexBase}" -idxargs "$temp" \
1214 -dotmax "$dotmaxIdx" -transform "${extrasBase}/meshtree.txt" -e2index )
1215 rm "$temp"
1216
1217 seconds_end=$(date "+%s")
1218 seconds=$((seconds_end - seconds_start))
1219 IDX=$seconds
1220 # echo "" >&2
1221 echo "IDX $IDX seconds" >&2
1222 echo "" >&2
1223 sleep 1
1224 fi
1225
1226 wait
1227
1228 if [ "$e2invert" = true ]
1229 then
1230 seconds_start=$(date "+%s")
1231 echo "Incremental Inversion" >&2
1232
1233 ( rchive -db "$dbase" -dotmax "$dotmaxInv" -e2incInvert "${indexBase}" "${invertBase}" )
1234
1235 if [ -d "${invertBase}" ]
1236 then
1237 cd "${invertBase}"
1238
1239 rm -f *.inv.gz
1240 fi
1241
1242 seconds_end=$(date "+%s")
1243 seconds=$((seconds_end - seconds_start))
1244 INV=$seconds
1245 echo "" >&2
1246 echo "INV $INV seconds" >&2
1247 echo "" >&2
1248 sleep 1
1249 fi
1250
1251 wait
1252
1253 if [ "$e2collect" = true ]
1254 then
1255 seconds_start=$(date "+%s")
1256 echo "Collect Inverted Sets" >&2
1257
1258 if [ -d "${invertBase}" ]
1259 then
1260 cd "${invertBase}"
1261
1262 rm -f *.inv.gz
1263
1264 idx=0
1265 for dir in "${invertBase}"/*
1266 do
1267 if [ -d "$dir" ]
1268 then
1269 cd "$dir"
1270 printf "."
1271 ( rchive -gzip -join *.inv.gz > "${invertBase}/${dbase}$(printf %02d $idx).inv.gz" )
1272 idx=$(( idx + 1 ))
1273 wait
1274 fi
1275 done
1276 printf "\n"
1277 fi
1278
1279 seconds_end=$(date "+%s")
1280 seconds=$((seconds_end - seconds_start))
1281 COL=$seconds
1282 echo "" >&2
1283 echo "COL $COL seconds" >&2
1284 echo "" >&2
1285 sleep 1
1286 fi
1287
1288 wait
1289
1290 if [ "$e2merge" = true ]
1291 then
1292 seconds_start=$(date "+%s")
1293 echo "Merging Inverted Indices" >&2
1294
1295 if [ -d "${invertBase}" ]
1296 then
1297 cd "${invertBase}"
1298
1299 ( rchive -gzip -db "$dbase" -merge "${mergedBase}" *.inv.gz )
1300 fi
1301
1302 seconds_end=$(date "+%s")
1303 seconds=$((seconds_end - seconds_start))
1304 MRG=$seconds
1305 echo "" >&2
1306 echo "MRG $MRG seconds" >&2
1307 echo "" >&2
1308 sleep 1
1309 if [ ! -f "${mergedBase}/zz.mrg.gz" ]
1310 then
1311 echo "ERROR: Merge failed to complete - missing zz.mrg.gz file" >&2
1312 echo "" >&2
1313 echo "EXITING DUE TO BUILD FAILURE" >&2
1314 echo "" >&2
1315 # do not continue
1316 e2post=false
1317 fi
1318 fi
1319
1320 wait
1321
1322 if [ "$e2post" = true ]
1323 then
1324 seconds_start=$(date "+%s")
1325 echo "Producing Postings Files" >&2
1326
1327 if [ -d "${mergedBase}" ]
1328 then
1329 cd "${mergedBase}"
1330
1331 for fl in *.mrg.gz
1332 do
1333 echo "$fl"
1334 done |
1335 sort |
1336 xargs -n 100 echo |
1337 while read files
1338 do
1339 ( rchive -db "$dbase" -promote "${postingsBase}" "$fields" $files )
1340 done
1341 fi
1342
1343 seconds_end=$(date "+%s")
1344 seconds=$((seconds_end - seconds_start))
1345 PST=$seconds
1346 echo "" >&2
1347 echo "PST $PST seconds" >&2
1348 echo "" >&2
1349 sleep 1
1350 fi
1351
1352 wait
1353
1354 # check postings
1355 okay=""
1356 if [ "$e2post" = true ]
1357 then
1358 okay=$( xsearch -query "mapping of spatio-temporal pollution status [TIAB] AND 2008 [YEAR]" |
1359 xfetch -db pubmed |
1360 xtract -pattern Author -if Affiliation -contains Medicine -element Initials )
1361 if [ "$okay" = "OK" ]
1362 then
1363 echo "Archive and Index are $okay" >&2
1364 echo "" >&2
1365 fi
1366 fi
1367
1368 if [ "$e2post" = true ] && [ "$okay" = "OK" ] && [ -d "${mergedBase}" ]
1369 then
1370 target="${mergedBase}"
1371 find "$target" -name "*.mrg" -delete
1372 find "$target" -name "*.mrg.gz" -delete
1373
1374 if [ -d "${invertBase}" ]
1375 then
1376 cd "${invertBase}"
1377 rm -f *.inv.gz
1378 fi
1379 fi
1380
1381 cd
1382
1383 echo "ARCHIVE-PUBMED" >&2
1384
1385 echo "" >&2
1386
1387 PrintTime() {
1388
1389 if [ "$1" = true ]
1390 then
1391 echo "$2 $3 seconds" >&2
1392 fi
1393 }
1394
1395 PrintTime "$datafiles" "DAT" "$DAT"
1396 PrintTime "$download" "DWN" "$DWN"
1397 PrintTime "$populate" "POP" "$POP"
1398
1399 PrintTime "$e2index" "IDX" "$IDX"
1400 PrintTime "$e2invert" "INV" "$INV"
1401 PrintTime "$e2collect" "COL" "$COL"
1402 PrintTime "$e2merge" "MRG" "$MRG"
1403 PrintTime "$e2post" "PST" "$PST"
1404
1405 echo "" >&2
1406
1407 function PrintTotalElapsedTime {
1408 local L=$1
1409 local T=$2
1410 local D=$((T/60/60/24))
1411 local H=$((T/60/60%24))
1412 local M=$((T/60%60))
1413 local S=$((T%60))
1414 printf '%s %d second' "$L" $T 1>&2
1415 (( $T > 1 )) && printf 's' 1>&2
1416 if [ "$T" -gt 59 ]
1417 then
1418 printf ', or' 1>&2
1419 (( $D > 0 )) && printf ' %d day' $D 1>&2
1420 (( $D > 1 )) && printf 's' 1>&2
1421 (( $H > 0 )) && printf ' %d hour' $H 1>&2
1422 (( $H > 1 )) && printf 's' 1>&2
1423 (( $M > 0 )) && printf ' %d minute' $M 1>&2
1424 (( $M > 1 )) && printf 's' 1>&2
1425 (( $S > 0 )) && printf ' %d second' $S 1>&2
1426 (( $S > 1 )) && printf 's' 1>&2
1427 fi
1428 printf '\n' 1>&2
1429 }
1430
1431 total_end=$(date "+%s")
1432 total=$((total_end - total_start))
1433 TOT=$total
1434 PrintTotalElapsedTime "TOT" "$TOT"
1435 echo "" >&2
1436
1437 if [ "$e2merge" = false ]
1438 then
1439 echo "TO BUILD LOCAL SEARCH INDICES, RUN:" >&2
1440 echo "" >&2
1441 echo " archive-pubmed -index" >&2
1442 echo "" >&2
1443 fi
1444
1445
1446 date >&2
1447 echo "" >&2