2 ==== Sequence Metadata Quick Query Component ====
3 This mason component can be used to embed one or more tables of stored sequence metadata features
4 over a relatively small sequence range. The `params` argument to the component takes a hashref
5 containing the sequence metadata query parameters in the following format:
9 'species' => 'Triticum aestivum',
10 'reference_genome' => 'RefSeq_v1',
16 'species' => 'Triticum durum',
17 'reference_genome' => 'Triticum durum',
29 if (!defined $params ) {
30 print "<p class='args-error'><strong>ERROR: </strong>missing component arguments!</p>";
35 <!-- Results Table(s) -->
36 % foreach my $id (keys %$params) {
38 <div class="quick-query-table-container">
39 <table class="table quick-query-table">
41 <th>Reference Genome</th>
49 <td><% $params->{$id}->{'reference_genome'} %></td>
50 <td><% $params->{$id}->{'species'} %></td>
51 <td><% $params->{$id}->{'feature'} %></td>
52 <td><% $params->{$id}->{'start'} %></td>
53 <td><% $params->{$id}->{'end'} %></td>
54 <td><a href="/search/sequence_metadata?reference_genome=<% $params->{$id}->{'reference_genome'} %>&feature=<% $params->{$id}->{'feature'} %>&start=<% $params->{$id}->{'start'} %>&end=<% $params->{$id}->{'end'} %>">Modify Query</a></td>
58 <table id="<% $id %>" class="display"></table>
63 <script type="text/javascript">
66 * Perform the query with the provided parameters
67 * - call display_results() with the query results, if successful
68 * @param {string} id Table ID
69 * @param {string} species Species Name
70 * @param {string} reference Reference Genome Name
71 * @param {string} feature Feature/Chromosome Name
72 * @param {int} start Start Position
73 * @param {int} end End Position
75 function quick_query(id, species, reference, feature, start, end) {
79 feature_name: feature,
80 species_name: species,
81 reference_genome: reference,
86 let q = new URLSearchParams(params).toString();
87 let url = '/ajax/sequence_metadata/query?' + q;
94 success: function(data) {
95 display_results(id, data);
98 console.log("ERROR: Could not query sequence metadata!");
105 * Display the query results in the specified table
106 * @param {string} id Table ID
107 * @param {Object} data Query Results
109 function display_results(id, data) {
110 let dt = jQuery('#' + id).DataTable();
112 if ( data && data.error ) {
113 console.log("ERROR: Could not query sequence metadata")
114 console.log(data.error);
116 else if ( data && data.results && data.results.length > 0) {
117 dt.rows.add(data.results);
120 console.log("No sequence metadata results found");
126 * Render the Attributes column
127 * @param data The column's data for the current row
128 * @param {String} type The display type
129 * @param {Object} row The current row's data
130 * @returns {String} The text/html to display in the table
132 function renderAttributesColumn(data, type, row) {
134 let sep = type === 'export' ? ';' : '<br />';
136 var keys = Object.keys(data);
138 for ( var i=0; i<keys.length; ++i ) {
140 let value = data[key];
141 if ( type === 'export' ) {
142 rtn.push(key + '=' + value);
145 rtn.push("<strong>" + key + ":</strong> " + value);
149 return rtn.join(sep);
153 * Render the Links column
154 * @param data The column's data for the current row
155 * @param {String} type The display type
156 * @param {Object} row The current row's data
157 * @returns {String} The text/html to display in the table
159 function renderLinksColumn(data, type, row) {
161 let sep = type === 'export' ? ';' : '<br /><br />';
163 var titles = Object.keys(data);
165 for ( var i=0; i<titles.length; i++ ){
166 let title = titles[i];
167 let url = data[title];
168 if ( type === 'export' ) {
169 rtn.push(title + '=' + url);
172 rtn.push("<a href='" + url + "'>" + title + "</a>");
176 return rtn.join(sep);
183 <!-- Init each table and perform the query -->
184 % foreach my $id (keys %$params) {
185 <script type="text/javascript">
186 jQuery(document).ready(function() {
189 jQuery("#<% $id %>").DataTable({
194 { title: "Protocol", data: "nd_protocol_name" },
195 { title: "Feature", data: "feature_name" },
196 { title: "Start", data: "start" },
197 { title: "End", data: "end" },
198 { title: "Score", data: "score" },
199 { title: "Attributes", data: "attributes", render: renderAttributesColumn },
200 { title: "Links", data: "links", render: renderLinksColumn }
202 order: [[ 2, "asc" ]]
208 "<% $params->{$id}->{'species'} %>",
209 "<% $params->{$id}->{'reference_genome'} %>",
210 "<% $params->{$id}->{'feature'} %>",
211 "<% $params->{$id}->{'start'} %>",
212 "<% $params->{$id}->{'end'} %>"
224 background-color: #f8d7da;
230 .quick-query-table-container {
232 border: 1px solid #ddd;