forked from hms-dbmi/i2b2v2-webclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenomicInfo.php
71 lines (55 loc) · 2.01 KB
/
genomicInfo.php
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
<?php
/*
* Copyright (c) 2024 Harvard Catalyst
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the i2b2 Software License v2.1
* which accompanies this distribution.
*
*/
$GENE_DB_FILENAME = './i2b2_gene_list-FTS3.db3';
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
// CORS: Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
// you want to allow, and if so:
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
// may also be using PUT, PATCH, HEAD etc
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
function find_rsid($search){
// this is an example function for returning hardcoded rsids to the autocomplete results
$output = array("rsid" => $search, "alleles" => array("T=T", "T>C"));
return json_encode($output);
}
function search_by_gene($search){
global $GENE_DB_FILENAME;
$db = new PDO('sqlite:'.$GENE_DB_FILENAME);
$stmt = $db->prepare("SELECT gene_id, symbol, name FROM genes_search AS gs JOIN genes AS g ON (g.rowid = gs.rowid) WHERE gs.content MATCH :term LIMIT 20;");
$stmt->execute(array($search.'*'));
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
return json_encode($data);
}
if(isset($_GET['op']) && isset($_GET['term'])){
$search = $_GET['term'];
$op = $_GET['op'];
switch($op) {
case 'rsid':
print find_rsid($search);
break;
case 'gene':
print search_by_gene($search);
break;
}
}
?>