-
Notifications
You must be signed in to change notification settings - Fork 0
/
prediction.php
260 lines (239 loc) · 15.2 KB
/
prediction.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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
$symptoms = array("Abdomen, Acute", "Abdominal Pain", "Acute Coronary Syndrome", "Aerophagy", "Ageusia", "Aging, Premature",
"Agnosia", "Akathisia, Drug-Induced", "Albuminuria", "Alexia, Pure", "Amaurosis Fugax", "Amblyopia", "Amnesia", "Amnesia, Anterograde",
"Amnesia, Retrograde", "Amnesia, Transient Global", "Angina Pectoris", "Angina Pectoris, Variant", "Angina, Unstable", "Anisocoria",
"Anomia", "Anorexia", "Anoxia", "Aphasia", "Aphasia, Broca", "Aphasia, Wernicke", "Aphonia", "Apnea", "Apraxia, Ideomotor", "Apraxias",
"Arthralgia", "Articulation Disorders", "Asthenia", "Ataxia", "Athetosis", "Auditory Perceptual Disorders", "Back Pain", "Birth Weight",
"Blindness", "Blindness, Cortical", "Body Weight", "Body Weight Changes", "Brown-Sequard Syndrome", "Bulimia", "Cachexia", "Cafe-au-Lait Spots",
"Cardiac Output, High", "Cardiac Output, Low", "Catalepsy", "Catatonia", "Cerebellar Ataxia", "Cerebrospinal Fluid Otorrhea",
"Cerebrospinal Fluid Rhinorrhea", "Chest Pain", "Cheyne-Stokes Respiration", "Chills", "Chorea", "Colic", "Color Vision Defects", "Coma",
"Communication Disorders", "Confusion", "Consciousness Disorders", "Constipation", "Coprophagia", "Cough", "Cyanosis", "Deafness",
"Decerebrate State", "Delirium", "Diarrhea", "Diarrhea, Infantile", "Diplopia", "Dizziness", "Dysarthria", "Dysgeusia", "Dyskinesias", "Dyslexia",
"Dyslexia, Acquired", "Dysmenorrhea", "Dyspepsia", "Dysphonia", "Dyspnea", "Dyspnea, Paroxysmal", "Dystonia", "Dysuria", "Earache", "Ecchymosis",
"Edema", "Edema, Cardiac", "Emaciation", "Encopresis", "Eructation", "Eye Hemorrhage", "Eye Manifestations", "Eye Pain", "Facial Pain",
"Facial Paralysis", "Fasciculation", "Fatigue", "Feminization", "Fetal Distress", "Fetal Hypoxia", "Fetal Macrosomia", "Fetal Weight", "Fever",
"Fever of Unknown Origin", "Flank Pain", "Flatulence", "Flushing", "Gagging", "Gait Apraxia", "Gait Ataxia", "Gait Disorders, Neurologic",
"Gastroparesis", "Glossalgia", "Halitosis", "Hallucinations", "Headache", "Hearing Disorders", "Hearing Loss", "Hearing Loss, Bilateral",
"Hearing Loss, Central", "Hearing Loss, Conductive", "Hearing Loss, Functional", "Hearing Loss, High-Frequency",
"Hearing Loss, Mixed Conductive-Sensorineural", "Hearing Loss, Noise-Induced", "Hearing Loss, Sensorineural", "Hearing Loss, Sudden",
"Hearing Loss, Unilateral", "Heart Murmurs", "Heartburn", "Hematemesis", "Hemianopsia", "Hemifacial Spasm", "Hemiplegia", "Hemoglobinuria",
"Hemoptysis", "Hiccup", "Hirsutism", "Hoarseness", "Horner Syndrome", "Hot Flashes", "Hydrops Fetalis", "Hyperalgesia", "Hypercalciuria",
"Hypercapnia", "Hyperemesis Gravidarum", "Hyperesthesia", "Hypergammaglobulinemia", "Hyperkinesis", "Hyperoxia", "Hyperphagia", "Hyperventilation",
"Hypesthesia", "Hypocapnia", "Hypokinesia", "Hypothermia", "Hypoventilation", "Illusions", "Intermittent Claudication", "Jaundice", "Jaundice, Obstructive",
"Labor Pain", "Language Development Disorders", "Language Disorders", "Learning Disorders", "Lethargy", "Livedo Reticularis", "Low Back Pain",
"Memory Disorders", "Meningism", "Mental Fatigue", "Mental Retardation", "Metatarsalgia", "Miosis", "Mobility Limitation", "Motion Sickness",
"Mouth Breathing", "Muscle Cramp", "Muscle Hypertonia", "Muscle Hypotonia", "Muscle Rigidity", "Muscle Spasticity", "Muscle Weakness", "Muscular Atrophy",
"Mutism", "Myoclonus", "Myokymia", "Myotonia", "Nausea", "Neck Pain", "Necrolytic Migratory Erythema", "Neuralgia", "Neuralgia, Postherpetic",
"Neurobehavioral Manifestations", "Neurologic Manifestations", "Nocturia", "Obesity", "Obesity, Morbid", "Olfaction Disorders", "Oliguria",
"Ophthalmoplegia", "Ophthalmoplegia, Chronic Progressive External", "Oral Hemorrhage", "Oral Manifestations", "Orthostatic Intolerance", "Overweight",
"Pain", "Pain, Intractable", "Pain, Postoperative", "Pain, Referred", "Pallor", "Paralysis", "Paraparesis", "Paraparesis, Spastic", "Paraplegia",
"Paresis", "Paresthesia", "Pelvic Pain", "Perceptual Disorders", "Persistent Vegetative State", "Phantom Limb", "Photophobia", "Polyuria",
"Postoperative Nausea and Vomiting", "Presbycusis", "Prostatism", "Proteinuria", "Pruritus", "Pseudobulbar Palsy", "Pseudophakia", "Psychomotor Agitation",
"Psychomotor Disorders", "Psychophysiologic Disorders", "Pupil Disorders", "Purpura", "Purpura Fulminans", "Purpura, Hyperglobulinemic",
"Purpura, Schoenlein-Henoch", "Purpura, Thrombocytopenic", "Purpura, Thrombocytopenic, Idiopathic", "Purpura, Thrombotic Thrombocytopenic", "Quadriplegia",
"Reflex, Abnormal", "Reflex, Babinski", "Renal Colic", "Respiratory Aspiration", "Respiratory Paralysis", "Respiratory Sounds", "Reticulocytosis",
"Sarcopenia", "Sciatica", "Scotoma", "Seizures", "Sensation Disorders", "Shoulder Pain", "Skin Manifestations", "Sleep Deprivation", "Sleep Disorders",
"Sneezing", "Snoring", "Somatosensory Disorders", "Space Motion Sickness", "Spasm", "Speech Disorders", "Stupor", "Stuttering", "Supranuclear Palsy, Progressive",
"Sweating Sickness", "Syncope", "Syncope, Vasovagal", "Synkinesis", "Systolic Murmurs", "Taste Disorders", "Tetany", "Thinness", "Tics", "Tinea Pedis",
"Tinnitus", "Tonic Pupil", "Toothache", "Torticollis", "Tremor", "Trismus", "Unconsciousness", "Urinary Bladder, Neurogenic", "Urinary Bladder, Overactive",
"Urinary Incontinence", "Urinary Incontinence, Stress", "Urinary Incontinence, Urge", "Urinoma", "Usher Syndromes", "Vertigo", "Virilism", "Vision Disorders",
"Vision, Low", "Vocal Cord Paralysis", "Voice Disorders", "Vomiting", "Vomiting, Anticipatory", "Waterhouse-Friderichsen Syndrome", "Weight Gain", "Weight Loss");
function assertKey($key) {
global $symptoms;
return array_search($key, $symptoms);
}
function assertValue($val) {
return is_numeric($val) && intval($val) >= 0 && intval($val) <= 10;
}
function validate($n, &$input_data) {
for($i = 0; $i < $n; ++$i){
$key = $_POST["k".strval($i)];
$val = $_POST["v".strval($i)];
// echo $key.",".assertKey($key)."<br/>";
// echo $val.",".assertValue($val)."<br/>";
if(assertKey($key) !== false && assertValue($val)) {
$input_data[$key] = intval($val);
} else {
return false;
}
}
return true;
}
function getDiseaseAssociations($symptoms) {
$associations = array();
$f = fopen("input/HSDN/pulmonary_symptom_disease_association_hsdn.tsv", "r");
while (($data = fgetcsv($f, 0, "\t")) !== false) {
if (array_search($data[1], $symptoms) !== false) {
if (array_key_exists($data[1], $associations))
array_push($associations[$data[1]], /*$data[2]."-".*/$data[3]);
else
$associations[$data[1]] = array(/*$data[2]."-".*/$data[3]);
}
}
fclose($f);
// foreach($associations as $s=>$a)
// echo $s." => ".implode(", ", $a)."<br/><br/>";
return $associations;
}
function getDrugHyperlinks($drugs) {
$links = array();
$f = fopen("input/CTD/pulmonary_drugs_ctd.tsv", "r");
while (($data = fgetcsv($f, 0, "\t")) !== false) {
$links[$data[2]] = $data[1];
}
fclose($f);
// foreach($links as $d=>$link)
// echo $d." => ".$link."<br/>";
return $links;
}
$input_data = array();
$symptom_count = $_POST["total_count"];
validate($symptom_count, $input_data);
$input_json = json_encode($input_data);
// echo $input_json;
// foreach($input_data as $k=>$v) {
// echo $k."=>".$v."<br/>";
// }
$command = "venv/bin/python -m python.web_driver.driver '".$input_json."' 2>&1";
// echo "<pre>".$command."</pre>\n";
exec($command, $out, $status);
// echo implode("</br/>", $out)."<br/>"; // for checking output with python errors, if any
// echo $out[0]."<br/>"; // for checking output only
$result = json_decode($out[0]);
// print_r($result);
// echo $result->estimator_id."<br/>";
// echo implode("; ", $result->drugs)."<br/>";
// echo implode("; ", $result->distances)."<br/>";
// echo json_encode($result->associations)."<br/>";
$drugHyperlinks = getDrugHyperlinks($result->drugs);
// $associations = getDiseaseAssociations(array_keys($input_data));
$n_drugs = count($result->drugs);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Prediction - SDLDpred</title>
<link rel = "stylesheet" type = "text/css" href = "css/main.css" />
<script type = "text/javascript" src = "js/plot_density.js"></script>
<script type = "text/javascript" src = "js/plot_heatmap.js"></script>
<script type = "text/javascript" src = "https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
body{
background-color: #ffffff;
}
</style>
</head>
<body>
<div class = "section_header">
<center><p class="title">SDLDpred - Symptom-based Drugs of Lifestyle-related Diseases prediction</p></center>
</div>
<div class = "section_menu">
<center>
<table cellpadding="3px">
<tr class="nav">
<td class="nav"><a href="index.html" class="side_nav">Home</a></td>
<td class="nav"><a href="about.html" class="side_nav">About</a></td>
<td class="nav"><a href="help.html" class="side_nav">Help</a></td>
<td class="nav"><a href="team.html" class="side_nav">Team</a></td>
</tr>
</table>
</center>
</div>
<!--<div class = "section_left"></div>-->
<div class = "section_middle">
<p style="width:80%; margin:20px 10% 0 10%; font-size:1.4em;">
<font style="font-size:1.3em"><b>Input symptoms: </b></font>
<?php
$input_symptoms = array_keys($input_data);
for ($i=0; $i<count($input_data); ++$i) {
echo $input_symptoms[$i] . " - " . $input_data[$input_symptoms[$i]];
if ($i == count($input_data))
echo ".<br/>";
else
echo "; ";
}
?>
<br/>
</p>
<div style="float:left; width:20%; margin:40px 0 0 10%;"><p style="padding:0; margin:0; font-size:1.7em;"><b>Drug prediction result:</b></p></div>
<?php
if ($n_drugs > 0) {
?>
<div style="float:left; width:60%; margin:40px 10% 0 0;">
<table class = "details" border = "0" cellpadding = "5px" id = "rtable">
<tr>
<th>Predicted drugs</th>
<th>Associations with the input symptoms</th>
<th>Associations with diseases</th>
<th>Confidence score (%)</th>
</tr>
<?php
$input_symptom_indices = array();
foreach ($input_symptoms as $s)
$input_symptom_indices[$s] = array_search($s, $symptoms);
for ($i = 0; $i < $n_drugs; ++$i) {
echo "<tr>";
echo "<td><a style=\"color:blue;\" target=\"_blank\" href=\"https://ctdbase.org/detail.go?type=chem&acc=".$drugHyperlinks[$result->drugs[$i]]."\">".$result->drugs[$i]."</a></td>";
// echo "<td>".strval($result->distances[$i])."</td>";
echo "<td>".implode("; ", $result->symptom_associations[$i])."</td>";
echo "<td>".implode("; ", $result->disease_associations[$i])."</td>";
echo "<td>".strval($result->confidences[$i])."</td>";
echo "</tr>";
}
?>
</table>
<p style="width:100%; padding:0; margin:0;">
N.B. - The confidence score is the probability that the euclidean
distance of the predicted drug is less than the euclidean distance
between any two drugs.
</p>
<p style="width:100%; padding:0; margin:0;">
Disclaimer - This tool is strictly for Research Use only. It should be used for medical purposes only by consulting with doctors.
</p>
</div>
<div style="clear:both;"></div>
<p style="padding:0; margin:40px 0 0 10%; font-size:1.7em;"><b>Probability density plot:</b></p>
<div id="plot_container_1" style="width:80%; margin:0px 10% 0 10%;"></div>
<p style="width:70%; margin:10px 15% 0 15%;">
N.B. - The grey region shows the euclidean distance range of 0 - 1.63
for which the confidence score > 90%.
</p>
<?php
} else {
echo "<div style=\"float:left; width:60%; margin:50px 10% 0 0;\"><p>No predicted drugs for the input symptom combination.</p></div><div style=\"clear:both;\"></div>";
}
?>
<!--<h2>Comparison of input symptoms with the symptom-associations of predicted drugs</h2>
<div id="plot_container_2" style="width:100%; margin:0 0 0 0;"></div>-->
<!--<h3>Disease associations of the input symptoms</h3>
<table class = "summary" border = "0" cellpadding = "5px">
<tr>
<th>Symptoms</th>
<th>Disease associations</th>
</tr>
<?php
// foreach($associations as $symptom=>$diseases) {
// echo "<tr><td>".$symptom."</td>";
// echo "<td>".implode("; ", $diseases)."</td></tr>";
// }
?>
</table>-->
<br/>
</div>
<?php
$dist_arg_string = "[" . implode(",", $result->distances) . "]";
$quoted_drug_strings = array();
foreach($result->drugs as $d)
array_push($quoted_drug_strings, "\"".$d."\"");
$drugs_arg_string = "[" . implode(",", $quoted_drug_strings) . "]";
echo "<script>plotDensity('plot_container_1', ".$dist_arg_string.", ".$drugs_arg_string.")</script>";
// echo "<script>plotHeatmap('plot_container_2', '".str_replace("'", "\\'", $out[0])."')</script>";
?>
<br/><hr/>
<p style="font-size:0.8em;text-align:center;">
Please contact Dr. Sudipto Saha (<a href="mailto:ssaha4@jcbose.ac.in">ssaha4@jcbose.ac.in</a>,
<a href="mailto:ssaha4@gmail.com">ssaha4@gmail.com</a>) regarding any further queries.
</p>
</body>
</html>