Debian Codegraph @

expand-current

raw
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 # expand-current
7
8 pth=$( dirname "$0" )
9
10 case "$pth" in
11 /* )
12 ;; # already absolute
13 * )
14 pth=$(cd "$pth" && pwd)
15 ;;
16 esac
17
18 case ":$PATH:" in
19 *:"$pth":* )
20 ;;
21 * )
22 PATH="$PATH:$pth"
23 export PATH
24 ;;
25 esac
26
27 # get path to local folder
28
29 osname=$( uname -s | sed -e 's/_NT-.*$/_NT/; s/^MINGW[0-9]*/CYGWIN/' )
30
31 GetLocalArchiveFolder() {
32
33 dbs="$1"
34 fld="$2"
35
36 # find selected local archive folder from environment variables or configuration file
37 target=$( rchive -local "$dbs" "$fld" )
38
39 if [ -z "$target" ] || [ "$target" = "" ]
40 then
41 echo "ERROR: Must supply path to local data by setting EDIRECT_LOCAL_ARCHIVE environment variable" >&2
42 exit 1
43 fi
44
45 if [ -n "$osname" ] && [ "$osname" = "CYGWIN_NT" -a -x /bin/cygpath ]
46 then
47 target=$( cygpath -w "$target" )
48 fi
49
50 # remove trailing slash
51 target=${target%/}
52
53 echo "$target"
54 }
55
56 date
57
58 archiveBase=$( GetLocalArchiveFolder "$dbase" "Archive" )
59 mergedBase=$( GetLocalArchiveFolder "$dbase" "Merged" )
60 currentBase=$( GetLocalArchiveFolder "$dbase" "Current" )
61 indexedBase=$( GetLocalArchiveFolder "$dbase" "Indexed" )
62 invertedBase=$( GetLocalArchiveFolder "$dbase" "Inverted" )
63
64 seconds_start=$(date "+%s")
65 echo "Removing Previous Indices"
66 cd "${indexedBase}"
67 target="${indexedBase}"
68 find "$target" -name "*.e2x" -delete
69 find "$target" -name "*.e2x.gz" -delete
70 cd "${invertedBase}"
71 target="${invertedBase}"
72 find "$target" -name "*.inv" -delete
73 find "$target" -name "*.inv.gz" -delete
74 cd "${mergedBase}"
75 target="${mergedBase}"
76 find "$target" -name "*.mrg" -delete
77 find "$target" -name "*.mrg.gz" -delete
78 seconds_end=$(date "+%s")
79 seconds=$((seconds_end - seconds_start))
80 echo "$seconds seconds"
81 CLR=$seconds
82
83 seconds_start=$(date "+%s")
84 echo "Collecting Current PubMed Archive"
85 cd "${currentBase}"
86 target="${currentBase}"
87 if [ \! -f pubmed001.xml ]
88 then
89 [ -f pubmed001.xml.gz ] || pm-collect "${archiveBase}" "${currentBase}"
90 echo "Expanding Current PubMed Archive"
91 for fl in *.xml.gz
92 do
93 base=${fl%.xml.gz}
94 echo "$base.xml"
95 gunzip -c "$fl" |
96 xtract -set PubmedArticleSet -index -pattern PubmedArticle > "$target/$base.xml"
97 sleep 1
98 rm "$fl"
99 done
100 fi
101 seconds_end=$(date "+%s")
102 seconds=$((seconds_end - seconds_start))
103 echo "$seconds seconds"
104 EXP=$seconds
105
106 echo ""
107
108 echo "EXPAND-CURRENT"
109
110 echo "CLR $CLR seconds"
111 echo "EXP $EXP seconds"
112
113 echo ""
114
115 date