Exemplo n.º 1
0
function goDeeper($parent, $key, $value, $link, $result)
{
    global $db_prefix;
    if (!is_object($value) && !is_array($value) && $key != "status") {
        $sql = 'INSERT INTO `' . $db_prefix . 'twitter_usermetadata` (`twitter_user_id`, `field_key`, `field_value`)VALUES("' . $result->id_str . '", "' . $parent . $key . '", "' . str_replace('"', "'", $value) . '")';
        $insert = query_mysql($sql, $link);
    } else {
        if ((is_object($value) || is_array($value)) && $key != "status") {
            foreach ($value as $inner_key => $inner_value) {
                goDeeper($key . " ", $inner_key, $inner_value, $link, $result);
            }
        }
    }
}
Exemplo n.º 2
0
<?php

/*
example-6.php
Square-Heatmat
With Dots underneath
*/
require_once "../config.php";
$geojson_webmer = array();
//If you want to show all points add the number of points you want to show here:
$db_max = 20000;
$sql = 'SELECT `' . $db_lat . '`, `' . $db_lng . '`, `x`, `y` FROM `' . $db_table . '` WHERE `validconversion` = 1 ORDER BY `' . $db_id . '` ASC LIMIT ' . $db_max;
$result = query_mysql($sql, $link);
if ($result) {
    while ($row = mysql_fetch_assoc($result)) {
        array_push($geojson_webmer, array($row["x"], $row["y"]));
    }
}
mysql_free_result($result);
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <style>
    	body,html{margin:0;padding:0;width:100%;height:100%;}
    	#map{width:100%;height:100%;}
    </style>
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
  </head>
  <body>
