-
Notifications
You must be signed in to change notification settings - Fork 1
/
tripal_bipaa_ui.module
456 lines (401 loc) · 25.4 KB
/
tripal_bipaa_ui.module
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<?php
require_once "includes/tripal_bipaa_ui.fields.inc";
/**
* Implements hook_menu().
*/
function tripal_bipaa_ui_menu() {
$items = array();
$items['heatmap'] = array(
'page callback' => 'render_expression_blocks',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['analysis-expression/heatmap/search'] = [
'title' => '',
'access arguments' => ['access content'],
'page callback' => 'tripal_analysis_expression_search_features_callback',
'type' => MENU_CALLBACK,
];
$items['analysis-expression/download'] = [
'title' => '',
'access arguments' => ['access content'],
'page callback' => 'analysis_expression_data_downloader::callback',
'type' => MENU_CALLBACK,
];
$items['gene_search'] = array(
'title' => 'Gene search',
'page callback' => 'es_render_form',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function es_render_form(){
$blockObjectInput = block_load('tripal_elasticsearch', 'es_local_gene_search_block');
$block = _block_get_renderable_array(_block_render_blocks(array($blockObjectInput)));
$output = drupal_render($block);
return $output;
}
function render_expression_blocks() {
$blockObjectInput = block_load('tripal_analysis_expression', 'input_features');
$blockObjectView = block_load('tripal_analysis_expression', 'heatmap_features');
$block = _block_get_renderable_array(_block_render_blocks(array($blockObjectInput, $blockObjectView)));
$output = drupal_render($block);
return $output;
}
/**
* Implements hook_views_default_views_alter(&$views)
*/
function tripal_bipaa_ui_views_default_views_alter(&$views) {
//Starts with organism
$handler = $views['Organism_search'];
//Cleanup
// Removed unneeded columns
unset($handler->display['default']->display_options['fields']['schema__description']);
unset($handler->display['default']->display_options['fields']['data__image']);
// Removed footer (data download option)
unset($handler->display['default']->display_options['footer']['tripal_area_collections']);
// Remove links in Genus Species columns
unset($handler->display['default']->display_options['fields']['taxrank__species']['alter']['make_link']);
unset($handler->display['default']->display_options['fields']['taxrank__genus']['alter']['make_link']);
// Remove user operator choice
unset($handler->display['default']->display_options['filters']['taxrank__species']['expose']['use_operator']);
unset($handler->display['default']->display_options['filters']['taxrank__genus']['expose']['use_operator']);
// Set up results without input
$handler->display['default']->display_options['exposed_form']['type'] = 'basic';
//Setup columns
// Scientific name field
$handler->display['default']->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display['default']->display_options['fields']['nothing']['table'] = 'views';
$handler->display['default']->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display['default']->display_options['fields']['nothing']['label'] = 'Scientific Name';
$handler->display['default']->display_options['fields']['nothing']['alter']['text'] = '[taxrank__genus] [taxrank__species]';
$handler->display['default']->display_options['fields']['nothing']['alter']['make_link'] = TRUE;
$handler->display['default']->display_options['fields']['nothing']['alter']['path'] = "organism/[taxrank__genus]/[taxrank__species]";
/* Field: Organism: Common Name */
$handler->display['default']->display_options['fields']['ncbitaxon__common_name']['id'] = 'ncbitaxon__common_name';
$handler->display['default']->display_options['fields']['ncbitaxon__common_name']['table'] = 'OBI__0100026';
$handler->display['default']->display_options['fields']['ncbitaxon__common_name']['field'] = 'ncbitaxon__common_name';
/* Field: Organism: Abbreviation */
$handler->display['default']->display_options['fields']['local__abbreviation']['id'] = 'local__abbreviation';
$handler->display['default']->display_options['fields']['local__abbreviation']['table'] = 'OBI__0100026';
$handler->display['default']->display_options['fields']['local__abbreviation']['field'] = 'local__abbreviation';
// Setup filters (Common name)
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['id'] = 'ncbitaxon__common_name';
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['table'] = 'OBI__0100026';
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['field'] = 'ncbitaxon__common_name';
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['operator'] = 'contains';
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['exposed'] = TRUE;
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['expose']['operator_id'] = 'ncbitaxon__common_name_op';
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['expose']['label'] = 'Common Name';
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['expose']['operator'] = 'ncbitaxon__common_name_op';
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['expose']['identifier'] = 'ncbitaxon__common_name';
$handler->display['default']->display_options['filters']['ncbitaxon__common_name']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
3 => 0,
);
// Analysis
$handler = $views['Analysis_search'];
//Cleanup
unset($handler->display['default']->display_options['footer']['tripal_area_collections']);
unset($handler->display['default']->display_options['fields']['schema__description']);
unset($handler->display['default']->display_options['filters']['schema__name']['expose']['use_operator']);
// Set up results without input
$handler->display['default']->display_options['exposed_form']['type'] = 'basic';
/* Field: Analysis: Data Source Name */
$handler->display['default']->display_options['fields']['local__source_data.schema:name']['id'] = 'local__source_data.schema:name';
$handler->display['default']->display_options['fields']['local__source_data.schema:name']['table'] = 'operation__2945';
$handler->display['default']->display_options['fields']['local__source_data.schema:name']['field'] = 'local__source_data.schema:name';
$handler->display['default']->display_options['fields']['local__source_data.schema:name']['label'] = 'Source Name';
/* Field: Analysis: Program, Pipeline, Workflow or Method Name */
$handler->display['default']->display_options['fields']['swo__software']['id'] = 'swo__software';
$handler->display['default']->display_options['fields']['swo__software']['table'] = 'operation__2945';
$handler->display['default']->display_options['fields']['swo__software']['field'] = 'swo__software';
$handler->display['default']->display_options['fields']['swo__software']['label'] = 'Program';
/* Filter criterion: Analysis: Program, Pipeline, Workflow or Method Name */
$handler->display['default']->display_options['filters']['swo__software']['id'] = 'swo__software';
$handler->display['default']->display_options['filters']['swo__software']['table'] = 'operation__2945';
$handler->display['default']->display_options['filters']['swo__software']['field'] = 'swo__software';
$handler->display['default']->display_options['filters']['swo__software']['operator'] = 'contains';
$handler->display['default']->display_options['filters']['swo__software']['group'] = 1;
$handler->display['default']->display_options['filters']['swo__software']['exposed'] = TRUE;
$handler->display['default']->display_options['filters']['swo__software']['expose']['operator_id'] = 'swo__software_op';
$handler->display['default']->display_options['filters']['swo__software']['expose']['label'] = 'Program';
$handler->display['default']->display_options['filters']['swo__software']['expose']['operator'] = 'swo__software_op';
$handler->display['default']->display_options['filters']['swo__software']['expose']['identifier'] = 'swo__software';
$handler->display['default']->display_options['filters']['swo__software']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
3 => 0,
);
/* Filter criterion: Analysis: Data Source Name */
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['id'] = 'local__source_data.schema:name';
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['table'] = 'operation__2945';
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['field'] = 'local__source_data.schema:name';
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['operator'] = 'contains';
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['group'] = 1;
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['exposed'] = TRUE;
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['expose']['operator_id'] = 'local__source_data_schema:name_op';
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['expose']['label'] = 'Data Source Name';
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['expose']['operator'] = 'local__source_data_schema:name_op';
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['expose']['identifier'] = 'local__source_data_schema:name';
$handler->display['default']->display_options['filters']['local__source_data.schema:name']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
3 => 0,
);
// Might as well not duplicate the code
$gene_handler = array(
"mRNA" => array(
"view" => $views['mRNA_search'],
"table" => 'SO__0000234'
),
"Polypeptide" => array(
"view" => $views['Polypeptide_search'],
"table" => 'SO__0000104'
)
);
foreach ($gene_handler as $key => $value){
$handler = $value["view"];
$table = $value["table"];
//Cleanup
unset($handler->display['default']->display_options['footer']['tripal_area_collections']);
unset($handler->display['default']->display_options['fields']['data__accession']);
unset($handler->display['default']->display_options['fields']['schema__alternate_name']);
unset($handler->display['default']->display_options['filters']['schema__name']['expose']['use_operator']);
unset($handler->display['default']->display_options['filters']['data__identifier']['expose']['use_operator']);
unset($handler->display['default']->display_options['filters']['data__accession']);
unset($handler->display['default']->display_options['filters']['obi__organism']['expose']['use_operator']);
unset($handler->display['default']->display_options['fields']);
unset($handler->display['default']->display_options['filters']);
// Set up results without input
$handler->display['default']->display_options['exposed_form']['type'] = 'basic';
$handler->display['default']->display_options['style_options']['columns'] = array(
'entity_id' => 'entity_id',
'data__identifier' => 'data__identifier',
'schema__name' => 'schema__name',
'data__accession' => 'data__accession',
'obi__organism' => 'obi__organism',
'schema__alternate_name' => 'schema__alternate_name',
);
$handler->display['default']->display_options['style_options']['default'] = '-1';
$handler->display['default']->display_options['style_options']['info'] = array(
'entity_id' => array(
'sortable' => 1,
'separator' => '',
),
'data__identifier' => array(
'separator' => '',
'sortable' => 1,
'default_sort_order' => 'asc',
),
'schema__name' => array(
'separator' => '',
'sortable' => 1,
'default_sort_order' => 'asc',
),
'data__accession' => array(
'separator' => '',
'sortable' => 1,
'default_sort_order' => 'asc',
),
'obi__organism' => array(
'separator' => '',
'sortable' => 1,
'default_sort_order' => 'asc',
),
'schema__alternate_name' => array(
'separator' => '',
'sortable' => 1,
'default_sort_order' => 'asc',
),
);
/* Field: Entity ID */
$handler->display['default']->display_options['fields']['entity_id']['id'] = 'entity_id';
$handler->display['default']->display_options['fields']['entity_id']['table'] = $table;
$handler->display['default']->display_options['fields']['entity_id']['field'] = 'entity_id';
$handler->display['default']->display_options['fields']['entity_id']['exclude'] = TRUE;
/* Field: Genus */
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000005']['id'] = 'obi__organism.TAXRANK:0000005';
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000005']['table'] = $table;
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000005']['field'] = 'obi__organism.TAXRANK:0000005';
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000005']['label'] = '';
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000005']['exclude'] = TRUE;
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000005']['element_label_colon'] = FALSE;
/* Field Species */
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000006']['id'] = 'obi__organism.TAXRANK:0000006';
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000006']['table'] = $table;
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000006']['field'] = 'obi__organism.TAXRANK:0000006';
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000006']['label'] = '';
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000006']['exclude'] = TRUE;
$handler->display['default']->display_options['fields']['obi__organism.TAXRANK:0000006']['element_label_colon'] = FALSE;
/* Field Identifier */
$handler->display['default']->display_options['fields']['data__identifier']['id'] = 'data__identifier';
$handler->display['default']->display_options['fields']['data__identifier']['table'] = $table;
$handler->display['default']->display_options['fields']['data__identifier']['field'] = 'data__identifier';
$handler->display['default']->display_options['fields']['data__identifier']['label'] = 'Unique Name';
$handler->display['default']->display_options['fields']['data__identifier']['alter']['alter_text'] = TRUE;
$handler->display['default']->display_options['fields']['data__identifier']['alter']['text'] = '[data__identifier]';
$handler->display['default']->display_options['fields']['data__identifier']['alter']['make_link'] = TRUE;
$handler->display['default']->display_options['fields']['data__identifier']['alter']['path'] = 'feature/[obi__organism.TAXRANK:0000005]/[obi__organism.TAXRANK:0000006]/'.$key.'/[data__identifier]';
/* Field Name */
$handler->display['default']->display_options['fields']['schema__name']['id'] = 'schema__name';
$handler->display['default']->display_options['fields']['schema__name']['table'] = $table;
$handler->display['default']->display_options['fields']['schema__name']['field'] = 'schema__name';
$handler->display['default']->display_options['fields']['schema__name']['alter']['alter_text'] = TRUE;
$handler->display['default']->display_options['fields']['schema__name']['alter']['text'] = '[schema__name]';
$handler->display['default']->display_options['fields']['schema__name']['alter']['make_link'] = TRUE;
$handler->display['default']->display_options['fields']['schema__name']['alter']['path'] = 'feature/[obi__organism.TAXRANK:0000005]/[obi__organism.TAXRANK:0000006]/'.$key.'/[data__identifier]';
/* Field Sequence Length */
$handler->display['default']->display_options['fields']['data__sequence_length']['id'] = 'data__sequence_length';
$handler->display['default']->display_options['fields']['data__sequence_length']['table'] = $table;
$handler->display['default']->display_options['fields']['data__sequence_length']['field'] = 'data__sequence_length';
/* Field Organism */
$handler->display['default']->display_options['fields']['obi__organism']['id'] = 'obi__organism';
$handler->display['default']->display_options['fields']['obi__organism']['table'] = $table;
$handler->display['default']->display_options['fields']['obi__organism']['field'] = 'obi__organism';
$handler->display['default']->display_options['fields']['obi__organism']['alter']['alter_text'] = TRUE;
$handler->display['default']->display_options['fields']['obi__organism']['alter']['text'] = '[obi__organism.TAXRANK:0000005] [obi__organism.TAXRANK:0000006]';
$handler->display['default']->display_options['fields']['obi__organism']['alter']['make_link'] = TRUE;
$handler->display['default']->display_options['fields']['obi__organism']['alter']['path'] = 'organism/[obi__organism.TAXRANK:0000005]/[obi__organism.TAXRANK:0000006]';
/* Sort criterion: : Identifier */
$handler->display['default']->display_options['sorts']['priority']['id'] = 'schema__alternate_name';
$handler->display['default']->display_options['sorts']['priority']['table'] = $table;
$handler->display['default']->display_options['sorts']['priority']['field'] = 'data__identifier';
/* Filter criterion: Published */
$handler->display['default']->display_options['filters']['status']['id'] = 'status';
$handler->display['default']->display_options['filters']['status']['table'] = $table;
$handler->display['default']->display_options['filters']['status']['field'] = 'status';
$handler->display['default']->display_options['filters']['status']['value'] = '1';
/* Filter criterion: Identifier */
$handler->display['default']->display_options['filters']['data__identifier']['id'] = 'data__identifier';
$handler->display['default']->display_options['filters']['data__identifier']['table'] = $table;
$handler->display['default']->display_options['filters']['data__identifier']['field'] = 'data__identifier';
$handler->display['default']->display_options['filters']['data__identifier']['operator'] = 'contains';
$handler->display['default']->display_options['filters']['data__identifier']['group'] = 1;
$handler->display['default']->display_options['filters']['data__identifier']['exposed'] = TRUE;
$handler->display['default']->display_options['filters']['data__identifier']['expose']['operator_id'] = 'data__identifier_op';
$handler->display['default']->display_options['filters']['data__identifier']['expose']['label'] = 'Unique Name';
$handler->display['default']->display_options['filters']['data__identifier']['expose']['operator'] = 'data__identifier_op';
$handler->display['default']->display_options['filters']['data__identifier']['expose']['identifier'] = 'data__identifier';
$handler->display['default']->display_options['filters']['data__identifier']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
3 => 0,
);
/* Filter criterion: Name */
$handler->display['default']->display_options['filters']['schema__name']['id'] = 'schema__name';
$handler->display['default']->display_options['filters']['schema__name']['table'] = $table;
$handler->display['default']->display_options['filters']['schema__name']['field'] = 'schema__name';
$handler->display['default']->display_options['filters']['schema__name']['operator'] = 'contains';
$handler->display['default']->display_options['filters']['schema__name']['group'] = 1;
$handler->display['default']->display_options['filters']['schema__name']['exposed'] = TRUE;
$handler->display['default']->display_options['filters']['schema__name']['expose']['operator_id'] = 'schema__name_op';
$handler->display['default']->display_options['filters']['schema__name']['expose']['label'] = 'Name';
$handler->display['default']->display_options['filters']['schema__name']['expose']['operator'] = 'schema__name_op';
$handler->display['default']->display_options['filters']['schema__name']['expose']['identifier'] = 'schema__name';
$handler->display['default']->display_options['filters']['schema__name']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
3 => 0,
);
/* Filter criterion: Organism */
$handler->display['default']->display_options['filters']['obi__organism']['id'] = 'obi__organism';
$handler->display['default']->display_options['filters']['obi__organism']['table'] = $table;
$handler->display['default']->display_options['filters']['obi__organism']['field'] = 'obi__organism';
$handler->display['default']->display_options['filters']['obi__organism']['operator'] = 'contains';
$handler->display['default']->display_options['filters']['obi__organism']['group'] = 1;
$handler->display['default']->display_options['filters']['obi__organism']['exposed'] = TRUE;
$handler->display['default']->display_options['filters']['obi__organism']['expose']['operator_id'] = 'obi__organism_op';
$handler->display['default']->display_options['filters']['obi__organism']['expose']['label'] = 'Organism';
$handler->display['default']->display_options['filters']['obi__organism']['expose']['operator'] = 'obi__organism_op';
$handler->display['default']->display_options['filters']['obi__organism']['expose']['identifier'] = 'obi__organism';
$handler->display['default']->display_options['filters']['obi__organism']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
3 => 0,
);
};
};
function tripal_bipaa_ui_form_alter(&$form, &$form_state, $form_id){
switch ($form_id){
case 'feature_heatmap_form':
// Might be better to fill it with proper value, but it would make sql database calls..
unset($form['example_button']);
unset($form['heatmap_feature_uniquename']['#attributes']['placeholder']);
unset($form['heatmap_feature_uniquename']['#description']);
};
}
function redirect_form($form, &$form_state){
global $base_url;
$form['options'] = [
'#type' => 'fieldset',
'#attributes' => [
'class' => [
'container-inline',
'es-cross-site-search-form',
],
],
];
$default_organism = ['' => 'Any Organism'];
$organisms = tripal_elasticsearch_get_gene_search_organisms();
$form['options']['organism'] = [
'#type' => 'select',
'#attributes' => [
'id' => 'tripal-elasticsearch-search-category',
'style' => 'max-width: 250px;',
],
'#options' => array_merge(
$default_organism,
drupal_map_assoc($organisms)
),
'#default_value' => isset($_GET['organism']) ? $_GET['organism'] : '',
'#required' => TRUE,
];
$form['option']['is_es_gene_form'] = [
'#type' => 'hidden',
'#value' => 'is_es_gene_form'
];
$form['options']['search_term'] = [
'#type' => 'textfield',
'#size' => '50',
'#attributes' => [
'placeholder' => t('Search for mRNA or polypeptide.(E,g. Kinase or IPR020405)'),
'id' => 'tripal-elasticsearch-search-field',
],
'#description' => '',
'#required' => TRUE,
'#default_value' => isset($_GET['search_term']) ? $_GET['search_term'] : '',
];
$form['options']['search_button'] = [
'#type' => 'submit',
'#value' => t('Search'),
];
$form['#method'] = 'GET';
$form['#action'] = $base_url . '/gene_search';
return $form;
}
function tripal_bipaa_ui_block_info(){
$blocks = [];
$blocks['redirect_block_mini'] = [
'info' => t('Redirect form block'),
'cache' => DRUPAL_NO_CACHE,
'status' => TRUE,
// 'region' => 'sidebar_first',
];
return $blocks;
}
function tripal_bipaa_ui_block_view($delta){
$block = [];
switch ($delta) {
case 'redirect_block_mini':
$block['subject'] = '';
$form = drupal_get_form('redirect_form');
unset($form['options']['organism']);
unset($form['options']['search_button']);
$block['content'] = $form;
break;
}
return $block;
}