| 1 |
#!/bin/sh |
| 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 |
if [ "$#" -eq 0 ] |
| 7 |
then |
| 8 |
echo "Must supply path for archive files" |
| 9 |
exit 1 |
| 10 |
fi |
| 11 |
|
| 12 |
archive="$1" |
| 13 |
index="$2" |
| 14 |
invert="$3" |
| 15 |
|
| 16 |
osname=$( uname -s | sed -e 's/_NT-.*$/_NT/; s/^MINGW[0-9]*/CYGWIN/' ) |
| 17 |
if [ "$osname" = "CYGWIN_NT" -a -x /bin/cygpath ] |
| 18 |
then |
| 19 |
archive=`cygpath -w "$archive"` |
| 20 |
fi |
| 21 |
|
| 22 |
archive=${archive%/} |
| 23 |
|
| 24 |
rm -f "versioned.xml.gz" |
| 25 |
rm -f "versioned.snt" |
| 26 |
|
| 27 |
tool="edirect" |
| 28 |
# modify tool if any local archive environment variable is set |
| 29 |
if [ -n "${EDIRECT_PUBMED_MASTER}" ] |
| 30 |
then |
| 31 |
tool="edirect_PM" |
| 32 |
elif [ -n "${EDIRECT_LOCAL_MASTER}" ] |
| 33 |
then |
| 34 |
tool="edirect_LM" |
| 35 |
elif [ -n "${EDIRECT_LOCAL_ARCHIVE}" ] |
| 36 |
then |
| 37 |
tool="edirect_LA" |
| 38 |
elif [ -n "${EDIRECT_LOCAL_CONFIG}" ] |
| 39 |
then |
| 40 |
tool="edirect_LC" |
| 41 |
fi |
| 42 |
|
| 43 |
# query to log population of local archive |
| 44 |
einfo -db pubmed -fields -tool "$tool" > /dev/null |
| 45 |
|
| 46 |
if [ ! -f "$archive/versioned.uid" ] |
| 47 |
then |
| 48 |
exit |
| 49 |
fi |
| 50 |
|
| 51 |
total=.REFRESH_TOTAL |
| 52 |
local=.REFRESH_LOCAL |
| 53 |
|
| 54 |
cat "$archive/versioned.uid" | sort -n | uniq > $total |
| 55 |
|
| 56 |
cat "$total" | xfetch -db pubmed -strict | |
| 57 |
xtract -pattern PubmedArticle -element MedlineCitation/PMID | |
| 58 |
sort | uniq > $local |
| 59 |
|
| 60 |
missing=$(comm -23 "$total" "$local") |
| 61 |
|
| 62 |
rm "$total" |
| 63 |
rm "$local" |
| 64 |
|
| 65 |
if [ -n "$missing" ] |
| 66 |
then |
| 67 |
|
| 68 |
echo "$missing" | |
| 69 |
efetch -db pubmed -format xml | |
| 70 |
xtract -strict -compress -format flush | |
| 71 |
rchive -gzip -db pubmed -strict \ |
| 72 |
-archive "$archive" "$index" "$invert" \ |
| 73 |
-index MedlineCitation/PMID^Version -pattern PubmedArticle |
| 74 |
fi |