-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmarker_selection.php
266 lines (252 loc) · 8.75 KB
/
marker_selection.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
260
261
262
263
264
265
266
<?php
/*
* Logged in page initialization
*
* 9/2/2010 J.Lee modify to add new snippet Gbrowse tracks
* 8/29/2010 J.Lee modify to not use iframe for link to Gbrowse
*/
$usegbrowse = true;
require 'config.php';
include $config['root_dir'].'includes/bootstrap.inc';
$mysqli = connecti();
session_start();
include $config['root_dir'].'theme/admin_header.php';
?>
<div id="primaryContentContainer">
<div id="primaryContent">
<h2> Select Markers</h2>
<br>
<div class="boxContent">
<h3>Currently selected markers</h3>
<?php
function get_submitted_mapid()
{
$us_mapname=$_POST['mapname'] or die('No mapname submitted.');
$sql = "select map_uid from map
where map_name='" . mysqli_real_escape_string($us_mapname) . "'";
$sqlr = mysqli_fetch_assoc(mysqli_query($mysqli, $sql));
return $sqlr['map_uid'];
}
if (isset($_POST['selMarkerstring']) && $_POST['selMarkerstring'] != "") {
// Handle <space>- and <tab-separated words.
//$selmkrnames = preg_split("/\r\n/", $_POST['selMarkerstring']);
$s = preg_replace("/\\s+/", "\\r\\n", $_POST['selMarkerstring']);
$selmkrnames = explode("\\r\\n", $s);
// Get the marker uids.
$selmkrs = array();
foreach ($selmkrnames as $mkrnm) {
$sql = "select distinct marker_uid from marker_synonyms where value = '$mkrnm'";
$r = mysqli_query($mysqli, $sql);
if (mysqli_num_rows($r) == 0)
echo "<font color=red>\"$mkrnm\" not found.</font><br>";
else {
$row = mysqli_fetch_row($r);
// Trap case where a marker is entered twice, even as synonym, e.g. 11_0090 and 1375-2534.
if (! in_array($row[0], $selmkrs))
array_push($selmkrs, $row[0]);
}
}
$clkmkrs=$_SESSION['clicked_buttons'];
if (!isset($clkmkrs) || ! is_array($clkmkrs)) $clkmkrs=array();
foreach($selmkrs as $mkruid) {
if (! in_array($mkruid, $clkmkrs))
array_push($clkmkrs, $mkruid);
}
$_SESSION['clicked_buttons'] = $clkmkrs;
// Get the uid of a map each of the markers is on.
$mapids = $_SESSION['mapids'];
if (!isset($mapids) || !is_array($mapids))
$mapids = array();
foreach ($selmkrs as $mkr) {
$sql = "select distinct map_uid from markers_in_maps where marker_uid = $mkr";
$r = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_row($r);
if (! in_array($row[0], $mapids))
array_push($mapids, $row[0]);
}
$_SESSION['mapids'] = $mapids;
}
if (isset($_POST['selMkrs']) || isset($_POST['selbyname'])) {
$mapid = get_submitted_mapid();
if (isset($_POST['selMkrs']))
$selmkrs=$_POST['selMkrs'];
else {
$selbyname = $_POST['selbyname'];
$sql = "select m.marker_uid from markers as m inner join
markers_in_maps as mm using(marker_uid) where mm.map_uid=$mapid and
m.marker_name='" . mysqli_real_escape_string($selbyname) . "'";
$sqlr = mysqli_fetch_assoc(mysqli_query($mysqli, $sql));
$selmkrs = array($sqlr['marker_uid']);
}
$mapids = $_SESSION['mapids'];
if (!isset($mapids) || !is_array($mapids))
$mapids = array();
$clkmkrs=$_SESSION['clicked_buttons'];
if (!isset($clkmkrs) || ! is_array($clkmkrs)) $clkmkrs=array();
foreach($selmkrs as $mkruid) {
if (! in_array($mkruid, $clkmkrs)) {
array_push($clkmkrs, $mkruid);
array_push($mapids, $mapid);
}
}
$_SESSION['clicked_buttons'] = $clkmkrs;
$_SESSION['mapids'] = $mapids;
}
if (isset($_POST['deselMkrs'])) {
$selmkrs=$_SESSION['clicked_buttons'];
$mapids=$_SESSION['mapids'];
foreach ($_POST['deselMkrs'] as $mkr) {
if (($mkridx=array_search($mkr, $selmkrs)) !== false) {
array_splice($selmkrs, $mkridx,1);
array_splice($mapids, $mkridx, 1);
}
}
$_SESSION['clicked_buttons']=$selmkrs;
$_SESSION['mapids']=$mapids;
}
// If anything is Currently Selected, show.
if (isset($_SESSION['clicked_buttons']) && count($_SESSION['clicked_buttons']) > 0) {
print "<form id='deselMkrsForm' action='".$_SERVER['PHP_SELF']."' method='post'>";
print "<table><tr><td>\n";
print "<select id='mlist' name='deselMkrs[]' multiple='multiple' size=10>";
$mapids = $_SESSION['mapids'];
if (!isset($mapids) || !is_array($mapids))
$mapids = array();
reset($mapids);
$chrlist = array();
$markerlist = array();
foreach ($_SESSION['clicked_buttons'] as $mkruid) {
$mapid = current($mapids);
next($mapids);
$sql = "select m.marker_name, mm.chromosome
from markers as m inner join markers_in_maps as mm using(marker_uid)
where marker_uid=$mkruid" . ($mapid ? " and mm.map_uid=$mapid":"");
$result=mysqli_query($mysqli, $sql)
// or die("invalid marker uid\n");
or die(mysqli_error($mysqli));
while ($row=mysqli_fetch_assoc($result)) {
$selval=$row['marker_name'];
$selchr=$row['chromosome'];
if(! in_array($selval,$markerlist)) {
array_push($markerlist, $selval);
array_push($chrlist, $selchr);
print "<option value='$mkruid'>$selval</option>\n";
}
}
}
$chrlist = array_unique($chrlist);
$chrlist.sort();
print "</select>";
print "</td><td>\n";
echo "<script type='text/javascript'>
var mlist = \$j('#mlist option').map(function () { return \$j(this).text(); });
</script>";
// Show GBrowse maps.
foreach ($chrlist as $chr) {
echo "<div id='gbrowse_$chr'></div>\n";
echo <<<EOD
<script type="text/javascript">
\$j('#gbrowse_$chr')
.bind('ajaxSend',
function () {
\$j(this).html("<p>Loading track for chromosome $chr... </p>");
\$j(this).addClass('inprogress');
})
.bind('ajaxComplete',
function () { \$j(this).removeClass('inprogress'); });
\$j(document).ready(function () {
var hilite = [], index;
for (index=0; index<mlist.length; ++index)
hilite.push(mlist[index] + '@orange');
loadGbrowse("#gbrowse_$chr", " #details_panel",
["name=" + encodeURIComponent('chr$chr'),
"h_feat=" + encodeURIComponent(hilite.join(' ')),
'label=' + encodeURIComponent('Marker OWB_2383'),
'label=' + encodeURIComponent('Marker UCR04162008'),
'label=' + encodeURIComponent('Marker SteptoeMorex'),
'label=' + encodeURIComponent('Marker MorexBarke'),
'grid=on', 'show_tooltips=on',
'.cgifields=show_tooltips', 'drag_and_drop=on']
.join('&'),
function () {
// \$j("#gbrowse_$chr").find("area[href^='?ref']")
// .each(function () {
// \$j(this).removeAttr('href');
// });
\$j("#gbrowse_$chr")
.prepend("<p>Chromosome $chr</p>");
// \$j("#mlist")
// .change(function () {
// \$j("#mlist option:selected")
// .map(function () {
// var outerThis = this;
// var filter = "#gbrowse_$chr area[href]";
// \$j(filter)
// .filter(function ()
// {
// return \$j(this).attr('href').indexOf("name=" + \$j(outerThis).text() + ";") != -1; }).trigger('mouseover');
// });
// });
});
});
</script>
EOD;
}
print "</td></tr></table>\n";
print "<p><input type='submit' value='Remove marker' style='color: blue' /></p>";
print "</form>";
print "<form action='".$config['base_url']."advanced_search.php'>";
print "<p><input type='submit' value='View haplotypes'></form>";
// store the selected markers into the database
$username=$_SESSION['username'];
if (! isset($username) || strlen($username)<1) $username="Public";
store_session_variables('clicked_buttons', $username);
store_session_variables('mapids',$username);
} // end of if Currently Selected
else print "None<br>";
?>
</div>
<div class="boxContent">
<h3>Select markers by name</h3>
<form action="<?php echo $config['base_url']; ?>genotyping/marker_selection.php" method="post">
<table><tr><td>
<textarea rows=6 cols=10 name=selMarkerstring></textarea>
<td>Synonyms will be translated.
<p><input type=submit value=Select style=color:blue>
</tr></table>
</form>
</div>
<div id="markerSel" class="boxContent">
<h3> Select markers in a range of map positions</h3>
<form id="markerSelForm" action="<?php echo $config['base_url']; ?>genotyping/marker_selection.php" method="post">
<table id="markeSelTab">
<thead>
<tr> <th>Maps</th><th>Range</th><th>Markers</th></tr>
</thead>
<tbody>
<tr><td>
<select name='mapname' size=10 onfocus="DispMapSel(this.value)" onchange="DispMapSel(this.value)">
<?php
$result=mysqli_query($mysqli, "select map_name from map") or die(mysqli_error($mysqli));
while ($row=mysqli_fetch_assoc($result)) {
$selval=$row['map_name'];
print "<option value='$selval'>$selval</option>\n";
}
?>
</select>
<td>Choose map.
<td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="boxContent">
<h3> Select using GBrowse</h3>
Hover over a marker and click "Select in THT" in the popup balloon.
<br><a href="/cgi-bin/gbrowse/tht">GBrowse</a><br><br>
</div>
</div>
</div>
</div>
<?php include($config['root_dir'].'theme/footer.php'); ?>