Debian Codegraph @

nhance.sh

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: nhance.sh
28 #
29 # Author: Jonathan Kans
30 #
31 # Version Creation Date: 06/15/20
32 #
33 # ==========================================================================
34
35 # external nquire shortcut extensions
36
37 xtra=""
38 ptrn=""
39 encd=""
40
41 if [ $# -gt 0 ]
42 then
43 xtra="$1"
44 case "$xtra" in
45 -pathway | -gene-to-pathway | -litvar | -citmatch )
46 shift
47 if [ $# -gt 0 ]
48 then
49 ptrn="$1"
50 encd=$( Escape "$ptrn" )
51 shift
52 else
53 echo "ERROR: Missing $xtra argument" >&2
54 exit 1
55 fi
56 ;;
57 * )
58 ;;
59 esac
60 fi
61
62 # convert encoded entities, but convert ", &apos, and ' (apostrophe) to space
63 # adapted from:
64 # https://stackoverflow.com/questions/5929492/bash-script-to-convert-from-html-entities-to-characters
65 HTMLtoText () {
66 LineOut=$1 # Parm 1= Input line
67 # Replace external command: Line=$(sed 's/&amp;/\&/g; s/&lt;/\</g;
68 # s/&gt;/\>/g; s/&quot;/\"/g; s/&#39;/\'"'"'/g; s/&ldquo;/\"/g;
69 # s/&rdquo;/\"/g;' <<< "$Line") -- With faster builtin commands.
70 LineOut="${LineOut//&nbsp;/ }"
71 LineOut="${LineOut//&amp;/&}"
72 LineOut="${LineOut//&lt;/<}"
73 LineOut="${LineOut//&gt;/>}"
74 LineOut="${LineOut//&quot;/ }"
75 LineOut="${LineOut//&apos;/ }"
76 LineOut="${LineOut//&#39;/ }"
77 echo "${LineOut}"
78 }
79
80 if [ -n "$encd" ]
81 then
82 case "$xtra" in
83 -pathway )
84 # Reactome:R-HSA-70171
85 nquire -pugview data pathway "${encd}" XML
86 ;;
87 -gene-to-pathway )
88 # 1956
89 fst='{"download":"*","collection":"pathway","where":{"ands":[{"geneid":"'
90 scd='"}]},"order":["taxname,asc"],"start":1,"limit":10000000,"downloadfilename":"GeneID_'
91 thd='_pathway"}'
92 jsn=$( echo "${fst}${encd}${scd}${encd}${thd}" )
93 nquire -pubchem sdq/sdqagent.cgi -infmt json -outfmt xml -query "${jsn}"
94 ;;
95 -litvar )
96 # rs11549407
97 nquire -get "https://www.ncbi.nlm.nih.gov/research/bionlp/litvar" \
98 "api/v1/entity/litvar/${encd}%23%23" |
99 transmute -j2x
100 ;;
101 -citmatch )
102 # clean encoded characters
103 ptrn=$( HTMLtoText "$ptrn" )
104 # echo "${ptrn}" >&2
105 # "nucleotide sequences required for tn3 transposition immunity"
106 nquire -get https://pubmed.ncbi.nlm.nih.gov/api/citmatch \
107 -method heuristic -raw-text "$ptrn" |
108 transmute -j2x |
109 xtract -pattern opt \
110 -if success -equals true -and result/count -eq 1 \
111 -sep "\n" -element uids/pubmed
112 ;;
113 * )
114 ;;
115 esac
116
117 exit 0
118 fi
119