Exemplo n.º 3
0
            echo json_encode($pert_collection_count);
            break;
        case 'fda_collections':
            // number of FDA approved drugs in collections
            $query = "SELECT pert_collection, COUNT(*) FROM drugs_lincs INNER JOIN drugs_drugbank ON drugs_lincs.pubchem_cid=drugs_drugbank.pubchem_cid OR drugs_lincs.pert_iname=drugs_drugbank.name GROUP BY pert_collection";
            $rs = query_mysql($query, $conn);
            $conn->close();
            $fda_approved_drug_count = array();
            foreach ($rs as $key => $line) {
                if (is_null($line['pert_collection'])) {
                    $fda_approved_drug_count['NA'] = (int) $line['COUNT(*)'];
                } else {
                    $fda_approved_drug_count[$line['pert_collection']] = (int) $line['COUNT(*)'];
                }
            }
            echo json_encode($fda_approved_drug_count);
            break;
        case 'summary_count':
            $arr = array();
            // container for all the output
            $tables = array('side_effects', 'drugs_lincs');
            foreach ($tables as $table) {
                $query = "SELECT COUNT(*) FROM {$table}";
                // get SE count and drug count
                $count = query_mysql($query, $conn);
                $arr[$table] = $count[0]['COUNT(*)'];
            }
            $conn->close();
            echo json_encode($arr);
    }
}
Exemplo n.º 4
0
function get_four_defs($connection, $correct_word, $num_headwords, $max_def_length = 256, $min_def_length = 0)
{
    $correct_def = get_def($connection, $correct_word);
    $correct_headword_id = $correct_word['headword_id'];
    $def1;
    $def2;
    $def3;
    //	$def_arr = array($correct_def);
    $pos = $correct_word['pos'];
    $regex_pos;
    if ($pos == 'sm' || $pos == 'sf' || $pos == 'smf') {
        $regex_pos = " AND pos REGEXP 'sm|sf'";
    } else {
        if ($pos == 'vt' || $pos == 'vi' || $pos == 'vp' || $pos == 'vti') {
            $regex_pos = " AND pos REGEXP 'v'";
        } else {
            if ($pos == 'adj') {
                $regex_pos = " AND pos REGEXP 'adj'";
            } else {
                $regex_pos = "";
            }
        }
    }
    $defs_query = "SELECT * FROM hms_defs \n" . "LEFT JOIN hms_headword ON headword_id=fk_defs_headword_id\n" . "WHERE CHAR_LENGTH(def) < {$max_def_length} AND CHAR_LENGTH(def) > {$min_def_length} {$regex_pos}";
    $defs_results = query_mysql($connection, $defs_query);
    $num_rows = mysqli_num_rows($defs_results);
    //$num_headwords in argument may not be necessary
    $random1 = unique_random($num_rows);
    $random2 = unique_random($num_rows, $random1);
    $random3 = unique_random($num_rows, $random1, $random2);
    mysqli_data_seek($defs_results, $random1);
    $row = mysqli_fetch_row($defs_results);
    $def1 = $row[2];
    //index 2 gets the definition
    $def1_headword_id = $row[1];
    //index 1 gets the headword_id
    mysqli_data_seek($defs_results, $random2);
    $row = mysqli_fetch_row($defs_results);
    $def2 = $row[2];
    $def2_headword_id = $row[1];
    mysqli_data_seek($defs_results, $random3);
    $row = mysqli_fetch_row($defs_results);
    $def3 = $row[2];
    $def3_headword_id = $row[1];
    $correct_def_str = $correct_def['def'];
    $headword = $correct_word['headword'];
    $pos = $correct_word['pos'];
    //	$def_arr = array("correct" => "$correct_def_str", "headword"=> $headword, "pos"=> $pos, "def1" => $def1, "def2" => $def2, "def3" => $def3);
    $def_arr = array("correct" => "{$correct_def_str}", "headword" => $headword, "pos" => $pos, "correct_headword_id" => $correct_headword_id, "def1" => $def1, "def2" => $def2, "def3" => $def3, "def1_headword_id" => "{$def1_headword_id}", "def2_headword_id" => "{$def2_headword_id}", "def3_headword_id" => "{$def3_headword_id}");
    //	print_r($def_arr);
    return $def_arr;
}
Exemplo n.º 5
0
foreach ($known_drugs as $key => $line) {
    $id = $line['drug_id'];
    array_push($known_drug_ids, $id);
}
$arr_out = array();
for ($i = 0; $i < count($drugs); $i++) {
    $drug_id = $drugs[$i]['drug_id'];
    $write_this = True;
    // whether to write this drug out
    if (in_array($drug_id, $known_drug_ids) && $filter) {
        $write_this = False;
    }
    if ($write_this) {
        $query = "SELECT pert_id,pert_iname FROM drugs_lincs WHERE id='{$drug_id}'";
        //to get names of pert_ids
        $drug_meta = query_mysql($query, $conn);
        $arr_out[$i]['name'] = $drug_meta[0]['pert_iname'];
        $arr_out[$i]['pert_id'] = $drug_meta[0]['pert_id'];
        $p_val = $drugs[$i]['p_val'];
        $arr_out[$i]['p_val'] = sprintf('%0.2f', $p_val);
        if (!$filter) {
            if (in_array($drug_id, $known_drug_ids)) {
                $arr_out[$i]['sider'] = 'yes';
            } else {
                $arr_out[$i]['sider'] = 'no';
            }
        }
    }
}
$conn->close();
$json = json_encode($arr_out);
Exemplo n.º 6
0
<?php

header('Content-type: text/plain;charset=utf8');
require_once '../config.php';
require_once '../lib/db.php';
$results = query_mysql('SELECT id FROM ' . $db_prefix . 'twitter_requests WHERE request = "' . $_GET["request"] . '"', $link);
while ($row = mysql_fetch_assoc($results)) {
    $id = $row["id"];
}
$results = query_mysql('SELECT field_value FROM ' . $db_prefix . 'twitter_tweetmetadata WHERE request_id = "' . $id . '" AND field_key = "created_at" ORDER BY twitter_tweet_id ASC LIMIT 0, 1', $link);
while ($row = mysql_fetch_assoc($results)) {
    $d1 = new DateTime($row["field_value"]);
}
$results = query_mysql('SELECT field_value FROM ' . $db_prefix . 'twitter_tweetmetadata WHERE request_id = "' . $id . '" AND field_key = "created_at" ORDER BY twitter_tweet_id DESC LIMIT 0, 1', $link);
while ($row = mysql_fetch_assoc($results)) {
    $d2 = new DateTime($row["field_value"]);
}
$diff = $d1->diff($d2);
echo $diff->d . ' days' . "\n";
echo $diff->h . ' hours' . "\n";
echo $diff->i . ' minutes' . "\n";
echo $diff->s . ' seconds' . "\n" . "\n";
$results = query_mysql('SELECT * FROM ' . $db_prefix . 'twitter_tweets', $link);
echo mysql_num_rows($results) . ' tweets' . "\n" . "\n";
$results = query_mysql('SELECT * FROM ' . $db_prefix . 'twitter_users', $link);
echo mysql_num_rows($results) . ' users' . "\n\n\n";
?>

