-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_xquery.sh
executable file
·99 lines (72 loc) · 1.74 KB
/
run_xquery.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
show_usage() {
echo "Usage: $0 -p PREFIX -q QUERY_FILE -e LOCATION -s SILENT"
echo " -p PREFIX : either 'bmr' (BMRB:default) or 'bms' (Metabolomics)."
echo " -q QUERY_FILE : XQuery file."
echo " -e (loc|pub) : localhost (loc) or bmrbpub.pdbj.org (pub)."
echo " -s (yes|no) : Silent mode of curl command (default:no)."
}
if [ $# = 0 ] ; then
echo "Couldn't specify XQuery file."
exit 1
fi
URL_LOC=http://localhost:8984/rest/
URL_PUB=https://bmrbpub.pdbj.org/xml/
PREFIX=bmr
QUERY_FILE=$1
LOCATION=loc
SILENT=no
ARGV=`getopt --long -o "p:q:e:s:" "$@"`
eval set -- "$ARGV"
while true ; do
case "$1" in
-p)
PREFIX=$2
shift
;;
-q)
QUERY_FILE=$2
shift
;;
-e)
LOCATION=$2
shift
;;
-s)
SILENT=$2
shift
;;
*)
break
;;
esac
shift
done
if [ ! -e $QUERY_FILE ] ; then
echo "Couldn't find $QUERY_FILE."
exit 1
fi
if [ $PREFIX != "bmr" ] && [ $PREFIX != "bms" ] ; then
echo "Usage: $0 -p PREFIX"
echo PREFIX should be either \"bmr\" or \"bms\".
exit 1
fi
if [ $LOCATION != "loc" ] && [ $LOCATION != "pub" ] ; then
echo LOCATION should be either \"loc\" or \"pub\".
show_usage
exit 1
fi
XQUERY_ENDPOINT=$URL_LOC/$PREFIX
if [ $LOCATION != "loc" ] ; then
XQUERY_ENDPOINT=$URL_PUB/$PREFIX
fi
if [ $SILENT != "no" ] && [ $SILENT != "yes" ] ; then
echo SILENT should be either \"no\" or \"yes\".
show_usage
exit 1
fi
if [ $SILENT = "no" ] ; then
curl -X POST -H "Content-Type: application/xml" -d "<rest:query xmlns:rest='http://basex.org/rest'><rest:text>`cat $QUERY_FILE`</rest:text></rest:query>" $XQUERY_ENDPOINT
else
curl -s -X POST -H "Content-Type: application/xml" -d "<rest:query xmlns:rest='http://basex.org/rest'><rest:text>`cat $QUERY_FILE`</rest:text></rest:query>" $XQUERY_ENDPOINT
fi