-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.sh
executable file
·222 lines (189 loc) · 7.61 KB
/
example.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
# API REQUEST EXAMPLES
set -e
cd "$(dirname "$0")"
log_checkpoint() {
local message="$1"
echo
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
echo "$message"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
}
log_checkpoint "Check server status:"
URL="http://localhost:8080/"
response="$(curl --write-out "%{http_code}" --silent --output /dev/null "$URL" || true)"
if [ "$response" -eq 200 ] || [ "$response" -eq 301 ] || [ "$response" -eq 302 ]; then
echo "ok"
else
cat << EOF
Error: response ${response} at ${URL}. Please follow these steps:
# From the root directory, run
# > ./configure.sh
#
# and then
# > ./docker/build-docker.sh
# > ./docker/start-docker.sh
EOF
exit 1
fi
if [ -z "$TOKEN" ]; then cat << EOF
Error: TOKEN is not defined. Please follow these steps:
# Access https://developers.google.com/oauthplayground/ with the account that
# you added as admin in 'scripts/init/init_data.cypher', and click in 'Authorize
# APIs' with the scope 'https://www.googleapis.com/auth/userinfo.email'. Or
# select it in list.
#
# In step 2, click in 'Exchange authorization code for tokens' and copy your
# own access token to the variable TOKEN below.
#
# Then, execute
#
# > export TOKEN="YOUR_ACCESS_TOKEN"
#
# and run this script again.
EOF
exit 1
else
echo "ok TOKEN is defined."
fi
../init/make_init_data.cypher.sh
# Let us try several requests:
log_checkpoint "List all users:"
curl -v --location --request GET 'http://localhost:8080/users?provider=google' --header "Authorization: Bearer $TOKEN"
log_checkpoint "List all taxa"
echo -n "Taxa: "
curl --location --request GET 'http://localhost:8080/taxa?provider=google' --header "Authorization: Bearer $TOKEN"
echo
log_checkpoint "Create taxon:"
curl -v --location --request PUT 'http://localhost:8080/taxa/bbacilliformis?provider=google' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKEN" \
--data-raw '{
"id": "bbacilliformis",
"description": "Example taxon"
}'
log_checkpoint "List all loci:"
echo -n "Loci: "
curl --location --request GET 'http://localhost:8080/taxa/bbacilliformis/loci?provider=google' \
--header "Authorization: Bearer $TOKEN"
echo
log_checkpoint "Delete locus (mark deprecated):"
curl -v --location --request DELETE 'http://localhost:8080/taxa/bbacilliformis/loci/ftsZ?provider=google' \
--header "Authorization: Bearer $TOKEN"
log_checkpoint "Create locus:"
for x in locus1 locus2 locus3 locus4 locus5 locus6 locus7; do
curl -v --location --request PUT "http://localhost:8080/taxa/bbacilliformis/loci/$x?provider=google" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKEN" \
--data-raw "{
\"id\": \"$x\",
\"description\": \"Example locus\"
}";
done
log_checkpoint "Load alleles:"
for x in 1 2 3 4 5 6 7; do
curl -v --location --request POST "http://localhost:8080/taxa/bbacilliformis/loci/locus${x}/alleles/files?provider=google" \
--header 'Content-Type: multipart/form-data' \
--header "Authorization: Bearer $TOKEN" \
--form "file=@profiles_${x}.txt" ;
done
log_checkpoint "List alleles:"
for x in 1 2 3 4 5 6 7; do
echo -n "Alleles[locus${x}]: "
curl --location --request GET "http://localhost:8080/taxa/bbacilliformis/loci/locus${x}/alleles?provider=google" \
--header "Authorization: Bearer $TOKEN";
echo ;
done
echo -n "An allele: "
curl --location --request GET "http://localhost:8080/taxa/bbacilliformis/loci/locus1/alleles/1?provider=google" \
--header "Authorization: Bearer $TOKEN"
echo
log_checkpoint "List all schemas:"
echo -n "Schemas: "
curl --location --request GET 'http://localhost:8080/taxa/bbacilliformis/schemas?provider=google' \
--header "Authorization: Bearer $TOKEN"
echo
echo -n "Schema: "
curl --location --request GET 'http://localhost:8080/taxa/bbacilliformis/schemas/mlst7?provider=google' \
--header "Authorization: Bearer $TOKEN"
echo
log_checkpoint "Create schema:"
curl -v --location --request PUT "http://localhost:8080/taxa/bbacilliformis/schemas/mlst7?provider=google" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKEN" \
--data-raw '{
"taxon_id": "bbacilliformis",
"id": "mlst7",
"type": "mlst",
"description": "demo 7 loci schema",
"loci": ["locus1", "locus2", "locus3", "locus4", "locus5", "locus6", "locus7"]
}';
log_checkpoint "List all projects:"
echo -n "Projects: "
curl --location --request GET 'http://localhost:8080/projects?provider=google' --header "Authorization: Bearer $TOKEN"
echo
log_checkpoint "Create project:"
curl -v --location --request POST 'http://localhost:8080/projects?provider=google' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKEN" \
--data-raw '{
"name": "Test",
"visibility": "private",
"description": "Test project",
"users": [{"id": "[email protected]", "provider": "google"}]
}'
# Set the project id.
PROJECT=$(curl -s --location --request GET 'http://localhost:8080/projects?provider=google' --header "Authorization: Bearer $TOKEN" | python3 -c "import sys, json; print(json.load(sys.stdin)[0]['id'])")
echo "Project: $PROJECT"
log_checkpoint "List all datasets:"
echo -n "Datasets: "
curl --location --request GET "http://localhost:8080/projects/$PROJECT/datasets?provider=google" \
--header "Authorization: Bearer $TOKEN"
echo
log_checkpoint "Create dataset:"
curl -v --location --request POST "http://localhost:8080/projects/$PROJECT/datasets?provider=google" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKEN" \
--data-raw '{
"taxon_id": "bbacilliformis",
"schema_id": "mlst7",
"description": "Example dataset"
}'
# Set dataset id:
DATASET=$(curl -s --location --request GET "http://localhost:8080/projects/$PROJECT/datasets?provider=google" --header "Authorization: Bearer $TOKEN" | python3 -c "import sys, json; print(json.load(sys.stdin)[0]['id'])")
echo "Dataset: $DATASET"
log_checkpoint "Load profiles:"
curl -v --location --request POST "http://localhost:8080/projects/$PROJECT/datasets/$DATASET/profiles/files?provider=google" \
--header 'Content-Type: multipart/form-data' \
--header "Authorization: Bearer $TOKEN" \
--form '[email protected]'
log_checkpoint "List profiles:"
echo -n "Profiles: "
curl --location --request GET "http://localhost:8080/projects/$PROJECT/datasets/$DATASET/profiles?provider=google" \
--header "Authorization: Bearer $TOKEN"
echo
for x in $(seq 10); do
echo -n "Profile[${x}]: "
curl --location --request GET "http://localhost:8080/projects/$PROJECT/datasets/$DATASET/profiles/${x}?provider=google" \
--header "Authorization: Bearer $TOKEN";
echo;
done
log_checkpoint "Run inference:"
curl -v --location --request POST "http://localhost:8080/projects/$PROJECT/jobs?provider=google" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKEN" \
--data-raw "{
\"analysis\": \"inference\",
\"algorithm\": \"goeburst\",
\"parameters\": [\"$DATASET\", 3]
}"
log_checkpoint "List inferences:"
echo -n "Inferences: "
curl --location --request GET "http://localhost:8080/projects/$PROJECT/datasets/$DATASET/inferences?provider=google" \
--header "Authorization: Bearer $TOKEN"
echo
INFERENCE=$(curl -s --location --request GET "http://localhost:8080/projects/$PROJECT/datasets/$DATASET/inferences?provider=google" --header "Authorization: Bearer $TOKEN" | python3 -c "import sys, json; print(json.load(sys.stdin)[0]['id'])")
echo -n "Inference: "
curl --location --request GET "http://localhost:8080/projects/$PROJECT/datasets/$DATASET/inferences/$INFERENCE?provider=google" \
--header "Authorization: Bearer $TOKEN"
echo