5 /search/variants.mas - Unified Marker / Variants search page
9 This page will display the results of the unified marker / variant
14 David Waring <djw64@cornell.edu>
20 <& /util/import_javascript.mas, classes => [ 'jquery', 'jquery.dataTables' ] &>
22 <& /page/page_title.mas, title=>"Marker Search Results" &>
25 <button id="btn-modify-search" class="btn btn-info">
26 <span class="glyphicon glyphicon-chevron-left"></span> Modify Marker Search
31 <div id="genotyped-markers" style="display: none">
32 <&| /page/info_section.mas, title=>'Markers From Genotype Projects', collapsible=>1, collapsed=>0 &>
33 <div id="genotyped-marker-results" class="well">
34 <table id="genotyped-marker-results-table" class="display"></table>
36 <div id="genotyped-marker-results-status">
37 <span style="float: left">
38 <span id="genotyped-marker-results-displayed"></span><br />
39 <span id="genotyped-marker-results-pages"></span>
41 <div class="btn-group" style="float: right">
42 <button id="genotyped-marker-page-prev" type="button" class="btn btn-default" disabled><span class="glyphicon glyphicon-chevron-left"></span> Prev</button>
43 <button id="genotyped-marker-page-next" type="button" class="btn btn-default" disabled>Next <span class="glyphicon glyphicon-chevron-right"></span></button>
53 <div id="mapped-markers" style="display: none">
54 <&| /page/info_section.mas, title=>'Markers from Maps', collapsible=>1, collapsed=>0 &>
55 <div id="mapped-marker-results" class="well">
56 <table id="mapped-marker-results-table" class="display"></table>
58 <div id="mapped-marker-results-status">
59 <span style="float: left">
60 <span id="mapped-marker-results-displayed"></span><br />
61 <span id="mapped-marker-results-pages"></span>
63 <div class="btn-group" style="float: right">
64 <button id="mapped-marker-page-prev" type="button" class="btn btn-default" disabled><span class="glyphicon glyphicon-chevron-left"></span> Prev</button>
65 <button id="mapped-marker-page-next" type="button" class="btn btn-default" disabled>Next <span class="glyphicon glyphicon-chevron-right"></span></button>
75 <script type="text/javascript">
77 // QUERY PARAMS SENT AS SEARCH ARGUMENTS
79 let MARKER_NAME, MARKER_NAME_MATCH;
80 let REFMAP, SPECIES, CHROM, START, END;
83 let GENOTYPED_MARKERS_PAGE = 1; // Current page of genotyped marker results
84 const GENOTYPED_MARKERS_LIMIT = 50; // Limit of markers for the genotyped marker search
85 let MAPPED_MARKERS_PAGE = 1; // Current page of mapped marker results
86 const MAPPED_MARKERS_LIMIT = 50; // Limit of markers for the mapped marker search
89 jQuery(document).ready(function() {
91 // Init Genotyped DataTable
92 jQuery('#genotyped-marker-results-table').DataTable({
95 pageLength: GENOTYPED_MARKERS_LIMIT,
97 zeroRecords: "No markers found",
104 render: function(data, type, row) {
105 return data && data !== "" ? "<strong><a href='/variant/" + row.variant_name + "/details'>" + data + "</a></strong>" : "";
110 data: "nd_protocol_name",
111 render: function(data, type, row) {
112 return data && data !== "" ? "<a href='/breeders_toolbox/protocol/" + row.nd_protocol_id + "'>" + data + "</a>" : "";
115 { title: "Species", data: "species_name" },
116 { title: "Reference Genome", data: "reference_genome_name" },
117 { title: "Chromosome", data: "chrom" },
118 { title: "Position", data: "pos" },
119 { title: "Ref", data: "ref" },
120 { title: "Alt", data: "alt" }
122 order: [[ 0, "asc" ]]
125 // Init Mapped DataTable
126 jQuery('#mapped-marker-results-table').DataTable({
129 pageLength: GENOTYPED_MARKERS_LIMIT,
131 zeroRecords: "No markers found",
138 render: function(data, type, row) {
139 return data && data !== "" ? "<strong><a href='/search/markers/markerinfo.pl?marker_id=" + row.marker_id + "'>" + data + "</a></strong>" : "";
142 { title: "Protocol", data: "protocol" },
143 { title: "Species", data: "species_name" },
144 { title: "Map", data: "map_name" },
145 { title: "Chromosome", data: "lg_name" },
146 { title: "Position", data: "position" },
147 { title: "Map Units", data: "map_units" },
149 order: [[ 0, "asc" ]]
153 jQuery("#genotyped-marker-page-prev").click(searchGenotypedMarkersPrev);
154 jQuery("#genotyped-marker-page-next").click(searchGenotypedMarkersNext);
155 jQuery("#mapped-marker-page-prev").click(searchMappedMarkersPrev);
156 jQuery("#mapped-marker-page-next").click(searchMappedMarkersNext);
157 jQuery("#btn-modify-search").click(backToSearch);
159 // Start the Marker Search
163 // Toggle the marker type display
164 jQuery("#genotyped-markers").css("display", !TYPE || TYPE==='genotyped' ? 'block' : 'none');
165 jQuery("#mapped-markers").css("display", !TYPE || TYPE==='mapped' ? 'block' : 'none');
171 * Parse the query params and set the search argument values
173 function parseArgs() {
174 const params = new URLSearchParams(window.location.search);
175 TYPE = _getValue("type");
176 MARKER_NAME = _getValue("marker_name");
177 MARKER_NAME_MATCH = _getValue("marker_name_match", "exactly");
178 REFMAP = _getValue("refmap");
179 SPECIES = _getValue("species");
180 CHROM = _getValue("chrom");
181 START = _getValue("start");
182 END = _getValue("end");
183 PROTOCOL = _getValue("protocol");
185 function _getValue(key, def) {
186 return params.has(key) ? params.get(key) : def;
192 * Start the initial search
193 * - start the genotyped marker search
194 * - start the mapped marker search
196 function startSearch() {
197 searchGenotypedMarkers();
198 searchMappedMarkers();
203 * Go to the marker search page with the same search parameters
205 function backToSearch() {
206 const params = new URLSearchParams(window.location.search);
207 window.location = "/search/variants?" + params.toString();
215 // GENOTYPED MARKER SEARCH
220 * Start the search for genotyped markers
221 * - Parse the query params to form the genotyped marker search
222 * - use GENOTYPED_MARKERS_PAGE and GENOTYPED_MARKERS_LIMIT for pagination
223 * - call displayGenotypedMarkers() when complete
225 function searchGenotypedMarkers() {
226 if ( TYPE && TYPE !== 'genotyped' ) return;
229 let dt = jQuery('#genotyped-marker-results-table').DataTable();
232 jQuery("#genotyped-marker-results-table .dataTables_empty").html("Searching...");
233 jQuery("#genotyped-marker-page-prev").attr('disabled', true);
234 jQuery("#genotyped-marker-page-next").attr('disabled', true);
236 // Query genotyped markers
239 url: '/ajax/markers/genotyped/query',
242 name_match: MARKER_NAME_MATCH,
244 reference_genome: REFMAP,
248 nd_protocol_id: PROTOCOL,
249 page: GENOTYPED_MARKERS_PAGE,
250 limit: GENOTYPED_MARKERS_LIMIT
253 success: function(data) {
254 displayGenotypedMarkers(dt, data);
257 alert("ERROR: Could not perform genotyped marker search");
264 * Start the search of genotyped markers for the previous page
265 * - Decrement GENOTYPED_MARKERS_PAGE
266 * - call searchGenotypedMarkers()
268 function searchGenotypedMarkersPrev() {
269 if ( GENOTYPED_MARKERS_PAGE > 1 ) {
270 GENOTYPED_MARKERS_PAGE--;
271 searchGenotypedMarkers();
276 * Start the search of genotyped markers for the next page
277 * - Increment GENOTYPED_MARKERS_PAGE
278 * - call searchGenotypedMarkers()
280 function searchGenotypedMarkersNext() {
281 GENOTYPED_MARKERS_PAGE++;
282 searchGenotypedMarkers();
286 * Display the results of the genotyped marker search
287 * @param {DataTable} dt The DataTable to put the results in
288 * @param {Object} data The response from the marker search request
290 function displayGenotypedMarkers(dt, data) {
292 // Get Markers from response
295 if ( data && data.results && data.results.counts && data.results.counts.markers && data.results.counts.markers > 0 ) {
296 let variants = data.results.variants;
297 total = data.results.counts.markers;
298 for ( let variant in variants ) {
299 if ( variants.hasOwnProperty(variant) ) {
300 let m = variants[variant];
301 for ( let i = 0; i < m.length; i++ ) {
308 // Update Table with Markers
310 dt.rows.add(markers);
313 // Update Status Info
314 let end = GENOTYPED_MARKERS_PAGE*GENOTYPED_MARKERS_LIMIT;
315 let start = (end-GENOTYPED_MARKERS_LIMIT)+1;
316 end = end > total ? total : end;
317 let displayed = start + " - " + end + " / " + total;
318 let max_page = Math.ceil(total/GENOTYPED_MARKERS_LIMIT);
319 let page = GENOTYPED_MARKERS_PAGE + " / " + max_page;
320 jQuery("#genotyped-marker-results-displayed").html("<strong>MARKERS:</strong> " + displayed);
321 jQuery("#genotyped-marker-results-pages").html("<strong>PAGE:</strong> " + page);
322 jQuery("#genotyped-marker-page-prev").attr('disabled', GENOTYPED_MARKERS_PAGE === 1);
323 jQuery("#genotyped-marker-page-next").attr('disabled', GENOTYPED_MARKERS_PAGE === max_page || max_page === 0);
330 // MAPPED MARKER SEARCH
335 * Start the search for mapped markers
336 * - Parse the query params to form the mapped marker search
337 * - use MAPPED_MARKERS_PAGE and MAPPED_MARKERS_LIMIT for pagination
338 * - call displayMappedMarkers() when complete
340 function searchMappedMarkers() {
341 if ( TYPE && TYPE !== 'mapped' ) return;
344 let dt = jQuery('#mapped-marker-results-table').DataTable();
347 jQuery("#mapped-marker-results-table .dataTables_empty").html("Searching...");
348 jQuery("#mapped-marker-page-prev").attr('disabled', true);
349 jQuery("#mapped-marker-page-next").attr('disabled', true);
351 // Query mapped markers
354 url: '/ajax/markers/mapped/query',
357 name_match: MARKER_NAME_MATCH,
363 page: MAPPED_MARKERS_PAGE,
364 limit: MAPPED_MARKERS_LIMIT
367 success: function(data) {
368 displayMappedMarkers(dt, data);
371 alert("ERROR: Could not perform mapped marker search");
378 * Start the search of mapped markers for the previous page
379 * - Decrement MAPPED_MARKERS_PAGE
380 * - call searchMappedMarkers()
382 function searchMappedMarkersPrev() {
383 if ( MAPPED_MARKERS_PAGE > 1 ) {
384 MAPPED_MARKERS_PAGE--;
385 searchMappedMarkers();
390 * Start the search of mapped markers for the next page
391 * - Increment MAPPED_MARKERS_PAGE
392 * - call searchMappedMarkers()
394 function searchMappedMarkersNext() {
395 MAPPED_MARKERS_PAGE++;
396 searchMappedMarkers();
400 * Display the results of the mapped marker search
401 * @param {DataTable} dt The DataTable to put the results in
402 * @param {Object} data The response from the marker search request
404 function displayMappedMarkers(dt, data) {
406 // Get Markers from response
409 if ( data && data.results && data.results.markers && data.results.markers.length > 0 ) {
410 markers = data.results.markers;
411 total = data.results.marker_count;
414 // Update Table with Markers
416 dt.rows.add(markers);
419 // Update Status Info
420 let end = MAPPED_MARKERS_PAGE*MAPPED_MARKERS_LIMIT;
421 let start = (end-MAPPED_MARKERS_LIMIT)+1;
422 end = end > total ? total : end;
423 let displayed = start + " - " + end + " / " + total;
424 let max_page = Math.ceil(total/MAPPED_MARKERS_LIMIT);
425 let page = MAPPED_MARKERS_PAGE + " / " + max_page;
426 jQuery("#mapped-marker-results-displayed").html("<strong>MARKERS:</strong> " + displayed);
427 jQuery("#mapped-marker-results-pages").html("<strong>PAGE:</strong> " + page);
428 jQuery("#mapped-marker-page-prev").attr('disabled', MAPPED_MARKERS_PAGE === 1);
429 jQuery("#mapped-marker-page-next").attr('disabled', MAPPED_MARKERS_PAGE === max_page || max_page === 0);