-
Notifications
You must be signed in to change notification settings - Fork 3
/
gbs_results.php
executable file
·257 lines (202 loc) · 12.9 KB
/
gbs_results.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
<?php
$body_class = "no-sidebar"; // This page does not have a sidebar
require 'php_header.php'; // Require the PHP header housing required PHP functions
require 'html_header.php'; // Require the HTML header housing the HTML structure of the page
?>
</div>
<!-- Main -->
<div class="wrapper">
<div class="container" id="main" style="padding-bottom:0em;">
<!-- Content -->
<article id="content">
<header>
<h2>Great. It's time for some <strong>results</strong>.</h2>
<p>The table below displays your blocks. You can save these results by clicking the "Download query results" link below the results table, alternatively, you can share these results by sending the URL of the page to anyone you wish to show the data.</p>
</header>
<?php
#############################################
# ERROR HANDLING
#############################################
// If no database session variable exists or it is empty
//if_set_display_error("query_no_database", "You have no selected a database to query. Perhaps your session expired and you need to log in again?");
#############################################
# CHECK THAT A QUERY RESULT HAS BEEN SUPPLIED AND EXISTS
#############################################
if (!isset($_GET["query"])) {
error("No query result specified.");
} else {
$result_file = $_GET["query"].".tsv";
$result_file_path = "temp/".$_GET["query"].".tsv";
if (!file_exists("temp/".$_GET["query"].".tsv")) {
error("This query result does not exist. Perhaps it's too old and has been purged?");
} else {
#############################################
# GRAB ANY ERRORS THAT OCCURRED DURING THE QUERY
#############################################
$errors_file = "temp/".$_GET["query"].".err";
// If the errors file exists
if (file_exists($errors_file)) {
// Read it in
if ($error_lines = file($errors_file, FILE_IGNORE_NEW_LINES)) {
foreach ($error_lines as $error_line) {
echo "<h4 style=\"color:red;\">";
echo $error_line;
echo "</h4>";
}
}
}
#############################################
if ($result = file($result_file_path, FILE_IGNORE_NEW_LINES)) {
#############################################
# ADD EXTRA COLUMNS
#############################################
// Go through every variant
for ($i = 0; $i < count($result); $i++) {
// Print the column header
if ($i == 0) {
// IGV column
$result[$i] .= "\tIGV";
// Print an empty column value for each variant (populated later based on values in other columns)
} else {
// IGV column
$result[$i] .= "\t ";
}
}
#############################################
# GENERATE COLUMN INDEX AND LIST OF HIDDEN COLUMNS
#############################################
$header = explode("\t", $result[0]); # Split the header row into an array by column
$hidden_columns_gbs = array(); // Define an array with the columns numbers to hide from the results table
$column_index = array(); // Define an array with the columns numebers to hide from the results table
for ($i = 0; $i < count($header); $i++) { # Create a column index
$column_index[$header[$i]] = $i;
# Format: $column_index[<column name>] = <column number>;
// If the current column is not whitelisted, add it to the array of hidden columns
if (!in_array($header[$i], $GLOBALS['whitelisted_gbs_results_columns'])) {
array_push($hidden_columns_gbs, $i);
}
}
#############################################
# TAKE THE RESULTS TABLE OUT OF THE NORMAL PAGE LAYOUT AND GIVE IT A NEW DIV
#############################################
echo "</article>";
echo "</div>";
echo "<div class=\"container\" id=\"results_table\">";
#############################################
# TABULATE RESULTS
#############################################
echo "<table id=\"gbs\" class=\"display\" cellspacing=\"0\" width=\"100%\" style=\"table-layout:fixed; display:none;\">";
echo "<thead>";
echo "<tr>";
foreach ($header as $column) {
if (strlen($column) > 10) { # If the column is longer than 10 characters, put the text in a tooltip
echo "<th title=\"".$column."\" style=\"line-height: 100%; font-size: 90%; font-weight: normal; overflow:hidden;\">".$column."</th>";
} else {
echo "<th style=\"overflow: hidden; white-space: nowrap; font-size: 90%; font-weight: normal; overflow:hidden;\">".$column."</th>";
}
}
echo "</tr>";
echo "</thead>";
echo "<tbody>";
// Go through each variant
for ($x = 1; $x < count($result); $x++) { // $x = 1 to avoid the header which has already been processed
$columns = explode("\t", $result[$x]);
// If the current row does not have the same number of columns as the header, go to the next row
if (count($columns) != count($header)) {
continue;
}
echo "<tr>";
// Go through each column for the current variant
for ($i = 0; $i < count($columns); $i++) {
// If the current column is one of the block coordinates columns
if ((isset($column_index["Block1 Coordinates"], $column_index["Block2 Coordinates"]) && ($column_index["Block1 Coordinates"] == $i || $column_index["Block2 Coordinates"] == $i)) || (isset($column_index["Block Coordinates"]) && $column_index["Block Coordinates"] == $i) || (isset($column_index["Overlapping Coordinates"]) && $column_index["Overlapping Coordinates"] == $i) || (isset($column_index["ROH Coordinates"]) && $column_index["ROH Coordinates"] == $i)) {
// Grab the correct coordinate set for the column
if (isset($column_index["Block1 Coordinates"]) && $column_index["Block1 Coordinates"] == $i) {
$coordinates = $columns[$column_index["Block1 Coordinates"]];
} elseif (isset($column_index["Block2 Coordinates"]) && $column_index["Block2 Coordinates"] == $i) {
$coordinates = $columns[$column_index["Block2 Coordinates"]];
} elseif (isset($column_index["Block Coordinates"]) && $column_index["Block Coordinates"] == $i) {
$coordinates = $columns[$column_index["Block Coordinates"]];
} elseif (isset($column_index["Overlapping Coordinates"]) && $column_index["Overlapping Coordinates"] == $i) {
$coordinates = $columns[$column_index["Overlapping Coordinates"]];
} elseif (isset($column_index["ROH Coordinates"]) && $column_index["ROH Coordinates"] == $i) {
$coordinates = $columns[$column_index["ROH Coordinates"]];
}
// Extract the block coordinates
preg_match('/(.*):(.*)\-(.*)/', $coordinates, $matches);
// If the chromosome is the mitochondria (chMT in our DBs), change it to the way UCSC specifies it (chrM)
if ($matches[1] == "chrMT") {
$matches[1] = "chrM";
}
print_table_cell($columns[$i], "https://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&position=".$matches[1]."%3A".$matches[2]."-".$matches[3], "", "");
// Populate the IGV column using the block coordinates
} elseif (isset($column_index["IGV"]) && $column_index["IGV"] == $i) {
if (isset($column_index["Block1 Coordinates"], $column_index["Block2 Coordinates"])) {
// Extract both block coordinates
preg_match('/(.*):(.*)\-(.*)/', $columns[$column_index["Block1 Coordinates"]], $block1_matches);
preg_match('/(.*):(.*)\-(.*)/', $columns[$column_index["Block2 Coordinates"]], $block2_matches);
// Block 1 button
$igv_link = "<a href=\"igv_link.php?locus=".$block1_matches[1].":".$block1_matches[2]."-".$block1_matches[3]."\" style=\"padding: 0.4em 0.5em 0.4em 0.5em; line-height: 100%; font-size: 90%;\" class=\"button\" target=\"_blank\" title=\"Navigate to the block 1 coordinates in a currently open IGV session\"><-IGV</a> ";
// Block2 button
$igv_link .= "<a href=\"igv_link.php?locus=".$block2_matches[1].":".$block2_matches[2]."-".$block2_matches[3]."\" style=\"padding: 0.4em 0.5em 0.4em 0.5em; line-height: 100%; font-size: 90%;\" class=\"button\" target=\"_blank\" title=\"Navigate to the block 2 coordinates in a currently open IGV session\">IGV-></a>";
} elseif (isset($column_index["Block Coordinates"])) {
// Extract the block coordinates
preg_match('/(.*):(.*)\-(.*)/', $columns[$column_index["Block Coordinates"]], $matches);
// IGV button
$igv_link = "<a href=\"igv_link.php?locus=".$matches[1].":".$matches[2]."-".$matches[3]."\" style=\"padding: 0.4em 0.5em 0.4em 0.5em; line-height: 100%; font-size: 90%;\" class=\"button\" target=\"_blank\" title=\"Navigate to the block 1 coordinates in a currently open IGV session\">IGV</a>";
} elseif (isset($column_index["Overlapping Coordinates"])) {
// Extract the overlapping block coordinates
preg_match('/(.*):(.*)\-(.*)/', $columns[$column_index["Overlapping Coordinates"]], $matches);
// IGV button
$igv_link = "<a href=\"igv_link.php?locus=".$matches[1].":".$matches[2]."-".$matches[3]."\" style=\"padding: 0.4em 0.5em 0.4em 0.5em; line-height: 100%; font-size: 90%;\" class=\"button\" target=\"_blank\" title=\"Navigate to the overlapping coordinates in a currently open IGV session\">IGV</a>";
} elseif (isset($column_index["ROH Coordinates"])) {
// Extract the overlapping block coordinates
preg_match('/(.*):(.*)\-(.*)/', $columns[$column_index["ROH Coordinates"]], $matches);
// IGV button
$igv_link = "<a href=\"igv_link.php?locus=".$matches[1].":".$matches[2]."-".$matches[3]."\" style=\"padding: 0.4em 0.5em 0.4em 0.5em; line-height: 100%; font-size: 90%;\" class=\"button\" target=\"_blank\" title=\"Navigate to the ROH coordinates in a currently open IGV session\">IGV</a>";
}
print_table_cell($igv_link, "", "", "");
} else {
print_table_cell($columns[$i], "", "", "");
}
}
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
#############################################
# BRING THE REST OF THE PAGE BACK INTO THE NORMAL PAGE LAYOUT
#############################################
echo "</div>";
echo "<div class=\"container\" id=\"main\">";
echo "<article id=\"content\">";
#############################################
# OPTIONS UNDER THE TABLE
#############################################
// Download query results link
echo "<div style=\"text-align:right; padding-top:10px;\"><strong><a href=\"".$result_file_path."\">Download query results (.tsv format)</a></strong></div>";
echo "<p style=\"line-height: 2em; font-size: 60%; text-align:right; margin-bottom: 0em;\" onclick=\"restrict_width('results_table');\">Increase/decrease table width</p>";
// Alternative style with arrow: echo "<div style=\"text-align:right; padding-bottom: 0em;\"><i class=\"fa fa-arrows-h\" style=\"font-size: 500%;\" onclick=\"restrict_width('results_table');\"></i></div>";
#############################################
# SHOW OR HIDE SPECIFIC COLUMNS
#############################################
echo "<h3>Show or hide specific columns</h3>";
echo "<p>Click on one or more buttons to dynamically show or hide the columns in the results table above.</p>";
#############################################
column_filter("gbs", $column_index, array("IGV"), "Navigate in IGV");
}
}
}
#############################################
# NAVIGATION BUTTONS
#############################################
echo "<br><br>";
echo "<a href=\"gbs_query\" class=\"button\">Back to query options</a>";
echo "<br><br><a href=\"databases?restart=true\" class=\"button\" style=\"padding: 0.4em 1em 0.4em 1em;\">Start over</a>";
?>
</article>
</div>
</div>
<?php
require 'html_footer.php';
?>