-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTML-FINAL-.html
204 lines (158 loc) · 5.31 KB
/
HTML-FINAL-.html
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
<!DOCTYPE html>
<html>
<head>
<title>Visualising the chemical structure of metabolite in biological pathways</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- jQuary Library -->
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<!-- Illustartion and layout -->
<style>
body{
font-family: Arial, Helvetica, sans-serif;
}
tbody tr{
border-bottom: 1px solid;
color: #000000;
font-size: system-ui;
line-height: 1.5;
text-align: left;
}
.wrapper {
width: min(900px, 100% - 3rem);
}
table{
border-collapse: collapse;
margin: 25px 0;
font-size: 1.5em;
min-width: 500px;
}
th,td{
border: 1rem #000;
text-align: center;
padding: 12px 15px;
text-align: left;
width: 600;
}
th{
font-size: 1.5rem;
text-align: left;
font-weight: bold;
}
caption{
font-size: 1.5rem;
font-weight: 1000;
}
</style>
</head>
<!-- Creating search tab -->
<div class="row">
<div class="col">
<div class="card card-body">
<div id="search-container">
<label for="search-input" style="font-weight: bold; margin-left: 5px;">Search:</label>
<input id="search-input" class="form-control" type="text">
</div>
</div>
</div>
</div>
<body>
<table > <!--Structure table -->
<caption>METABOLITES</caption>
<tr>
<th data-column="name" data-order="desc">Name ▲</th>
<th data-column="structure" data-order="desc">Structure</th>
</tr>
<tbody id="myTable">
<!-- Table body will be populated dynamically with JavaScript -->
</tbody>
</table>
<script type="text/javascript"> //SPARQL query code
var url = "https://sparql.wikipathways.org/sparql/";
var query = "PREFIX cheminf: <http://semanticscience.org/resource/>\
SELECT (SAMPLE(str(?label)) as ?MetaboliteLabel) (SAMPLE(?smilesDepict) as ?smilesDepict)\
WHERE {\
?Metabolite a wp:Metabolite ; \
rdfs:label ?label ;\
dcterms:isPartOf ?pathway .\
?pathway a wp:Pathway ;\
dcterms:identifier \"WP2360\" .\
?Metabolite wp:bdbWikidata/cheminf:CHEMINF_000018 ?smilesDepict .\
} GROUP BY ?Metabolite";
// Extracting and storing data
var sparqlData = [];
var queryUrl = url + "?query=" + encodeURIComponent(query) + "&format=json";
console.log("Query URL: " + queryUrl);
// AJAX request to get data from SPARQL
$.ajax({
dataType: "jsonp",
url: queryUrl,
success: function(response) {
var results = response.results.bindings;
for (var i in results) {
var molecules = results[i].MetaboliteLabel.value;
// Create valiable with URL of each smileDepict
var smilesURL = "https://www.simolecule.com/cdkdepict/depict/bot/svg?smi=" + encodeURIComponent(results[i].smilesDepict.value);
sparqlData.push({ Metabolite: molecules, smilesUrl: smilesURL });
}
buildTable(sparqlData); //Iniciate te function to fill the table
}
});
//Function to fill table with SPARQL results
function buildTable(sparqlData){
var tableBody = document.getElementById("myTable");
tableBody.innerHTML = "";
for(var i = 0; i < sparqlData.length; i++)
{
var row = document.createElement("tr");
var cell1 = document.createElement("td");
var cell2 = document.createElement("td");
cell1.innerHTML = sparqlData[i].Metabolite;
cell2.innerHTML = "<img src= \""+ sparqlData[i].smilesUrl + "\">"; //Get image form URL
row.appendChild(cell1);
row.appendChild(cell2);
tableBody.appendChild(row);
}
}
//Serach section : taken form : https://www.youtube.com/watch?v=DzXmAKdEYIs&list=PL-51WBLyFTg1l3K0aTH0uX6PzgaLfzJBK&index=3
// Input
$("#search-input").on("keyup", function(){
var value = $(this).val()
console.log("Value:", value)
var data = searchTable(value, sparqlData)
buildTable(data)
})
//Search and extract
function searchTable(value, data){
var filteredData = []
for (var i=0; i<data.length; i++){
value = value.toLowerCase() //Hangle upper and lower cases
var metabolite = data[i].Metabolite.toLowerCase()
if(metabolite.includes(value)){
filteredData.push(data[i])
}
}
return filteredData;
}
//Sort by Column - Taken from: https://www.youtube.com/watch?v=Q9aYU1Ufkpk
//Click on screen function
$('th').on('click', function()
{
var column = $(this).data('column');
var order = $(this).data('order');
var text = $(this).html();
text = text.substring(0, text.length -1);
if(order == 'desc'){
$(this).data('order', 'asc');
sparqlData=sparqlData.sort((a,b) => a[column] > b[column] ? 1 : -1);
text += '▼';
}else{
$(this).data('order', 'desc');
sparqlData=sparqlData.sort((a,b) => a[column] < b[column] ? 1 : -1);
text += '▲'
}
$(this).html(text);
buildTable(sparqlData);
});
</script>
</body>
</html>