Debian Codegraph @

xinfo

raw
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: xinfo
28 #
29 # Author: Jonathan Kans, Aaron Ucko
30 #
31 # Version Creation Date: 01/11/2025
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"/xcommon.sh ]
57 then
58 echo "ERROR: Unable to find '$pth/xcommon.sh' file" >&2
59 exit 1
60 fi
61
62 . "$pth"/xcommon.sh
63
64 # initialize specific flags
65
66 dbase=""
67 field=""
68 debug=false
69
70 while [ $# -gt 0 ]
71 do
72 case "$1" in
73 -version )
74 version=$( einfo -version )
75 echo "$version"
76 exit 0
77 ;;
78 -h | -help | --help | help )
79 version=$( einfo -version )
80 echo "xinfo $version"
81 echo ""
82 echo "USAGE: xinfo"
83 echo " -count | -counts | -fields | -terms | -totals"
84 echo ""
85 echo "EXAMPLES"
86 echo ""
87 echo " xinfo -db pubmed -fields"
88 echo ""
89 echo " xinfo -db pubmed -terms SUBH"
90 echo ""
91 echo " xinfo -db pubmed -count \"catabolite repress*\""
92 echo ""
93 echo " xinfo -db pubmed -counts \"catabolite repress*\""
94 echo ""
95 echo " xinfo -db pubmed -totals PROP"
96 echo ""
97 echo " xinfo -db pubmed -totals YEAR |"
98 echo " print-columns '\$2, \$1, total += \$1' |"
99 echo " print-columns '\$1, log(\$2)/log(10), log(\$3)/log(10)' |"
100 echo " filter-columns '\$1 >= 1800 && \$1 < YR' |"
101 echo " xy-plot annual-and-cumulative.png"
102 echo ""
103 exit 0
104 ;;
105 * )
106 break
107 ;;
108 esac
109 done
110
111 while [ $# -gt 0 ]
112 do
113 tag="$1"
114 rem="$#"
115 case "$tag" in
116 -debug )
117 debug=true
118 shift
119 ;;
120 -path | -master )
121 # ignore for backward compatibility, but now requiring environment variable for path
122 # target=$2
123 shift
124 shift
125 ;;
126 -db )
127 CheckForArgumentValue "$tag" "$rem"
128 shift
129 dbase="$1"
130 shift
131 ;;
132 * )
133 break
134 ;;
135 esac
136 done
137
138 # set pubmed as default database for the time being
139 if [ -z "$dbase" ]
140 then
141 dbase="pubmed"
142 fi
143
144 # eventually will require explicit database in argument or piped message
145 if [ -z "$dbase" ]
146 then
147 echo "Must supply database in -db argument"
148 exit 1
149 fi
150
151 # get path to local postings folder
152
153 FindPostingsFolder
154
155 if [ $# -lt 1 ]
156 then
157 echo "ERROR: Insufficient arguments given to xinfo" >&2
158 exit 1
159 fi
160
161 # call rchive -count, -terms, or -totals functions
162
163 val="$1"
164 shift
165 case "$val" in
166 -count )
167 rchive -db "$dbase" -count "$*"
168 ;;
169 -counts )
170 rchive -db "$dbase" -counts "$*"
171 ;;
172 -countr )
173 rchive -db "$dbase" -countr "$*"
174 ;;
175 -countp )
176 rchive -db "$dbase" -countp "$*"
177 ;;
178 -field | -fields )
179 cd "$postingsBase"
180 for dr in *
181 do
182 if [ -d "$dr" ]
183 then
184 echo "$dr"
185 fi
186 done
187 ;;
188 -term | -terms )
189 if [ $# -gt 0 ]
190 then
191 field=$1
192 shift
193 fi
194 if [ -n "$field" ]
195 then
196 rchive -db "$dbase" -terms "$field"
197 fi
198 ;;
199 -total | -totals )
200 if [ $# -gt 0 ]
201 then
202 field=$1
203 shift
204 fi
205 if [ -n "$field" ]
206 then
207 rchive -db "$dbase" -totals "$field"
208 fi
209 ;;
210 -* )
211 exec >&2
212 echo "ERROR: Unrecognized option $val" >&2
213 exit 1
214 ;;
215 * )
216 exec >&2
217 echo "ERROR: Unrecognized argument $val" >&2
218 exit 1
219 ;;
220 esac
221
222 exit 0