-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathowapi.php
More file actions
180 lines (148 loc) · 5.21 KB
/
Copy pathowapi.php
File metadata and controls
180 lines (148 loc) · 5.21 KB
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
<?php
/*
Oligowizard API PHP Wrapper
(C) OLIGOWIZARD LTD
VERSION 1.0
2025
A lightweight PHP wrapper for sending requests to the Oligowizard API. Includes examples for authentication, sequence queries, and result parsing.
https://github.com/Oligowizard/oligowizard-api-wrapper
*/
// Set authentication tokens (ACTION REQUIRED)
$API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Treat your API key like a password - this key links your requests to your account
$CF_client_id = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$CF_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
// Set HTTP headers
$URL = "https://api.oligowizard.app";
$headers = [
"API-Key: $API_KEY",
"Content-Type: application/json",
"CF-Access-Client-Id: $CF_client_id",
"CF-Access-Client-Secret: $CF_secret"
];
function test_connection($URL, $headers) {
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode === 200) {
return true;
} else {
return false;
}
}
function advanced($sequence, $A260 = 1.0, $three_prime = "OH", $five_prime = "OH", $five_is_PS = "FALSE", $Na_conc = 50, $K_conc = 0, $Mg_conc = 0, $URL, $headers) {
$full_URL = $URL . "/advanced";
$payload = json_encode([
"sequence" => $sequence,
"three_prime" => $three_prime,
"five_prime" => $five_prime,
"A260" => $A260,
"five_is_PS" => $five_is_PS,
"Na_conc" => $Na_conc,
"K_conc" => $K_conc,
"Mg_conc" => $Mg_conc
]);
$ch = curl_init($full_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($response, true);
if ($data !== null) {
return $data;
} else {
echo $httpcode;
return false;
}
}
function convert($sequence, $input_code, $output_code, $URL, $headers) {
$full_URL = $URL . "/convert";
$ribose_mods = [
"DNA" => 0,
"RNA" => 1,
"LNA" => 2,
"MOE" => 3,
"OMe" => 4,
"2'F" => 5
];
$input_code = $ribose_mods[$input_code];
$output_code = $ribose_mods[$output_code];
$payload = json_encode([
"sequence" => $sequence,
"input_code" => $input_code,
"output_code" => $output_code
]);
$ch = curl_init($full_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($response, true);
if ($data !== null) {
return $data;
} else {
echo $httpcode;
return false;
}
}
function structure($sequence, $scale = 0.45, $size = 12, $width = 1, $face = 96, $filename = null, $URL, $headers) {
$full_URL = $URL . "/structure";
$payload = json_encode([
"sequence" => $sequence,
"scale" => $scale,
"size" => $size,
"width" => $width,
"face" => $face
]);
$ch = curl_init($full_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers_raw = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode === 200) {
if (!$filename) {
if (preg_match('/filename=([^\s;]+)/', $headers_raw, $matches)) {
$filename = $matches[1];
} else {
$filename = "oligo_structure.cdxml";
}
}
if (file_put_contents($filename, $body)) {
return $filename;
} else {
echo "failed to retrieve structure file";
return false;
}
} else {
echo $httpcode;
return false;
}
}
// === EXAMPLE ===
if (test_connection($URL, $headers)) {
$example_sequence = "tcactttcataatgctgg";
$nus_moe = convert($example_sequence, "DNA", "MOE", $URL, $headers)["output"];
$example_query = advanced($nus_moe, 1.0, "OH", "OH", "FALSE", 50, 0, 0, $URL, $headers);
echo $example_query["molext"] . "\n";
echo $example_query["mass3"] . " g/mol " . $example_query["mass3_text"] . "\n";
structure($nus_moe, 0.45, 12, 1, 96, "Nusinersen_structure.cdxml", $URL, $headers);
} else {
echo "Connection Error\n";
}
?>