Exemplo n.º 7
0
<?php

// API for legends
require_once 'login.php';
include 'functions.php';
$conn = new mysqli($db_hostname, $db_username, $db_password, $db_database);
if ($conn->connect_error) {
      trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
if (isset($_GET['type'])) {
    $type = $_GET['type'];
    if ($type == 'side_effect_network.json') {
        $query = "SELECT name,CONCAT('#',color) AS color FROM soc";
    } else {
        $query = "SELECT pert_icollection FROM drugs_lincs GROUP BY pert_icollection";
    }
}
$result = query_mysql($query, $conn);
$conn->close();
$json = json_encode($result);
echo $json;
Exemplo n.º 8
0
<?php

require_once 'login.php';
include 'functions.php';
$conn = new mysqli($db_hostname, $db_username, $db_password, $db_database);
if ($conn->connect_error) {
      trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
$query = "SELECT umls_id,name,synonyms FROM side_effects WHERE umls_id IS NOT NULL AND auroc IS NOT NULL";
$rs_arr = query_mysql($query, $conn);
$conn->close();
$num_rows = count($rs_arr);
$out_arr = array();
foreach ($rs_arr as $row) {
    $synonyms = explode("|", $row["synonyms"]);
    $row["synonyms"] = $synonyms;
    array_push($out_arr, $row);
}
$json = json_encode($out_arr);
echo $json;
Exemplo n.º 9
0
<?php

include "config.php";
require_once 'lib/codebird.php';
include "lib/db.php";
\Codebird\Codebird::setConsumerKey($key, $secret);
$cb = \Codebird\Codebird::getInstance();
session_start();
if (!isset($_GET['oauth_verifier'])) {
    $reply = $cb->oauth_requestToken(array('oauth_callback' => $url . '1-create_tokens.php'));
    $cb->setToken($reply->oauth_token, $reply->oauth_token_secret);
    $_SESSION['oauth_token'] = $reply->oauth_token;
    $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;
    $auth_url = $cb->oauth_authorize();
    header('Location: ' . $auth_url);
    die;
} elseif (isset($_GET['oauth_verifier'])) {
    $cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    $reply = $cb->oauth_accessToken(array('oauth_verifier' => $_GET['oauth_verifier']));
    $sql = 'INSERT INTO `' . $db_prefix . 'twitter_token` (`token`, `secret`)VALUES("' . $reply->oauth_token . '", "' . $reply->oauth_token_secret . '")';
    $insert = query_mysql($sql, $link);
}
?>
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></head><body>
<?php 
echo 'Twitter Token Creation completed. <a href="2-create_request.php">Continue</a>';
?>
</body></html>
Exemplo n.º 10
0
function getCount($query, $conn)
{
    $result = query_mysql($query, $conn);
    return $result[0]['COUNT(*)'];
}
Exemplo n.º 11
0
# all the predicted se_ids of the drug
// get SE associated with this drug in SIDER
$query = "SELECT se_id FROM sider_connections INNER JOIN drugs_lincs ON sider_connections.drug_id = drugs_lincs.id WHERE pert_id='{$pert_id}'";
$known_side_effects = query_mysql($query, $conn);
$known_side_effect_ids = array();
// se_id of known connections
foreach ($known_side_effects as $key => $line) {
    $id = $line['se_id'];
    array_push($known_side_effect_ids, $id);
}
$arr_out = array();
for ($i = 0; $i < count($side_effects); $i++) {
    $se_id = $side_effects[$i]['se_id'];
    $query = "SELECT umls_id,name FROM side_effects WHERE id='{$se_id}'";
    //to get names of side effects
    $se_meta = query_mysql($query, $conn);
    if ($se_meta[0]['umls_id']) {
        // filter out se without umls_id
        $arr_out[$i]['name'] = $se_meta[0]['name'];
        $arr_out[$i]['umls_id'] = $se_meta[0]['umls_id'];
        $p_val = $side_effects[$i]['p_val'];
        $arr_out[$i]['p_val'] = sprintf('%0.2f', $p_val);
        if (in_array($se_id, $known_side_effect_ids)) {
            $arr_out[$i]['sider'] = 'yes';
        } else {
            $arr_out[$i]['sider'] = 'no';
        }
    }
}
$conn->close();
$json = json_encode($arr_out);
Exemplo n.º 12
0
<?php

require_once 'login.php';
include 'functions.php';
$pert_id = $_GET['pert_id'];
$conn = new mysqli($db_hostname, $db_username, $db_password, $db_database);
if ($conn->connect_error) {
      trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
$query = "SELECT * FROM drugs_lincs WHERE pert_id='{$pert_id}'";
$rs_lincs = query_mysql($query, $conn);
$drug_meta['drugs_lincs'] = $rs_lincs[0];
// to store info for the drug
$pcid = $rs_lincs[0]['pubchem_cid'];
// don't want to show info from drugbank and stitch
// if (!is_null($pcid)) {
//   $tables = array("drugs_drugbank", "drugs_stitch");
//   foreach ($tables as $table) {
//     $query = "SELECT * FROM $table WHERE pubchem_cid='$pcid'";
//     $rs_arr = query_mysql($query, $conn);
//     if(count($rs_arr) == 1) {
//     	$drug_meta[$table] = $rs_arr[0];
//     }
//   }
// }
$conn->close();
$json = json_encode($drug_meta);
echo $json;
Exemplo n.º 13
0
<?php

require_once 'login.php';
include 'functions.php';
$conn = new mysqli($db_hostname, $db_username, $db_password, $db_database);
if ($conn->connect_error) {
      trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
if (isset($_GET['term'])) {
    $searchq = $_GET["term"];
    $searchq = preg_replace("#[^0-9a-z-]#i", "", $searchq);
    $searchq = "%" . $searchq . "%";
    $query1 = "SELECT pert_id, pert_iname, alt_name FROM drugs_lincs WHERE pert_id LIKE '{$searchq}' OR pert_iname LIKE '{$searchq}' OR alt_name LIKE '{$searchq}'";
    $query2 = "SELECT umls_id, name, synonyms FROM side_effects WHERE umls_id LIKE '{$searchq}' OR name LIKE '{$searchq}' OR synonyms LIKE '{$searchq}'";
    $rs_arr1 = query_mysql($query1, $conn);
    $rs_arr2 = query_mysql($query2, $conn);
    $count = count($rs_arr1) + count($rs_arr2);
    if ($count == 0) {
        $output = 'NULL';
    } else {
        $rs_arr = array("drugs" => $rs_arr1, "se" => $rs_arr2);
        $output = $rs_arr;
    }
    $json = json_encode($output);
    echo $json;
}
Exemplo n.º 14
0
<?php

require_once 'login.php';
include 'functions.php';
$umls_id = $_GET['umls_id'];
$conn = new mysqli($db_hostname, $db_username, $db_password, $db_database);
if ($conn->connect_error) {
      trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
// $query = "SELECT * FROM umls_ids INNER JOIN side_effects ON side_effects.umls_id=umls_ids.umls_id WHERE umls_ids.umls_id='$umls_id'";
$query = "SELECT * FROM side_effects WHERE umls_id='{$umls_id}'";
$rs_se = query_mysql($query, $conn);
$rs_se[0]['synonyms'] = explode("|", $rs_se[0]["synonyms"]);
$conn->close();
$json = json_encode($rs_se[0]);
echo $json;